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 | { | |
123 | uint64_t signature; | |
124 | dwarf_vma section_offsets[DW_SECT_MAX]; | |
125 | size_t section_sizes[DW_SECT_MAX]; | |
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 | |
4cb93e3b TG |
135 | /* Values for do_debug_lines. */ |
136 | #define FLAG_DEBUG_LINES_RAW 1 | |
137 | #define FLAG_DEBUG_LINES_DECODED 2 | |
138 | ||
77ef8654 | 139 | static unsigned int |
f1c4cc75 RH |
140 | size_of_encoded_value (int encoding) |
141 | { | |
142 | switch (encoding & 0x7) | |
143 | { | |
144 | default: /* ??? */ | |
145 | case 0: return eh_addr_size; | |
146 | case 2: return 2; | |
147 | case 3: return 4; | |
148 | case 4: return 8; | |
149 | } | |
150 | } | |
151 | ||
152 | static dwarf_vma | |
041830e0 | 153 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 154 | int encoding, |
041830e0 NC |
155 | struct dwarf_section *section, |
156 | unsigned char * end) | |
f1c4cc75 | 157 | { |
041830e0 | 158 | unsigned char * data = * pdata; |
6937bb54 | 159 | unsigned int size = size_of_encoded_value (encoding); |
bad62cf5 | 160 | dwarf_vma val; |
f1c4cc75 | 161 | |
041830e0 NC |
162 | if (data + size >= end) |
163 | { | |
164 | warn (_("Encoded value extends past end of section\n")); | |
165 | * pdata = end; | |
166 | return 0; | |
167 | } | |
168 | ||
6937bb54 NC |
169 | /* PR 17512: file: 002-829853-0.004. */ |
170 | if (size > 8) | |
171 | { | |
172 | warn (_("Encoded size of %d is too large to read\n"), size); | |
173 | * pdata = end; | |
174 | return 0; | |
175 | } | |
176 | ||
0a9d414a NC |
177 | /* PR 17512: file: 1085-5603-0.004. */ |
178 | if (size == 0) | |
179 | { | |
180 | warn (_("Encoded size of 0 is too small to read\n")); | |
181 | * pdata = end; | |
182 | return 0; | |
183 | } | |
184 | ||
f1c4cc75 | 185 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 186 | val = byte_get_signed (data, size); |
f1c4cc75 | 187 | else |
bad62cf5 AM |
188 | val = byte_get (data, size); |
189 | ||
190 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
191 | val += section->address + (data - section->start); | |
041830e0 NC |
192 | |
193 | * pdata = data + size; | |
bad62cf5 | 194 | return val; |
f1c4cc75 RH |
195 | } |
196 | ||
4c219c2e AM |
197 | #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
198 | # ifndef __MINGW32__ | |
199 | # define DWARF_VMA_FMT "ll" | |
200 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
201 | # else | |
202 | # define DWARF_VMA_FMT "I64" | |
203 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
204 | # endif | |
2e14fae2 | 205 | #else |
4c219c2e AM |
206 | # define DWARF_VMA_FMT "l" |
207 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
208 | #endif |
209 | ||
bf5117e3 NC |
210 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
211 | buffer containing the converted VALUE. The value is converted according | |
212 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
213 | it specifies the maximum number of bytes to be displayed in the converted | |
214 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 215 | |
47704ddf | 216 | static const char * |
bf5117e3 | 217 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
218 | { |
219 | /* As dwarf_vmatoa is used more then once in a printf call | |
220 | for output, we are cycling through an fixed array of pointers | |
221 | for return address. */ | |
222 | static int buf_pos = 0; | |
467c65bc NC |
223 | static struct dwarf_vmatoa_buf |
224 | { | |
47704ddf KT |
225 | char place[64]; |
226 | } buf[16]; | |
47704ddf KT |
227 | char *ret; |
228 | ||
47704ddf | 229 | ret = buf[buf_pos++].place; |
467c65bc | 230 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 231 | |
bf5117e3 NC |
232 | if (num_bytes) |
233 | { | |
222c2bf0 | 234 | /* Printf does not have a way of specifying a maximum field width for an |
bf5117e3 NC |
235 | integer value, so we print the full value into a buffer and then select |
236 | the precision we need. */ | |
237 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
238 | if (num_bytes > 8) | |
239 | num_bytes = 8; | |
240 | return ret + (16 - 2 * num_bytes); | |
241 | } | |
242 | else | |
243 | { | |
244 | char fmt[32]; | |
245 | ||
0bae9e9e NC |
246 | if (fmtch) |
247 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
248 | else | |
249 | sprintf (fmt, "%%%s", DWARF_VMA_FMT); | |
bf5117e3 NC |
250 | snprintf (ret, sizeof (buf[0].place), fmt, value); |
251 | return ret; | |
252 | } | |
253 | } | |
47704ddf | 254 | |
bf5117e3 NC |
255 | static inline const char * |
256 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
257 | { | |
258 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
259 | } | |
260 | ||
261 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
262 | hexadecimal format, followed by a space. The length of the VALUE (and | |
263 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
264 | ||
265 | static void | |
266 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
267 | { | |
268 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
269 | } |
270 | ||
9f272209 AO |
271 | /* Print a view number in hexadecimal value, with the same width |
272 | print_dwarf_vma would have printed it with the same num_bytes. | |
273 | Print blanks for zero view, unless force is nonzero. */ | |
274 | ||
275 | static void | |
276 | print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force) | |
277 | { | |
278 | int len; | |
279 | if (!num_bytes) | |
280 | len = 4; | |
281 | else | |
282 | len = num_bytes * 2; | |
283 | ||
284 | assert (value == (unsigned long) value); | |
285 | if (value || force) | |
286 | printf ("v%0*lx ", len - 1, (unsigned long) value); | |
287 | else | |
288 | printf ("%*s", len + 1, ""); | |
289 | } | |
290 | ||
74bc6052 CC |
291 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
292 | For reentrancy, this uses a buffer provided by the caller. */ | |
293 | ||
294 | static const char * | |
295 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, | |
296 | unsigned int buf_len) | |
297 | { | |
298 | int len = 0; | |
299 | ||
300 | if (hvalue == 0) | |
301 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); | |
302 | else | |
303 | { | |
304 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); | |
305 | snprintf (buf + len, buf_len - len, | |
306 | "%08" DWARF_VMA_FMT "x", lvalue); | |
307 | } | |
308 | ||
309 | return buf; | |
310 | } | |
311 | ||
f6f0e17b NC |
312 | /* Read in a LEB128 encoded value starting at address DATA. |
313 | If SIGN is true, return a signed LEB128 value. | |
314 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
315 | No bytes will be read at address END or beyond. */ | |
316 | ||
467c65bc | 317 | dwarf_vma |
f6f0e17b NC |
318 | read_leb128 (unsigned char *data, |
319 | unsigned int *length_return, | |
320 | bfd_boolean sign, | |
321 | const unsigned char * const end) | |
19e6b90e | 322 | { |
467c65bc | 323 | dwarf_vma result = 0; |
19e6b90e L |
324 | unsigned int num_read = 0; |
325 | unsigned int shift = 0; | |
f6f0e17b | 326 | unsigned char byte = 0; |
19e6b90e | 327 | |
f6f0e17b | 328 | while (data < end) |
19e6b90e L |
329 | { |
330 | byte = *data++; | |
331 | num_read++; | |
332 | ||
467c65bc | 333 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; |
19e6b90e L |
334 | |
335 | shift += 7; | |
f6f0e17b NC |
336 | if ((byte & 0x80) == 0) |
337 | break; | |
77ef8654 NC |
338 | |
339 | /* PR 17512: file: 0ca183b8. | |
340 | FIXME: Should we signal this error somehow ? */ | |
f641dd96 | 341 | if (shift >= sizeof (result) * 8) |
77ef8654 | 342 | break; |
19e6b90e | 343 | } |
19e6b90e L |
344 | |
345 | if (length_return != NULL) | |
346 | *length_return = num_read; | |
347 | ||
348 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
c4e0beac | 349 | result |= -((dwarf_vma) 1 << shift); |
19e6b90e L |
350 | |
351 | return result; | |
352 | } | |
353 | ||
467c65bc | 354 | /* Create a signed version to avoid painful typecasts. */ |
f6f0e17b NC |
355 | static inline dwarf_signed_vma |
356 | read_sleb128 (unsigned char * data, | |
357 | unsigned int * length_return, | |
358 | const unsigned char * const end) | |
359 | { | |
360 | return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end); | |
361 | } | |
362 | ||
363 | static inline dwarf_vma | |
364 | read_uleb128 (unsigned char * data, | |
365 | unsigned int * length_return, | |
366 | const unsigned char * const end) | |
467c65bc | 367 | { |
f6f0e17b | 368 | return read_leb128 (data, length_return, FALSE, end); |
467c65bc NC |
369 | } |
370 | ||
7f2c8a1d NC |
371 | #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return |
372 | #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return | |
373 | ||
374 | #define READ_ULEB(var) \ | |
375 | do \ | |
376 | { \ | |
377 | dwarf_vma _val; \ | |
378 | \ | |
379 | (var) = _val = read_uleb128 (start, &length_return, end); \ | |
380 | if ((var) != _val) \ | |
66cfc0fd AM |
381 | error (_("Internal error: %s:%d: LEB value (%s) " \ |
382 | "too large for containing variable\n"), \ | |
383 | __FILE__, __LINE__, dwarf_vmatoa ("u", _val)); \ | |
7f2c8a1d NC |
384 | start += length_return; \ |
385 | } \ | |
386 | while (0) | |
387 | ||
388 | #define READ_SLEB(var) \ | |
389 | do \ | |
390 | { \ | |
391 | dwarf_signed_vma _val; \ | |
392 | \ | |
393 | (var) = _val = read_sleb128 (start, &length_return, end); \ | |
394 | if ((var) != _val) \ | |
66cfc0fd AM |
395 | error (_("Internal error: %s:%d: LEB value (%s) " \ |
396 | "too large for containing variable\n"), \ | |
397 | __FILE__, __LINE__, dwarf_vmatoa ("d", _val)); \ | |
7f2c8a1d NC |
398 | start += length_return; \ |
399 | } \ | |
400 | while (0) | |
401 | ||
d11ae95e NC |
402 | /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value. |
403 | Checks to make sure that the read will not reach or pass END | |
404 | and that VAL is big enough to hold AMOUNT bytes. */ | |
0c588247 NC |
405 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
406 | do \ | |
407 | { \ | |
408 | unsigned int amount = (AMOUNT); \ | |
34b9f729 NC |
409 | if (sizeof (VAL) < amount) \ |
410 | { \ | |
d3a49aa8 AM |
411 | error (ngettext ("internal error: attempt to read %d byte " \ |
412 | "of data in to %d sized variable", \ | |
413 | "internal error: attempt to read %d bytes " \ | |
414 | "of data in to %d sized variable", \ | |
415 | amount), \ | |
34b9f729 NC |
416 | amount, (int) sizeof (VAL)); \ |
417 | amount = sizeof (VAL); \ | |
418 | } \ | |
0c588247 NC |
419 | if (((PTR) + amount) >= (END)) \ |
420 | { \ | |
421 | if ((PTR) < (END)) \ | |
422 | amount = (END) - (PTR); \ | |
423 | else \ | |
424 | amount = 0; \ | |
425 | } \ | |
6937bb54 | 426 | if (amount == 0 || amount > 8) \ |
0c588247 | 427 | VAL = 0; \ |
6937bb54 NC |
428 | else \ |
429 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
430 | } \ |
431 | while (0) | |
432 | ||
d11ae95e | 433 | /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
434 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
435 | do \ | |
436 | { \ | |
437 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
438 | PTR += AMOUNT; \ | |
439 | } \ | |
440 | while (0) | |
441 | ||
d11ae95e | 442 | /* Like SAFE_BYTE_GET, but reads a signed value. */ |
0c588247 NC |
443 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
444 | do \ | |
445 | { \ | |
446 | unsigned int amount = (AMOUNT); \ | |
447 | if (((PTR) + amount) >= (END)) \ | |
448 | { \ | |
449 | if ((PTR) < (END)) \ | |
450 | amount = (END) - (PTR); \ | |
451 | else \ | |
452 | amount = 0; \ | |
453 | } \ | |
454 | if (amount) \ | |
455 | VAL = byte_get_signed ((PTR), amount); \ | |
456 | else \ | |
457 | VAL = 0; \ | |
458 | } \ | |
459 | while (0) | |
460 | ||
d11ae95e | 461 | /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
462 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
463 | do \ | |
464 | { \ | |
465 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
466 | PTR += AMOUNT; \ | |
467 | } \ | |
468 | while (0) | |
469 | ||
470 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
471 | do \ | |
472 | { \ | |
87bc83b3 | 473 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
474 | { \ |
475 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
476 | } \ | |
477 | else \ | |
478 | { \ | |
0c588247 NC |
479 | * (LOW) = * (HIGH) = 0; \ |
480 | } \ | |
481 | } \ | |
482 | while (0) | |
483 | ||
19e6b90e L |
484 | typedef struct State_Machine_Registers |
485 | { | |
467c65bc | 486 | dwarf_vma address; |
ba8826a8 | 487 | unsigned int view; |
19e6b90e L |
488 | unsigned int file; |
489 | unsigned int line; | |
490 | unsigned int column; | |
491 | int is_stmt; | |
492 | int basic_block; | |
a233b20c JJ |
493 | unsigned char op_index; |
494 | unsigned char end_sequence; | |
ba8826a8 AO |
495 | /* This variable hold the number of the last entry seen |
496 | in the File Table. */ | |
19e6b90e L |
497 | unsigned int last_file_entry; |
498 | } SMR; | |
499 | ||
500 | static SMR state_machine_regs; | |
501 | ||
502 | static void | |
503 | reset_state_machine (int is_stmt) | |
504 | { | |
505 | state_machine_regs.address = 0; | |
ba8826a8 | 506 | state_machine_regs.view = 0; |
a233b20c | 507 | state_machine_regs.op_index = 0; |
19e6b90e L |
508 | state_machine_regs.file = 1; |
509 | state_machine_regs.line = 1; | |
510 | state_machine_regs.column = 0; | |
511 | state_machine_regs.is_stmt = is_stmt; | |
512 | state_machine_regs.basic_block = 0; | |
513 | state_machine_regs.end_sequence = 0; | |
514 | state_machine_regs.last_file_entry = 0; | |
515 | } | |
516 | ||
517 | /* Handled an extend line op. | |
518 | Returns the number of bytes read. */ | |
519 | ||
520 | static int | |
f6f0e17b NC |
521 | process_extended_line_op (unsigned char * data, |
522 | int is_stmt, | |
523 | unsigned char * end) | |
19e6b90e L |
524 | { |
525 | unsigned char op_code; | |
526 | unsigned int bytes_read; | |
527 | unsigned int len; | |
528 | unsigned char *name; | |
143a3db0 | 529 | unsigned char *orig_data = data; |
f6f0e17b | 530 | dwarf_vma adr; |
19e6b90e | 531 | |
f6f0e17b | 532 | len = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
533 | data += bytes_read; |
534 | ||
e44c58ce | 535 | if (len == 0 || data == end || len > (uintptr_t) (end - data)) |
19e6b90e | 536 | { |
f41e4712 | 537 | warn (_("Badly formed extended line op encountered!\n")); |
19e6b90e L |
538 | return bytes_read; |
539 | } | |
540 | ||
541 | len += bytes_read; | |
542 | op_code = *data++; | |
543 | ||
544 | printf (_(" Extended opcode %d: "), op_code); | |
545 | ||
546 | switch (op_code) | |
547 | { | |
548 | case DW_LNE_end_sequence: | |
549 | printf (_("End of Sequence\n\n")); | |
550 | reset_state_machine (is_stmt); | |
551 | break; | |
552 | ||
553 | case DW_LNE_set_address: | |
6937bb54 NC |
554 | /* PR 17512: file: 002-100480-0.004. */ |
555 | if (len - bytes_read - 1 > 8) | |
77ef8654 NC |
556 | { |
557 | warn (_("Length (%d) of DW_LNE_set_address op is too long\n"), | |
558 | len - bytes_read - 1); | |
559 | adr = 0; | |
560 | } | |
561 | else | |
562 | SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end); | |
47704ddf | 563 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 564 | state_machine_regs.address = adr; |
ba8826a8 | 565 | state_machine_regs.view = 0; |
a233b20c | 566 | state_machine_regs.op_index = 0; |
19e6b90e L |
567 | break; |
568 | ||
569 | case DW_LNE_define_file: | |
143a3db0 | 570 | printf (_("define new File Table entry\n")); |
19e6b90e | 571 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 572 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 573 | |
d949ff56 NC |
574 | { |
575 | size_t l; | |
576 | ||
577 | name = data; | |
578 | l = strnlen ((char *) data, end - data); | |
579 | data += len + 1; | |
580 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
581 | data += bytes_read; | |
582 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
583 | data += bytes_read; | |
584 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
585 | data += bytes_read; | |
586 | printf ("%.*s\n\n", (int) l, name); | |
587 | } | |
f6f0e17b NC |
588 | |
589 | if (((unsigned int) (data - orig_data) != len) || data == end) | |
b4eb7656 | 590 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
591 | break; |
592 | ||
ed4a4bdf | 593 | case DW_LNE_set_discriminator: |
47704ddf | 594 | printf (_("set Discriminator to %s\n"), |
f6f0e17b | 595 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
ed4a4bdf CC |
596 | break; |
597 | ||
e2a0d921 NC |
598 | /* HP extensions. */ |
599 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 600 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
601 | break; |
602 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 603 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
604 | break; |
605 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 606 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
607 | break; |
608 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 609 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
610 | break; |
611 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 612 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
613 | break; |
614 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 615 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
616 | break; |
617 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 618 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
619 | break; |
620 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 621 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
622 | break; |
623 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 624 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
625 | break; |
626 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 627 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 628 | break; |
43294ab7 TG |
629 | case DW_LNE_HP_source_file_correlation: |
630 | { | |
b4eb7656 AM |
631 | unsigned char *edata = data + len - bytes_read - 1; |
632 | ||
633 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
634 | ||
635 | while (data < edata) | |
636 | { | |
637 | unsigned int opc; | |
638 | ||
639 | opc = read_uleb128 (data, & bytes_read, edata); | |
640 | data += bytes_read; | |
641 | ||
642 | switch (opc) | |
643 | { | |
644 | case DW_LNE_HP_SFC_formfeed: | |
645 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
646 | break; | |
647 | case DW_LNE_HP_SFC_set_listing_line: | |
648 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", | |
649 | dwarf_vmatoa ("u", | |
650 | read_uleb128 (data, & bytes_read, edata))); | |
651 | data += bytes_read; | |
652 | break; | |
653 | case DW_LNE_HP_SFC_associate: | |
654 | printf (" DW_LNE_HP_SFC_associate "); | |
655 | printf ("(%s", | |
656 | dwarf_vmatoa ("u", | |
657 | read_uleb128 (data, & bytes_read, edata))); | |
658 | data += bytes_read; | |
659 | printf (",%s", | |
660 | dwarf_vmatoa ("u", | |
661 | read_uleb128 (data, & bytes_read, edata))); | |
662 | data += bytes_read; | |
663 | printf (",%s)\n", | |
664 | dwarf_vmatoa ("u", | |
665 | read_uleb128 (data, & bytes_read, edata))); | |
666 | data += bytes_read; | |
667 | break; | |
668 | default: | |
669 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
670 | data = edata; | |
671 | break; | |
672 | } | |
673 | } | |
43294ab7 TG |
674 | } |
675 | break; | |
cecf136e | 676 | |
19e6b90e | 677 | default: |
7e665af3 | 678 | { |
b4eb7656 AM |
679 | unsigned int rlen = len - bytes_read - 1; |
680 | ||
681 | if (op_code >= DW_LNE_lo_user | |
682 | /* The test against DW_LNW_hi_user is redundant due to | |
683 | the limited range of the unsigned char data type used | |
684 | for op_code. */ | |
685 | /*&& op_code <= DW_LNE_hi_user*/) | |
686 | printf (_("user defined: ")); | |
687 | else | |
688 | printf (_("UNKNOWN: ")); | |
689 | printf (_("length %d ["), rlen); | |
690 | for (; rlen; rlen--) | |
691 | printf (" %02x", *data++); | |
692 | printf ("]\n"); | |
7e665af3 | 693 | } |
19e6b90e L |
694 | break; |
695 | } | |
696 | ||
697 | return len; | |
698 | } | |
699 | ||
0c588247 | 700 | static const unsigned char * |
467c65bc | 701 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
702 | { |
703 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 704 | const unsigned char * ret; |
19e6b90e L |
705 | |
706 | if (section->start == NULL) | |
0c588247 | 707 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 708 | |
d949ff56 | 709 | if (offset >= section->size) |
19e6b90e | 710 | { |
467c65bc NC |
711 | warn (_("DW_FORM_strp offset too big: %s\n"), |
712 | dwarf_vmatoa ("x", offset)); | |
0c588247 | 713 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
714 | } |
715 | ||
d949ff56 NC |
716 | ret = section->start + offset; |
717 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
718 | NUL byte. Since our caller is expecting to receive a well formed C | |
719 | string we test for the lack of a terminating byte here. */ | |
720 | if (strnlen ((const char *) ret, section->size - offset) | |
721 | == section->size - offset) | |
722 | ret = (const unsigned char *) | |
723 | _("<no NUL byte at end of .debug_str section>"); | |
724 | ||
725 | return ret; | |
19e6b90e L |
726 | } |
727 | ||
77145576 JK |
728 | static const unsigned char * |
729 | fetch_indirect_line_string (dwarf_vma offset) | |
730 | { | |
731 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 732 | const unsigned char * ret; |
77145576 JK |
733 | |
734 | if (section->start == NULL) | |
735 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
736 | ||
d949ff56 | 737 | if (offset >= section->size) |
77145576 JK |
738 | { |
739 | warn (_("DW_FORM_line_strp offset too big: %s\n"), | |
740 | dwarf_vmatoa ("x", offset)); | |
741 | return (const unsigned char *) _("<offset is too big>"); | |
742 | } | |
743 | ||
d949ff56 NC |
744 | ret = section->start + offset; |
745 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
746 | with a NUL byte. Since our caller is expecting to receive a well formed | |
747 | C string we test for the lack of a terminating byte here. */ | |
748 | if (strnlen ((const char *) ret, section->size - offset) | |
749 | == section->size - offset) | |
750 | ret = (const unsigned char *) | |
751 | _("<no NUL byte at end of .debug_line_str section>"); | |
752 | ||
753 | return ret; | |
77145576 JK |
754 | } |
755 | ||
4723351a | 756 | static const char * |
341f9135 | 757 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
d85bf2ba | 758 | dwarf_vma offset_size, bfd_boolean dwo) |
4723351a CC |
759 | { |
760 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
761 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
762 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
763 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
764 | dwarf_vma index_offset = idx * offset_size; | |
765 | dwarf_vma str_offset; | |
d949ff56 | 766 | const char * ret; |
4723351a CC |
767 | |
768 | if (index_section->start == NULL) | |
769 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
770 | : _("<no .debug_str_offsets section>")); | |
771 | ||
341f9135 CC |
772 | if (this_set != NULL) |
773 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
d949ff56 | 774 | if (index_offset >= index_section->size) |
4723351a CC |
775 | { |
776 | warn (_("DW_FORM_GNU_str_index offset too big: %s\n"), | |
777 | dwarf_vmatoa ("x", index_offset)); | |
778 | return _("<index offset is too big>"); | |
779 | } | |
780 | ||
781 | if (str_section->start == NULL) | |
782 | return (dwo ? _("<no .debug_str.dwo section>") | |
783 | : _("<no .debug_str section>")); | |
784 | ||
785 | str_offset = byte_get (index_section->start + index_offset, offset_size); | |
786 | str_offset -= str_section->address; | |
d949ff56 | 787 | if (str_offset >= str_section->size) |
4723351a CC |
788 | { |
789 | warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), | |
790 | dwarf_vmatoa ("x", str_offset)); | |
791 | return _("<indirect index offset is too big>"); | |
792 | } | |
793 | ||
d949ff56 NC |
794 | ret = (const char *) str_section->start + str_offset; |
795 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
796 | Since our caller is expecting to receive a well formed C string we test | |
797 | for the lack of a terminating byte here. */ | |
798 | if (strnlen (ret, str_section->size - str_offset) | |
799 | == str_section->size - str_offset) | |
800 | ret = (const char *) _("<no NUL byte at end of section>"); | |
801 | ||
802 | return ret; | |
4723351a CC |
803 | } |
804 | ||
805 | static const char * | |
806 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
807 | { | |
808 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
809 | ||
810 | if (section->start == NULL) | |
811 | return (_("<no .debug_addr section>")); | |
812 | ||
813 | if (offset + bytes > section->size) | |
814 | { | |
815 | warn (_("Offset into section %s too big: %s\n"), | |
b4eb7656 | 816 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
817 | return "<offset too big>"; |
818 | } | |
819 | ||
820 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
821 | } | |
822 | ||
823 | ||
19e6b90e L |
824 | /* FIXME: There are better and more efficient ways to handle |
825 | these structures. For now though, I just want something that | |
826 | is simple to implement. */ | |
827 | typedef struct abbrev_attr | |
828 | { | |
829 | unsigned long attribute; | |
830 | unsigned long form; | |
77145576 | 831 | bfd_signed_vma implicit_const; |
19e6b90e L |
832 | struct abbrev_attr *next; |
833 | } | |
834 | abbrev_attr; | |
835 | ||
836 | typedef struct abbrev_entry | |
837 | { | |
838 | unsigned long entry; | |
839 | unsigned long tag; | |
840 | int children; | |
841 | struct abbrev_attr *first_attr; | |
842 | struct abbrev_attr *last_attr; | |
843 | struct abbrev_entry *next; | |
844 | } | |
845 | abbrev_entry; | |
846 | ||
847 | static abbrev_entry *first_abbrev = NULL; | |
848 | static abbrev_entry *last_abbrev = NULL; | |
849 | ||
850 | static void | |
851 | free_abbrevs (void) | |
852 | { | |
91d6fa6a | 853 | abbrev_entry *abbrv; |
19e6b90e | 854 | |
91d6fa6a | 855 | for (abbrv = first_abbrev; abbrv;) |
19e6b90e | 856 | { |
91d6fa6a | 857 | abbrev_entry *next_abbrev = abbrv->next; |
19e6b90e L |
858 | abbrev_attr *attr; |
859 | ||
91d6fa6a | 860 | for (attr = abbrv->first_attr; attr;) |
19e6b90e | 861 | { |
91d6fa6a | 862 | abbrev_attr *next_attr = attr->next; |
19e6b90e L |
863 | |
864 | free (attr); | |
91d6fa6a | 865 | attr = next_attr; |
19e6b90e L |
866 | } |
867 | ||
91d6fa6a NC |
868 | free (abbrv); |
869 | abbrv = next_abbrev; | |
19e6b90e L |
870 | } |
871 | ||
872 | last_abbrev = first_abbrev = NULL; | |
873 | } | |
874 | ||
875 | static void | |
876 | add_abbrev (unsigned long number, unsigned long tag, int children) | |
877 | { | |
878 | abbrev_entry *entry; | |
879 | ||
3f5e193b | 880 | entry = (abbrev_entry *) malloc (sizeof (*entry)); |
19e6b90e L |
881 | if (entry == NULL) |
882 | /* ugg */ | |
883 | return; | |
884 | ||
885 | entry->entry = number; | |
886 | entry->tag = tag; | |
887 | entry->children = children; | |
888 | entry->first_attr = NULL; | |
889 | entry->last_attr = NULL; | |
890 | entry->next = NULL; | |
891 | ||
892 | if (first_abbrev == NULL) | |
893 | first_abbrev = entry; | |
894 | else | |
895 | last_abbrev->next = entry; | |
896 | ||
897 | last_abbrev = entry; | |
898 | } | |
899 | ||
900 | static void | |
77145576 JK |
901 | add_abbrev_attr (unsigned long attribute, unsigned long form, |
902 | bfd_signed_vma implicit_const) | |
19e6b90e L |
903 | { |
904 | abbrev_attr *attr; | |
905 | ||
3f5e193b | 906 | attr = (abbrev_attr *) malloc (sizeof (*attr)); |
19e6b90e L |
907 | if (attr == NULL) |
908 | /* ugg */ | |
909 | return; | |
910 | ||
911 | attr->attribute = attribute; | |
912 | attr->form = form; | |
77145576 | 913 | attr->implicit_const = implicit_const; |
19e6b90e L |
914 | attr->next = NULL; |
915 | ||
916 | if (last_abbrev->first_attr == NULL) | |
917 | last_abbrev->first_attr = attr; | |
918 | else | |
919 | last_abbrev->last_attr->next = attr; | |
920 | ||
921 | last_abbrev->last_attr = attr; | |
922 | } | |
923 | ||
924 | /* Processes the (partial) contents of a .debug_abbrev section. | |
925 | Returns NULL if the end of the section was encountered. | |
926 | Returns the address after the last byte read if the end of | |
927 | an abbreviation set was found. */ | |
928 | ||
929 | static unsigned char * | |
930 | process_abbrev_section (unsigned char *start, unsigned char *end) | |
931 | { | |
932 | if (first_abbrev != NULL) | |
933 | return NULL; | |
934 | ||
935 | while (start < end) | |
936 | { | |
937 | unsigned int bytes_read; | |
938 | unsigned long entry; | |
939 | unsigned long tag; | |
940 | unsigned long attribute; | |
941 | int children; | |
942 | ||
f6f0e17b | 943 | entry = read_uleb128 (start, & bytes_read, end); |
19e6b90e L |
944 | start += bytes_read; |
945 | ||
946 | /* A single zero is supposed to end the section according | |
947 | to the standard. If there's more, then signal that to | |
948 | the caller. */ | |
f6f0e17b NC |
949 | if (start == end) |
950 | return NULL; | |
19e6b90e | 951 | if (entry == 0) |
f6f0e17b | 952 | return start; |
19e6b90e | 953 | |
f6f0e17b | 954 | tag = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 955 | start += bytes_read; |
f6f0e17b NC |
956 | if (start == end) |
957 | return NULL; | |
19e6b90e L |
958 | |
959 | children = *start++; | |
960 | ||
961 | add_abbrev (entry, tag, children); | |
962 | ||
963 | do | |
964 | { | |
965 | unsigned long form; | |
77145576 JK |
966 | /* Initialize it due to a false compiler warning. */ |
967 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 968 | |
f6f0e17b | 969 | attribute = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 970 | start += bytes_read; |
f6f0e17b NC |
971 | if (start == end) |
972 | break; | |
19e6b90e | 973 | |
f6f0e17b | 974 | form = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 975 | start += bytes_read; |
f6f0e17b NC |
976 | if (start == end) |
977 | break; | |
19e6b90e | 978 | |
77145576 JK |
979 | if (form == DW_FORM_implicit_const) |
980 | { | |
981 | implicit_const = read_sleb128 (start, & bytes_read, end); | |
982 | start += bytes_read; | |
983 | if (start == end) | |
984 | break; | |
985 | } | |
986 | ||
987 | add_abbrev_attr (attribute, form, implicit_const); | |
19e6b90e L |
988 | } |
989 | while (attribute != 0); | |
990 | } | |
991 | ||
399c99f7 L |
992 | /* Report the missing single zero which ends the section. */ |
993 | error (_(".debug_abbrev section not zero terminated\n")); | |
994 | ||
19e6b90e L |
995 | return NULL; |
996 | } | |
997 | ||
a19c41a7 | 998 | static const char * |
19e6b90e L |
999 | get_TAG_name (unsigned long tag) |
1000 | { | |
04914e37 | 1001 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
a19c41a7 TT |
1002 | |
1003 | if (name == NULL) | |
19e6b90e | 1004 | { |
a19c41a7 | 1005 | static char buffer[100]; |
19e6b90e | 1006 | |
04914e37 NC |
1007 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
1008 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); | |
1009 | else | |
1010 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); | |
a19c41a7 | 1011 | return buffer; |
19e6b90e | 1012 | } |
a19c41a7 TT |
1013 | |
1014 | return name; | |
19e6b90e L |
1015 | } |
1016 | ||
a19c41a7 | 1017 | static const char * |
19e6b90e L |
1018 | get_FORM_name (unsigned long form) |
1019 | { | |
399c99f7 | 1020 | const char *name; |
bf5117e3 | 1021 | |
399c99f7 L |
1022 | if (form == 0) |
1023 | return "DW_FORM value: 0"; | |
a19c41a7 | 1024 | |
399c99f7 | 1025 | name = get_DW_FORM_name (form); |
a19c41a7 | 1026 | if (name == NULL) |
19e6b90e | 1027 | { |
a19c41a7 | 1028 | static char buffer[100]; |
19e6b90e | 1029 | |
a19c41a7 TT |
1030 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
1031 | return buffer; | |
19e6b90e | 1032 | } |
a19c41a7 TT |
1033 | |
1034 | return name; | |
19e6b90e L |
1035 | } |
1036 | ||
61364358 JK |
1037 | static const char * |
1038 | get_IDX_name (unsigned long idx) | |
1039 | { | |
1040 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
1041 | ||
1042 | if (name == NULL) | |
1043 | { | |
1044 | static char buffer[100]; | |
1045 | ||
1046 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1047 | return buffer; | |
1048 | } | |
1049 | ||
1050 | return name; | |
1051 | } | |
1052 | ||
19e6b90e | 1053 | static unsigned char * |
0c588247 NC |
1054 | display_block (unsigned char *data, |
1055 | dwarf_vma length, | |
ef0b5f1c | 1056 | const unsigned char * const end, char delimiter) |
19e6b90e | 1057 | { |
0c588247 NC |
1058 | dwarf_vma maxlen; |
1059 | ||
ef0b5f1c | 1060 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1061 | if (data > end) |
1062 | return (unsigned char *) end; | |
19e6b90e | 1063 | |
0c588247 NC |
1064 | maxlen = (dwarf_vma) (end - data); |
1065 | length = length > maxlen ? maxlen : length; | |
1066 | ||
19e6b90e L |
1067 | while (length --) |
1068 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1069 | ||
1070 | return data; | |
1071 | } | |
1072 | ||
1073 | static int | |
1074 | decode_location_expression (unsigned char * data, | |
1075 | unsigned int pointer_size, | |
b7807392 JJ |
1076 | unsigned int offset_size, |
1077 | int dwarf_version, | |
467c65bc NC |
1078 | dwarf_vma length, |
1079 | dwarf_vma cu_offset, | |
f1c4cc75 | 1080 | struct dwarf_section * section) |
19e6b90e L |
1081 | { |
1082 | unsigned op; | |
1083 | unsigned int bytes_read; | |
467c65bc | 1084 | dwarf_vma uvalue; |
0c588247 | 1085 | dwarf_signed_vma svalue; |
19e6b90e L |
1086 | unsigned char *end = data + length; |
1087 | int need_frame_base = 0; | |
1088 | ||
1089 | while (data < end) | |
1090 | { | |
1091 | op = *data++; | |
1092 | ||
1093 | switch (op) | |
1094 | { | |
1095 | case DW_OP_addr: | |
0c588247 NC |
1096 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1097 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1098 | break; |
1099 | case DW_OP_deref: | |
1100 | printf ("DW_OP_deref"); | |
1101 | break; | |
1102 | case DW_OP_const1u: | |
0c588247 NC |
1103 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1104 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1105 | break; |
1106 | case DW_OP_const1s: | |
0c588247 NC |
1107 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1108 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1109 | break; |
1110 | case DW_OP_const2u: | |
87bc83b3 | 1111 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1112 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1113 | break; |
1114 | case DW_OP_const2s: | |
0c588247 NC |
1115 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1116 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1117 | break; |
1118 | case DW_OP_const4u: | |
0c588247 NC |
1119 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1120 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1121 | break; |
1122 | case DW_OP_const4s: | |
0c588247 NC |
1123 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1124 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1125 | break; |
1126 | case DW_OP_const8u: | |
0c588247 NC |
1127 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1128 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1129 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1130 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1131 | break; |
1132 | case DW_OP_const8s: | |
0c588247 NC |
1133 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1134 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1135 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1136 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1137 | break; |
1138 | case DW_OP_constu: | |
467c65bc | 1139 | printf ("DW_OP_constu: %s", |
f6f0e17b | 1140 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1141 | data += bytes_read; |
1142 | break; | |
1143 | case DW_OP_consts: | |
467c65bc | 1144 | printf ("DW_OP_consts: %s", |
f6f0e17b | 1145 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1146 | data += bytes_read; |
1147 | break; | |
1148 | case DW_OP_dup: | |
1149 | printf ("DW_OP_dup"); | |
1150 | break; | |
1151 | case DW_OP_drop: | |
1152 | printf ("DW_OP_drop"); | |
1153 | break; | |
1154 | case DW_OP_over: | |
1155 | printf ("DW_OP_over"); | |
1156 | break; | |
1157 | case DW_OP_pick: | |
0c588247 NC |
1158 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1159 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1160 | break; |
1161 | case DW_OP_swap: | |
1162 | printf ("DW_OP_swap"); | |
1163 | break; | |
1164 | case DW_OP_rot: | |
1165 | printf ("DW_OP_rot"); | |
1166 | break; | |
1167 | case DW_OP_xderef: | |
1168 | printf ("DW_OP_xderef"); | |
1169 | break; | |
1170 | case DW_OP_abs: | |
1171 | printf ("DW_OP_abs"); | |
1172 | break; | |
1173 | case DW_OP_and: | |
1174 | printf ("DW_OP_and"); | |
1175 | break; | |
1176 | case DW_OP_div: | |
1177 | printf ("DW_OP_div"); | |
1178 | break; | |
1179 | case DW_OP_minus: | |
1180 | printf ("DW_OP_minus"); | |
1181 | break; | |
1182 | case DW_OP_mod: | |
1183 | printf ("DW_OP_mod"); | |
1184 | break; | |
1185 | case DW_OP_mul: | |
1186 | printf ("DW_OP_mul"); | |
1187 | break; | |
1188 | case DW_OP_neg: | |
1189 | printf ("DW_OP_neg"); | |
1190 | break; | |
1191 | case DW_OP_not: | |
1192 | printf ("DW_OP_not"); | |
1193 | break; | |
1194 | case DW_OP_or: | |
1195 | printf ("DW_OP_or"); | |
1196 | break; | |
1197 | case DW_OP_plus: | |
1198 | printf ("DW_OP_plus"); | |
1199 | break; | |
1200 | case DW_OP_plus_uconst: | |
467c65bc | 1201 | printf ("DW_OP_plus_uconst: %s", |
f6f0e17b | 1202 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1203 | data += bytes_read; |
1204 | break; | |
1205 | case DW_OP_shl: | |
1206 | printf ("DW_OP_shl"); | |
1207 | break; | |
1208 | case DW_OP_shr: | |
1209 | printf ("DW_OP_shr"); | |
1210 | break; | |
1211 | case DW_OP_shra: | |
1212 | printf ("DW_OP_shra"); | |
1213 | break; | |
1214 | case DW_OP_xor: | |
1215 | printf ("DW_OP_xor"); | |
1216 | break; | |
1217 | case DW_OP_bra: | |
0c588247 NC |
1218 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1219 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1220 | break; |
1221 | case DW_OP_eq: | |
1222 | printf ("DW_OP_eq"); | |
1223 | break; | |
1224 | case DW_OP_ge: | |
1225 | printf ("DW_OP_ge"); | |
1226 | break; | |
1227 | case DW_OP_gt: | |
1228 | printf ("DW_OP_gt"); | |
1229 | break; | |
1230 | case DW_OP_le: | |
1231 | printf ("DW_OP_le"); | |
1232 | break; | |
1233 | case DW_OP_lt: | |
1234 | printf ("DW_OP_lt"); | |
1235 | break; | |
1236 | case DW_OP_ne: | |
1237 | printf ("DW_OP_ne"); | |
1238 | break; | |
1239 | case DW_OP_skip: | |
0c588247 NC |
1240 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1241 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1242 | break; |
1243 | ||
1244 | case DW_OP_lit0: | |
1245 | case DW_OP_lit1: | |
1246 | case DW_OP_lit2: | |
1247 | case DW_OP_lit3: | |
1248 | case DW_OP_lit4: | |
1249 | case DW_OP_lit5: | |
1250 | case DW_OP_lit6: | |
1251 | case DW_OP_lit7: | |
1252 | case DW_OP_lit8: | |
1253 | case DW_OP_lit9: | |
1254 | case DW_OP_lit10: | |
1255 | case DW_OP_lit11: | |
1256 | case DW_OP_lit12: | |
1257 | case DW_OP_lit13: | |
1258 | case DW_OP_lit14: | |
1259 | case DW_OP_lit15: | |
1260 | case DW_OP_lit16: | |
1261 | case DW_OP_lit17: | |
1262 | case DW_OP_lit18: | |
1263 | case DW_OP_lit19: | |
1264 | case DW_OP_lit20: | |
1265 | case DW_OP_lit21: | |
1266 | case DW_OP_lit22: | |
1267 | case DW_OP_lit23: | |
1268 | case DW_OP_lit24: | |
1269 | case DW_OP_lit25: | |
1270 | case DW_OP_lit26: | |
1271 | case DW_OP_lit27: | |
1272 | case DW_OP_lit28: | |
1273 | case DW_OP_lit29: | |
1274 | case DW_OP_lit30: | |
1275 | case DW_OP_lit31: | |
1276 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1277 | break; | |
1278 | ||
1279 | case DW_OP_reg0: | |
1280 | case DW_OP_reg1: | |
1281 | case DW_OP_reg2: | |
1282 | case DW_OP_reg3: | |
1283 | case DW_OP_reg4: | |
1284 | case DW_OP_reg5: | |
1285 | case DW_OP_reg6: | |
1286 | case DW_OP_reg7: | |
1287 | case DW_OP_reg8: | |
1288 | case DW_OP_reg9: | |
1289 | case DW_OP_reg10: | |
1290 | case DW_OP_reg11: | |
1291 | case DW_OP_reg12: | |
1292 | case DW_OP_reg13: | |
1293 | case DW_OP_reg14: | |
1294 | case DW_OP_reg15: | |
1295 | case DW_OP_reg16: | |
1296 | case DW_OP_reg17: | |
1297 | case DW_OP_reg18: | |
1298 | case DW_OP_reg19: | |
1299 | case DW_OP_reg20: | |
1300 | case DW_OP_reg21: | |
1301 | case DW_OP_reg22: | |
1302 | case DW_OP_reg23: | |
1303 | case DW_OP_reg24: | |
1304 | case DW_OP_reg25: | |
1305 | case DW_OP_reg26: | |
1306 | case DW_OP_reg27: | |
1307 | case DW_OP_reg28: | |
1308 | case DW_OP_reg29: | |
1309 | case DW_OP_reg30: | |
1310 | case DW_OP_reg31: | |
18464d4d JK |
1311 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1312 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1313 | break; |
1314 | ||
1315 | case DW_OP_breg0: | |
1316 | case DW_OP_breg1: | |
1317 | case DW_OP_breg2: | |
1318 | case DW_OP_breg3: | |
1319 | case DW_OP_breg4: | |
1320 | case DW_OP_breg5: | |
1321 | case DW_OP_breg6: | |
1322 | case DW_OP_breg7: | |
1323 | case DW_OP_breg8: | |
1324 | case DW_OP_breg9: | |
1325 | case DW_OP_breg10: | |
1326 | case DW_OP_breg11: | |
1327 | case DW_OP_breg12: | |
1328 | case DW_OP_breg13: | |
1329 | case DW_OP_breg14: | |
1330 | case DW_OP_breg15: | |
1331 | case DW_OP_breg16: | |
1332 | case DW_OP_breg17: | |
1333 | case DW_OP_breg18: | |
1334 | case DW_OP_breg19: | |
1335 | case DW_OP_breg20: | |
1336 | case DW_OP_breg21: | |
1337 | case DW_OP_breg22: | |
1338 | case DW_OP_breg23: | |
1339 | case DW_OP_breg24: | |
1340 | case DW_OP_breg25: | |
1341 | case DW_OP_breg26: | |
1342 | case DW_OP_breg27: | |
1343 | case DW_OP_breg28: | |
1344 | case DW_OP_breg29: | |
1345 | case DW_OP_breg30: | |
1346 | case DW_OP_breg31: | |
467c65bc | 1347 | printf ("DW_OP_breg%d (%s): %s", |
47704ddf | 1348 | op - DW_OP_breg0, |
18464d4d | 1349 | regname (op - DW_OP_breg0, 1), |
f6f0e17b | 1350 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1351 | data += bytes_read; |
1352 | break; | |
1353 | ||
1354 | case DW_OP_regx: | |
f6f0e17b | 1355 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1356 | data += bytes_read; |
467c65bc NC |
1357 | printf ("DW_OP_regx: %s (%s)", |
1358 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1359 | break; |
1360 | case DW_OP_fbreg: | |
1361 | need_frame_base = 1; | |
467c65bc | 1362 | printf ("DW_OP_fbreg: %s", |
f6f0e17b | 1363 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1364 | data += bytes_read; |
1365 | break; | |
1366 | case DW_OP_bregx: | |
f6f0e17b | 1367 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1368 | data += bytes_read; |
467c65bc NC |
1369 | printf ("DW_OP_bregx: %s (%s) %s", |
1370 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
f6f0e17b | 1371 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1372 | data += bytes_read; |
1373 | break; | |
1374 | case DW_OP_piece: | |
467c65bc | 1375 | printf ("DW_OP_piece: %s", |
f6f0e17b | 1376 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1377 | data += bytes_read; |
1378 | break; | |
1379 | case DW_OP_deref_size: | |
0c588247 NC |
1380 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1381 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1382 | break; |
1383 | case DW_OP_xderef_size: | |
0c588247 NC |
1384 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1385 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1386 | break; |
1387 | case DW_OP_nop: | |
1388 | printf ("DW_OP_nop"); | |
1389 | break; | |
1390 | ||
1391 | /* DWARF 3 extensions. */ | |
1392 | case DW_OP_push_object_address: | |
1393 | printf ("DW_OP_push_object_address"); | |
1394 | break; | |
1395 | case DW_OP_call2: | |
d85bf2ba | 1396 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1397 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1398 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1399 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1400 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1401 | break; |
1402 | case DW_OP_call4: | |
d85bf2ba | 1403 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1404 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1405 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1406 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1407 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1408 | break; |
1409 | case DW_OP_call_ref: | |
d85bf2ba | 1410 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1411 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1412 | if (dwarf_version == -1) |
1413 | { | |
1414 | printf (_("(DW_OP_call_ref in frame info)")); | |
1415 | /* No way to tell where the next op is, so just bail. */ | |
1416 | return need_frame_base; | |
1417 | } | |
1418 | if (dwarf_version == 2) | |
1419 | { | |
0c588247 | 1420 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1421 | } |
1422 | else | |
1423 | { | |
0c588247 | 1424 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1425 | } |
0c588247 | 1426 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1427 | break; |
a87b0a59 NS |
1428 | case DW_OP_form_tls_address: |
1429 | printf ("DW_OP_form_tls_address"); | |
1430 | break; | |
e2a0d921 NC |
1431 | case DW_OP_call_frame_cfa: |
1432 | printf ("DW_OP_call_frame_cfa"); | |
1433 | break; | |
1434 | case DW_OP_bit_piece: | |
1435 | printf ("DW_OP_bit_piece: "); | |
9cf03b7e | 1436 | printf (_("size: %s "), |
f6f0e17b | 1437 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 | 1438 | data += bytes_read; |
9cf03b7e | 1439 | printf (_("offset: %s "), |
f6f0e17b | 1440 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 NC |
1441 | data += bytes_read; |
1442 | break; | |
19e6b90e | 1443 | |
3244e8f5 JJ |
1444 | /* DWARF 4 extensions. */ |
1445 | case DW_OP_stack_value: | |
1446 | printf ("DW_OP_stack_value"); | |
1447 | break; | |
1448 | ||
1449 | case DW_OP_implicit_value: | |
1450 | printf ("DW_OP_implicit_value"); | |
f6f0e17b | 1451 | uvalue = read_uleb128 (data, &bytes_read, end); |
3244e8f5 | 1452 | data += bytes_read; |
ef0b5f1c | 1453 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1454 | break; |
1455 | ||
19e6b90e L |
1456 | /* GNU extensions. */ |
1457 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1458 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1459 | break; |
1460 | case DW_OP_GNU_uninit: | |
1461 | printf ("DW_OP_GNU_uninit"); | |
1462 | /* FIXME: Is there data associated with this OP ? */ | |
1463 | break; | |
f1c4cc75 RH |
1464 | case DW_OP_GNU_encoded_addr: |
1465 | { | |
6937bb54 | 1466 | int encoding = 0; |
f1c4cc75 | 1467 | dwarf_vma addr; |
467c65bc | 1468 | |
6937bb54 NC |
1469 | if (data < end) |
1470 | encoding = *data++; | |
041830e0 | 1471 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1472 | |
1473 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1474 | print_dwarf_vma (addr, pointer_size); | |
1475 | } | |
1476 | break; | |
bc0a77d2 | 1477 | case DW_OP_implicit_pointer: |
b7807392 | 1478 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1479 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1480 | this ought to be an 8-byte wide computation. */ |
1481 | if (dwarf_version == -1) | |
1482 | { | |
bc0a77d2 JK |
1483 | printf (_("(%s in frame info)"), |
1484 | (op == DW_OP_implicit_pointer | |
1485 | ? "DW_OP_implicit_pointer" | |
1486 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1487 | /* No way to tell where the next op is, so just bail. */ |
1488 | return need_frame_base; | |
1489 | } | |
1490 | if (dwarf_version == 2) | |
1491 | { | |
0c588247 | 1492 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1493 | } |
1494 | else | |
1495 | { | |
0c588247 | 1496 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1497 | } |
bc0a77d2 JK |
1498 | printf ("%s: <0x%s> %s", |
1499 | (op == DW_OP_implicit_pointer | |
1500 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 NC |
1501 | dwarf_vmatoa ("x", uvalue), |
1502 | dwarf_vmatoa ("d", read_sleb128 (data, | |
1503 | &bytes_read, end))); | |
1504 | data += bytes_read; | |
b7807392 | 1505 | break; |
77145576 | 1506 | case DW_OP_entry_value: |
0892011d | 1507 | case DW_OP_GNU_entry_value: |
f6f0e17b | 1508 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1509 | data += bytes_read; |
058037d3 NC |
1510 | /* PR 17531: file: 0cc9cd00. */ |
1511 | if (uvalue > (dwarf_vma) (end - data)) | |
1512 | uvalue = end - data; | |
77145576 JK |
1513 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1514 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1515 | if (decode_location_expression (data, pointer_size, offset_size, |
1516 | dwarf_version, uvalue, | |
1517 | cu_offset, section)) | |
1518 | need_frame_base = 1; | |
1519 | putchar (')'); | |
1520 | data += uvalue; | |
6937bb54 NC |
1521 | if (data > end) |
1522 | data = end; | |
0892011d | 1523 | break; |
bc0a77d2 | 1524 | case DW_OP_const_type: |
0892011d | 1525 | case DW_OP_GNU_const_type: |
f6f0e17b | 1526 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1527 | data += bytes_read; |
bc0a77d2 JK |
1528 | printf ("%s: <0x%s> ", |
1529 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1530 | : "DW_OP_GNU_const_type"), | |
0892011d | 1531 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1532 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1533 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1534 | break; |
bc0a77d2 | 1535 | case DW_OP_regval_type: |
0892011d | 1536 | case DW_OP_GNU_regval_type: |
f6f0e17b | 1537 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1538 | data += bytes_read; |
bc0a77d2 JK |
1539 | printf ("%s: %s (%s)", |
1540 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1541 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1542 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
f6f0e17b | 1543 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1544 | data += bytes_read; |
1545 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1546 | break; | |
bc0a77d2 | 1547 | case DW_OP_deref_type: |
0892011d | 1548 | case DW_OP_GNU_deref_type: |
0c588247 | 1549 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1550 | printf ("%s: %ld", |
1551 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1552 | : "DW_OP_GNU_deref_type"), | |
1553 | (long) uvalue); | |
f6f0e17b | 1554 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1555 | data += bytes_read; |
1556 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1557 | break; | |
bc0a77d2 | 1558 | case DW_OP_convert: |
0892011d | 1559 | case DW_OP_GNU_convert: |
f6f0e17b | 1560 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1561 | data += bytes_read; |
bc0a77d2 JK |
1562 | printf ("%s <0x%s>", |
1563 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1564 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1565 | break; |
bc0a77d2 | 1566 | case DW_OP_reinterpret: |
0892011d | 1567 | case DW_OP_GNU_reinterpret: |
f6f0e17b | 1568 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1569 | data += bytes_read; |
bc0a77d2 JK |
1570 | printf ("%s <0x%s>", |
1571 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1572 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1573 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1574 | break; | |
1575 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1576 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1577 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1578 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1579 | break; |
b4eb7656 AM |
1580 | case DW_OP_GNU_addr_index: |
1581 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1582 | data += bytes_read; | |
1583 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1584 | break; | |
1585 | case DW_OP_GNU_const_index: | |
1586 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1587 | data += bytes_read; | |
1588 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1589 | break; | |
f384a1f0 KB |
1590 | case DW_OP_GNU_variable_value: |
1591 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1592 | this ought to be an 8-byte wide computation. */ | |
1593 | if (dwarf_version == -1) | |
1594 | { | |
1595 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1596 | /* No way to tell where the next op is, so just bail. */ | |
1597 | return need_frame_base; | |
1598 | } | |
1599 | if (dwarf_version == 2) | |
1600 | { | |
1601 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1602 | } | |
1603 | else | |
1604 | { | |
1605 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1606 | } | |
1607 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1608 | break; | |
e2a0d921 NC |
1609 | |
1610 | /* HP extensions. */ | |
1611 | case DW_OP_HP_is_value: | |
1612 | printf ("DW_OP_HP_is_value"); | |
1613 | /* FIXME: Is there data associated with this OP ? */ | |
1614 | break; | |
1615 | case DW_OP_HP_fltconst4: | |
1616 | printf ("DW_OP_HP_fltconst4"); | |
1617 | /* FIXME: Is there data associated with this OP ? */ | |
1618 | break; | |
1619 | case DW_OP_HP_fltconst8: | |
1620 | printf ("DW_OP_HP_fltconst8"); | |
1621 | /* FIXME: Is there data associated with this OP ? */ | |
1622 | break; | |
1623 | case DW_OP_HP_mod_range: | |
1624 | printf ("DW_OP_HP_mod_range"); | |
1625 | /* FIXME: Is there data associated with this OP ? */ | |
1626 | break; | |
1627 | case DW_OP_HP_unmod_range: | |
1628 | printf ("DW_OP_HP_unmod_range"); | |
1629 | /* FIXME: Is there data associated with this OP ? */ | |
1630 | break; | |
1631 | case DW_OP_HP_tls: | |
1632 | printf ("DW_OP_HP_tls"); | |
1633 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1634 | break; |
1635 | ||
35d60fe4 NC |
1636 | /* PGI (STMicroelectronics) extensions. */ |
1637 | case DW_OP_PGI_omp_thread_num: | |
1638 | /* Pushes the thread number for the current thread as it would be | |
1639 | returned by the standard OpenMP library function: | |
1640 | omp_get_thread_num(). The "current thread" is the thread for | |
1641 | which the expression is being evaluated. */ | |
1642 | printf ("DW_OP_PGI_omp_thread_num"); | |
1643 | break; | |
1644 | ||
19e6b90e L |
1645 | default: |
1646 | if (op >= DW_OP_lo_user | |
1647 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1648 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1649 | else |
0502a2b4 | 1650 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1651 | /* No way to tell where the next op is, so just bail. */ |
1652 | return need_frame_base; | |
1653 | } | |
1654 | ||
1655 | /* Separate the ops. */ | |
1656 | if (data < end) | |
1657 | printf ("; "); | |
1658 | } | |
1659 | ||
1660 | return need_frame_base; | |
1661 | } | |
1662 | ||
341f9135 CC |
1663 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1664 | This is used for DWARF package files. */ | |
1665 | ||
1666 | static struct cu_tu_set * | |
1667 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1668 | { | |
1669 | struct cu_tu_set *p; | |
1670 | unsigned int nsets; | |
1671 | unsigned int dw_sect; | |
1672 | ||
1673 | if (do_types) | |
1674 | { | |
1675 | p = tu_sets; | |
1676 | nsets = tu_count; | |
1677 | dw_sect = DW_SECT_TYPES; | |
1678 | } | |
1679 | else | |
1680 | { | |
1681 | p = cu_sets; | |
1682 | nsets = cu_count; | |
1683 | dw_sect = DW_SECT_INFO; | |
1684 | } | |
1685 | while (nsets > 0) | |
1686 | { | |
1687 | if (p->section_offsets [dw_sect] == cu_offset) | |
1688 | return p; | |
1689 | p++; | |
1690 | nsets--; | |
1691 | } | |
1692 | return NULL; | |
1693 | } | |
1694 | ||
a69c4772 NC |
1695 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1696 | static void | |
1697 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1698 | { | |
1699 | dwarf_vma tmp = * low_bits; | |
1700 | ||
1701 | tmp += inc; | |
1702 | ||
1703 | /* FIXME: There is probably a better way of handling this: | |
1704 | ||
1705 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1706 | type. Plus regardless of its size LOW_BITS is meant to | |
1707 | only hold 32-bits, so if there is overflow or wrap around | |
1708 | we must propagate into HIGH_BITS. */ | |
1709 | if (tmp < * low_bits) | |
1710 | { | |
1711 | ++ * high_bits; | |
1712 | } | |
1713 | else if (sizeof (tmp) > 8 | |
1714 | && (tmp >> 31) > 1) | |
1715 | { | |
1716 | ++ * high_bits; | |
1717 | tmp &= 0xFFFFFFFF; | |
1718 | } | |
1719 | ||
1720 | * low_bits = tmp; | |
1721 | } | |
1722 | ||
dda8d76d NC |
1723 | static const char * |
1724 | fetch_alt_indirect_string (dwarf_vma offset) | |
1725 | { | |
24841daa | 1726 | separate_info * i; |
dda8d76d NC |
1727 | |
1728 | if (! do_follow_links) | |
1729 | return ""; | |
1730 | ||
24841daa NC |
1731 | if (first_separate_info == NULL) |
1732 | return _("<no links available>"); | |
dda8d76d | 1733 | |
24841daa NC |
1734 | for (i = first_separate_info; i != NULL; i = i->next) |
1735 | { | |
1736 | struct dwarf_section * section; | |
1737 | const char * ret; | |
dda8d76d | 1738 | |
24841daa NC |
1739 | if (! load_debug_section (separate_debug_str, i->handle)) |
1740 | continue; | |
dda8d76d | 1741 | |
24841daa | 1742 | section = &debug_displays [separate_debug_str].section; |
dda8d76d | 1743 | |
24841daa NC |
1744 | if (section->start == NULL) |
1745 | continue; | |
dda8d76d | 1746 | |
24841daa NC |
1747 | if (offset >= section->size) |
1748 | continue; | |
1749 | ||
1750 | ret = (const char *) (section->start + offset); | |
1751 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1752 | NUL byte. Since our caller is expecting to receive a well formed C | |
1753 | string we test for the lack of a terminating byte here. */ | |
1754 | if (strnlen ((const char *) ret, section->size - offset) | |
1755 | == section->size - offset) | |
1756 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1757 | ||
1758 | return ret; | |
1759 | } | |
1760 | ||
1761 | warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"), | |
1762 | dwarf_vmatoa ("x", offset)); | |
1763 | return _("<offset is too big>"); | |
dda8d76d NC |
1764 | } |
1765 | ||
d85bf2ba NC |
1766 | static const char * |
1767 | get_AT_name (unsigned long attribute) | |
1768 | { | |
1769 | const char *name; | |
1770 | ||
1771 | if (attribute == 0) | |
1772 | return "DW_AT value: 0"; | |
1773 | ||
1774 | /* One value is shared by the MIPS and HP extensions: */ | |
1775 | if (attribute == DW_AT_MIPS_fde) | |
1776 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1777 | ||
1778 | name = get_DW_AT_name (attribute); | |
1779 | ||
1780 | if (name == NULL) | |
1781 | { | |
1782 | static char buffer[100]; | |
1783 | ||
1784 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1785 | attribute); | |
1786 | return buffer; | |
1787 | } | |
1788 | ||
1789 | return name; | |
1790 | } | |
1791 | ||
24841daa NC |
1792 | static void |
1793 | add_dwo_info (const char * field, dwo_type type) | |
1794 | { | |
1795 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1796 | ||
1797 | dwinfo->type = type; | |
1798 | dwinfo->value = field; | |
1799 | dwinfo->next = first_dwo_info; | |
1800 | first_dwo_info = dwinfo; | |
1801 | } | |
1802 | ||
1803 | static void | |
1804 | add_dwo_name (const char * name) | |
1805 | { | |
1806 | add_dwo_info (name, DWO_NAME); | |
1807 | } | |
1808 | ||
1809 | static void | |
1810 | add_dwo_dir (const char * dir) | |
1811 | { | |
1812 | add_dwo_info (dir, DWO_DIR); | |
1813 | } | |
1814 | ||
1815 | static void | |
1816 | add_dwo_id (const char * id) | |
1817 | { | |
1818 | add_dwo_info (id, DWO_ID); | |
1819 | } | |
1820 | ||
1821 | static void | |
1822 | free_dwo_info (void) | |
1823 | { | |
1824 | dwo_info * dwinfo; | |
1825 | dwo_info * next; | |
1826 | ||
1827 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1828 | { | |
1829 | next = dwinfo->next; | |
1830 | free (dwinfo); | |
1831 | } | |
1832 | first_dwo_info = NULL; | |
1833 | } | |
1834 | ||
afc72f15 NC |
1835 | /* Ensure that START + UVALUE is less than END. |
1836 | Return an adjusted UVALUE if necessary to ensure this relationship. */ | |
1837 | ||
1838 | static inline dwarf_vma | |
1839 | check_uvalue (const unsigned char * start, | |
1840 | dwarf_vma uvalue, | |
1841 | const unsigned char * end) | |
1842 | { | |
1843 | dwarf_vma max_uvalue = end - start; | |
1844 | ||
1845 | /* FIXME: Testing "(start + uvalue) < start" miscompiles with gcc 4.8.3 | |
1846 | running on an x86_64 host in 32-bit mode. So we pre-compute the value | |
1847 | here. */ | |
1848 | const unsigned char * ptr = start + uvalue; | |
1849 | ||
1850 | /* See PR 17512: file: 008-103549-0.001:0.1. | |
1851 | and PR 24829 for examples of where these tests are triggered. */ | |
1852 | if (uvalue > max_uvalue | |
1853 | || ptr > end | |
1854 | || ptr < start) | |
1855 | { | |
1856 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1857 | uvalue = max_uvalue; | |
1858 | } | |
1859 | ||
1860 | return uvalue; | |
1861 | } | |
1862 | ||
19e6b90e | 1863 | static unsigned char * |
dda8d76d NC |
1864 | read_and_display_attr_value (unsigned long attribute, |
1865 | unsigned long form, | |
1866 | dwarf_signed_vma implicit_const, | |
1867 | unsigned char * data, | |
1868 | unsigned char * end, | |
1869 | dwarf_vma cu_offset, | |
1870 | dwarf_vma pointer_size, | |
1871 | dwarf_vma offset_size, | |
1872 | int dwarf_version, | |
1873 | debug_info * debug_info_p, | |
1874 | int do_loc, | |
1875 | struct dwarf_section * section, | |
1876 | struct cu_tu_set * this_set, | |
1877 | char delimiter) | |
19e6b90e | 1878 | { |
467c65bc | 1879 | dwarf_vma uvalue = 0; |
19e6b90e | 1880 | unsigned char *block_start = NULL; |
6e3d6dc1 | 1881 | unsigned char * orig_data = data; |
19e6b90e L |
1882 | unsigned int bytes_read; |
1883 | ||
f41e4712 | 1884 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 1885 | { |
f41e4712 | 1886 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
1887 | return data; |
1888 | } | |
1889 | ||
19e6b90e L |
1890 | switch (form) |
1891 | { | |
1892 | default: | |
1893 | break; | |
1894 | ||
1895 | case DW_FORM_ref_addr: | |
1896 | if (dwarf_version == 2) | |
0c588247 | 1897 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
932fd279 | 1898 | else if (dwarf_version == 3 || dwarf_version == 4) |
0c588247 | 1899 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 1900 | else |
467c65bc NC |
1901 | error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); |
1902 | ||
19e6b90e L |
1903 | break; |
1904 | ||
1905 | case DW_FORM_addr: | |
0c588247 | 1906 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
1907 | break; |
1908 | ||
1909 | case DW_FORM_strp: | |
77145576 | 1910 | case DW_FORM_line_strp: |
932fd279 | 1911 | case DW_FORM_sec_offset: |
a081f3cd JJ |
1912 | case DW_FORM_GNU_ref_alt: |
1913 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 1914 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
1915 | break; |
1916 | ||
932fd279 JJ |
1917 | case DW_FORM_flag_present: |
1918 | uvalue = 1; | |
1919 | break; | |
1920 | ||
19e6b90e L |
1921 | case DW_FORM_ref1: |
1922 | case DW_FORM_flag: | |
1923 | case DW_FORM_data1: | |
0c588247 | 1924 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
1925 | break; |
1926 | ||
1927 | case DW_FORM_ref2: | |
1928 | case DW_FORM_data2: | |
0c588247 | 1929 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
1930 | break; |
1931 | ||
1932 | case DW_FORM_ref4: | |
1933 | case DW_FORM_data4: | |
0c588247 | 1934 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
1935 | break; |
1936 | ||
1937 | case DW_FORM_sdata: | |
f6f0e17b | 1938 | uvalue = read_sleb128 (data, & bytes_read, end); |
19e6b90e L |
1939 | data += bytes_read; |
1940 | break; | |
1941 | ||
4723351a | 1942 | case DW_FORM_GNU_str_index: |
f6f0e17b | 1943 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
1944 | data += bytes_read; |
1945 | break; | |
1946 | ||
19e6b90e L |
1947 | case DW_FORM_ref_udata: |
1948 | case DW_FORM_udata: | |
f6f0e17b | 1949 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
1950 | data += bytes_read; |
1951 | break; | |
1952 | ||
1953 | case DW_FORM_indirect: | |
f6f0e17b | 1954 | form = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
1955 | data += bytes_read; |
1956 | if (!do_loc) | |
ef0b5f1c | 1957 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 JK |
1958 | if (form == DW_FORM_implicit_const) |
1959 | { | |
1960 | implicit_const = read_sleb128 (data, & bytes_read, end); | |
1961 | data += bytes_read; | |
1962 | } | |
1963 | return read_and_display_attr_value (attribute, form, implicit_const, data, | |
1964 | end, cu_offset, pointer_size, | |
19e6b90e | 1965 | offset_size, dwarf_version, |
ec4d4525 | 1966 | debug_info_p, do_loc, |
ef0b5f1c | 1967 | section, this_set, delimiter); |
4723351a | 1968 | case DW_FORM_GNU_addr_index: |
f6f0e17b | 1969 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
1970 | data += bytes_read; |
1971 | break; | |
19e6b90e L |
1972 | } |
1973 | ||
1974 | switch (form) | |
1975 | { | |
1976 | case DW_FORM_ref_addr: | |
1977 | if (!do_loc) | |
ef0b5f1c | 1978 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
1979 | break; |
1980 | ||
a081f3cd JJ |
1981 | case DW_FORM_GNU_ref_alt: |
1982 | if (!do_loc) | |
ef0b5f1c | 1983 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
dda8d76d | 1984 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
1985 | break; |
1986 | ||
19e6b90e L |
1987 | case DW_FORM_ref1: |
1988 | case DW_FORM_ref2: | |
1989 | case DW_FORM_ref4: | |
1990 | case DW_FORM_ref_udata: | |
1991 | if (!do_loc) | |
ef0b5f1c | 1992 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
1993 | break; |
1994 | ||
1995 | case DW_FORM_data4: | |
1996 | case DW_FORM_addr: | |
932fd279 | 1997 | case DW_FORM_sec_offset: |
19e6b90e | 1998 | if (!do_loc) |
ef0b5f1c | 1999 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2000 | break; |
2001 | ||
932fd279 | 2002 | case DW_FORM_flag_present: |
19e6b90e L |
2003 | case DW_FORM_flag: |
2004 | case DW_FORM_data1: | |
2005 | case DW_FORM_data2: | |
2006 | case DW_FORM_sdata: | |
2007 | case DW_FORM_udata: | |
2008 | if (!do_loc) | |
ef0b5f1c | 2009 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
2010 | break; |
2011 | ||
77145576 JK |
2012 | case DW_FORM_implicit_const: |
2013 | if (!do_loc) | |
2014 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
2015 | break; | |
2016 | ||
19e6b90e L |
2017 | case DW_FORM_ref8: |
2018 | case DW_FORM_data8: | |
2bc8690c | 2019 | if (!do_loc) |
19e6b90e | 2020 | { |
74bc6052 | 2021 | dwarf_vma high_bits; |
a69c4772 | 2022 | dwarf_vma utmp; |
74bc6052 CC |
2023 | char buf[64]; |
2024 | ||
0c588247 | 2025 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
2026 | utmp = uvalue; |
2027 | if (form == DW_FORM_ref8) | |
2028 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 2029 | printf ("%c0x%s", delimiter, |
a69c4772 | 2030 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 2031 | } |
0c588247 | 2032 | |
19e6b90e L |
2033 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2034 | && num_debug_info_entries == 0) | |
2035 | { | |
2036 | if (sizeof (uvalue) == 8) | |
0c588247 | 2037 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 2038 | else |
467c65bc | 2039 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 2040 | } |
0c588247 | 2041 | |
19e6b90e L |
2042 | data += 8; |
2043 | break; | |
2044 | ||
2f6cd591 JK |
2045 | case DW_FORM_data16: |
2046 | if (!do_loc) | |
2047 | { | |
2048 | dwarf_vma left_high_bits, left_low_bits; | |
2049 | dwarf_vma right_high_bits, right_low_bits; | |
2050 | ||
2051 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
2052 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
2053 | if (byte_get == byte_get_little_endian) | |
2054 | { | |
2055 | /* Swap them. */ | |
2056 | left_high_bits ^= right_high_bits; | |
2057 | right_high_bits ^= left_high_bits; | |
2058 | left_high_bits ^= right_high_bits; | |
2059 | left_low_bits ^= right_low_bits; | |
2060 | right_low_bits ^= left_low_bits; | |
2061 | left_low_bits ^= right_low_bits; | |
2062 | } | |
2063 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
2064 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
2065 | left_high_bits, left_low_bits, right_high_bits, | |
2066 | right_low_bits); | |
2067 | } | |
2068 | data += 16; | |
2069 | break; | |
2070 | ||
19e6b90e L |
2071 | case DW_FORM_string: |
2072 | if (!do_loc) | |
ef0b5f1c | 2073 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 2074 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
2075 | break; |
2076 | ||
2077 | case DW_FORM_block: | |
932fd279 | 2078 | case DW_FORM_exprloc: |
f6f0e17b | 2079 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e | 2080 | block_start = data + bytes_read; |
a1165289 NC |
2081 | if (block_start >= end) |
2082 | { | |
2083 | warn (_("Block ends prematurely\n")); | |
2084 | uvalue = 0; | |
2085 | block_start = end; | |
2086 | } | |
afc72f15 NC |
2087 | |
2088 | uvalue = check_uvalue (block_start, uvalue, end); | |
2089 | ||
19e6b90e L |
2090 | if (do_loc) |
2091 | data = block_start + uvalue; | |
2092 | else | |
ef0b5f1c | 2093 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2094 | break; |
2095 | ||
2096 | case DW_FORM_block1: | |
0c588247 | 2097 | SAFE_BYTE_GET (uvalue, data, 1, end); |
19e6b90e | 2098 | block_start = data + 1; |
a1165289 NC |
2099 | if (block_start >= end) |
2100 | { | |
2101 | warn (_("Block ends prematurely\n")); | |
2102 | uvalue = 0; | |
2103 | block_start = end; | |
2104 | } | |
afc72f15 NC |
2105 | |
2106 | uvalue = check_uvalue (block_start, uvalue, end); | |
2107 | ||
19e6b90e L |
2108 | if (do_loc) |
2109 | data = block_start + uvalue; | |
2110 | else | |
ef0b5f1c | 2111 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2112 | break; |
2113 | ||
2114 | case DW_FORM_block2: | |
0c588247 | 2115 | SAFE_BYTE_GET (uvalue, data, 2, end); |
19e6b90e | 2116 | block_start = data + 2; |
a1165289 NC |
2117 | if (block_start >= end) |
2118 | { | |
2119 | warn (_("Block ends prematurely\n")); | |
2120 | uvalue = 0; | |
2121 | block_start = end; | |
2122 | } | |
afc72f15 NC |
2123 | |
2124 | uvalue = check_uvalue (block_start, uvalue, end); | |
2125 | ||
19e6b90e L |
2126 | if (do_loc) |
2127 | data = block_start + uvalue; | |
2128 | else | |
ef0b5f1c | 2129 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2130 | break; |
2131 | ||
2132 | case DW_FORM_block4: | |
0c588247 | 2133 | SAFE_BYTE_GET (uvalue, data, 4, end); |
19e6b90e | 2134 | block_start = data + 4; |
a1165289 NC |
2135 | /* PR 17512: file: 3371-3907-0.004. */ |
2136 | if (block_start >= end) | |
2137 | { | |
2138 | warn (_("Block ends prematurely\n")); | |
2139 | uvalue = 0; | |
2140 | block_start = end; | |
2141 | } | |
afc72f15 NC |
2142 | |
2143 | uvalue = check_uvalue (block_start, uvalue, end); | |
2144 | ||
19e6b90e L |
2145 | if (do_loc) |
2146 | data = block_start + uvalue; | |
2147 | else | |
ef0b5f1c | 2148 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2149 | break; |
2150 | ||
2151 | case DW_FORM_strp: | |
2152 | if (!do_loc) | |
ef0b5f1c | 2153 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, |
47704ddf KT |
2154 | dwarf_vmatoa ("x", uvalue), |
2155 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
2156 | break; |
2157 | ||
77145576 JK |
2158 | case DW_FORM_line_strp: |
2159 | if (!do_loc) | |
2160 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2161 | dwarf_vmatoa ("x", uvalue), | |
2162 | fetch_indirect_line_string (uvalue)); | |
2163 | break; | |
2164 | ||
4723351a CC |
2165 | case DW_FORM_GNU_str_index: |
2166 | if (!do_loc) | |
b4eb7656 | 2167 | { |
d85bf2ba NC |
2168 | const char * suffix = strrchr (section->name, '.'); |
2169 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
b4eb7656 | 2170 | |
ef0b5f1c | 2171 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2172 | dwarf_vmatoa ("x", uvalue), |
2173 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2174 | } | |
4723351a CC |
2175 | break; |
2176 | ||
a081f3cd JJ |
2177 | case DW_FORM_GNU_strp_alt: |
2178 | if (!do_loc) | |
dda8d76d NC |
2179 | { |
2180 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2181 | dwarf_vmatoa ("x", uvalue), | |
2182 | fetch_alt_indirect_string (uvalue)); | |
2183 | } | |
a081f3cd JJ |
2184 | break; |
2185 | ||
19e6b90e L |
2186 | case DW_FORM_indirect: |
2187 | /* Handled above. */ | |
2188 | break; | |
2189 | ||
2b6f5997 CC |
2190 | case DW_FORM_ref_sig8: |
2191 | if (!do_loc) | |
2192 | { | |
74bc6052 CC |
2193 | dwarf_vma high_bits; |
2194 | char buf[64]; | |
2195 | ||
0c588247 | 2196 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
ef0b5f1c | 2197 | printf ("%csignature: 0x%s", delimiter, |
74bc6052 | 2198 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); |
2b6f5997 | 2199 | } |
74bc6052 | 2200 | data += 8; |
2b6f5997 CC |
2201 | break; |
2202 | ||
4723351a CC |
2203 | case DW_FORM_GNU_addr_index: |
2204 | if (!do_loc) | |
ef0b5f1c | 2205 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2206 | dwarf_vmatoa ("x", uvalue), |
2207 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
4723351a CC |
2208 | break; |
2209 | ||
19e6b90e L |
2210 | default: |
2211 | warn (_("Unrecognized form: %lu\n"), form); | |
2212 | break; | |
2213 | } | |
2214 | ||
19e6b90e | 2215 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2216 | && num_debug_info_entries == 0 |
2217 | && debug_info_p != NULL) | |
19e6b90e L |
2218 | { |
2219 | switch (attribute) | |
2220 | { | |
2221 | case DW_AT_frame_base: | |
2222 | have_frame_base = 1; | |
1a0670f3 | 2223 | /* Fall through. */ |
19e6b90e | 2224 | case DW_AT_location: |
9f272209 | 2225 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2226 | case DW_AT_string_length: |
2227 | case DW_AT_return_addr: | |
19e6b90e L |
2228 | case DW_AT_data_member_location: |
2229 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2230 | case DW_AT_segment: |
2231 | case DW_AT_static_link: | |
2232 | case DW_AT_use_location: | |
bc0a77d2 | 2233 | case DW_AT_call_value: |
629e7ca8 | 2234 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2235 | case DW_AT_call_data_value: |
629e7ca8 | 2236 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2237 | case DW_AT_call_target: |
629e7ca8 | 2238 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2239 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2240 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2241 | if ((dwarf_version < 4 |
212b6063 | 2242 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2243 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2244 | { |
2245 | /* Process location list. */ | |
91d6fa6a | 2246 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2247 | unsigned int num = debug_info_p->num_loc_offsets; |
2248 | ||
91d6fa6a | 2249 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2250 | { |
91d6fa6a | 2251 | lmax += 1024; |
467c65bc | 2252 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2253 | xcrealloc (debug_info_p->loc_offsets, |
2254 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2255 | debug_info_p->loc_views = (dwarf_vma *) |
2256 | xcrealloc (debug_info_p->loc_views, | |
2257 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2258 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2259 | xcrealloc (debug_info_p->have_frame_base, |
2260 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2261 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2262 | } |
341f9135 | 2263 | if (this_set != NULL) |
b4eb7656 | 2264 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2265 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2266 | if (attribute != DW_AT_GNU_locviews) |
2267 | { | |
a7504f87 NC |
2268 | /* Corrupt DWARF info can produce more offsets than views. |
2269 | See PR 23062 for an example. */ | |
2270 | if (debug_info_p->num_loc_offsets | |
2271 | > debug_info_p->num_loc_views) | |
2272 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2273 | else | |
2274 | { | |
2275 | debug_info_p->loc_offsets [num] = uvalue; | |
2276 | debug_info_p->num_loc_offsets++; | |
2277 | } | |
9f272209 AO |
2278 | } |
2279 | else | |
2280 | { | |
2281 | assert (debug_info_p->num_loc_views <= num); | |
2282 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2283 | if (num > debug_info_p->num_loc_offsets) |
2284 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2285 | else | |
2286 | { | |
2287 | debug_info_p->loc_views [num] = uvalue; | |
2288 | debug_info_p->num_loc_views++; | |
2289 | } | |
9f272209 | 2290 | } |
19e6b90e L |
2291 | } |
2292 | break; | |
e2a0d921 | 2293 | |
19e6b90e L |
2294 | case DW_AT_low_pc: |
2295 | if (need_base_address) | |
2296 | debug_info_p->base_address = uvalue; | |
2297 | break; | |
2298 | ||
4723351a | 2299 | case DW_AT_GNU_addr_base: |
b4eb7656 | 2300 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2301 | break; |
2302 | ||
2303 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2304 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2305 | break; |
2306 | ||
19e6b90e | 2307 | case DW_AT_ranges: |
b4eb7656 | 2308 | if ((dwarf_version < 4 |
212b6063 | 2309 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2310 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2311 | { |
2312 | /* Process range list. */ | |
91d6fa6a | 2313 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2314 | unsigned int num = debug_info_p->num_range_lists; |
2315 | ||
91d6fa6a | 2316 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2317 | { |
91d6fa6a | 2318 | lmax += 1024; |
467c65bc | 2319 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2320 | xcrealloc (debug_info_p->range_lists, |
2321 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2322 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2323 | } |
2324 | debug_info_p->range_lists [num] = uvalue; | |
2325 | debug_info_p->num_range_lists++; | |
2326 | } | |
2327 | break; | |
2328 | ||
d85bf2ba NC |
2329 | case DW_AT_GNU_dwo_name: |
2330 | case DW_AT_dwo_name: | |
2331 | if (need_dwo_info) | |
2332 | switch (form) | |
2333 | { | |
2334 | case DW_FORM_strp: | |
24841daa | 2335 | add_dwo_name ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba NC |
2336 | break; |
2337 | case DW_FORM_GNU_str_index: | |
24841daa | 2338 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2339 | break; |
2340 | case DW_FORM_string: | |
24841daa | 2341 | add_dwo_name ((const char *) orig_data); |
d85bf2ba NC |
2342 | break; |
2343 | default: | |
2344 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2345 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2346 | break; |
2347 | } | |
2348 | break; | |
2349 | ||
2350 | case DW_AT_comp_dir: | |
2351 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2352 | if (need_dwo_info) | |
2353 | switch (form) | |
2354 | { | |
2355 | case DW_FORM_strp: | |
24841daa | 2356 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba NC |
2357 | break; |
2358 | case DW_FORM_line_strp: | |
24841daa | 2359 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue)); |
d85bf2ba NC |
2360 | break; |
2361 | case DW_FORM_GNU_str_index: | |
24841daa | 2362 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2363 | break; |
2364 | case DW_FORM_string: | |
24841daa | 2365 | add_dwo_dir ((const char *) orig_data); |
d85bf2ba NC |
2366 | break; |
2367 | default: | |
2368 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2369 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2370 | break; |
2371 | } | |
2372 | break; | |
2373 | ||
2374 | case DW_AT_GNU_dwo_id: | |
2375 | if (need_dwo_info) | |
2376 | switch (form) | |
2377 | { | |
2378 | case DW_FORM_data8: | |
24841daa NC |
2379 | /* FIXME: Record the length of the ID as well ? */ |
2380 | add_dwo_id ((const char *) (data - 8)); | |
d85bf2ba NC |
2381 | break; |
2382 | default: | |
2383 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2384 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2385 | break; |
2386 | } | |
2387 | break; | |
2388 | ||
19e6b90e L |
2389 | default: |
2390 | break; | |
2391 | } | |
2392 | } | |
2393 | ||
4ccf1e31 | 2394 | if (do_loc || attribute == 0) |
19e6b90e L |
2395 | return data; |
2396 | ||
ec4d4525 | 2397 | /* For some attributes we can display further information. */ |
19e6b90e L |
2398 | switch (attribute) |
2399 | { | |
2400 | case DW_AT_inline: | |
2e9e81a8 | 2401 | printf ("\t"); |
19e6b90e L |
2402 | switch (uvalue) |
2403 | { | |
2404 | case DW_INL_not_inlined: | |
2405 | printf (_("(not inlined)")); | |
2406 | break; | |
2407 | case DW_INL_inlined: | |
2408 | printf (_("(inlined)")); | |
2409 | break; | |
2410 | case DW_INL_declared_not_inlined: | |
2411 | printf (_("(declared as inline but ignored)")); | |
2412 | break; | |
2413 | case DW_INL_declared_inlined: | |
2414 | printf (_("(declared as inline and inlined)")); | |
2415 | break; | |
2416 | default: | |
47704ddf KT |
2417 | printf (_(" (Unknown inline attribute value: %s)"), |
2418 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2419 | break; |
2420 | } | |
2421 | break; | |
2422 | ||
2423 | case DW_AT_language: | |
2e9e81a8 | 2424 | printf ("\t"); |
19e6b90e L |
2425 | switch (uvalue) |
2426 | { | |
4b78141a | 2427 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 2428 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
2429 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
2430 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 2431 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
2432 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
2433 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
2434 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
2435 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 2436 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 2437 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 2438 | /* DWARF 2.1 values. */ |
4b78141a | 2439 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
2440 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
2441 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
2442 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
2443 | /* DWARF 3 values. */ |
2444 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
2445 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
2446 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
2447 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
2448 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
2449 | /* DWARF 4 values. */ |
2450 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 2451 | /* DWARF 5 values. */ |
2008a0db | 2452 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 2453 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
2454 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
2455 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
2456 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 2457 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
2458 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
2459 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 2460 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
2461 | case DW_LANG_Swift: printf ("(Swift)"); break; |
2462 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
2463 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 2464 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
2465 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
2466 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 2467 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
2468 | /* MIPS extension. */ |
2469 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
2470 | /* UPC extension. */ | |
2471 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
2472 | default: | |
4b78141a | 2473 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 2474 | printf (_("(implementation defined: %s)"), |
467c65bc | 2475 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 2476 | else |
9cf03b7e | 2477 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2478 | break; |
2479 | } | |
2480 | break; | |
2481 | ||
2482 | case DW_AT_encoding: | |
2e9e81a8 | 2483 | printf ("\t"); |
19e6b90e L |
2484 | switch (uvalue) |
2485 | { | |
2486 | case DW_ATE_void: printf ("(void)"); break; | |
2487 | case DW_ATE_address: printf ("(machine address)"); break; | |
2488 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
2489 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
2490 | case DW_ATE_float: printf ("(float)"); break; | |
2491 | case DW_ATE_signed: printf ("(signed)"); break; | |
2492 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
2493 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
2494 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 2495 | /* DWARF 2.1 values: */ |
19e6b90e L |
2496 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
2497 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
2498 | /* DWARF 3 values: */ |
2499 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
2500 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
2501 | case DW_ATE_edited: printf ("(edited)"); break; | |
2502 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
2503 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
2504 | /* DWARF 4 values: */ |
2505 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
2506 | /* DWARF 5 values: */ | |
2507 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
2508 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
2509 | ||
e2a0d921 NC |
2510 | /* HP extensions: */ |
2511 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
2512 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
2513 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
2514 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
2515 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
2516 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
2517 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
2518 | ||
19e6b90e L |
2519 | default: |
2520 | if (uvalue >= DW_ATE_lo_user | |
2521 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 2522 | printf (_("(user defined type)")); |
19e6b90e | 2523 | else |
9cf03b7e | 2524 | printf (_("(unknown type)")); |
19e6b90e L |
2525 | break; |
2526 | } | |
2527 | break; | |
2528 | ||
2529 | case DW_AT_accessibility: | |
2e9e81a8 | 2530 | printf ("\t"); |
19e6b90e L |
2531 | switch (uvalue) |
2532 | { | |
2533 | case DW_ACCESS_public: printf ("(public)"); break; | |
2534 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
2535 | case DW_ACCESS_private: printf ("(private)"); break; | |
2536 | default: | |
9cf03b7e | 2537 | printf (_("(unknown accessibility)")); |
19e6b90e L |
2538 | break; |
2539 | } | |
2540 | break; | |
2541 | ||
2542 | case DW_AT_visibility: | |
2e9e81a8 | 2543 | printf ("\t"); |
19e6b90e L |
2544 | switch (uvalue) |
2545 | { | |
2546 | case DW_VIS_local: printf ("(local)"); break; | |
2547 | case DW_VIS_exported: printf ("(exported)"); break; | |
2548 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 2549 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
2550 | } |
2551 | break; | |
2552 | ||
04914e37 NC |
2553 | case DW_AT_endianity: |
2554 | printf ("\t"); | |
2555 | switch (uvalue) | |
2556 | { | |
2557 | case DW_END_default: printf ("(default)"); break; | |
2558 | case DW_END_big: printf ("(big)"); break; | |
2559 | case DW_END_little: printf ("(little)"); break; | |
2560 | default: | |
2561 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
2562 | printf (_("(user specified)")); | |
2563 | else | |
2564 | printf (_("(unknown endianity)")); | |
2565 | break; | |
2566 | } | |
2567 | break; | |
2568 | ||
19e6b90e | 2569 | case DW_AT_virtuality: |
2e9e81a8 | 2570 | printf ("\t"); |
19e6b90e L |
2571 | switch (uvalue) |
2572 | { | |
2573 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
2574 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
2575 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 2576 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
2577 | } |
2578 | break; | |
2579 | ||
2580 | case DW_AT_identifier_case: | |
2e9e81a8 | 2581 | printf ("\t"); |
19e6b90e L |
2582 | switch (uvalue) |
2583 | { | |
2584 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
2585 | case DW_ID_up_case: printf ("(up_case)"); break; | |
2586 | case DW_ID_down_case: printf ("(down_case)"); break; | |
2587 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 2588 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
2589 | } |
2590 | break; | |
2591 | ||
2592 | case DW_AT_calling_convention: | |
2e9e81a8 | 2593 | printf ("\t"); |
19e6b90e L |
2594 | switch (uvalue) |
2595 | { | |
2596 | case DW_CC_normal: printf ("(normal)"); break; | |
2597 | case DW_CC_program: printf ("(program)"); break; | |
2598 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
2599 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
2600 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
2601 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
2602 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
2603 | default: |
2604 | if (uvalue >= DW_CC_lo_user | |
2605 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 2606 | printf (_("(user defined)")); |
19e6b90e | 2607 | else |
9cf03b7e | 2608 | printf (_("(unknown convention)")); |
19e6b90e L |
2609 | } |
2610 | break; | |
2611 | ||
2612 | case DW_AT_ordering: | |
2e9e81a8 | 2613 | printf ("\t"); |
19e6b90e L |
2614 | switch (uvalue) |
2615 | { | |
04914e37 | 2616 | case 255: |
9cf03b7e | 2617 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
2618 | case 0: printf ("(row major)"); break; |
2619 | case 1: printf ("(column major)"); break; | |
2620 | } | |
2621 | break; | |
2622 | ||
04914e37 NC |
2623 | case DW_AT_decimal_sign: |
2624 | printf ("\t"); | |
2625 | switch (uvalue) | |
2626 | { | |
2627 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
2628 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
2629 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
2630 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
2631 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
2632 | default: printf (_("(unrecognised)")); break; | |
2633 | } | |
2634 | break; | |
2635 | ||
2636 | case DW_AT_defaulted: | |
2637 | printf ("\t"); | |
2638 | switch (uvalue) | |
2639 | { | |
2640 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
2641 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
2642 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
2643 | default: printf (_("(unrecognised)")); break; | |
2644 | } | |
2645 | break; | |
2646 | ||
2647 | case DW_AT_discr_list: | |
2648 | printf ("\t"); | |
2649 | switch (uvalue) | |
2650 | { | |
2651 | case DW_DSC_label: printf (_("(label)")); break; | |
2652 | case DW_DSC_range: printf (_("(range)")); break; | |
2653 | default: printf (_("(unrecognised)")); break; | |
2654 | } | |
2655 | break; | |
2656 | ||
19e6b90e L |
2657 | case DW_AT_frame_base: |
2658 | have_frame_base = 1; | |
1a0670f3 | 2659 | /* Fall through. */ |
19e6b90e | 2660 | case DW_AT_location: |
e2a0d921 NC |
2661 | case DW_AT_string_length: |
2662 | case DW_AT_return_addr: | |
19e6b90e L |
2663 | case DW_AT_data_member_location: |
2664 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2665 | case DW_AT_segment: |
2666 | case DW_AT_static_link: | |
2667 | case DW_AT_use_location: | |
bc0a77d2 | 2668 | case DW_AT_call_value: |
629e7ca8 | 2669 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2670 | case DW_AT_call_data_value: |
629e7ca8 | 2671 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2672 | case DW_AT_call_target: |
629e7ca8 | 2673 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2674 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2675 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 2676 | if ((dwarf_version < 4 |
b4eb7656 | 2677 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2678 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 2679 | printf (_(" (location list)")); |
e2a0d921 | 2680 | /* Fall through. */ |
19e6b90e L |
2681 | case DW_AT_allocated: |
2682 | case DW_AT_associated: | |
2683 | case DW_AT_data_location: | |
2684 | case DW_AT_stride: | |
2685 | case DW_AT_upper_bound: | |
cecf136e | 2686 | case DW_AT_lower_bound: |
19e6b90e L |
2687 | if (block_start) |
2688 | { | |
2689 | int need_frame_base; | |
2690 | ||
2e9e81a8 | 2691 | printf ("\t("); |
19e6b90e L |
2692 | need_frame_base = decode_location_expression (block_start, |
2693 | pointer_size, | |
b7807392 JJ |
2694 | offset_size, |
2695 | dwarf_version, | |
19e6b90e | 2696 | uvalue, |
f1c4cc75 | 2697 | cu_offset, section); |
19e6b90e L |
2698 | printf (")"); |
2699 | if (need_frame_base && !have_frame_base) | |
2700 | printf (_(" [without DW_AT_frame_base]")); | |
2701 | } | |
19e6b90e L |
2702 | break; |
2703 | ||
c54207d3 NC |
2704 | case DW_AT_data_bit_offset: |
2705 | case DW_AT_byte_size: | |
2706 | case DW_AT_bit_size: | |
2707 | case DW_AT_string_length_byte_size: | |
2708 | case DW_AT_string_length_bit_size: | |
2709 | case DW_AT_bit_stride: | |
2710 | if (form == DW_FORM_exprloc) | |
2711 | { | |
2712 | printf ("\t("); | |
2713 | (void) decode_location_expression (block_start, pointer_size, | |
2714 | offset_size, dwarf_version, | |
2715 | uvalue, cu_offset, section); | |
2716 | printf (")"); | |
2717 | } | |
2718 | break; | |
2719 | ||
ec4d4525 NC |
2720 | case DW_AT_import: |
2721 | { | |
a081f3cd JJ |
2722 | if (form == DW_FORM_ref_sig8 |
2723 | || form == DW_FORM_GNU_ref_alt) | |
b4eb7656 | 2724 | break; |
2b6f5997 | 2725 | |
ec4d4525 NC |
2726 | if (form == DW_FORM_ref1 |
2727 | || form == DW_FORM_ref2 | |
a7a0b6a5 JK |
2728 | || form == DW_FORM_ref4 |
2729 | || form == DW_FORM_ref_udata) | |
ec4d4525 NC |
2730 | uvalue += cu_offset; |
2731 | ||
6e3d6dc1 | 2732 | if (uvalue >= section->size) |
f3853b34 | 2733 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
47704ddf KT |
2734 | dwarf_vmatoa ("x", uvalue), |
2735 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
2736 | else |
2737 | { | |
2738 | unsigned long abbrev_number; | |
2739 | abbrev_entry * entry; | |
2740 | ||
f6f0e17b | 2741 | abbrev_number = read_uleb128 (section->start + uvalue, NULL, end); |
cecf136e | 2742 | |
2e9e81a8 | 2743 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
afd6e1ff JJ |
2744 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
2745 | use different abbrev table, and we don't track .debug_info chunks | |
2746 | yet. */ | |
2747 | if (form != DW_FORM_ref_addr) | |
2748 | { | |
2749 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
2750 | if (entry->entry == abbrev_number) | |
2751 | break; | |
2752 | if (entry != NULL) | |
2753 | printf (" (%s)", get_TAG_name (entry->tag)); | |
2754 | } | |
6e3d6dc1 NC |
2755 | printf ("]"); |
2756 | } | |
ec4d4525 NC |
2757 | } |
2758 | break; | |
2759 | ||
19e6b90e L |
2760 | default: |
2761 | break; | |
2762 | } | |
2763 | ||
2764 | return data; | |
2765 | } | |
2766 | ||
19e6b90e | 2767 | static unsigned char * |
dda8d76d NC |
2768 | read_and_display_attr (unsigned long attribute, |
2769 | unsigned long form, | |
2770 | dwarf_signed_vma implicit_const, | |
2771 | unsigned char * data, | |
2772 | unsigned char * end, | |
2773 | dwarf_vma cu_offset, | |
2774 | dwarf_vma pointer_size, | |
2775 | dwarf_vma offset_size, | |
2776 | int dwarf_version, | |
2777 | debug_info * debug_info_p, | |
2778 | int do_loc, | |
2779 | struct dwarf_section * section, | |
2780 | struct cu_tu_set * this_set) | |
19e6b90e L |
2781 | { |
2782 | if (!do_loc) | |
750f03b7 | 2783 | printf (" %-18s:", get_AT_name (attribute)); |
77145576 | 2784 | data = read_and_display_attr_value (attribute, form, implicit_const, data, end, |
f6f0e17b | 2785 | cu_offset, pointer_size, offset_size, |
19e6b90e | 2786 | dwarf_version, debug_info_p, |
ef0b5f1c | 2787 | do_loc, section, this_set, ' '); |
19e6b90e L |
2788 | if (!do_loc) |
2789 | printf ("\n"); | |
2790 | return data; | |
2791 | } | |
2792 | ||
dda8d76d | 2793 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
2794 | following debug links, then attempt to load the requested section |
2795 | from one of the separate debug info files. */ | |
dda8d76d NC |
2796 | |
2797 | static bfd_boolean | |
2798 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, | |
24841daa | 2799 | void * handle) |
dda8d76d | 2800 | { |
24841daa | 2801 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 2802 | { |
24841daa NC |
2803 | if (debug_displays[sec_enum].section.filename == NULL) |
2804 | { | |
2805 | /* See if we can associate a filename with this section. */ | |
2806 | separate_info * i; | |
2807 | ||
2808 | for (i = first_separate_info; i != NULL; i = i->next) | |
2809 | if (i->handle == handle) | |
2810 | { | |
2811 | debug_displays[sec_enum].section.filename = i->filename; | |
2812 | break; | |
2813 | } | |
2814 | } | |
2815 | ||
dda8d76d NC |
2816 | return TRUE; |
2817 | } | |
2818 | ||
24841daa NC |
2819 | if (do_follow_links) |
2820 | { | |
2821 | separate_info * i; | |
2822 | ||
2823 | for (i = first_separate_info; i != NULL; i = i->next) | |
2824 | { | |
2825 | if (load_debug_section (sec_enum, i->handle)) | |
2826 | { | |
2827 | debug_displays[sec_enum].section.filename = i->filename; | |
2828 | ||
2829 | /* FIXME: We should check to see if any of the remaining debug info | |
2830 | files also contain this section, and, umm, do something about it. */ | |
2831 | return TRUE; | |
2832 | } | |
2833 | } | |
2834 | } | |
dda8d76d NC |
2835 | |
2836 | return FALSE; | |
2837 | } | |
2838 | ||
2839 | static void | |
2840 | introduce (struct dwarf_section * section, bfd_boolean raw) | |
2841 | { | |
2842 | if (raw) | |
2843 | { | |
2844 | if (do_follow_links && section->filename) | |
2845 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
2846 | section->name, section->filename); | |
2847 | else | |
2848 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
2849 | } | |
2850 | else | |
2851 | { | |
2852 | if (do_follow_links && section->filename) | |
2853 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
2854 | section->name, section->filename); | |
2855 | else | |
2856 | printf (_("Contents of the %s section:\n\n"), section->name); | |
2857 | } | |
2858 | } | |
2859 | ||
d85bf2ba NC |
2860 | /* Process the contents of a .debug_info section. |
2861 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
2862 | and we do not want to display anything to the user. | |
2863 | If do_types is TRUE, we are processing a .debug_types section instead of | |
2864 | a .debug_info section. | |
2865 | The information displayed is restricted by the values in DWARF_START_DIE | |
2866 | and DWARF_CUTOFF_LEVEL. | |
2867 | Returns TRUE upon success. Otherwise an error or warning message is | |
2868 | printed and FALSE is returned. */ | |
19e6b90e | 2869 | |
d85bf2ba NC |
2870 | static bfd_boolean |
2871 | process_debug_info (struct dwarf_section * section, | |
2872 | void * file, | |
2873 | enum dwarf_section_display_enum abbrev_sec, | |
2874 | bfd_boolean do_loc, | |
2875 | bfd_boolean do_types) | |
19e6b90e L |
2876 | { |
2877 | unsigned char *start = section->start; | |
2878 | unsigned char *end = start + section->size; | |
2879 | unsigned char *section_begin; | |
2880 | unsigned int unit; | |
2881 | unsigned int num_units = 0; | |
2882 | ||
2883 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
2884 | && num_debug_info_entries == 0 |
2885 | && ! do_types) | |
19e6b90e | 2886 | { |
767221a9 | 2887 | dwarf_vma length; |
19e6b90e L |
2888 | |
2889 | /* First scan the section to get the number of comp units. */ | |
2890 | for (section_begin = start, num_units = 0; section_begin < end; | |
2891 | num_units ++) | |
2892 | { | |
2893 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
2894 | will be the length. For a 64-bit DWARF section, it'll be | |
2895 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 2896 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
2897 | |
2898 | if (length == 0xffffffff) | |
2899 | { | |
0c588247 | 2900 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
2901 | section_begin += length + 12; |
2902 | } | |
ec4d4525 NC |
2903 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
2904 | { | |
767221a9 NC |
2905 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
2906 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 2907 | return FALSE; |
ec4d4525 | 2908 | } |
19e6b90e L |
2909 | else |
2910 | section_begin += length + 4; | |
aca88567 NC |
2911 | |
2912 | /* Negative values are illegal, they may even cause infinite | |
2913 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
2914 | relocations to an object file, or if the file is corrupt. */ |
2915 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 2916 | { |
767221a9 NC |
2917 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
2918 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 2919 | return FALSE; |
aca88567 | 2920 | } |
19e6b90e L |
2921 | } |
2922 | ||
2923 | if (num_units == 0) | |
2924 | { | |
f41e4712 | 2925 | error (_("No comp units in %s section ?\n"), section->name); |
d85bf2ba | 2926 | return FALSE; |
19e6b90e L |
2927 | } |
2928 | ||
2929 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 2930 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 2931 | sizeof (* debug_information)); |
19e6b90e L |
2932 | if (debug_information == NULL) |
2933 | { | |
f41e4712 | 2934 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 2935 | num_units); |
82b1b41b | 2936 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
d85bf2ba | 2937 | return FALSE; |
19e6b90e | 2938 | } |
d85bf2ba | 2939 | |
03a91817 NC |
2940 | /* PR 17531: file: 92ca3797. |
2941 | We cannot rely upon the debug_information array being initialised | |
2942 | before it is used. A corrupt file could easily contain references | |
2943 | to a unit for which information has not been made available. So | |
2944 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
2945 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
2946 | ||
82b1b41b | 2947 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
2948 | } |
2949 | ||
2950 | if (!do_loc) | |
2951 | { | |
dda8d76d NC |
2952 | load_debug_section_with_follow (str, file); |
2953 | load_debug_section_with_follow (line_str, file); | |
2954 | load_debug_section_with_follow (str_dwo, file); | |
2955 | load_debug_section_with_follow (str_index, file); | |
2956 | load_debug_section_with_follow (str_index_dwo, file); | |
2957 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e L |
2958 | } |
2959 | ||
dda8d76d | 2960 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 2961 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
2962 | { |
2963 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 2964 | debug_displays [abbrev_sec].section.uncompressed_name); |
d85bf2ba | 2965 | return FALSE; |
19e6b90e L |
2966 | } |
2967 | ||
dda8d76d NC |
2968 | if (!do_loc && dwarf_start_die == 0) |
2969 | introduce (section, FALSE); | |
2970 | ||
19e6b90e L |
2971 | for (section_begin = start, unit = 0; start < end; unit++) |
2972 | { | |
2973 | DWARF2_Internal_CompUnit compunit; | |
2974 | unsigned char *hdrptr; | |
19e6b90e | 2975 | unsigned char *tags; |
fd2f0033 | 2976 | int level, last_level, saved_level; |
467c65bc | 2977 | dwarf_vma cu_offset; |
e98fdf1a | 2978 | unsigned long sec_off; |
bf5117e3 | 2979 | unsigned int offset_size; |
19485196 | 2980 | unsigned int initial_length_size; |
74bc6052 CC |
2981 | dwarf_vma signature_high = 0; |
2982 | dwarf_vma signature_low = 0; | |
767221a9 | 2983 | dwarf_vma type_offset = 0; |
341f9135 CC |
2984 | struct cu_tu_set *this_set; |
2985 | dwarf_vma abbrev_base; | |
2986 | size_t abbrev_size; | |
19e6b90e L |
2987 | |
2988 | hdrptr = start; | |
2989 | ||
0c588247 | 2990 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
2991 | |
2992 | if (compunit.cu_length == 0xffffffff) | |
2993 | { | |
0c588247 | 2994 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
2995 | offset_size = 8; |
2996 | initial_length_size = 12; | |
2997 | } | |
2998 | else | |
2999 | { | |
3000 | offset_size = 4; | |
3001 | initial_length_size = 4; | |
3002 | } | |
3003 | ||
0c588247 | 3004 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
3005 | |
3006 | cu_offset = start - section_begin; | |
19e6b90e | 3007 | |
341f9135 CC |
3008 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3009 | ||
77145576 JK |
3010 | if (compunit.cu_version < 5) |
3011 | { | |
3012 | compunit.cu_unit_type = DW_UT_compile; | |
3013 | /* Initialize it due to a false compiler warning. */ | |
3014 | compunit.cu_pointer_size = -1; | |
3015 | } | |
3016 | else | |
3017 | { | |
3018 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3019 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3020 | ||
3021 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3022 | } | |
3023 | ||
0c588247 | 3024 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 3025 | |
341f9135 CC |
3026 | if (this_set == NULL) |
3027 | { | |
3028 | abbrev_base = 0; | |
3029 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3030 | } | |
3031 | else | |
3032 | { | |
3033 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3034 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3035 | } | |
3036 | ||
77145576 JK |
3037 | if (compunit.cu_version < 5) |
3038 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3039 | ||
f41e4712 NC |
3040 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3041 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3042 | { | |
3043 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3044 | compunit.cu_pointer_size, offset_size); | |
3045 | compunit.cu_pointer_size = offset_size; | |
3046 | } | |
2b6f5997 CC |
3047 | |
3048 | if (do_types) | |
b4eb7656 | 3049 | { |
0c588247 | 3050 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 3051 | hdrptr += 8; |
0c588247 | 3052 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 3053 | } |
2b6f5997 | 3054 | |
ae7e7825 NC |
3055 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
3056 | + initial_length_size)) | |
3057 | { | |
3058 | start = section_begin + cu_offset + compunit.cu_length | |
3059 | + initial_length_size; | |
3060 | continue; | |
3061 | } | |
3062 | ||
19e6b90e | 3063 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 CC |
3064 | && num_debug_info_entries == 0 |
3065 | && ! do_types) | |
19e6b90e L |
3066 | { |
3067 | debug_information [unit].cu_offset = cu_offset; | |
3068 | debug_information [unit].pointer_size | |
3069 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3070 | debug_information [unit].offset_size = offset_size; |
3071 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3072 | debug_information [unit].base_address = 0; |
4723351a CC |
3073 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3074 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3075 | debug_information [unit].loc_offsets = NULL; |
3076 | debug_information [unit].have_frame_base = NULL; | |
3077 | debug_information [unit].max_loc_offsets = 0; | |
3078 | debug_information [unit].num_loc_offsets = 0; | |
3079 | debug_information [unit].range_lists = NULL; | |
3080 | debug_information [unit].max_range_lists= 0; | |
3081 | debug_information [unit].num_range_lists = 0; | |
3082 | } | |
3083 | ||
fd2f0033 | 3084 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3085 | { |
47704ddf KT |
3086 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3087 | dwarf_vmatoa ("x", cu_offset)); | |
3088 | printf (_(" Length: 0x%s (%s)\n"), | |
3089 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3090 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3091 | printf (_(" Version: %d\n"), compunit.cu_version); |
7282333f AM |
3092 | printf (_(" Abbrev Offset: 0x%s\n"), |
3093 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3094 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3095 | if (do_types) |
3096 | { | |
74bc6052 CC |
3097 | char buf[64]; |
3098 | ||
3099 | printf (_(" Signature: 0x%s\n"), | |
3100 | dwarf_vmatoa64 (signature_high, signature_low, | |
3101 | buf, sizeof (buf))); | |
3102 | printf (_(" Type Offset: 0x%s\n"), | |
3103 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3104 | } |
341f9135 CC |
3105 | if (this_set != NULL) |
3106 | { | |
3107 | dwarf_vma *offsets = this_set->section_offsets; | |
3108 | size_t *sizes = this_set->section_sizes; | |
3109 | ||
3110 | printf (_(" Section contributions:\n")); | |
3111 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3112 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3113 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3114 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3115 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3116 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3117 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3118 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3119 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3120 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3121 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3122 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3123 | } | |
19e6b90e L |
3124 | } |
3125 | ||
e98fdf1a AM |
3126 | sec_off = cu_offset + initial_length_size; |
3127 | if (sec_off + compunit.cu_length < sec_off | |
3128 | || sec_off + compunit.cu_length > section->size) | |
460c89ff | 3129 | { |
e98fdf1a AM |
3130 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
3131 | section->name, | |
3132 | (unsigned long) cu_offset, | |
19485196 NC |
3133 | dwarf_vmatoa ("x", compunit.cu_length)); |
3134 | num_units = unit; | |
3135 | break; | |
3136 | } | |
3137 | ||
460c89ff NS |
3138 | tags = hdrptr; |
3139 | start += compunit.cu_length + initial_length_size; | |
3140 | ||
77145576 | 3141 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3142 | { |
47704ddf KT |
3143 | warn (_("CU at offset %s contains corrupt or " |
3144 | "unsupported version number: %d.\n"), | |
3145 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3146 | continue; |
3147 | } | |
3148 | ||
77145576 JK |
3149 | if (compunit.cu_unit_type != DW_UT_compile |
3150 | && compunit.cu_unit_type != DW_UT_type) | |
3151 | { | |
3152 | warn (_("CU at offset %s contains corrupt or " | |
3153 | "unsupported unit type: %d.\n"), | |
3154 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3155 | continue; | |
3156 | } | |
3157 | ||
19e6b90e L |
3158 | free_abbrevs (); |
3159 | ||
d493b283 | 3160 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 3161 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
3162 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
3163 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 3164 | (unsigned long) abbrev_size); |
b4eb7656 | 3165 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
3166 | else if ((abbrev_base + abbrev_size) |
3167 | > debug_displays [abbrev_sec].section.size) | |
3168 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
3169 | (unsigned long) abbrev_base + abbrev_size, | |
3170 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff NS |
3171 | else |
3172 | process_abbrev_section | |
341f9135 CC |
3173 | (((unsigned char *) debug_displays [abbrev_sec].section.start |
3174 | + abbrev_base + compunit.cu_abbrev_offset), | |
3175 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3176 | + abbrev_base + abbrev_size)); | |
19e6b90e L |
3177 | |
3178 | level = 0; | |
fd2f0033 TT |
3179 | last_level = level; |
3180 | saved_level = -1; | |
19e6b90e L |
3181 | while (tags < start) |
3182 | { | |
3183 | unsigned int bytes_read; | |
3184 | unsigned long abbrev_number; | |
ec4d4525 | 3185 | unsigned long die_offset; |
19e6b90e L |
3186 | abbrev_entry *entry; |
3187 | abbrev_attr *attr; | |
fd2f0033 | 3188 | int do_printing = 1; |
19e6b90e | 3189 | |
ec4d4525 NC |
3190 | die_offset = tags - section_begin; |
3191 | ||
f6f0e17b | 3192 | abbrev_number = read_uleb128 (tags, & bytes_read, start); |
19e6b90e L |
3193 | tags += bytes_read; |
3194 | ||
eb7cc021 JK |
3195 | /* A null DIE marks the end of a list of siblings or it may also be |
3196 | a section padding. */ | |
19e6b90e L |
3197 | if (abbrev_number == 0) |
3198 | { | |
eb7cc021 JK |
3199 | /* Check if it can be a section padding for the last CU. */ |
3200 | if (level == 0 && start == end) | |
3201 | { | |
3202 | unsigned char *chk; | |
3203 | ||
3204 | for (chk = tags; chk < start; chk++) | |
3205 | if (*chk != 0) | |
3206 | break; | |
3207 | if (chk == start) | |
3208 | break; | |
3209 | } | |
3210 | ||
4337774f TT |
3211 | if (!do_loc && die_offset >= dwarf_start_die |
3212 | && (dwarf_cutoff_level == -1 | |
3213 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3214 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3215 | level, die_offset); | |
3216 | ||
19e6b90e | 3217 | --level; |
ec4d4525 NC |
3218 | if (level < 0) |
3219 | { | |
3220 | static unsigned num_bogus_warns = 0; | |
3221 | ||
3222 | if (num_bogus_warns < 3) | |
3223 | { | |
4723351a CC |
3224 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3225 | die_offset, section->name); | |
ec4d4525 NC |
3226 | num_bogus_warns ++; |
3227 | if (num_bogus_warns == 3) | |
3228 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3229 | } | |
3230 | } | |
fd2f0033 | 3231 | if (dwarf_start_die != 0 && level < saved_level) |
d85bf2ba | 3232 | return TRUE; |
19e6b90e L |
3233 | continue; |
3234 | } | |
3235 | ||
4b78141a | 3236 | if (!do_loc) |
fd2f0033 TT |
3237 | { |
3238 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3239 | do_printing = 0; | |
3240 | else | |
3241 | { | |
3242 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3243 | saved_level = level; | |
3244 | do_printing = (dwarf_cutoff_level == -1 | |
3245 | || level < dwarf_cutoff_level); | |
3246 | if (do_printing) | |
3247 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
3248 | level, die_offset, abbrev_number); | |
3249 | else if (dwarf_cutoff_level == -1 | |
3250 | || last_level < dwarf_cutoff_level) | |
3251 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
3252 | last_level = level; | |
3253 | } | |
3254 | } | |
cecf136e | 3255 | |
19e6b90e L |
3256 | /* Scan through the abbreviation list until we reach the |
3257 | correct entry. */ | |
3258 | for (entry = first_abbrev; | |
3259 | entry && entry->entry != abbrev_number; | |
3260 | entry = entry->next) | |
3261 | continue; | |
3262 | ||
3263 | if (entry == NULL) | |
3264 | { | |
fd2f0033 | 3265 | if (!do_loc && do_printing) |
4b78141a NC |
3266 | { |
3267 | printf ("\n"); | |
3268 | fflush (stdout); | |
3269 | } | |
f3853b34 | 3270 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 3271 | die_offset, abbrev_number); |
d85bf2ba | 3272 | return FALSE; |
19e6b90e L |
3273 | } |
3274 | ||
fd2f0033 | 3275 | if (!do_loc && do_printing) |
cc5914eb | 3276 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 3277 | |
19e6b90e L |
3278 | switch (entry->tag) |
3279 | { | |
3280 | default: | |
3281 | need_base_address = 0; | |
3282 | break; | |
3283 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
3284 | need_base_address = 1; |
3285 | need_dwo_info = do_loc; | |
19e6b90e L |
3286 | break; |
3287 | case DW_TAG_entry_point: | |
19e6b90e L |
3288 | case DW_TAG_subprogram: |
3289 | need_base_address = 0; | |
3290 | /* Assuming that there is no DW_AT_frame_base. */ | |
3291 | have_frame_base = 0; | |
3292 | break; | |
3293 | } | |
3294 | ||
9f272209 AO |
3295 | debug_info *debug_info_p = |
3296 | (debug_information && unit < alloc_num_debug_info_entries) | |
3297 | ? debug_information + unit : NULL; | |
3298 | ||
3299 | assert (!debug_info_p | |
3300 | || (debug_info_p->num_loc_offsets | |
3301 | == debug_info_p->num_loc_views)); | |
3302 | ||
399c99f7 L |
3303 | for (attr = entry->first_attr; |
3304 | attr && attr->attribute; | |
3305 | attr = attr->next) | |
4b78141a | 3306 | { |
fd2f0033 | 3307 | if (! do_loc && do_printing) |
4b78141a | 3308 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 | 3309 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
3310 | tags = read_and_display_attr (attr->attribute, |
3311 | attr->form, | |
77145576 | 3312 | attr->implicit_const, |
341f9135 | 3313 | tags, |
f6f0e17b | 3314 | end, |
341f9135 | 3315 | cu_offset, |
4b78141a NC |
3316 | compunit.cu_pointer_size, |
3317 | offset_size, | |
3318 | compunit.cu_version, | |
9f272209 | 3319 | debug_info_p, |
341f9135 CC |
3320 | do_loc || ! do_printing, |
3321 | section, | |
3322 | this_set); | |
4b78141a | 3323 | } |
cecf136e | 3324 | |
9f272209 AO |
3325 | /* If a locview attribute appears before a location one, |
3326 | make sure we don't associate it with an earlier | |
3327 | loclist. */ | |
3328 | if (debug_info_p) | |
3329 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
3330 | { | |
3331 | case 1: | |
3332 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
3333 | debug_info_p->num_loc_views++; | |
3334 | assert (debug_info_p->num_loc_views | |
3335 | == debug_info_p->num_loc_offsets); | |
3336 | break; | |
3337 | ||
3338 | case 0: | |
3339 | break; | |
3340 | ||
3341 | case -1: | |
3342 | warn(_("DIE has locviews without loclist\n")); | |
3343 | debug_info_p->num_loc_views--; | |
3344 | break; | |
3345 | ||
3346 | default: | |
3347 | assert (0); | |
3348 | } | |
3349 | ||
b4eb7656 AM |
3350 | if (entry->children) |
3351 | ++level; | |
3352 | } | |
19e6b90e | 3353 | } |
cecf136e | 3354 | |
19e6b90e L |
3355 | /* Set num_debug_info_entries here so that it can be used to check if |
3356 | we need to process .debug_loc and .debug_ranges sections. */ | |
3357 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3358 | && num_debug_info_entries == 0 |
3359 | && ! do_types) | |
82b1b41b | 3360 | { |
b4eb7656 | 3361 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
3362 | num_debug_info_entries = alloc_num_debug_info_entries; |
3363 | else | |
3364 | num_debug_info_entries = num_units; | |
3365 | } | |
cecf136e | 3366 | |
19e6b90e | 3367 | if (!do_loc) |
467c65bc | 3368 | printf ("\n"); |
cecf136e | 3369 | |
d85bf2ba | 3370 | return TRUE; |
19e6b90e L |
3371 | } |
3372 | ||
3373 | /* Locate and scan the .debug_info section in the file and record the pointer | |
3374 | sizes and offsets for the compilation units in it. Usually an executable | |
3375 | will have just one pointer size, but this is not guaranteed, and so we try | |
3376 | not to make any assumptions. Returns zero upon failure, or the number of | |
3377 | compilation units upon success. */ | |
3378 | ||
3379 | static unsigned int | |
3380 | load_debug_info (void * file) | |
3381 | { | |
1febe64d | 3382 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 3383 | section then do not bother to repeat the task. */ |
cc86f28f | 3384 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
3385 | return 0; |
3386 | ||
19e6b90e L |
3387 | /* If we already have the information there is nothing else to do. */ |
3388 | if (num_debug_info_entries > 0) | |
3389 | return num_debug_info_entries; | |
3390 | ||
341f9135 | 3391 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 3392 | (void) load_cu_tu_indexes (file); |
341f9135 | 3393 | |
dda8d76d | 3394 | if (load_debug_section_with_follow (info, file) |
d85bf2ba | 3395 | && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE)) |
19e6b90e | 3396 | return num_debug_info_entries; |
82b1b41b | 3397 | |
dda8d76d | 3398 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 3399 | && process_debug_info (&debug_displays [info_dwo].section, file, |
d85bf2ba | 3400 | abbrev_dwo, TRUE, FALSE)) |
4723351a | 3401 | return num_debug_info_entries; |
1febe64d | 3402 | |
cc86f28f | 3403 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 3404 | return 0; |
19e6b90e L |
3405 | } |
3406 | ||
b40bf0a2 NC |
3407 | /* Read a DWARF .debug_line section header starting at DATA. |
3408 | Upon success returns an updated DATA pointer and the LINFO | |
3409 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
3410 | Otherwise returns NULL. */ | |
19e6b90e | 3411 | |
b40bf0a2 NC |
3412 | static unsigned char * |
3413 | read_debug_line_header (struct dwarf_section * section, | |
3414 | unsigned char * data, | |
3415 | unsigned char * end, | |
3416 | DWARF2_Internal_LineInfo * linfo, | |
3417 | unsigned char ** end_of_sequence) | |
3418 | { | |
3419 | unsigned char *hdrptr; | |
b40bf0a2 | 3420 | unsigned int initial_length_size; |
77145576 | 3421 | unsigned char address_size, segment_selector_size; |
19e6b90e | 3422 | |
b40bf0a2 NC |
3423 | /* Extract information from the Line Number Program Header. |
3424 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 3425 | hdrptr = data; |
19e6b90e | 3426 | |
b40bf0a2 NC |
3427 | /* Get and check the length of the block. */ |
3428 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 3429 | |
b40bf0a2 | 3430 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
3431 | { |
3432 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 3433 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 3434 | linfo->li_offset_size = 8; |
f41e4712 NC |
3435 | initial_length_size = 12; |
3436 | } | |
3437 | else | |
3438 | { | |
77145576 | 3439 | linfo->li_offset_size = 4; |
f41e4712 NC |
3440 | initial_length_size = 4; |
3441 | } | |
19e6b90e | 3442 | |
b40bf0a2 | 3443 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 3444 | { |
8fcc61b4 NC |
3445 | /* If the length field has a relocation against it, then we should |
3446 | not complain if it is inaccurate (and probably negative). This | |
3447 | happens in object files when the .debug_line section is actually | |
3448 | comprised of several different .debug_line.* sections, (some of | |
3449 | which may be removed by linker garbage collection), and a relocation | |
3450 | is used to compute the correct length once that is done. */ | |
77145576 | 3451 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 3452 | { |
8fcc61b4 | 3453 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
3454 | } |
3455 | else | |
3456 | { | |
8fcc61b4 NC |
3457 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
3458 | (long) linfo->li_length); | |
b40bf0a2 NC |
3459 | return NULL; |
3460 | } | |
f41e4712 | 3461 | } |
19e6b90e | 3462 | |
b40bf0a2 NC |
3463 | /* Get and check the version number. */ |
3464 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
3465 | ||
3466 | if (linfo->li_version != 2 | |
3467 | && linfo->li_version != 3 | |
77145576 JK |
3468 | && linfo->li_version != 4 |
3469 | && linfo->li_version != 5) | |
f41e4712 | 3470 | { |
77145576 JK |
3471 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
3472 | "is currently supported.\n")); | |
b40bf0a2 | 3473 | return NULL; |
f41e4712 | 3474 | } |
19e6b90e | 3475 | |
77145576 JK |
3476 | if (linfo->li_version >= 5) |
3477 | { | |
3478 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
3479 | ||
3480 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
3481 | if (segment_selector_size != 0) | |
3482 | { | |
3483 | warn (_("The %s section contains " | |
3484 | "unsupported segment selector size: %d.\n"), | |
3485 | section->name, segment_selector_size); | |
3486 | return 0; | |
3487 | } | |
3488 | } | |
3489 | ||
3490 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
3491 | linfo->li_offset_size, end); | |
b40bf0a2 | 3492 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 3493 | |
b40bf0a2 | 3494 | if (linfo->li_version >= 4) |
f41e4712 | 3495 | { |
b40bf0a2 | 3496 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 3497 | |
b40bf0a2 | 3498 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
3499 | { |
3500 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 3501 | return NULL; |
a233b20c | 3502 | } |
f41e4712 NC |
3503 | } |
3504 | else | |
b40bf0a2 | 3505 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 3506 | |
b40bf0a2 | 3507 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 3508 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
3509 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
3510 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 3511 | |
b40bf0a2 | 3512 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 3513 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
3514 | if (* end_of_sequence > end) |
3515 | { | |
4c219c2e AM |
3516 | warn (_("Line length %s extends beyond end of section\n"), |
3517 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
3518 | * end_of_sequence = end; |
3519 | return NULL; | |
3520 | } | |
3521 | ||
b40bf0a2 NC |
3522 | return hdrptr; |
3523 | } | |
19e6b90e | 3524 | |
77145576 | 3525 | static unsigned char * |
dda8d76d NC |
3526 | display_formatted_table (unsigned char * data, |
3527 | unsigned char * start, | |
3528 | unsigned char * end, | |
3529 | const DWARF2_Internal_LineInfo * linfo, | |
3530 | struct dwarf_section * section, | |
7b8d9e8c | 3531 | bfd_boolean is_dir) |
77145576 JK |
3532 | { |
3533 | unsigned char *format_start, format_count, *format, formati; | |
3534 | dwarf_vma data_count, datai; | |
3535 | unsigned int bytes_read, namepass, last_entry = 0; | |
3536 | ||
3537 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
3538 | format_start = data; | |
3539 | for (formati = 0; formati < format_count; formati++) | |
3540 | { | |
3541 | read_uleb128 (data, & bytes_read, end); | |
3542 | data += bytes_read; | |
3543 | read_uleb128 (data, & bytes_read, end); | |
3544 | data += bytes_read; | |
3545 | if (data == end) | |
3546 | { | |
7b8d9e8c AM |
3547 | if (is_dir) |
3548 | warn (_("Corrupt directory format table entry\n")); | |
3549 | else | |
3550 | warn (_("Corrupt file name format table entry\n")); | |
77145576 JK |
3551 | return data; |
3552 | } | |
3553 | } | |
3554 | ||
3555 | data_count = read_uleb128 (data, & bytes_read, end); | |
3556 | data += bytes_read; | |
3557 | if (data == end) | |
3558 | { | |
7b8d9e8c AM |
3559 | if (is_dir) |
3560 | warn (_("Corrupt directory list\n")); | |
3561 | else | |
3562 | warn (_("Corrupt file name list\n")); | |
77145576 JK |
3563 | return data; |
3564 | } | |
3565 | ||
3566 | if (data_count == 0) | |
3567 | { | |
7b8d9e8c AM |
3568 | if (is_dir) |
3569 | printf (_("\n The Directory Table is empty.\n")); | |
3570 | else | |
3571 | printf (_("\n The File Name Table is empty.\n")); | |
77145576 JK |
3572 | return data; |
3573 | } | |
3574 | ||
7b8d9e8c AM |
3575 | if (is_dir) |
3576 | printf (_("\n The Directory Table (offset 0x%lx):\n"), | |
3577 | (long) (data - start)); | |
3578 | else | |
3579 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
3580 | (long) (data - start)); | |
77145576 JK |
3581 | |
3582 | printf (_(" Entry")); | |
3583 | /* Delay displaying name as the last entry for better screen layout. */ | |
3584 | for (namepass = 0; namepass < 2; namepass++) | |
3585 | { | |
3586 | format = format_start; | |
3587 | for (formati = 0; formati < format_count; formati++) | |
3588 | { | |
3589 | dwarf_vma content_type; | |
3590 | ||
3591 | content_type = read_uleb128 (format, & bytes_read, end); | |
3592 | format += bytes_read; | |
3593 | if ((content_type == DW_LNCT_path) == (namepass == 1)) | |
3594 | switch (content_type) | |
3595 | { | |
3596 | case DW_LNCT_path: | |
3597 | printf (_("\tName")); | |
3598 | break; | |
3599 | case DW_LNCT_directory_index: | |
3600 | printf (_("\tDir")); | |
3601 | break; | |
3602 | case DW_LNCT_timestamp: | |
3603 | printf (_("\tTime")); | |
3604 | break; | |
3605 | case DW_LNCT_size: | |
3606 | printf (_("\tSize")); | |
3607 | break; | |
3608 | case DW_LNCT_MD5: | |
3609 | printf (_("\tMD5")); | |
3610 | break; | |
3611 | default: | |
3612 | printf (_("\t(Unknown format content type %s)"), | |
3613 | dwarf_vmatoa ("u", content_type)); | |
3614 | } | |
3615 | read_uleb128 (format, & bytes_read, end); | |
3616 | format += bytes_read; | |
3617 | } | |
3618 | } | |
3619 | putchar ('\n'); | |
3620 | ||
3621 | for (datai = 0; datai < data_count; datai++) | |
3622 | { | |
3623 | unsigned char *datapass = data; | |
3624 | ||
3625 | printf (" %d", last_entry++); | |
3626 | /* Delay displaying name as the last entry for better screen layout. */ | |
3627 | for (namepass = 0; namepass < 2; namepass++) | |
3628 | { | |
3629 | format = format_start; | |
3630 | data = datapass; | |
3631 | for (formati = 0; formati < format_count; formati++) | |
3632 | { | |
3633 | dwarf_vma content_type, form; | |
3634 | ||
3635 | content_type = read_uleb128 (format, & bytes_read, end); | |
3636 | format += bytes_read; | |
3637 | form = read_uleb128 (format, & bytes_read, end); | |
3638 | format += bytes_read; | |
3639 | data = read_and_display_attr_value (0, form, 0, data, end, 0, 0, | |
3640 | linfo->li_offset_size, | |
3641 | linfo->li_version, NULL, | |
3642 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
3643 | section, NULL, '\t'); | |
3644 | } | |
3645 | } | |
3646 | if (data == end) | |
3647 | { | |
7b8d9e8c AM |
3648 | if (is_dir) |
3649 | warn (_("Corrupt directory entries list\n")); | |
3650 | else | |
3651 | warn (_("Corrupt file name entries list\n")); | |
77145576 JK |
3652 | return data; |
3653 | } | |
3654 | putchar ('\n'); | |
3655 | } | |
3656 | return data; | |
3657 | } | |
3658 | ||
b40bf0a2 | 3659 | static int |
dda8d76d NC |
3660 | display_debug_lines_raw (struct dwarf_section * section, |
3661 | unsigned char * data, | |
3662 | unsigned char * end, | |
3663 | void * file) | |
b40bf0a2 NC |
3664 | { |
3665 | unsigned char *start = section->start; | |
ba8826a8 | 3666 | int verbose_view = 0; |
19e6b90e | 3667 | |
dda8d76d | 3668 | introduce (section, TRUE); |
19e6b90e | 3669 | |
b40bf0a2 NC |
3670 | while (data < end) |
3671 | { | |
3672 | static DWARF2_Internal_LineInfo saved_linfo; | |
3673 | DWARF2_Internal_LineInfo linfo; | |
3674 | unsigned char *standard_opcodes; | |
3675 | unsigned char *end_of_sequence; | |
fe59e83d | 3676 | int i; |
19e6b90e | 3677 | |
4925cdd7 NC |
3678 | if (const_strneq (section->name, ".debug_line.") |
3679 | /* Note: the following does not apply to .debug_line.dwo sections. | |
3680 | These are full debug_line sections. */ | |
3681 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 3682 | { |
b40bf0a2 NC |
3683 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
3684 | section containing just the Line Number Statements. They are | |
3685 | created by the assembler and intended to be used alongside gcc's | |
3686 | -ffunction-sections command line option. When the linker's | |
3687 | garbage collection decides to discard a .text.<foo> section it | |
3688 | can then also discard the line number information in .debug_line.<foo>. | |
3689 | ||
4925cdd7 | 3690 | Since the section is a fragment it does not have the details |
b40bf0a2 | 3691 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 3692 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
3693 | end_of_sequence = end; |
3694 | standard_opcodes = NULL; | |
3695 | linfo = saved_linfo; | |
058037d3 NC |
3696 | /* PR 17531: file: 0522b371. */ |
3697 | if (linfo.li_line_range == 0) | |
3698 | { | |
1306a742 | 3699 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
3700 | return 0; |
3701 | } | |
b40bf0a2 | 3702 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3703 | } |
19e6b90e L |
3704 | else |
3705 | { | |
b40bf0a2 | 3706 | unsigned char * hdrptr; |
19e6b90e | 3707 | |
b40bf0a2 NC |
3708 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
3709 | & end_of_sequence)) == NULL) | |
3710 | return 0; | |
19e6b90e | 3711 | |
b40bf0a2 NC |
3712 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
3713 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
3714 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
77ef8654 | 3715 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
3716 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
3717 | if (linfo.li_version >= 4) | |
3718 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
3719 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
3720 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
3721 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
3722 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 3723 | |
0a9d414a NC |
3724 | /* PR 17512: file: 1665-6428-0.004. */ |
3725 | if (linfo.li_line_range == 0) | |
3726 | { | |
3727 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
3728 | linfo.li_line_range = 1; | |
3729 | } | |
77ef8654 | 3730 | |
b40bf0a2 | 3731 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3732 | |
b40bf0a2 NC |
3733 | /* Display the contents of the Opcodes table. */ |
3734 | standard_opcodes = hdrptr; | |
19e6b90e | 3735 | |
6937bb54 NC |
3736 | /* PR 17512: file: 002-417945-0.004. */ |
3737 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
3738 | { | |
3739 | warn (_("Line Base extends beyond end of section\n")); | |
3740 | return 0; | |
3741 | } | |
3742 | ||
b40bf0a2 | 3743 | printf (_("\n Opcodes:\n")); |
19e6b90e | 3744 | |
b40bf0a2 | 3745 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
3746 | printf (ngettext (" Opcode %d has %d arg\n", |
3747 | " Opcode %d has %d args\n", | |
3748 | standard_opcodes[i - 1]), | |
3749 | i, standard_opcodes[i - 1]); | |
19e6b90e | 3750 | |
b40bf0a2 NC |
3751 | /* Display the contents of the Directory table. */ |
3752 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 3753 | |
77145576 | 3754 | if (linfo.li_version >= 5) |
b40bf0a2 | 3755 | { |
dda8d76d | 3756 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 3757 | |
77145576 | 3758 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 3759 | TRUE); |
77145576 | 3760 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 3761 | FALSE); |
77145576 JK |
3762 | } |
3763 | else | |
3764 | { | |
3765 | if (*data == 0) | |
3766 | printf (_("\n The Directory Table is empty.\n")); | |
3767 | else | |
a233b20c | 3768 | { |
77145576 | 3769 | unsigned int last_dir_entry = 0; |
6937bb54 | 3770 | |
77145576 JK |
3771 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
3772 | (long)(data - start)); | |
19e6b90e | 3773 | |
77145576 JK |
3774 | while (data < end && *data != 0) |
3775 | { | |
3776 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 3777 | |
77145576 JK |
3778 | data += strnlen ((char *) data, end - data) + 1; |
3779 | } | |
19e6b90e | 3780 | |
77145576 JK |
3781 | /* PR 17512: file: 002-132094-0.004. */ |
3782 | if (data >= end - 1) | |
3783 | break; | |
3784 | } | |
19e6b90e | 3785 | |
77145576 JK |
3786 | /* Skip the NUL at the end of the table. */ |
3787 | data++; | |
19e6b90e | 3788 | |
77145576 JK |
3789 | /* Display the contents of the File Name table. */ |
3790 | if (*data == 0) | |
3791 | printf (_("\n The File Name Table is empty.\n")); | |
3792 | else | |
3793 | { | |
3794 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
3795 | (long)(data - start)); | |
3796 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 3797 | |
77145576 | 3798 | while (data < end && *data != 0) |
b40bf0a2 | 3799 | { |
77145576 JK |
3800 | unsigned char *name; |
3801 | unsigned int bytes_read; | |
3802 | ||
3803 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
3804 | name = data; | |
3805 | data += strnlen ((char *) data, end - data) + 1; | |
3806 | ||
3807 | printf ("%s\t", | |
3808 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
3809 | data += bytes_read; | |
3810 | printf ("%s\t", | |
3811 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
3812 | data += bytes_read; | |
3813 | printf ("%s\t", | |
3814 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
3815 | data += bytes_read; | |
3816 | printf ("%.*s\n", (int)(end - name), name); | |
3817 | ||
3818 | if (data == end) | |
3819 | { | |
3820 | warn (_("Corrupt file name table entry\n")); | |
3821 | break; | |
3822 | } | |
b40bf0a2 | 3823 | } |
a233b20c | 3824 | } |
77145576 JK |
3825 | |
3826 | /* Skip the NUL at the end of the table. */ | |
3827 | data++; | |
b40bf0a2 | 3828 | } |
19e6b90e | 3829 | |
b40bf0a2 NC |
3830 | putchar ('\n'); |
3831 | saved_linfo = linfo; | |
3832 | } | |
19e6b90e | 3833 | |
b40bf0a2 NC |
3834 | /* Now display the statements. */ |
3835 | if (data >= end_of_sequence) | |
3836 | printf (_(" No Line Number Statements.\n")); | |
3837 | else | |
3838 | { | |
3839 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 3840 | |
b40bf0a2 NC |
3841 | while (data < end_of_sequence) |
3842 | { | |
3843 | unsigned char op_code; | |
3844 | dwarf_signed_vma adv; | |
3845 | dwarf_vma uladv; | |
3846 | unsigned int bytes_read; | |
19e6b90e | 3847 | |
fe59e83d CC |
3848 | printf (" [0x%08lx]", (long)(data - start)); |
3849 | ||
b40bf0a2 | 3850 | op_code = *data++; |
19e6b90e | 3851 | |
b40bf0a2 | 3852 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 3853 | { |
b40bf0a2 NC |
3854 | op_code -= linfo.li_opcode_base; |
3855 | uladv = (op_code / linfo.li_line_range); | |
3856 | if (linfo.li_max_ops_per_insn == 1) | |
3857 | { | |
3858 | uladv *= linfo.li_min_insn_length; | |
3859 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
3860 | if (uladv) |
3861 | state_machine_regs.view = 0; | |
b40bf0a2 | 3862 | printf (_(" Special opcode %d: " |
ba8826a8 | 3863 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 3864 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
3865 | dwarf_vmatoa ("x", state_machine_regs.address), |
3866 | verbose_view && uladv | |
3867 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3868 | } |
3869 | else | |
3870 | { | |
ba8826a8 AO |
3871 | unsigned addrdelta |
3872 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
3873 | / linfo.li_max_ops_per_insn) |
3874 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
3875 | |
3876 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
3877 | state_machine_regs.op_index |
3878 | = (state_machine_regs.op_index + uladv) | |
3879 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
3880 | if (addrdelta) |
3881 | state_machine_regs.view = 0; | |
b40bf0a2 | 3882 | printf (_(" Special opcode %d: " |
ba8826a8 | 3883 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
3884 | op_code, dwarf_vmatoa ("u", uladv), |
3885 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
3886 | state_machine_regs.op_index, |
3887 | verbose_view && addrdelta | |
3888 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3889 | } |
3890 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
3891 | state_machine_regs.line += adv; | |
ba8826a8 | 3892 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 3893 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
3894 | if (verbose_view || state_machine_regs.view) |
3895 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
3896 | else | |
3897 | putchar ('\n'); | |
3898 | state_machine_regs.view++; | |
19e6b90e | 3899 | } |
b40bf0a2 NC |
3900 | else switch (op_code) |
3901 | { | |
3902 | case DW_LNS_extended_op: | |
3903 | data += process_extended_line_op (data, linfo.li_default_is_stmt, end); | |
3904 | break; | |
3905 | ||
3906 | case DW_LNS_copy: | |
ba8826a8 AO |
3907 | printf (_(" Copy")); |
3908 | if (verbose_view || state_machine_regs.view) | |
3909 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
3910 | else | |
3911 | putchar ('\n'); | |
3912 | state_machine_regs.view++; | |
b40bf0a2 NC |
3913 | break; |
3914 | ||
3915 | case DW_LNS_advance_pc: | |
3916 | uladv = read_uleb128 (data, & bytes_read, end); | |
3917 | data += bytes_read; | |
3918 | if (linfo.li_max_ops_per_insn == 1) | |
3919 | { | |
3920 | uladv *= linfo.li_min_insn_length; | |
3921 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
3922 | if (uladv) |
3923 | state_machine_regs.view = 0; | |
3924 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
b40bf0a2 | 3925 | dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
3926 | dwarf_vmatoa ("x", state_machine_regs.address), |
3927 | verbose_view && uladv | |
3928 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3929 | } |
3930 | else | |
3931 | { | |
ba8826a8 AO |
3932 | unsigned addrdelta |
3933 | = ((state_machine_regs.op_index + uladv) | |
3934 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 3935 | * linfo.li_min_insn_length; |
ba8826a8 AO |
3936 | state_machine_regs.address |
3937 | += addrdelta; | |
b40bf0a2 NC |
3938 | state_machine_regs.op_index |
3939 | = (state_machine_regs.op_index + uladv) | |
3940 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
3941 | if (addrdelta) |
3942 | state_machine_regs.view = 0; | |
3943 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
b40bf0a2 NC |
3944 | dwarf_vmatoa ("u", uladv), |
3945 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
3946 | state_machine_regs.op_index, |
3947 | verbose_view && addrdelta | |
3948 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3949 | } |
3950 | break; | |
3951 | ||
3952 | case DW_LNS_advance_line: | |
3953 | adv = read_sleb128 (data, & bytes_read, end); | |
3954 | data += bytes_read; | |
3955 | state_machine_regs.line += adv; | |
3956 | printf (_(" Advance Line by %s to %d\n"), | |
3957 | dwarf_vmatoa ("d", adv), | |
3958 | state_machine_regs.line); | |
3959 | break; | |
3960 | ||
3961 | case DW_LNS_set_file: | |
3962 | adv = read_uleb128 (data, & bytes_read, end); | |
3963 | data += bytes_read; | |
3964 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
3965 | dwarf_vmatoa ("d", adv)); | |
3966 | state_machine_regs.file = adv; | |
3967 | break; | |
3968 | ||
3969 | case DW_LNS_set_column: | |
3970 | uladv = read_uleb128 (data, & bytes_read, end); | |
3971 | data += bytes_read; | |
3972 | printf (_(" Set column to %s\n"), | |
3973 | dwarf_vmatoa ("u", uladv)); | |
3974 | state_machine_regs.column = uladv; | |
3975 | break; | |
3976 | ||
3977 | case DW_LNS_negate_stmt: | |
3978 | adv = state_machine_regs.is_stmt; | |
3979 | adv = ! adv; | |
3980 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
3981 | state_machine_regs.is_stmt = adv; | |
3982 | break; | |
3983 | ||
3984 | case DW_LNS_set_basic_block: | |
3985 | printf (_(" Set basic block\n")); | |
3986 | state_machine_regs.basic_block = 1; | |
3987 | break; | |
3988 | ||
3989 | case DW_LNS_const_add_pc: | |
3990 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
3991 | if (linfo.li_max_ops_per_insn) | |
3992 | { | |
3993 | uladv *= linfo.li_min_insn_length; | |
3994 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
3995 | if (uladv) |
3996 | state_machine_regs.view = 0; | |
3997 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
b40bf0a2 | 3998 | dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
3999 | dwarf_vmatoa ("x", state_machine_regs.address), |
4000 | verbose_view && uladv | |
4001 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4002 | } |
4003 | else | |
4004 | { | |
ba8826a8 AO |
4005 | unsigned addrdelta |
4006 | = ((state_machine_regs.op_index + uladv) | |
4007 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4008 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4009 | state_machine_regs.address |
4010 | += addrdelta; | |
b40bf0a2 NC |
4011 | state_machine_regs.op_index |
4012 | = (state_machine_regs.op_index + uladv) | |
4013 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4014 | if (addrdelta) |
4015 | state_machine_regs.view = 0; | |
4016 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
b40bf0a2 NC |
4017 | dwarf_vmatoa ("u", uladv), |
4018 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4019 | state_machine_regs.op_index, |
4020 | verbose_view && addrdelta | |
4021 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4022 | } |
4023 | break; | |
4024 | ||
4025 | case DW_LNS_fixed_advance_pc: | |
4026 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4027 | state_machine_regs.address += uladv; | |
4028 | state_machine_regs.op_index = 0; | |
4029 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4030 | dwarf_vmatoa ("u", uladv), | |
4031 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
ba8826a8 | 4032 | /* Do NOT reset view. */ |
b40bf0a2 NC |
4033 | break; |
4034 | ||
4035 | case DW_LNS_set_prologue_end: | |
4036 | printf (_(" Set prologue_end to true\n")); | |
4037 | break; | |
4038 | ||
4039 | case DW_LNS_set_epilogue_begin: | |
4040 | printf (_(" Set epilogue_begin to true\n")); | |
4041 | break; | |
4042 | ||
4043 | case DW_LNS_set_isa: | |
4044 | uladv = read_uleb128 (data, & bytes_read, end); | |
4045 | data += bytes_read; | |
4046 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4047 | break; | |
4048 | ||
4049 | default: | |
4050 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4051 | ||
4052 | if (standard_opcodes != NULL) | |
4053 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4054 | { | |
4055 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
4056 | &bytes_read, end)), | |
4057 | i == 1 ? "" : ", "); | |
4058 | data += bytes_read; | |
4059 | } | |
4060 | putchar ('\n'); | |
4061 | break; | |
4062 | } | |
19e6b90e | 4063 | } |
b40bf0a2 | 4064 | putchar ('\n'); |
19e6b90e | 4065 | } |
19e6b90e L |
4066 | } |
4067 | ||
4068 | return 1; | |
4069 | } | |
4070 | ||
a262ae96 NC |
4071 | typedef struct |
4072 | { | |
467c65bc NC |
4073 | unsigned char *name; |
4074 | unsigned int directory_index; | |
4075 | unsigned int modification_date; | |
4076 | unsigned int length; | |
a262ae96 NC |
4077 | } File_Entry; |
4078 | ||
4079 | /* Output a decoded representation of the .debug_line section. */ | |
4080 | ||
4081 | static int | |
dda8d76d NC |
4082 | display_debug_lines_decoded (struct dwarf_section * section, |
4083 | unsigned char * data, | |
4084 | unsigned char * end, | |
4085 | void * fileptr) | |
a262ae96 | 4086 | { |
b40bf0a2 NC |
4087 | static DWARF2_Internal_LineInfo saved_linfo; |
4088 | ||
dda8d76d | 4089 | introduce (section, FALSE); |
a262ae96 NC |
4090 | |
4091 | while (data < end) | |
4092 | { | |
4093 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4094 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4095 | unsigned char *standard_opcodes; |
4096 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4097 | int i; |
4098 | File_Entry *file_table = NULL; | |
143a3db0 | 4099 | unsigned int n_files = 0; |
a262ae96 | 4100 | unsigned char **directory_table = NULL; |
77145576 | 4101 | dwarf_vma n_directories = 0; |
a262ae96 | 4102 | |
4925cdd7 NC |
4103 | if (const_strneq (section->name, ".debug_line.") |
4104 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4105 | These are full debug_line sections. */ | |
4106 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4107 | { |
4925cdd7 | 4108 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4109 | end_of_sequence = end; |
4110 | standard_opcodes = NULL; | |
4111 | linfo = saved_linfo; | |
058037d3 NC |
4112 | /* PR 17531: file: 0522b371. */ |
4113 | if (linfo.li_line_range == 0) | |
4114 | { | |
1306a742 | 4115 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4116 | return 0; |
4117 | } | |
b40bf0a2 | 4118 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4119 | } |
a262ae96 | 4120 | else |
b4eb7656 | 4121 | { |
b40bf0a2 | 4122 | unsigned char *hdrptr; |
a262ae96 | 4123 | |
b40bf0a2 NC |
4124 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4125 | & end_of_sequence)) == NULL) | |
a233b20c | 4126 | return 0; |
0c588247 | 4127 | |
058037d3 NC |
4128 | /* PR 17531: file: 0522b371. */ |
4129 | if (linfo.li_line_range == 0) | |
4130 | { | |
4131 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4132 | linfo.li_line_range = 1; | |
4133 | } | |
b40bf0a2 | 4134 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4135 | |
b40bf0a2 NC |
4136 | /* Save a pointer to the contents of the Opcodes table. */ |
4137 | standard_opcodes = hdrptr; | |
a262ae96 | 4138 | |
b40bf0a2 NC |
4139 | /* Traverse the Directory table just to count entries. */ |
4140 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4141 | /* PR 20440 */ |
4142 | if (data >= end) | |
4143 | { | |
4144 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4145 | linfo.li_opcode_base); | |
4146 | return 0; | |
4147 | } | |
4148 | ||
77145576 | 4149 | if (linfo.li_version >= 5) |
b40bf0a2 | 4150 | { |
77145576 JK |
4151 | unsigned char *format_start, format_count, *format; |
4152 | dwarf_vma formati, entryi; | |
4153 | unsigned int bytes_read; | |
a262ae96 | 4154 | |
dda8d76d | 4155 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4156 | |
4157 | /* Skip directories format. */ | |
4158 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
4159 | format_start = data; | |
4160 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4161 | { |
77145576 JK |
4162 | read_uleb128 (data, & bytes_read, end); |
4163 | data += bytes_read; | |
4164 | read_uleb128 (data, & bytes_read, end); | |
4165 | data += bytes_read; | |
b40bf0a2 | 4166 | } |
a262ae96 | 4167 | |
77145576 JK |
4168 | n_directories = read_uleb128 (data, & bytes_read, end); |
4169 | data += bytes_read; | |
4170 | if (data == end) | |
d8024a91 | 4171 | { |
77145576 | 4172 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4173 | break; |
4174 | } | |
4175 | ||
b40bf0a2 NC |
4176 | directory_table = (unsigned char **) |
4177 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 4178 | |
77145576 | 4179 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 4180 | { |
77145576 | 4181 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 4182 | |
77145576 JK |
4183 | format = format_start; |
4184 | for (formati = 0; formati < format_count; formati++) | |
4185 | { | |
4186 | dwarf_vma content_type, form; | |
4187 | dwarf_vma uvalue; | |
4188 | ||
4189 | content_type = read_uleb128 (format, & bytes_read, end); | |
4190 | format += bytes_read; | |
4191 | form = read_uleb128 (format, & bytes_read, end); | |
4192 | format += bytes_read; | |
4193 | if (data == end) | |
4194 | { | |
4195 | warn (_("Corrupt directories list\n")); | |
4196 | break; | |
4197 | } | |
4198 | switch (content_type) | |
4199 | { | |
4200 | case DW_LNCT_path: | |
4201 | switch (form) | |
4202 | { | |
4203 | case DW_FORM_string: | |
4204 | *pathp = data; | |
4205 | break; | |
4206 | case DW_FORM_line_strp: | |
4207 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4208 | end); | |
4209 | /* Remove const by the cast. */ | |
4210 | *pathp = (unsigned char *) | |
4211 | fetch_indirect_line_string (uvalue); | |
4212 | break; | |
4213 | } | |
4214 | break; | |
4215 | } | |
4216 | data = read_and_display_attr_value (0, form, 0, data, end, | |
4217 | 0, 0, | |
4218 | linfo.li_offset_size, | |
4219 | linfo.li_version, | |
4220 | NULL, 1, section, | |
4221 | NULL, '\t'); | |
4222 | } | |
4223 | if (data == end) | |
4224 | { | |
4225 | warn (_("Corrupt directories list\n")); | |
4226 | break; | |
4227 | } | |
4228 | } | |
a262ae96 | 4229 | |
77145576 JK |
4230 | /* Skip files format. */ |
4231 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
4232 | format_start = data; | |
4233 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4234 | { |
b40bf0a2 NC |
4235 | read_uleb128 (data, & bytes_read, end); |
4236 | data += bytes_read; | |
4237 | read_uleb128 (data, & bytes_read, end); | |
4238 | data += bytes_read; | |
b40bf0a2 | 4239 | } |
a262ae96 | 4240 | |
77145576 JK |
4241 | n_files = read_uleb128 (data, & bytes_read, end); |
4242 | data += bytes_read; | |
4243 | if (data == end) | |
d8024a91 | 4244 | { |
77145576 | 4245 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
4246 | break; |
4247 | } | |
4248 | ||
77145576 JK |
4249 | file_table = (File_Entry *) xcalloc (1, n_files |
4250 | * sizeof (File_Entry)); | |
a262ae96 | 4251 | |
77145576 | 4252 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 4253 | { |
77145576 | 4254 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 4255 | |
77145576 JK |
4256 | format = format_start; |
4257 | for (formati = 0; formati < format_count; formati++) | |
4258 | { | |
4259 | dwarf_vma content_type, form; | |
4260 | dwarf_vma uvalue; | |
4261 | ||
4262 | content_type = read_uleb128 (format, & bytes_read, end); | |
4263 | format += bytes_read; | |
4264 | form = read_uleb128 (format, & bytes_read, end); | |
4265 | format += bytes_read; | |
4266 | if (data == end) | |
4267 | { | |
4268 | warn (_("Corrupt file name list\n")); | |
4269 | break; | |
4270 | } | |
4271 | switch (content_type) | |
4272 | { | |
4273 | case DW_LNCT_path: | |
4274 | switch (form) | |
4275 | { | |
4276 | case DW_FORM_string: | |
4277 | file->name = data; | |
4278 | break; | |
4279 | case DW_FORM_line_strp: | |
4280 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4281 | end); | |
4282 | /* Remove const by the cast. */ | |
4283 | file->name = (unsigned char *) | |
4284 | fetch_indirect_line_string (uvalue); | |
4285 | break; | |
4286 | } | |
4287 | break; | |
4288 | case DW_LNCT_directory_index: | |
4289 | switch (form) | |
4290 | { | |
4291 | case DW_FORM_data1: | |
4292 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
4293 | end); | |
4294 | break; | |
4295 | case DW_FORM_data2: | |
4296 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
4297 | end); | |
4298 | break; | |
4299 | case DW_FORM_udata: | |
4300 | file->directory_index = read_uleb128 (data, NULL, | |
4301 | end); | |
4302 | break; | |
4303 | } | |
4304 | break; | |
4305 | } | |
4306 | data = read_and_display_attr_value (0, form, 0, data, end, | |
4307 | 0, 0, | |
4308 | linfo.li_offset_size, | |
4309 | linfo.li_version, | |
4310 | NULL, 1, section, | |
4311 | NULL, '\t'); | |
4312 | } | |
4313 | if (data == end) | |
4314 | { | |
4315 | warn (_("Corrupt file name list\n")); | |
4316 | break; | |
4317 | } | |
4318 | } | |
4319 | } | |
4320 | else | |
4321 | { | |
4322 | if (*data != 0) | |
b40bf0a2 | 4323 | { |
77145576 JK |
4324 | unsigned char *ptr_directory_table = data; |
4325 | ||
4326 | while (data < end && *data != 0) | |
4327 | { | |
4328 | data += strnlen ((char *) data, end - data) + 1; | |
4329 | n_directories++; | |
4330 | } | |
4331 | ||
4332 | /* PR 20440 */ | |
4333 | if (data >= end) | |
4334 | { | |
4335 | warn (_("directory table ends unexpectedly\n")); | |
4336 | n_directories = 0; | |
4337 | break; | |
4338 | } | |
4339 | ||
4340 | /* Go through the directory table again to save the directories. */ | |
4341 | directory_table = (unsigned char **) | |
4342 | xmalloc (n_directories * sizeof (unsigned char *)); | |
4343 | ||
4344 | i = 0; | |
4345 | while (*ptr_directory_table != 0) | |
4346 | { | |
4347 | directory_table[i] = ptr_directory_table; | |
4348 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
4349 | ptr_directory_table - end) + 1; | |
4350 | i++; | |
4351 | } | |
b40bf0a2 | 4352 | } |
77145576 JK |
4353 | /* Skip the NUL at the end of the table. */ |
4354 | data++; | |
4355 | ||
4356 | /* Traverse the File Name table just to count the entries. */ | |
4357 | if (data < end && *data != 0) | |
b40bf0a2 | 4358 | { |
77145576 JK |
4359 | unsigned char *ptr_file_name_table = data; |
4360 | ||
4361 | while (data < end && *data != 0) | |
db9537d2 | 4362 | { |
77145576 JK |
4363 | unsigned int bytes_read; |
4364 | ||
4365 | /* Skip Name, directory index, last modification time and length | |
4366 | of file. */ | |
4367 | data += strnlen ((char *) data, end - data) + 1; | |
4368 | read_uleb128 (data, & bytes_read, end); | |
4369 | data += bytes_read; | |
4370 | read_uleb128 (data, & bytes_read, end); | |
4371 | data += bytes_read; | |
4372 | read_uleb128 (data, & bytes_read, end); | |
4373 | data += bytes_read; | |
4374 | ||
4375 | n_files++; | |
db9537d2 | 4376 | } |
a262ae96 | 4377 | |
77145576 JK |
4378 | if (data >= end) |
4379 | { | |
4380 | warn (_("file table ends unexpectedly\n")); | |
4381 | n_files = 0; | |
4382 | break; | |
4383 | } | |
4384 | ||
4385 | /* Go through the file table again to save the strings. */ | |
4386 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 4387 | |
77145576 JK |
4388 | i = 0; |
4389 | while (*ptr_file_name_table != 0) | |
4390 | { | |
4391 | unsigned int bytes_read; | |
4392 | ||
4393 | file_table[i].name = ptr_file_name_table; | |
4394 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
4395 | end - ptr_file_name_table) + 1; | |
4396 | ||
4397 | /* We are not interested in directory, time or size. */ | |
4398 | file_table[i].directory_index = read_uleb128 (ptr_file_name_table, | |
4399 | & bytes_read, end); | |
4400 | ptr_file_name_table += bytes_read; | |
4401 | file_table[i].modification_date = read_uleb128 (ptr_file_name_table, | |
4402 | & bytes_read, end); | |
4403 | ptr_file_name_table += bytes_read; | |
4404 | file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end); | |
4405 | ptr_file_name_table += bytes_read; | |
4406 | i++; | |
4407 | } | |
4408 | i = 0; | |
b40bf0a2 | 4409 | } |
77145576 JK |
4410 | |
4411 | /* Skip the NUL at the end of the table. */ | |
4412 | data++; | |
b40bf0a2 | 4413 | } |
cc5914eb | 4414 | |
77145576 | 4415 | /* Print the Compilation Unit's name and a header. */ |
f082820d AM |
4416 | if (file_table == NULL) |
4417 | ; | |
4418 | else if (directory_table == NULL) | |
4419 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
4420 | else |
4421 | { | |
4422 | unsigned int ix = file_table[0].directory_index; | |
4423 | const char *directory; | |
4424 | ||
4425 | if (ix == 0) | |
4426 | directory = "."; | |
4427 | /* PR 20439 */ | |
4428 | else if (n_directories == 0) | |
4429 | directory = _("<unknown>"); | |
4430 | else if (ix > n_directories) | |
4431 | { | |
4432 | warn (_("directory index %u > number of directories %s\n"), | |
4433 | ix, dwarf_vmatoa ("u", n_directories)); | |
4434 | directory = _("<corrupt>"); | |
4435 | } | |
4436 | else | |
4437 | directory = (char *) directory_table[ix - 1]; | |
4438 | ||
4439 | if (do_wide || strlen (directory) < 76) | |
4440 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
4441 | else | |
4442 | printf ("%s:\n", file_table[0].name); | |
77145576 | 4443 | } |
a262ae96 | 4444 | |
17f6ade2 | 4445 | printf (_("File name Line number Starting address View Stmt\n")); |
b40bf0a2 NC |
4446 | saved_linfo = linfo; |
4447 | } | |
a262ae96 NC |
4448 | |
4449 | /* This loop iterates through the Dwarf Line Number Program. */ | |
4450 | while (data < end_of_sequence) | |
b4eb7656 | 4451 | { |
a262ae96 | 4452 | unsigned char op_code; |
ba8826a8 | 4453 | int xop; |
b4eb7656 AM |
4454 | int adv; |
4455 | unsigned long int uladv; | |
4456 | unsigned int bytes_read; | |
4457 | int is_special_opcode = 0; | |
a262ae96 | 4458 | |
b4eb7656 | 4459 | op_code = *data++; |
ba8826a8 | 4460 | xop = op_code; |
a262ae96 | 4461 | |
b4eb7656 | 4462 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 4463 | { |
91d6fa6a | 4464 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
4465 | uladv = (op_code / linfo.li_line_range); |
4466 | if (linfo.li_max_ops_per_insn == 1) | |
4467 | { | |
4468 | uladv *= linfo.li_min_insn_length; | |
4469 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4470 | if (uladv) |
4471 | state_machine_regs.view = 0; | |
a233b20c JJ |
4472 | } |
4473 | else | |
4474 | { | |
ba8826a8 AO |
4475 | unsigned addrdelta |
4476 | = ((state_machine_regs.op_index + uladv) | |
4477 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4478 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4479 | state_machine_regs.address |
4480 | += addrdelta; | |
a233b20c JJ |
4481 | state_machine_regs.op_index |
4482 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 4483 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
4484 | if (addrdelta) |
4485 | state_machine_regs.view = 0; | |
a233b20c | 4486 | } |
a262ae96 | 4487 | |
b4eb7656 AM |
4488 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
4489 | state_machine_regs.line += adv; | |
4490 | is_special_opcode = 1; | |
ba8826a8 | 4491 | /* Increment view after printing this row. */ |
b4eb7656 AM |
4492 | } |
4493 | else switch (op_code) | |
b40bf0a2 NC |
4494 | { |
4495 | case DW_LNS_extended_op: | |
4496 | { | |
4497 | unsigned int ext_op_code_len; | |
4498 | unsigned char ext_op_code; | |
4499 | unsigned char *op_code_data = data; | |
4500 | ||
4501 | ext_op_code_len = read_uleb128 (op_code_data, &bytes_read, | |
4502 | end_of_sequence); | |
4503 | op_code_data += bytes_read; | |
4504 | ||
4505 | if (ext_op_code_len == 0) | |
4506 | { | |
f41e4712 | 4507 | warn (_("Badly formed extended line op encountered!\n")); |
b40bf0a2 NC |
4508 | break; |
4509 | } | |
4510 | ext_op_code_len += bytes_read; | |
4511 | ext_op_code = *op_code_data++; | |
ba8826a8 AO |
4512 | xop = ext_op_code; |
4513 | xop = -xop; | |
b40bf0a2 NC |
4514 | |
4515 | switch (ext_op_code) | |
4516 | { | |
4517 | case DW_LNE_end_sequence: | |
ba8826a8 | 4518 | /* Reset stuff after printing this row. */ |
b40bf0a2 NC |
4519 | break; |
4520 | case DW_LNE_set_address: | |
4521 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
87bc83b3 CC |
4522 | op_code_data, |
4523 | ext_op_code_len - bytes_read - 1, | |
b40bf0a2 NC |
4524 | end); |
4525 | state_machine_regs.op_index = 0; | |
ba8826a8 | 4526 | state_machine_regs.view = 0; |
b40bf0a2 NC |
4527 | break; |
4528 | case DW_LNE_define_file: | |
4529 | { | |
4530 | file_table = (File_Entry *) xrealloc | |
4531 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
4532 | ||
4533 | ++state_machine_regs.last_file_entry; | |
4534 | /* Source file name. */ | |
4535 | file_table[n_files].name = op_code_data; | |
4536 | op_code_data += strlen ((char *) op_code_data) + 1; | |
4537 | /* Directory index. */ | |
4538 | file_table[n_files].directory_index = | |
4539 | read_uleb128 (op_code_data, & bytes_read, | |
4540 | end_of_sequence); | |
4541 | op_code_data += bytes_read; | |
4542 | /* Last modification time. */ | |
4543 | file_table[n_files].modification_date = | |
4544 | read_uleb128 (op_code_data, & bytes_read, | |
4545 | end_of_sequence); | |
4546 | op_code_data += bytes_read; | |
4547 | /* File length. */ | |
4548 | file_table[n_files].length = | |
4549 | read_uleb128 (op_code_data, & bytes_read, | |
4550 | end_of_sequence); | |
4551 | ||
4552 | n_files++; | |
4553 | break; | |
4554 | } | |
4555 | case DW_LNE_set_discriminator: | |
4556 | case DW_LNE_HP_set_sequence: | |
4557 | /* Simply ignored. */ | |
4558 | break; | |
4559 | ||
4560 | default: | |
4561 | printf (_("UNKNOWN (%u): length %d\n"), | |
4562 | ext_op_code, ext_op_code_len - bytes_read); | |
4563 | break; | |
4564 | } | |
4565 | data += ext_op_code_len; | |
4566 | break; | |
4567 | } | |
4568 | case DW_LNS_copy: | |
ba8826a8 | 4569 | /* Increment view after printing this row. */ |
b40bf0a2 NC |
4570 | break; |
4571 | ||
4572 | case DW_LNS_advance_pc: | |
4573 | uladv = read_uleb128 (data, & bytes_read, end); | |
4574 | data += bytes_read; | |
4575 | if (linfo.li_max_ops_per_insn == 1) | |
4576 | { | |
4577 | uladv *= linfo.li_min_insn_length; | |
4578 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4579 | if (uladv) |
4580 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4581 | } |
4582 | else | |
4583 | { | |
ba8826a8 AO |
4584 | unsigned addrdelta |
4585 | = ((state_machine_regs.op_index + uladv) | |
4586 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4587 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4588 | state_machine_regs.address |
4589 | += addrdelta; | |
b40bf0a2 NC |
4590 | state_machine_regs.op_index |
4591 | = (state_machine_regs.op_index + uladv) | |
4592 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4593 | if (addrdelta) |
4594 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4595 | } |
4596 | break; | |
4597 | ||
4598 | case DW_LNS_advance_line: | |
4599 | adv = read_sleb128 (data, & bytes_read, end); | |
4600 | data += bytes_read; | |
4601 | state_machine_regs.line += adv; | |
4602 | break; | |
4603 | ||
4604 | case DW_LNS_set_file: | |
4605 | adv = read_uleb128 (data, & bytes_read, end); | |
4606 | data += bytes_read; | |
4607 | state_machine_regs.file = adv; | |
4608 | ||
db9537d2 NC |
4609 | { |
4610 | unsigned file = state_machine_regs.file - 1; | |
4611 | unsigned dir; | |
4612 | ||
4613 | if (file_table == NULL || n_files == 0) | |
4614 | printf (_("\n [Use file table entry %d]\n"), file); | |
4615 | /* PR 20439 */ | |
4616 | else if (file >= n_files) | |
4617 | { | |
4618 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
4619 | printf (_("\n <over large file table index %u>"), file); | |
4620 | } | |
4621 | else if ((dir = file_table[file].directory_index) == 0) | |
4622 | /* If directory index is 0, that means current directory. */ | |
4623 | printf ("\n./%s:[++]\n", file_table[file].name); | |
4624 | else if (directory_table == NULL || n_directories == 0) | |
4625 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
4626 | file_table[file].name, dir); | |
4627 | /* PR 20439 */ | |
4628 | else if (dir > n_directories) | |
4629 | { | |
77145576 JK |
4630 | warn (_("directory index %u > number of directories %s\n"), |
4631 | dir, dwarf_vmatoa ("u", n_directories)); | |
db9537d2 NC |
4632 | printf (_("\n <over large directory table entry %u>\n"), dir); |
4633 | } | |
4634 | else | |
4635 | printf ("\n%s/%s:\n", | |
4636 | /* The directory index starts counting at 1. */ | |
4637 | directory_table[dir - 1], file_table[file].name); | |
4638 | } | |
b40bf0a2 NC |
4639 | break; |
4640 | ||
4641 | case DW_LNS_set_column: | |
4642 | uladv = read_uleb128 (data, & bytes_read, end); | |
4643 | data += bytes_read; | |
4644 | state_machine_regs.column = uladv; | |
4645 | break; | |
4646 | ||
4647 | case DW_LNS_negate_stmt: | |
4648 | adv = state_machine_regs.is_stmt; | |
4649 | adv = ! adv; | |
4650 | state_machine_regs.is_stmt = adv; | |
4651 | break; | |
4652 | ||
4653 | case DW_LNS_set_basic_block: | |
4654 | state_machine_regs.basic_block = 1; | |
4655 | break; | |
4656 | ||
4657 | case DW_LNS_const_add_pc: | |
4658 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4659 | if (linfo.li_max_ops_per_insn == 1) | |
4660 | { | |
4661 | uladv *= linfo.li_min_insn_length; | |
4662 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4663 | if (uladv) |
4664 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4665 | } |
4666 | else | |
4667 | { | |
ba8826a8 AO |
4668 | unsigned addrdelta |
4669 | = ((state_machine_regs.op_index + uladv) | |
4670 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4671 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4672 | state_machine_regs.address |
4673 | += addrdelta; | |
b40bf0a2 NC |
4674 | state_machine_regs.op_index |
4675 | = (state_machine_regs.op_index + uladv) | |
4676 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4677 | if (addrdelta) |
4678 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4679 | } |
4680 | break; | |
4681 | ||
4682 | case DW_LNS_fixed_advance_pc: | |
4683 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4684 | state_machine_regs.address += uladv; | |
4685 | state_machine_regs.op_index = 0; | |
ba8826a8 | 4686 | /* Do NOT reset view. */ |
b40bf0a2 NC |
4687 | break; |
4688 | ||
4689 | case DW_LNS_set_prologue_end: | |
4690 | break; | |
4691 | ||
4692 | case DW_LNS_set_epilogue_begin: | |
4693 | break; | |
4694 | ||
4695 | case DW_LNS_set_isa: | |
4696 | uladv = read_uleb128 (data, & bytes_read, end); | |
4697 | data += bytes_read; | |
4698 | printf (_(" Set ISA to %lu\n"), uladv); | |
4699 | break; | |
4700 | ||
4701 | default: | |
4702 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4703 | ||
4704 | if (standard_opcodes != NULL) | |
4705 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4706 | { | |
4707 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
4708 | &bytes_read, end)), | |
4709 | i == 1 ? "" : ", "); | |
4710 | data += bytes_read; | |
4711 | } | |
4712 | putchar ('\n'); | |
4713 | break; | |
4714 | } | |
a262ae96 | 4715 | |
b4eb7656 AM |
4716 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
4717 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
4718 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
4719 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
4720 | { |
4721 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
4722 | char *fileName; | |
4723 | char *newFileName = NULL; | |
4724 | size_t fileNameLength; | |
b40bf0a2 NC |
4725 | |
4726 | if (file_table) | |
db9537d2 NC |
4727 | { |
4728 | unsigned indx = state_machine_regs.file - 1; | |
4729 | /* PR 20439 */ | |
4730 | if (indx >= n_files) | |
4731 | { | |
4732 | warn (_("corrupt file index %u encountered\n"), indx); | |
4733 | fileName = _("<corrupt>"); | |
4734 | } | |
4735 | else | |
4736 | fileName = (char *) file_table[indx].name; | |
4737 | } | |
b40bf0a2 | 4738 | else |
db9537d2 | 4739 | fileName = _("<unknown>"); |
b40bf0a2 NC |
4740 | |
4741 | fileNameLength = strlen (fileName); | |
a262ae96 | 4742 | |
b4eb7656 AM |
4743 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
4744 | { | |
4745 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
4746 | /* Truncate file name */ | |
4747 | strncpy (newFileName, | |
4748 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
4749 | MAX_FILENAME_LENGTH + 1); | |
4750 | } | |
4751 | else | |
4752 | { | |
4753 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
4754 | strncpy (newFileName, fileName, fileNameLength + 1); | |
4755 | } | |
4756 | ||
4757 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) | |
4758 | { | |
a233b20c | 4759 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 4760 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 4761 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4762 | state_machine_regs.address); |
4763 | else | |
ba8826a8 | 4764 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 4765 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4766 | state_machine_regs.address, |
4767 | state_machine_regs.op_index); | |
b4eb7656 AM |
4768 | } |
4769 | else | |
4770 | { | |
a233b20c | 4771 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 4772 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 4773 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4774 | state_machine_regs.address); |
4775 | else | |
ba8826a8 | 4776 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 4777 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4778 | state_machine_regs.address, |
4779 | state_machine_regs.op_index); | |
b4eb7656 | 4780 | } |
a262ae96 | 4781 | |
ba8826a8 | 4782 | if (state_machine_regs.view) |
17f6ade2 | 4783 | printf (" %6u", state_machine_regs.view); |
ba8826a8 | 4784 | else |
17f6ade2 JD |
4785 | printf (" "); |
4786 | ||
4787 | if (state_machine_regs.is_stmt) | |
4788 | printf (" x"); | |
4789 | ||
4790 | putchar ('\n'); | |
ba8826a8 AO |
4791 | state_machine_regs.view++; |
4792 | ||
4793 | if (xop == -DW_LNE_end_sequence) | |
4794 | { | |
4795 | reset_state_machine (linfo.li_default_is_stmt); | |
4796 | putchar ('\n'); | |
4797 | } | |
a262ae96 | 4798 | |
b4eb7656 AM |
4799 | free (newFileName); |
4800 | } | |
4801 | } | |
b40bf0a2 NC |
4802 | |
4803 | if (file_table) | |
4804 | { | |
4805 | free (file_table); | |
4806 | file_table = NULL; | |
4807 | n_files = 0; | |
4808 | } | |
4809 | ||
4810 | if (directory_table) | |
4811 | { | |
4812 | free (directory_table); | |
4813 | directory_table = NULL; | |
4814 | n_directories = 0; | |
4815 | } | |
4816 | ||
a262ae96 NC |
4817 | putchar ('\n'); |
4818 | } | |
4819 | ||
4820 | return 1; | |
4821 | } | |
4822 | ||
4823 | static int | |
77145576 | 4824 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
4825 | { |
4826 | unsigned char *data = section->start; | |
4827 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
4828 | int retValRaw = 1; |
4829 | int retValDecoded = 1; | |
a262ae96 | 4830 | |
008f4c78 NC |
4831 | if (do_debug_lines == 0) |
4832 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
4833 | ||
4cb93e3b | 4834 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 4835 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 4836 | |
4cb93e3b | 4837 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
77145576 | 4838 | retValDecoded = display_debug_lines_decoded (section, data, end, file); |
a262ae96 | 4839 | |
4cb93e3b | 4840 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
4841 | return 0; |
4842 | ||
4843 | return 1; | |
4844 | } | |
4845 | ||
6e3d6dc1 NC |
4846 | static debug_info * |
4847 | find_debug_info_for_offset (unsigned long offset) | |
4848 | { | |
4849 | unsigned int i; | |
4850 | ||
4851 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
4852 | return NULL; | |
4853 | ||
4854 | for (i = 0; i < num_debug_info_entries; i++) | |
4855 | if (debug_information[i].cu_offset == offset) | |
4856 | return debug_information + i; | |
4857 | ||
4858 | return NULL; | |
4859 | } | |
4860 | ||
459d52c8 DE |
4861 | static const char * |
4862 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
4863 | { | |
4864 | /* See gdb/gdb-index.h. */ | |
4865 | static const char * const kinds[] = | |
4866 | { | |
4867 | N_ ("no info"), | |
4868 | N_ ("type"), | |
4869 | N_ ("variable"), | |
4870 | N_ ("function"), | |
4871 | N_ ("other"), | |
4872 | N_ ("unused5"), | |
4873 | N_ ("unused6"), | |
4874 | N_ ("unused7") | |
4875 | }; | |
4876 | ||
4877 | return _ (kinds[kind]); | |
4878 | } | |
4879 | ||
19e6b90e | 4880 | static int |
459d52c8 DE |
4881 | display_debug_pubnames_worker (struct dwarf_section *section, |
4882 | void *file ATTRIBUTE_UNUSED, | |
4883 | int is_gnu) | |
19e6b90e | 4884 | { |
91d6fa6a | 4885 | DWARF2_Internal_PubNames names; |
19e6b90e L |
4886 | unsigned char *start = section->start; |
4887 | unsigned char *end = start + section->size; | |
4888 | ||
6e3d6dc1 NC |
4889 | /* It does not matter if this load fails, |
4890 | we test for that later on. */ | |
4891 | load_debug_info (file); | |
4892 | ||
dda8d76d | 4893 | introduce (section, FALSE); |
19e6b90e L |
4894 | |
4895 | while (start < end) | |
4896 | { | |
4897 | unsigned char *data; | |
e98fdf1a | 4898 | unsigned long sec_off; |
bf5117e3 | 4899 | unsigned int offset_size, initial_length_size; |
19e6b90e | 4900 | |
e98fdf1a | 4901 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 4902 | if (names.pn_length == 0xffffffff) |
19e6b90e | 4903 | { |
e98fdf1a | 4904 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e L |
4905 | offset_size = 8; |
4906 | initial_length_size = 12; | |
4907 | } | |
4908 | else | |
4909 | { | |
4910 | offset_size = 4; | |
4911 | initial_length_size = 4; | |
4912 | } | |
4913 | ||
e98fdf1a AM |
4914 | sec_off = start - section->start; |
4915 | if (sec_off + names.pn_length < sec_off | |
4916 | || sec_off + names.pn_length > section->size) | |
4917 | { | |
4918 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
4919 | section->name, | |
4920 | sec_off - initial_length_size, | |
4921 | dwarf_vmatoa ("x", names.pn_length)); | |
4922 | break; | |
4923 | } | |
4924 | ||
4925 | data = start; | |
4926 | start += names.pn_length; | |
4927 | ||
0c588247 NC |
4928 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
4929 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
4930 | |
4931 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
4932 | && num_debug_info_entries > 0 | |
91d6fa6a | 4933 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 4934 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 4935 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 4936 | |
0c588247 | 4937 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 4938 | |
058037d3 NC |
4939 | printf (_(" Length: %ld\n"), |
4940 | (long) names.pn_length); | |
4941 | printf (_(" Version: %d\n"), | |
4942 | names.pn_version); | |
4943 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
4944 | (unsigned long) names.pn_offset); | |
4945 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
4946 | (long) names.pn_size); | |
19e6b90e | 4947 | |
91d6fa6a | 4948 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
4949 | { |
4950 | static int warned = 0; | |
4951 | ||
4952 | if (! warned) | |
4953 | { | |
4954 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
4955 | warned = 1; | |
4956 | } | |
4957 | ||
4958 | continue; | |
4959 | } | |
4960 | ||
459d52c8 DE |
4961 | if (is_gnu) |
4962 | printf (_("\n Offset Kind Name\n")); | |
4963 | else | |
4964 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 4965 | |
e98fdf1a | 4966 | while (1) |
19e6b90e | 4967 | { |
f41e4712 | 4968 | bfd_size_type maxprint; |
e98fdf1a | 4969 | dwarf_vma offset; |
f41e4712 | 4970 | |
0c588247 | 4971 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e | 4972 | |
e98fdf1a AM |
4973 | if (offset == 0) |
4974 | break; | |
b4eb7656 | 4975 | |
e98fdf1a AM |
4976 | data += offset_size; |
4977 | if (data >= end) | |
4978 | break; | |
4979 | maxprint = (end - data) - 1; | |
f41e4712 | 4980 | |
e98fdf1a AM |
4981 | if (is_gnu) |
4982 | { | |
4983 | unsigned int kind_data; | |
4984 | gdb_index_symbol_kind kind; | |
4985 | const char *kind_name; | |
4986 | int is_static; | |
4987 | ||
4988 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
4989 | data++; | |
4990 | maxprint --; | |
4991 | /* GCC computes the kind as the upper byte in the CU index | |
4992 | word, and then right shifts it by the CU index size. | |
4993 | Left shift KIND to where the gdb-index.h accessor macros | |
4994 | can use it. */ | |
4995 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
4996 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
4997 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
4998 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
4999 | printf (" %-6lx %s,%-10s %.*s\n", | |
5000 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
5001 | kind_name, (int) maxprint, data); | |
19e6b90e | 5002 | } |
e98fdf1a AM |
5003 | else |
5004 | printf (" %-6lx\t%.*s\n", | |
5005 | (unsigned long) offset, (int) maxprint, data); | |
5006 | ||
5007 | data += strnlen ((char *) data, maxprint) + 1; | |
5008 | if (data >= end) | |
5009 | break; | |
19e6b90e | 5010 | } |
19e6b90e L |
5011 | } |
5012 | ||
5013 | printf ("\n"); | |
5014 | return 1; | |
5015 | } | |
5016 | ||
459d52c8 DE |
5017 | static int |
5018 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5019 | { | |
5020 | return display_debug_pubnames_worker (section, file, 0); | |
5021 | } | |
5022 | ||
5023 | static int | |
5024 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5025 | { | |
5026 | return display_debug_pubnames_worker (section, file, 1); | |
5027 | } | |
5028 | ||
19e6b90e L |
5029 | static int |
5030 | display_debug_macinfo (struct dwarf_section *section, | |
5031 | void *file ATTRIBUTE_UNUSED) | |
5032 | { | |
5033 | unsigned char *start = section->start; | |
5034 | unsigned char *end = start + section->size; | |
5035 | unsigned char *curr = start; | |
5036 | unsigned int bytes_read; | |
5037 | enum dwarf_macinfo_record_type op; | |
5038 | ||
dda8d76d | 5039 | introduce (section, FALSE); |
19e6b90e L |
5040 | |
5041 | while (curr < end) | |
5042 | { | |
5043 | unsigned int lineno; | |
0c588247 | 5044 | const unsigned char *string; |
19e6b90e | 5045 | |
3f5e193b | 5046 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5047 | curr++; |
5048 | ||
5049 | switch (op) | |
5050 | { | |
5051 | case DW_MACINFO_start_file: | |
5052 | { | |
5053 | unsigned int filenum; | |
5054 | ||
f6f0e17b | 5055 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5056 | curr += bytes_read; |
f6f0e17b | 5057 | filenum = read_uleb128 (curr, & bytes_read, end); |
19e6b90e L |
5058 | curr += bytes_read; |
5059 | ||
5060 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), | |
5061 | lineno, filenum); | |
5062 | } | |
5063 | break; | |
5064 | ||
5065 | case DW_MACINFO_end_file: | |
5066 | printf (_(" DW_MACINFO_end_file\n")); | |
5067 | break; | |
5068 | ||
5069 | case DW_MACINFO_define: | |
f6f0e17b | 5070 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5071 | curr += bytes_read; |
0c588247 NC |
5072 | string = curr; |
5073 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5074 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
5075 | lineno, string); | |
5076 | break; | |
5077 | ||
5078 | case DW_MACINFO_undef: | |
f6f0e17b | 5079 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5080 | curr += bytes_read; |
0c588247 NC |
5081 | string = curr; |
5082 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5083 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
5084 | lineno, string); | |
5085 | break; | |
5086 | ||
5087 | case DW_MACINFO_vendor_ext: | |
5088 | { | |
5089 | unsigned int constant; | |
5090 | ||
f6f0e17b | 5091 | constant = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5092 | curr += bytes_read; |
0c588247 NC |
5093 | string = curr; |
5094 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5095 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
5096 | constant, string); | |
5097 | } | |
5098 | break; | |
5099 | } | |
5100 | } | |
5101 | ||
5102 | return 1; | |
5103 | } | |
5104 | ||
4ccf1e31 JJ |
5105 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5106 | filename and dirname corresponding to file name table entry with index | |
5107 | FILEIDX. Return NULL on failure. */ | |
5108 | ||
5109 | static unsigned char * | |
f6f0e17b NC |
5110 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5111 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5112 | unsigned char **dir_name) |
5113 | { | |
5114 | struct dwarf_section *section = &debug_displays [line].section; | |
5115 | unsigned char *hdrptr, *dirtable, *file_name; | |
5116 | unsigned int offset_size, initial_length_size; | |
5117 | unsigned int version, opcode_base, bytes_read; | |
5118 | dwarf_vma length, diridx; | |
f6f0e17b | 5119 | const unsigned char * end; |
4ccf1e31 JJ |
5120 | |
5121 | *dir_name = NULL; | |
5122 | if (section->start == NULL | |
5123 | || line_offset >= section->size | |
5124 | || fileidx == 0) | |
5125 | return NULL; | |
5126 | ||
5127 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5128 | end = section->start + section->size; |
0c588247 NC |
5129 | |
5130 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5131 | if (length == 0xffffffff) |
5132 | { | |
5133 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5134 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
5135 | offset_size = 8; |
5136 | initial_length_size = 12; | |
5137 | } | |
5138 | else | |
5139 | { | |
5140 | offset_size = 4; | |
5141 | initial_length_size = 4; | |
5142 | } | |
e98fdf1a AM |
5143 | if (length + initial_length_size < length |
5144 | || length + initial_length_size > section->size) | |
4ccf1e31 | 5145 | return NULL; |
0c588247 NC |
5146 | |
5147 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5148 | if (version != 2 && version != 3 && version != 4) |
5149 | return NULL; | |
5150 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5151 | if (version >= 4) | |
5152 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5153 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5154 | |
5155 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
5156 | if (opcode_base == 0) |
5157 | return NULL; | |
0c588247 | 5158 | |
4ccf1e31 | 5159 | hdrptr += opcode_base - 1; |
5c1c468d NC |
5160 | if (hdrptr >= end) |
5161 | return NULL; | |
5162 | ||
4ccf1e31 JJ |
5163 | dirtable = hdrptr; |
5164 | /* Skip over dirname table. */ | |
5165 | while (*hdrptr != '\0') | |
5c1c468d NC |
5166 | { |
5167 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; | |
5168 | if (hdrptr >= end) | |
5169 | return NULL; | |
5170 | } | |
4ccf1e31 | 5171 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 5172 | |
4ccf1e31 | 5173 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 5174 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 5175 | { |
0c588247 | 5176 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
f6f0e17b | 5177 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 5178 | hdrptr += bytes_read; |
f6f0e17b | 5179 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 5180 | hdrptr += bytes_read; |
f6f0e17b | 5181 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
5182 | hdrptr += bytes_read; |
5183 | } | |
5c1c468d | 5184 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 5185 | return NULL; |
5c1c468d | 5186 | |
4ccf1e31 | 5187 | file_name = hdrptr; |
0c588247 | 5188 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
5c1c468d NC |
5189 | if (hdrptr >= end) |
5190 | return NULL; | |
f6f0e17b | 5191 | diridx = read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
5192 | if (diridx == 0) |
5193 | return file_name; | |
5c1c468d | 5194 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
0c588247 | 5195 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
5c1c468d | 5196 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
5197 | return NULL; |
5198 | *dir_name = dirtable; | |
5199 | return file_name; | |
5200 | } | |
5201 | ||
5202 | static int | |
5203 | display_debug_macro (struct dwarf_section *section, | |
5204 | void *file) | |
5205 | { | |
5206 | unsigned char *start = section->start; | |
5207 | unsigned char *end = start + section->size; | |
5208 | unsigned char *curr = start; | |
5209 | unsigned char *extended_op_buf[256]; | |
5210 | unsigned int bytes_read; | |
5211 | ||
dda8d76d NC |
5212 | load_debug_section_with_follow (str, file); |
5213 | load_debug_section_with_follow (line, file); | |
4ccf1e31 | 5214 | |
dda8d76d | 5215 | introduce (section, FALSE); |
4ccf1e31 JJ |
5216 | |
5217 | while (curr < end) | |
5218 | { | |
5219 | unsigned int lineno, version, flags; | |
5220 | unsigned int offset_size = 4; | |
0c588247 | 5221 | const unsigned char *string; |
4ccf1e31 JJ |
5222 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
5223 | unsigned char **extended_ops = NULL; | |
5224 | ||
0c588247 | 5225 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 5226 | if (version != 4 && version != 5) |
4ccf1e31 | 5227 | { |
7a7e1061 | 5228 | error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"), |
4ccf1e31 JJ |
5229 | section->name); |
5230 | return 0; | |
5231 | } | |
5232 | ||
0c588247 | 5233 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
5234 | if (flags & 1) |
5235 | offset_size = 8; | |
5236 | printf (_(" Offset: 0x%lx\n"), | |
5237 | (unsigned long) sec_offset); | |
5238 | printf (_(" Version: %d\n"), version); | |
5239 | printf (_(" Offset size: %d\n"), offset_size); | |
5240 | if (flags & 2) | |
5241 | { | |
0c588247 | 5242 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
5243 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
5244 | (unsigned long) line_offset); | |
5245 | } | |
5246 | if (flags & 4) | |
5247 | { | |
0c588247 | 5248 | unsigned int i, count, op; |
4ccf1e31 | 5249 | dwarf_vma nargs, n; |
0c588247 NC |
5250 | |
5251 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 5252 | |
4ccf1e31 JJ |
5253 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
5254 | extended_ops = extended_op_buf; | |
5255 | if (count) | |
5256 | { | |
5257 | printf (_(" Extension opcode arguments:\n")); | |
5258 | for (i = 0; i < count; i++) | |
5259 | { | |
0c588247 | 5260 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 5261 | extended_ops[op] = curr; |
f6f0e17b | 5262 | nargs = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
5263 | curr += bytes_read; |
5264 | if (nargs == 0) | |
7a7e1061 | 5265 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
5266 | else |
5267 | { | |
7a7e1061 | 5268 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
5269 | for (n = 0; n < nargs; n++) |
5270 | { | |
0c588247 NC |
5271 | unsigned int form; |
5272 | ||
5273 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
5274 | printf ("%s%s", get_FORM_name (form), |
5275 | n == nargs - 1 ? "\n" : ", "); | |
5276 | switch (form) | |
5277 | { | |
5278 | case DW_FORM_data1: | |
5279 | case DW_FORM_data2: | |
5280 | case DW_FORM_data4: | |
5281 | case DW_FORM_data8: | |
5282 | case DW_FORM_sdata: | |
5283 | case DW_FORM_udata: | |
5284 | case DW_FORM_block: | |
5285 | case DW_FORM_block1: | |
5286 | case DW_FORM_block2: | |
5287 | case DW_FORM_block4: | |
5288 | case DW_FORM_flag: | |
5289 | case DW_FORM_string: | |
5290 | case DW_FORM_strp: | |
5291 | case DW_FORM_sec_offset: | |
5292 | break; | |
5293 | default: | |
5294 | error (_("Invalid extension opcode form %s\n"), | |
5295 | get_FORM_name (form)); | |
5296 | return 0; | |
5297 | } | |
5298 | } | |
5299 | } | |
5300 | } | |
5301 | } | |
5302 | } | |
5303 | printf ("\n"); | |
5304 | ||
5305 | while (1) | |
5306 | { | |
5307 | unsigned int op; | |
5308 | ||
5309 | if (curr >= end) | |
5310 | { | |
5311 | error (_(".debug_macro section not zero terminated\n")); | |
5312 | return 0; | |
5313 | } | |
5314 | ||
0c588247 | 5315 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
5316 | if (op == 0) |
5317 | break; | |
5318 | ||
5319 | switch (op) | |
5320 | { | |
7a7e1061 | 5321 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
5322 | { |
5323 | unsigned int filenum; | |
5324 | unsigned char *file_name = NULL, *dir_name = NULL; | |
5325 | ||
f6f0e17b | 5326 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5327 | curr += bytes_read; |
f6f0e17b | 5328 | filenum = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
5329 | curr += bytes_read; |
5330 | ||
5331 | if ((flags & 2) == 0) | |
7a7e1061 | 5332 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
5333 | else |
5334 | file_name | |
5335 | = get_line_filename_and_dirname (line_offset, filenum, | |
5336 | &dir_name); | |
5337 | if (file_name == NULL) | |
7a7e1061 | 5338 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
5339 | lineno, filenum); |
5340 | else | |
7a7e1061 | 5341 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
5342 | lineno, filenum, |
5343 | dir_name != NULL ? (const char *) dir_name : "", | |
5344 | dir_name != NULL ? "/" : "", file_name); | |
5345 | } | |
5346 | break; | |
5347 | ||
7a7e1061 JK |
5348 | case DW_MACRO_end_file: |
5349 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
5350 | break; |
5351 | ||
7a7e1061 | 5352 | case DW_MACRO_define: |
f6f0e17b | 5353 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5354 | curr += bytes_read; |
0c588247 NC |
5355 | string = curr; |
5356 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5357 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5358 | lineno, string); |
5359 | break; | |
5360 | ||
7a7e1061 | 5361 | case DW_MACRO_undef: |
f6f0e17b | 5362 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5363 | curr += bytes_read; |
0c588247 NC |
5364 | string = curr; |
5365 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5366 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5367 | lineno, string); |
5368 | break; | |
5369 | ||
7a7e1061 | 5370 | case DW_MACRO_define_strp: |
f6f0e17b | 5371 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5372 | curr += bytes_read; |
0c588247 | 5373 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5374 | string = fetch_indirect_string (offset); |
7a7e1061 | 5375 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5376 | lineno, string); |
5377 | break; | |
5378 | ||
7a7e1061 | 5379 | case DW_MACRO_undef_strp: |
f6f0e17b | 5380 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5381 | curr += bytes_read; |
0c588247 | 5382 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5383 | string = fetch_indirect_string (offset); |
7a7e1061 | 5384 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5385 | lineno, string); |
5386 | break; | |
5387 | ||
7a7e1061 | 5388 | case DW_MACRO_import: |
0c588247 | 5389 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5390 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
5391 | (unsigned long) offset); |
5392 | break; | |
5393 | ||
7a7e1061 | 5394 | case DW_MACRO_define_sup: |
f6f0e17b | 5395 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 5396 | curr += bytes_read; |
0c588247 | 5397 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5398 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5399 | lineno, (unsigned long) offset); |
5400 | break; | |
5401 | ||
7a7e1061 | 5402 | case DW_MACRO_undef_sup: |
f6f0e17b | 5403 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 5404 | curr += bytes_read; |
0c588247 | 5405 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5406 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5407 | lineno, (unsigned long) offset); |
5408 | break; | |
5409 | ||
7a7e1061 | 5410 | case DW_MACRO_import_sup: |
0c588247 | 5411 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5412 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
5413 | (unsigned long) offset); |
5414 | break; | |
5415 | ||
4ccf1e31 JJ |
5416 | default: |
5417 | if (extended_ops == NULL || extended_ops[op] == NULL) | |
5418 | { | |
5419 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
5420 | return 0; | |
5421 | } | |
5422 | else | |
5423 | { | |
5424 | /* Skip over unhandled opcodes. */ | |
5425 | dwarf_vma nargs, n; | |
5426 | unsigned char *desc = extended_ops[op]; | |
f6f0e17b | 5427 | nargs = read_uleb128 (desc, &bytes_read, end); |
4ccf1e31 JJ |
5428 | desc += bytes_read; |
5429 | if (nargs == 0) | |
5430 | { | |
7a7e1061 | 5431 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
5432 | break; |
5433 | } | |
7a7e1061 | 5434 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
5435 | for (n = 0; n < nargs; n++) |
5436 | { | |
0c588247 NC |
5437 | int val; |
5438 | ||
77145576 | 5439 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 5440 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 5441 | curr |
77145576 | 5442 | = read_and_display_attr_value (0, val, 0, |
f6f0e17b | 5443 | curr, end, 0, 0, offset_size, |
341f9135 | 5444 | version, NULL, 0, NULL, |
ef0b5f1c | 5445 | NULL, ' '); |
4ccf1e31 JJ |
5446 | if (n != nargs - 1) |
5447 | printf (","); | |
5448 | } | |
5449 | printf ("\n"); | |
5450 | } | |
5451 | break; | |
5452 | } | |
5453 | } | |
5454 | ||
5455 | printf ("\n"); | |
b4eb7656 | 5456 | } |
4ccf1e31 JJ |
5457 | |
5458 | return 1; | |
5459 | } | |
5460 | ||
19e6b90e L |
5461 | static int |
5462 | display_debug_abbrev (struct dwarf_section *section, | |
5463 | void *file ATTRIBUTE_UNUSED) | |
5464 | { | |
5465 | abbrev_entry *entry; | |
5466 | unsigned char *start = section->start; | |
5467 | unsigned char *end = start + section->size; | |
5468 | ||
dda8d76d | 5469 | introduce (section, FALSE); |
19e6b90e L |
5470 | |
5471 | do | |
5472 | { | |
7282333f AM |
5473 | unsigned char *last; |
5474 | ||
19e6b90e L |
5475 | free_abbrevs (); |
5476 | ||
7282333f | 5477 | last = start; |
19e6b90e L |
5478 | start = process_abbrev_section (start, end); |
5479 | ||
5480 | if (first_abbrev == NULL) | |
5481 | continue; | |
5482 | ||
7282333f | 5483 | printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); |
19e6b90e L |
5484 | |
5485 | for (entry = first_abbrev; entry; entry = entry->next) | |
5486 | { | |
5487 | abbrev_attr *attr; | |
5488 | ||
cc5914eb | 5489 | printf (" %ld %s [%s]\n", |
19e6b90e L |
5490 | entry->entry, |
5491 | get_TAG_name (entry->tag), | |
5492 | entry->children ? _("has children") : _("no children")); | |
5493 | ||
5494 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
5495 | { |
5496 | printf (" %-18s %s", | |
5497 | get_AT_name (attr->attribute), | |
5498 | get_FORM_name (attr->form)); | |
5499 | if (attr->form == DW_FORM_implicit_const) | |
5500 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
5501 | putchar ('\n'); | |
5502 | } | |
19e6b90e L |
5503 | } |
5504 | } | |
5505 | while (start); | |
5506 | ||
5507 | printf ("\n"); | |
5508 | ||
5509 | return 1; | |
5510 | } | |
5511 | ||
42bcef4a AB |
5512 | /* Return true when ADDR is the maximum address, when addresses are |
5513 | POINTER_SIZE bytes long. */ | |
5514 | ||
5515 | static bfd_boolean | |
5516 | is_max_address (dwarf_vma addr, unsigned int pointer_size) | |
5517 | { | |
5518 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
5519 | return ((addr & mask) == mask); | |
5520 | } | |
5521 | ||
9f272209 AO |
5522 | /* Display a view pair list starting at *VSTART_PTR and ending at |
5523 | VLISTEND within SECTION. */ | |
5524 | ||
5525 | static void | |
5526 | display_view_pair_list (struct dwarf_section *section, | |
5527 | unsigned char **vstart_ptr, | |
5528 | unsigned int debug_info_entry, | |
5529 | unsigned char *vlistend) | |
5530 | { | |
5531 | unsigned char *vstart = *vstart_ptr; | |
5532 | unsigned char *section_end = section->start + section->size; | |
5533 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
5534 | ||
5535 | if (vlistend < section_end) | |
5536 | section_end = vlistend; | |
5537 | ||
5538 | putchar ('\n'); | |
5539 | ||
5540 | while (vstart < section_end) | |
5541 | { | |
5542 | dwarf_vma off = vstart - section->start; | |
5543 | dwarf_vma vbegin, vend; | |
5544 | ||
5545 | unsigned int bytes_read; | |
5546 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
5547 | vstart += bytes_read; | |
5548 | if (vstart == section_end) | |
5549 | { | |
5550 | vstart -= bytes_read; | |
5551 | break; | |
5552 | } | |
5553 | ||
5554 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
5555 | vstart += bytes_read; | |
5556 | ||
5557 | printf (" %8.8lx ", (unsigned long) off); | |
5558 | ||
5559 | print_dwarf_view (vbegin, pointer_size, 1); | |
5560 | print_dwarf_view (vend, pointer_size, 1); | |
5561 | printf (_("location view pair\n")); | |
5562 | } | |
5563 | ||
5564 | putchar ('\n'); | |
5565 | *vstart_ptr = vstart; | |
5566 | } | |
5567 | ||
4723351a CC |
5568 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
5569 | ||
5570 | static void | |
5571 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
5572 | unsigned char **start_ptr, |
5573 | unsigned int debug_info_entry, | |
359ca075 JK |
5574 | dwarf_vma offset, |
5575 | dwarf_vma base_address, | |
9f272209 | 5576 | unsigned char **vstart_ptr, |
b4eb7656 | 5577 | int has_frame_base) |
4723351a | 5578 | { |
9f272209 | 5579 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 5580 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
5581 | unsigned long cu_offset; |
5582 | unsigned int pointer_size; | |
5583 | unsigned int offset_size; | |
5584 | int dwarf_version; | |
4723351a CC |
5585 | |
5586 | dwarf_vma begin; | |
5587 | dwarf_vma end; | |
5588 | unsigned short length; | |
5589 | int need_frame_base; | |
5590 | ||
82b1b41b NC |
5591 | if (debug_info_entry >= num_debug_info_entries) |
5592 | { | |
5593 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
5594 | debug_info_entry); | |
5595 | return; | |
5596 | } | |
b4eb7656 | 5597 | |
82b1b41b NC |
5598 | cu_offset = debug_information [debug_info_entry].cu_offset; |
5599 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5600 | offset_size = debug_information [debug_info_entry].offset_size; | |
5601 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 5602 | |
f41e4712 NC |
5603 | if (pointer_size < 2 || pointer_size > 8) |
5604 | { | |
5605 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5606 | pointer_size, debug_info_entry); | |
5607 | return; | |
5608 | } | |
5609 | ||
4723351a CC |
5610 | while (1) |
5611 | { | |
359ca075 | 5612 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 5613 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 5614 | |
4723351a | 5615 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
5616 | { |
5617 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5618 | (unsigned long) offset); |
b4eb7656 AM |
5619 | break; |
5620 | } | |
4723351a | 5621 | |
359ca075 | 5622 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 5623 | |
0c588247 NC |
5624 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
5625 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 5626 | |
4723351a | 5627 | if (begin == 0 && end == 0) |
b4eb7656 | 5628 | { |
d1c4b12b NC |
5629 | /* PR 18374: In a object file we can have a location list that |
5630 | starts with a begin and end of 0 because there are relocations | |
5631 | that need to be applied to the addresses. Actually applying | |
5632 | the relocations now does not help as they will probably resolve | |
5633 | to 0, since the object file has not been fully linked. Real | |
5634 | end of list markers will not have any relocations against them. */ | |
5635 | if (! reloc_at (section, off) | |
5636 | && ! reloc_at (section, off + pointer_size)) | |
5637 | { | |
5638 | printf (_("<End of list>\n")); | |
5639 | break; | |
5640 | } | |
b4eb7656 | 5641 | } |
4723351a CC |
5642 | |
5643 | /* Check base address specifiers. */ | |
42bcef4a AB |
5644 | if (is_max_address (begin, pointer_size) |
5645 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
5646 | { |
5647 | base_address = end; | |
5648 | print_dwarf_vma (begin, pointer_size); | |
5649 | print_dwarf_vma (end, pointer_size); | |
5650 | printf (_("(base address)\n")); | |
5651 | continue; | |
5652 | } | |
4723351a | 5653 | |
9f272209 AO |
5654 | if (vstart) |
5655 | { | |
5656 | unsigned int bytes_read; | |
5657 | ||
5658 | off = offset + (vstart - *start_ptr); | |
5659 | ||
5660 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
5661 | vstart += bytes_read; | |
5662 | print_dwarf_view (vbegin, pointer_size, 1); | |
5663 | ||
5664 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
5665 | vstart += bytes_read; | |
5666 | print_dwarf_view (vend, pointer_size, 1); | |
5667 | ||
5668 | printf (_("views at %8.8lx for:\n %*s "), | |
5669 | (unsigned long) off, 8, ""); | |
5670 | } | |
5671 | ||
4723351a | 5672 | if (start + 2 > section_end) |
b4eb7656 AM |
5673 | { |
5674 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5675 | (unsigned long) offset); |
b4eb7656 AM |
5676 | break; |
5677 | } | |
4723351a | 5678 | |
0c588247 | 5679 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
5680 | |
5681 | if (start + length > section_end) | |
b4eb7656 AM |
5682 | { |
5683 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5684 | (unsigned long) offset); |
b4eb7656 AM |
5685 | break; |
5686 | } | |
4723351a CC |
5687 | |
5688 | print_dwarf_vma (begin + base_address, pointer_size); | |
5689 | print_dwarf_vma (end + base_address, pointer_size); | |
5690 | ||
5691 | putchar ('('); | |
5692 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
5693 | pointer_size, |
5694 | offset_size, | |
5695 | dwarf_version, | |
5696 | length, | |
5697 | cu_offset, section); | |
4723351a CC |
5698 | putchar (')'); |
5699 | ||
5700 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 5701 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 5702 | |
9f272209 | 5703 | if (begin == end && vbegin == vend) |
b4eb7656 | 5704 | fputs (_(" (start == end)"), stdout); |
9f272209 | 5705 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 5706 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
5707 | |
5708 | putchar ('\n'); | |
5709 | ||
5710 | start += length; | |
5711 | } | |
5712 | ||
5713 | *start_ptr = start; | |
9f272209 | 5714 | *vstart_ptr = vstart; |
4723351a CC |
5715 | } |
5716 | ||
77145576 JK |
5717 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
5718 | ||
5719 | static void | |
5720 | display_loclists_list (struct dwarf_section *section, | |
5721 | unsigned char **start_ptr, | |
5722 | unsigned int debug_info_entry, | |
5723 | dwarf_vma offset, | |
5724 | dwarf_vma base_address, | |
9f272209 | 5725 | unsigned char **vstart_ptr, |
77145576 JK |
5726 | int has_frame_base) |
5727 | { | |
9f272209 | 5728 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
5729 | unsigned char *section_end = section->start + section->size; |
5730 | unsigned long cu_offset; | |
5731 | unsigned int pointer_size; | |
5732 | unsigned int offset_size; | |
5733 | int dwarf_version; | |
5734 | unsigned int bytes_read; | |
5735 | ||
9dfd0db9 | 5736 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
5737 | dwarf_vma begin = -1, vbegin = -1; |
5738 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
5739 | dwarf_vma length; |
5740 | int need_frame_base; | |
5741 | ||
5742 | if (debug_info_entry >= num_debug_info_entries) | |
5743 | { | |
5744 | warn (_("No debug information available for " | |
5745 | "loclists lists of entry: %u\n"), | |
5746 | debug_info_entry); | |
5747 | return; | |
5748 | } | |
5749 | ||
5750 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
5751 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5752 | offset_size = debug_information [debug_info_entry].offset_size; | |
5753 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
5754 | ||
5755 | if (pointer_size < 2 || pointer_size > 8) | |
5756 | { | |
5757 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5758 | pointer_size, debug_info_entry); | |
5759 | return; | |
5760 | } | |
5761 | ||
5762 | while (1) | |
5763 | { | |
5764 | dwarf_vma off = offset + (start - *start_ptr); | |
5765 | enum dwarf_location_list_entry_type llet; | |
5766 | ||
5767 | if (start + 1 > section_end) | |
5768 | { | |
5769 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5770 | (unsigned long) offset); | |
5771 | break; | |
5772 | } | |
5773 | ||
5774 | printf (" %8.8lx ", (unsigned long) off); | |
5775 | ||
5776 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
5777 | ||
9f272209 AO |
5778 | if (vstart && llet == DW_LLE_offset_pair) |
5779 | { | |
5780 | off = offset + (vstart - *start_ptr); | |
5781 | ||
5782 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
5783 | vstart += bytes_read; | |
5784 | print_dwarf_view (vbegin, pointer_size, 1); | |
5785 | ||
5786 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
5787 | vstart += bytes_read; | |
5788 | print_dwarf_view (vend, pointer_size, 1); | |
5789 | ||
5790 | printf (_("views at %8.8lx for:\n %*s "), | |
5791 | (unsigned long) off, 8, ""); | |
5792 | } | |
5793 | ||
77145576 JK |
5794 | switch (llet) |
5795 | { | |
5796 | case DW_LLE_end_of_list: | |
5797 | printf (_("<End of list>\n")); | |
5798 | break; | |
5799 | case DW_LLE_offset_pair: | |
5800 | begin = read_uleb128 (start, &bytes_read, section_end); | |
5801 | start += bytes_read; | |
5802 | end = read_uleb128 (start, &bytes_read, section_end); | |
5803 | start += bytes_read; | |
5804 | break; | |
5805 | case DW_LLE_base_address: | |
5806 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
5807 | section_end); | |
5808 | print_dwarf_vma (base_address, pointer_size); | |
5809 | printf (_("(base address)\n")); | |
5810 | break; | |
9f272209 AO |
5811 | #ifdef DW_LLE_view_pair |
5812 | case DW_LLE_view_pair: | |
5813 | if (vstart) | |
5814 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
5815 | vbegin = read_uleb128 (start, &bytes_read, section_end); | |
5816 | start += bytes_read; | |
5817 | print_dwarf_view (vbegin, pointer_size, 1); | |
5818 | ||
5819 | vend = read_uleb128 (start, &bytes_read, section_end); | |
5820 | start += bytes_read; | |
5821 | print_dwarf_view (vend, pointer_size, 1); | |
5822 | ||
5823 | printf (_("views for:\n")); | |
5824 | continue; | |
5825 | #endif | |
77145576 JK |
5826 | default: |
5827 | error (_("Invalid location list entry type %d\n"), llet); | |
5828 | return; | |
5829 | } | |
5830 | if (llet == DW_LLE_end_of_list) | |
5831 | break; | |
5832 | if (llet != DW_LLE_offset_pair) | |
5833 | continue; | |
5834 | ||
5835 | if (start + 2 > section_end) | |
5836 | { | |
5837 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5838 | (unsigned long) offset); | |
5839 | break; | |
5840 | } | |
5841 | ||
5842 | length = read_uleb128 (start, &bytes_read, section_end); | |
5843 | start += bytes_read; | |
5844 | ||
5845 | print_dwarf_vma (begin + base_address, pointer_size); | |
5846 | print_dwarf_vma (end + base_address, pointer_size); | |
5847 | ||
5848 | putchar ('('); | |
5849 | need_frame_base = decode_location_expression (start, | |
5850 | pointer_size, | |
5851 | offset_size, | |
5852 | dwarf_version, | |
5853 | length, | |
5854 | cu_offset, section); | |
5855 | putchar (')'); | |
5856 | ||
5857 | if (need_frame_base && !has_frame_base) | |
5858 | printf (_(" [without DW_AT_frame_base]")); | |
5859 | ||
9f272209 | 5860 | if (begin == end && vbegin == vend) |
77145576 | 5861 | fputs (_(" (start == end)"), stdout); |
9f272209 | 5862 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
5863 | fputs (_(" (start > end)"), stdout); |
5864 | ||
5865 | putchar ('\n'); | |
5866 | ||
5867 | start += length; | |
9f272209 | 5868 | vbegin = vend = -1; |
77145576 JK |
5869 | } |
5870 | ||
9f272209 AO |
5871 | if (vbegin != vm1 || vend != vm1) |
5872 | printf (_("Trailing view pair not used in a range")); | |
5873 | ||
77145576 | 5874 | *start_ptr = start; |
9f272209 | 5875 | *vstart_ptr = vstart; |
77145576 JK |
5876 | } |
5877 | ||
fab128ef CC |
5878 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
5879 | right-adjusted in a field of length LEN, and followed by a space. */ | |
5880 | ||
5881 | static void | |
5882 | print_addr_index (unsigned int idx, unsigned int len) | |
5883 | { | |
5884 | static char buf[15]; | |
5885 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 5886 | printf ("%*s ", len, buf); |
fab128ef CC |
5887 | } |
5888 | ||
4723351a CC |
5889 | /* Display a location list from a .dwo section. It uses address indexes rather |
5890 | than embedded addresses. This code closely follows display_loc_list, but the | |
5891 | two are sufficiently different that combining things is very ugly. */ | |
5892 | ||
5893 | static void | |
5894 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
5895 | unsigned char **start_ptr, |
5896 | unsigned int debug_info_entry, | |
359ca075 | 5897 | dwarf_vma offset, |
9f272209 | 5898 | unsigned char **vstart_ptr, |
b4eb7656 | 5899 | int has_frame_base) |
4723351a | 5900 | { |
9f272209 | 5901 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 5902 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
5903 | unsigned long cu_offset; |
5904 | unsigned int pointer_size; | |
5905 | unsigned int offset_size; | |
5906 | int dwarf_version; | |
4723351a CC |
5907 | int entry_type; |
5908 | unsigned short length; | |
5909 | int need_frame_base; | |
fab128ef | 5910 | unsigned int idx; |
4723351a CC |
5911 | unsigned int bytes_read; |
5912 | ||
82b1b41b NC |
5913 | if (debug_info_entry >= num_debug_info_entries) |
5914 | { | |
5915 | warn (_("No debug information for loc lists of entry: %u\n"), | |
5916 | debug_info_entry); | |
5917 | return; | |
5918 | } | |
5919 | ||
5920 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
5921 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5922 | offset_size = debug_information [debug_info_entry].offset_size; | |
5923 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
5924 | ||
f41e4712 NC |
5925 | if (pointer_size < 2 || pointer_size > 8) |
5926 | { | |
5927 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5928 | pointer_size, debug_info_entry); | |
5929 | return; | |
5930 | } | |
5931 | ||
4723351a CC |
5932 | while (1) |
5933 | { | |
359ca075 | 5934 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 5935 | |
fab128ef | 5936 | if (start >= section_end) |
b4eb7656 AM |
5937 | { |
5938 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5939 | (unsigned long) offset); |
b4eb7656 AM |
5940 | break; |
5941 | } | |
4723351a | 5942 | |
0c588247 | 5943 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
5944 | |
5945 | if (vstart) | |
5946 | switch (entry_type) | |
5947 | { | |
5948 | default: | |
5949 | break; | |
5950 | ||
5951 | case 2: | |
5952 | case 3: | |
5953 | case 4: | |
5954 | { | |
5955 | dwarf_vma view; | |
5956 | dwarf_vma off = offset + (vstart - *start_ptr); | |
5957 | ||
5958 | view = read_uleb128 (vstart, &bytes_read, section_end); | |
5959 | vstart += bytes_read; | |
5960 | print_dwarf_view (view, 8, 1); | |
5961 | ||
5962 | view = read_uleb128 (vstart, &bytes_read, section_end); | |
5963 | vstart += bytes_read; | |
5964 | print_dwarf_view (view, 8, 1); | |
5965 | ||
5966 | printf (_("views at %8.8lx for:\n %*s "), | |
5967 | (unsigned long) off, 8, ""); | |
5968 | ||
5969 | } | |
5970 | break; | |
5971 | } | |
5972 | ||
4723351a | 5973 | switch (entry_type) |
b4eb7656 AM |
5974 | { |
5975 | case 0: /* A terminating entry. */ | |
5976 | *start_ptr = start; | |
9f272209 | 5977 | *vstart_ptr = vstart; |
b4eb7656 AM |
5978 | printf (_("<End of list>\n")); |
5979 | return; | |
5980 | case 1: /* A base-address entry. */ | |
5981 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5982 | start += bytes_read; | |
5983 | print_addr_index (idx, 8); | |
9f272209 | 5984 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
5985 | printf (_("(base address selection entry)\n")); |
5986 | continue; | |
5987 | case 2: /* A start/end entry. */ | |
5988 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5989 | start += bytes_read; | |
5990 | print_addr_index (idx, 8); | |
5991 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5992 | start += bytes_read; | |
5993 | print_addr_index (idx, 8); | |
5994 | break; | |
5995 | case 3: /* A start/length entry. */ | |
5996 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5997 | start += bytes_read; | |
5998 | print_addr_index (idx, 8); | |
5999 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6000 | printf ("%08x ", idx); | |
6001 | break; | |
6002 | case 4: /* An offset pair entry. */ | |
6003 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6004 | printf ("%08x ", idx); | |
6005 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6006 | printf ("%08x ", idx); | |
6007 | break; | |
6008 | default: | |
6009 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6010 | *start_ptr = start; | |
9f272209 | 6011 | *vstart_ptr = vstart; |
b4eb7656 AM |
6012 | return; |
6013 | } | |
4723351a CC |
6014 | |
6015 | if (start + 2 > section_end) | |
b4eb7656 AM |
6016 | { |
6017 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6018 | (unsigned long) offset); |
b4eb7656 AM |
6019 | break; |
6020 | } | |
4723351a | 6021 | |
0c588247 | 6022 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6023 | if (start + length > section_end) |
b4eb7656 AM |
6024 | { |
6025 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6026 | (unsigned long) offset); |
b4eb7656 AM |
6027 | break; |
6028 | } | |
4723351a CC |
6029 | |
6030 | putchar ('('); | |
6031 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6032 | pointer_size, |
6033 | offset_size, | |
6034 | dwarf_version, | |
6035 | length, | |
6036 | cu_offset, section); | |
4723351a CC |
6037 | putchar (')'); |
6038 | ||
6039 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6040 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6041 | |
6042 | putchar ('\n'); | |
6043 | ||
6044 | start += length; | |
6045 | } | |
6046 | ||
6047 | *start_ptr = start; | |
9f272209 | 6048 | *vstart_ptr = vstart; |
4723351a CC |
6049 | } |
6050 | ||
9f272209 AO |
6051 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6052 | loc_views. */ | |
51d0d03f | 6053 | |
9f272209 | 6054 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6055 | |
6056 | static int | |
6057 | loc_offsets_compar (const void *ap, const void *bp) | |
6058 | { | |
6059 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6060 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6061 | ||
9f272209 AO |
6062 | int ret = (a > b) - (b > a); |
6063 | if (ret) | |
6064 | return ret; | |
6065 | ||
6066 | a = loc_views[*(const unsigned int *) ap]; | |
6067 | b = loc_views[*(const unsigned int *) bp]; | |
6068 | ||
6069 | ret = (a > b) - (b > a); | |
6070 | ||
6071 | return ret; | |
51d0d03f JJ |
6072 | } |
6073 | ||
19e6b90e L |
6074 | static int |
6075 | display_debug_loc (struct dwarf_section *section, void *file) | |
6076 | { | |
9f272209 | 6077 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6078 | unsigned long bytes; |
6079 | unsigned char *section_begin = start; | |
6080 | unsigned int num_loc_list = 0; | |
6081 | unsigned long last_offset = 0; | |
9f272209 | 6082 | unsigned long last_view = 0; |
19e6b90e L |
6083 | unsigned int first = 0; |
6084 | unsigned int i; | |
6085 | unsigned int j; | |
6086 | int seen_first_offset = 0; | |
51d0d03f | 6087 | int locs_sorted = 1; |
9f272209 | 6088 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6089 | unsigned int *array = NULL; |
4723351a | 6090 | const char *suffix = strrchr (section->name, '.'); |
24841daa | 6091 | bfd_boolean is_dwo = FALSE; |
77145576 JK |
6092 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6093 | dwarf_vma expected_start = 0; | |
4723351a CC |
6094 | |
6095 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
24841daa | 6096 | is_dwo = TRUE; |
19e6b90e L |
6097 | |
6098 | bytes = section->size; | |
19e6b90e L |
6099 | |
6100 | if (bytes == 0) | |
6101 | { | |
6102 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6103 | return 0; | |
6104 | } | |
6105 | ||
77145576 JK |
6106 | if (is_loclists) |
6107 | { | |
6108 | unsigned char *hdrptr = section_begin; | |
6109 | dwarf_vma ll_length; | |
6110 | unsigned short ll_version; | |
6111 | unsigned char *end = section_begin + section->size; | |
6112 | unsigned char address_size, segment_selector_size; | |
6113 | uint32_t offset_entry_count; | |
6114 | ||
6115 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6116 | if (ll_length == 0xffffffff) | |
6117 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6118 | ||
6119 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6120 | if (ll_version != 5) | |
6121 | { | |
6122 | warn (_("The %s section contains corrupt or " | |
6123 | "unsupported version number: %d.\n"), | |
6124 | section->name, ll_version); | |
6125 | return 0; | |
6126 | } | |
6127 | ||
6128 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6129 | ||
6130 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6131 | if (segment_selector_size != 0) | |
6132 | { | |
6133 | warn (_("The %s section contains " | |
6134 | "unsupported segment selector size: %d.\n"), | |
6135 | section->name, segment_selector_size); | |
6136 | return 0; | |
6137 | } | |
6138 | ||
6139 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6140 | if (offset_entry_count != 0) | |
6141 | { | |
6142 | warn (_("The %s section contains " | |
6143 | "unsupported offset entry count: %d.\n"), | |
6144 | section->name, offset_entry_count); | |
6145 | return 0; | |
6146 | } | |
6147 | ||
6148 | expected_start = hdrptr - section_begin; | |
6149 | } | |
6150 | ||
1febe64d NC |
6151 | if (load_debug_info (file) == 0) |
6152 | { | |
6153 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6154 | section->name); | |
6155 | return 0; | |
6156 | } | |
19e6b90e L |
6157 | |
6158 | /* Check the order of location list in .debug_info section. If | |
6159 | offsets of location lists are in the ascending order, we can | |
6160 | use `debug_information' directly. */ | |
6161 | for (i = 0; i < num_debug_info_entries; i++) | |
6162 | { | |
6163 | unsigned int num; | |
6164 | ||
6165 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
6166 | if (num > num_loc_list) |
6167 | num_loc_list = num; | |
19e6b90e L |
6168 | |
6169 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 6170 | if (locs_sorted && num != 0) |
19e6b90e L |
6171 | { |
6172 | if (!seen_first_offset) | |
6173 | { | |
6174 | /* This is the first location list. */ | |
6175 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 6176 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
6177 | first = i; |
6178 | seen_first_offset = 1; | |
6179 | j = 1; | |
6180 | } | |
6181 | else | |
6182 | j = 0; | |
6183 | ||
6184 | for (; j < num; j++) | |
6185 | { | |
6186 | if (last_offset > | |
9f272209 AO |
6187 | debug_information [i].loc_offsets [j] |
6188 | || (last_offset == debug_information [i].loc_offsets [j] | |
6189 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 6190 | { |
51d0d03f | 6191 | locs_sorted = 0; |
19e6b90e L |
6192 | break; |
6193 | } | |
6194 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 6195 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
6196 | } |
6197 | } | |
6198 | } | |
6199 | ||
19e6b90e L |
6200 | if (!seen_first_offset) |
6201 | error (_("No location lists in .debug_info section!\n")); | |
6202 | ||
d4bfc77b | 6203 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
6204 | && debug_information [first].loc_offsets [0] != expected_start |
6205 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
6206 | warn (_("Location lists in %s section start at 0x%s\n"), |
6207 | section->name, | |
6208 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 6209 | |
51d0d03f JJ |
6210 | if (!locs_sorted) |
6211 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d NC |
6212 | |
6213 | introduce (section, FALSE); | |
6214 | ||
d1c4b12b NC |
6215 | if (reloc_at (section, 0)) |
6216 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 6217 | |
d1c4b12b | 6218 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
6219 | |
6220 | seen_first_offset = 0; | |
6221 | for (i = first; i < num_debug_info_entries; i++) | |
6222 | { | |
9f272209 | 6223 | dwarf_vma offset, voffset; |
359ca075 | 6224 | dwarf_vma base_address; |
d1c4b12b | 6225 | unsigned int k; |
19e6b90e L |
6226 | int has_frame_base; |
6227 | ||
51d0d03f JJ |
6228 | if (!locs_sorted) |
6229 | { | |
6230 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
6231 | array[k] = k; | |
6232 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 6233 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
6234 | qsort (array, debug_information [i].num_loc_offsets, |
6235 | sizeof (*array), loc_offsets_compar); | |
6236 | } | |
19e6b90e | 6237 | |
9f272209 | 6238 | int adjacent_view_loclists = 1; |
51d0d03f | 6239 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 6240 | { |
51d0d03f JJ |
6241 | j = locs_sorted ? k : array[k]; |
6242 | if (k | |
9f272209 | 6243 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 6244 | ? k - 1 : array [k - 1]] |
9f272209 AO |
6245 | == debug_information [i].loc_offsets [j]) |
6246 | && (debug_information [i].loc_views [locs_sorted | |
6247 | ? k - 1 : array [k - 1]] | |
6248 | == debug_information [i].loc_views [j])) | |
51d0d03f | 6249 | continue; |
19e6b90e | 6250 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 6251 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 6252 | next = section_begin + offset; |
9f272209 AO |
6253 | voffset = debug_information [i].loc_views [j]; |
6254 | if (voffset != vm1) | |
6255 | vnext = section_begin + voffset; | |
6256 | else | |
6257 | vnext = NULL; | |
19e6b90e L |
6258 | base_address = debug_information [i].base_address; |
6259 | ||
9f272209 AO |
6260 | if (vnext && vnext < next) |
6261 | { | |
6262 | vstart = vnext; | |
6263 | display_view_pair_list (section, &vstart, i, next); | |
6264 | if (start == vnext) | |
6265 | start = vstart; | |
6266 | } | |
6267 | ||
6268 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
6269 | seen_first_offset = 1; |
6270 | else | |
6271 | { | |
6272 | if (start < next) | |
6273 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6274 | (unsigned long) (start - section_begin), |
c8071705 | 6275 | (unsigned long) offset); |
19e6b90e L |
6276 | else if (start > next) |
6277 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6278 | (unsigned long) (start - section_begin), |
c8071705 | 6279 | (unsigned long) offset); |
19e6b90e L |
6280 | } |
6281 | start = next; | |
9f272209 | 6282 | vstart = vnext; |
19e6b90e L |
6283 | |
6284 | if (offset >= bytes) | |
6285 | { | |
6286 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 6287 | (unsigned long) offset); |
19e6b90e L |
6288 | continue; |
6289 | } | |
6290 | ||
9f272209 AO |
6291 | if (vnext && voffset >= bytes) |
6292 | { | |
6293 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
6294 | (unsigned long) voffset); | |
6295 | continue; | |
6296 | } | |
6297 | ||
77145576 JK |
6298 | if (!is_loclists) |
6299 | { | |
6300 | if (is_dwo) | |
6301 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 6302 | &vstart, has_frame_base); |
77145576 JK |
6303 | else |
6304 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 6305 | &vstart, has_frame_base); |
77145576 | 6306 | } |
b4eb7656 | 6307 | else |
77145576 JK |
6308 | { |
6309 | if (is_dwo) | |
6310 | warn (_("DWO is not yet supported.\n")); | |
6311 | else | |
6312 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
6313 | &vstart, has_frame_base); |
6314 | } | |
6315 | ||
6316 | /* FIXME: this arrangement is quite simplistic. Nothing | |
6317 | requires locview lists to be adjacent to corresponding | |
6318 | loclists, and a single loclist could be augmented by | |
6319 | different locview lists, and vice-versa, unlikely as it | |
6320 | is that it would make sense to do so. Hopefully we'll | |
6321 | have view pair support built into loclists before we ever | |
6322 | need to address all these possibilities. */ | |
6323 | if (adjacent_view_loclists && vnext | |
6324 | && vnext != start && vstart != next) | |
6325 | { | |
6326 | adjacent_view_loclists = 0; | |
6327 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 6328 | } |
9f272209 AO |
6329 | |
6330 | if (vnext && vnext == start) | |
6331 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
6332 | } |
6333 | } | |
031cd65f | 6334 | |
4723351a | 6335 | if (start < section->start + section->size) |
d3a49aa8 AM |
6336 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
6337 | "There are %ld unused bytes at the end of section %s\n", | |
6338 | (long) (section->start + section->size - start)), | |
4723351a | 6339 | (long) (section->start + section->size - start), section->name); |
98fb390a | 6340 | putchar ('\n'); |
51d0d03f | 6341 | free (array); |
19e6b90e L |
6342 | return 1; |
6343 | } | |
6344 | ||
6345 | static int | |
6346 | display_debug_str (struct dwarf_section *section, | |
6347 | void *file ATTRIBUTE_UNUSED) | |
6348 | { | |
6349 | unsigned char *start = section->start; | |
6350 | unsigned long bytes = section->size; | |
6351 | dwarf_vma addr = section->address; | |
6352 | ||
6353 | if (bytes == 0) | |
6354 | { | |
6355 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6356 | return 0; | |
6357 | } | |
6358 | ||
dda8d76d | 6359 | introduce (section, FALSE); |
19e6b90e L |
6360 | |
6361 | while (bytes) | |
6362 | { | |
6363 | int j; | |
6364 | int k; | |
6365 | int lbytes; | |
6366 | ||
6367 | lbytes = (bytes > 16 ? 16 : bytes); | |
6368 | ||
6369 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
6370 | ||
6371 | for (j = 0; j < 16; j++) | |
6372 | { | |
6373 | if (j < lbytes) | |
6374 | printf ("%2.2x", start[j]); | |
6375 | else | |
6376 | printf (" "); | |
6377 | ||
6378 | if ((j & 3) == 3) | |
6379 | printf (" "); | |
6380 | } | |
6381 | ||
6382 | for (j = 0; j < lbytes; j++) | |
6383 | { | |
6384 | k = start[j]; | |
6385 | if (k >= ' ' && k < 0x80) | |
6386 | printf ("%c", k); | |
6387 | else | |
6388 | printf ("."); | |
6389 | } | |
6390 | ||
6391 | putchar ('\n'); | |
6392 | ||
6393 | start += lbytes; | |
6394 | addr += lbytes; | |
6395 | bytes -= lbytes; | |
6396 | } | |
6397 | ||
6398 | putchar ('\n'); | |
6399 | ||
6400 | return 1; | |
6401 | } | |
6402 | ||
19e6b90e L |
6403 | static int |
6404 | display_debug_info (struct dwarf_section *section, void *file) | |
6405 | { | |
d85bf2ba | 6406 | return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE); |
19e6b90e L |
6407 | } |
6408 | ||
2b6f5997 CC |
6409 | static int |
6410 | display_debug_types (struct dwarf_section *section, void *file) | |
6411 | { | |
d85bf2ba | 6412 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
6f875884 TG |
6413 | } |
6414 | ||
6415 | static int | |
6416 | display_trace_info (struct dwarf_section *section, void *file) | |
6417 | { | |
d85bf2ba | 6418 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
2b6f5997 | 6419 | } |
19e6b90e L |
6420 | |
6421 | static int | |
6422 | display_debug_aranges (struct dwarf_section *section, | |
6423 | void *file ATTRIBUTE_UNUSED) | |
6424 | { | |
6425 | unsigned char *start = section->start; | |
6426 | unsigned char *end = start + section->size; | |
6427 | ||
dda8d76d | 6428 | introduce (section, FALSE); |
19e6b90e | 6429 | |
6e3d6dc1 NC |
6430 | /* It does not matter if this load fails, |
6431 | we test for that later on. */ | |
6432 | load_debug_info (file); | |
6433 | ||
19e6b90e L |
6434 | while (start < end) |
6435 | { | |
6436 | unsigned char *hdrptr; | |
6437 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 6438 | unsigned char *addr_ranges; |
2d9472a2 NC |
6439 | dwarf_vma length; |
6440 | dwarf_vma address; | |
e98fdf1a | 6441 | unsigned long sec_off; |
53b8873b | 6442 | unsigned char address_size; |
19e6b90e | 6443 | int excess; |
bf5117e3 NC |
6444 | unsigned int offset_size; |
6445 | unsigned int initial_length_size; | |
19e6b90e L |
6446 | |
6447 | hdrptr = start; | |
6448 | ||
0c588247 | 6449 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
6450 | if (arange.ar_length == 0xffffffff) |
6451 | { | |
0c588247 | 6452 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
6453 | offset_size = 8; |
6454 | initial_length_size = 12; | |
6455 | } | |
6456 | else | |
6457 | { | |
6458 | offset_size = 4; | |
6459 | initial_length_size = 4; | |
6460 | } | |
6461 | ||
e98fdf1a AM |
6462 | sec_off = hdrptr - section->start; |
6463 | if (sec_off + arange.ar_length < sec_off | |
6464 | || sec_off + arange.ar_length > section->size) | |
6465 | { | |
6466 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
6467 | section->name, | |
6468 | sec_off - initial_length_size, | |
6469 | dwarf_vmatoa ("x", arange.ar_length)); | |
6470 | break; | |
6471 | } | |
6472 | ||
0c588247 NC |
6473 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
6474 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 6475 | |
6e3d6dc1 NC |
6476 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
6477 | && num_debug_info_entries > 0 | |
6478 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
6479 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 6480 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 6481 | |
0c588247 NC |
6482 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
6483 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
6484 | |
6485 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
6486 | { | |
67f101ee NC |
6487 | /* PR 19872: A version number of 0 probably means that there is |
6488 | padding at the end of the .debug_aranges section. Gold puts | |
6489 | it there when performing an incremental link, for example. | |
6490 | So do not generate a warning in this case. */ | |
6491 | if (arange.ar_version) | |
6492 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
6493 | break; |
6494 | } | |
6495 | ||
47704ddf KT |
6496 | printf (_(" Length: %ld\n"), |
6497 | (long) arange.ar_length); | |
19e6b90e | 6498 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
6499 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
6500 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
6501 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
6502 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
6503 | ||
53b8873b NC |
6504 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
6505 | ||
f41e4712 NC |
6506 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
6507 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
6508 | { |
6509 | error (_("Invalid address size in %s section!\n"), | |
6510 | section->name); | |
6511 | break; | |
6512 | } | |
6513 | ||
53b8873b NC |
6514 | /* The DWARF spec does not require that the address size be a power |
6515 | of two, but we do. This will have to change if we ever encounter | |
6516 | an uneven architecture. */ | |
6517 | if ((address_size & (address_size - 1)) != 0) | |
6518 | { | |
6519 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
6520 | break; | |
6521 | } | |
cecf136e | 6522 | |
209c9a13 NC |
6523 | if (address_size > 4) |
6524 | printf (_("\n Address Length\n")); | |
6525 | else | |
6526 | printf (_("\n Address Length\n")); | |
19e6b90e | 6527 | |
91d6fa6a | 6528 | addr_ranges = hdrptr; |
19e6b90e | 6529 | |
53b8873b NC |
6530 | /* Must pad to an alignment boundary that is twice the address size. */ |
6531 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 6532 | if (excess) |
91d6fa6a | 6533 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 6534 | |
e98fdf1a | 6535 | start += arange.ar_length + initial_length_size; |
1617e571 | 6536 | |
91d6fa6a | 6537 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 6538 | { |
0c588247 NC |
6539 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
6540 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 6541 | |
80c35038 | 6542 | printf (" "); |
2d9472a2 NC |
6543 | print_dwarf_vma (address, address_size); |
6544 | print_dwarf_vma (length, address_size); | |
6545 | putchar ('\n'); | |
19e6b90e | 6546 | } |
19e6b90e L |
6547 | } |
6548 | ||
6549 | printf ("\n"); | |
6550 | ||
6551 | return 1; | |
6552 | } | |
6553 | ||
4723351a CC |
6554 | /* Comparison function for qsort. */ |
6555 | static int | |
6556 | comp_addr_base (const void * v0, const void * v1) | |
6557 | { | |
d367307b AM |
6558 | debug_info *info0 = *(debug_info **) v0; |
6559 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
6560 | return info0->addr_base - info1->addr_base; |
6561 | } | |
6562 | ||
6563 | /* Display the debug_addr section. */ | |
6564 | static int | |
6565 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 6566 | void *file) |
4723351a CC |
6567 | { |
6568 | debug_info **debug_addr_info; | |
6569 | unsigned char *entry; | |
6570 | unsigned char *end; | |
6571 | unsigned int i; | |
6572 | unsigned int count; | |
6573 | ||
6574 | if (section->size == 0) | |
6575 | { | |
6576 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6577 | return 0; | |
6578 | } | |
6579 | ||
6580 | if (load_debug_info (file) == 0) | |
6581 | { | |
6582 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6583 | section->name); | |
6584 | return 0; | |
6585 | } | |
6586 | ||
dda8d76d | 6587 | introduce (section, FALSE); |
4723351a | 6588 | |
1306a742 NC |
6589 | /* PR 17531: file: cf38d01b. |
6590 | We use xcalloc because a corrupt file may not have initialised all of the | |
6591 | fields in the debug_info structure, which means that the sort below might | |
6592 | try to move uninitialised data. */ | |
6593 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 6594 | sizeof (debug_info *)); |
4723351a CC |
6595 | |
6596 | count = 0; | |
6597 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 6598 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
6599 | { |
6600 | /* PR 17531: file: cf38d01b. */ | |
6601 | if (debug_information[i].addr_base >= section->size) | |
6602 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
6603 | (unsigned long) debug_information[i].addr_base, i); | |
6604 | else | |
6605 | debug_addr_info [count++] = debug_information + i; | |
6606 | } | |
4723351a CC |
6607 | |
6608 | /* Add a sentinel to make iteration convenient. */ | |
6609 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
6610 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 6611 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 6612 | |
4723351a CC |
6613 | for (i = 0; i < count; i++) |
6614 | { | |
6615 | unsigned int idx; | |
fab128ef | 6616 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
6617 | |
6618 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 6619 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 6620 | |
fab128ef | 6621 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
6622 | entry = section->start + debug_addr_info [i]->addr_base; |
6623 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
6624 | idx = 0; | |
6625 | while (entry < end) | |
b4eb7656 AM |
6626 | { |
6627 | dwarf_vma base = byte_get (entry, address_size); | |
6628 | printf (_("\t%d:\t"), idx); | |
6629 | print_dwarf_vma (base, address_size); | |
6630 | printf ("\n"); | |
6631 | entry += address_size; | |
6632 | idx++; | |
6633 | } | |
4723351a CC |
6634 | } |
6635 | printf ("\n"); | |
6636 | ||
6637 | free (debug_addr_info); | |
6638 | return 1; | |
6639 | } | |
6640 | ||
6641 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 6642 | |
4723351a CC |
6643 | static int |
6644 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 6645 | void *file ATTRIBUTE_UNUSED) |
4723351a CC |
6646 | { |
6647 | if (section->size == 0) | |
6648 | { | |
6649 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6650 | return 0; | |
6651 | } | |
6652 | /* TODO: Dump the contents. This is made somewhat difficult by not knowing | |
6653 | what the offset size is for this section. */ | |
6654 | return 1; | |
6655 | } | |
6656 | ||
01a8f077 JK |
6657 | /* Each debug_information[x].range_lists[y] gets this representation for |
6658 | sorting purposes. */ | |
6659 | ||
6660 | struct range_entry | |
467c65bc NC |
6661 | { |
6662 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 6663 | dwarf_vma ranges_offset; |
01a8f077 | 6664 | |
467c65bc NC |
6665 | /* Original debug_information to find parameters of the data. */ |
6666 | debug_info *debug_info_p; | |
6667 | }; | |
01a8f077 JK |
6668 | |
6669 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
6670 | ||
6671 | static int | |
6672 | range_entry_compar (const void *ap, const void *bp) | |
6673 | { | |
3f5e193b NC |
6674 | const struct range_entry *a_re = (const struct range_entry *) ap; |
6675 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
6676 | const dwarf_vma a = a_re->ranges_offset; |
6677 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
6678 | |
6679 | return (a > b) - (b > a); | |
6680 | } | |
6681 | ||
77145576 JK |
6682 | static void |
6683 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
6684 | unsigned int pointer_size, unsigned long offset, | |
6685 | unsigned long base_address) | |
6686 | { | |
6687 | while (start < finish) | |
6688 | { | |
6689 | dwarf_vma begin; | |
6690 | dwarf_vma end; | |
6691 | ||
6692 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6693 | if (start >= finish) | |
6694 | break; | |
6695 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
6696 | ||
d11ae95e | 6697 | |
77145576 JK |
6698 | printf (" %8.8lx ", offset); |
6699 | ||
6700 | if (begin == 0 && end == 0) | |
6701 | { | |
6702 | printf (_("<End of list>\n")); | |
6703 | break; | |
6704 | } | |
6705 | ||
6706 | /* Check base address specifiers. */ | |
6707 | if (is_max_address (begin, pointer_size) | |
6708 | && !is_max_address (end, pointer_size)) | |
6709 | { | |
6710 | base_address = end; | |
6711 | print_dwarf_vma (begin, pointer_size); | |
6712 | print_dwarf_vma (end, pointer_size); | |
6713 | printf ("(base address)\n"); | |
6714 | continue; | |
6715 | } | |
6716 | ||
6717 | print_dwarf_vma (begin + base_address, pointer_size); | |
6718 | print_dwarf_vma (end + base_address, pointer_size); | |
6719 | ||
6720 | if (begin == end) | |
6721 | fputs (_("(start == end)"), stdout); | |
6722 | else if (begin > end) | |
6723 | fputs (_("(start > end)"), stdout); | |
6724 | ||
6725 | putchar ('\n'); | |
6726 | } | |
6727 | } | |
6728 | ||
6729 | static void | |
6730 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
6731 | unsigned int pointer_size, unsigned long offset, | |
6732 | unsigned long base_address) | |
6733 | { | |
6734 | unsigned char *next = start; | |
6735 | ||
6736 | while (1) | |
6737 | { | |
6738 | unsigned long off = offset + (start - next); | |
6739 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
6740 | /* Initialize it due to a false compiler warning. */ |
6741 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
6742 | unsigned int bytes_read; |
6743 | ||
6744 | if (start + 1 > finish) | |
6745 | { | |
6746 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
6747 | offset); | |
6748 | break; | |
6749 | } | |
6750 | ||
6751 | printf (" %8.8lx ", off); | |
6752 | ||
6753 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
6754 | ||
6755 | switch (rlet) | |
6756 | { | |
6757 | case DW_RLE_end_of_list: | |
6758 | printf (_("<End of list>\n")); | |
6759 | break; | |
6760 | case DW_RLE_base_address: | |
6761 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
6762 | print_dwarf_vma (base_address, pointer_size); | |
6763 | printf (_("(base address)\n")); | |
6764 | break; | |
6765 | case DW_RLE_start_length: | |
6766 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6767 | length = read_uleb128 (start, &bytes_read, finish); | |
6768 | start += bytes_read; | |
6769 | end = begin + length; | |
6770 | break; | |
6771 | case DW_RLE_offset_pair: | |
6772 | begin = read_uleb128 (start, &bytes_read, finish); | |
6773 | start += bytes_read; | |
6774 | end = read_uleb128 (start, &bytes_read, finish); | |
6775 | start += bytes_read; | |
6776 | break; | |
6777 | case DW_RLE_start_end: | |
6778 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6779 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
6780 | break; | |
6781 | default: | |
6782 | error (_("Invalid range list entry type %d\n"), rlet); | |
6783 | rlet = DW_RLE_end_of_list; | |
6784 | break; | |
6785 | } | |
6786 | if (rlet == DW_RLE_end_of_list) | |
6787 | break; | |
6788 | if (rlet == DW_RLE_base_address) | |
6789 | continue; | |
6790 | ||
6791 | print_dwarf_vma (begin + base_address, pointer_size); | |
6792 | print_dwarf_vma (end + base_address, pointer_size); | |
6793 | ||
6794 | if (begin == end) | |
6795 | fputs (_("(start == end)"), stdout); | |
6796 | else if (begin > end) | |
6797 | fputs (_("(start > end)"), stdout); | |
6798 | ||
6799 | putchar ('\n'); | |
6800 | } | |
6801 | } | |
6802 | ||
19e6b90e L |
6803 | static int |
6804 | display_debug_ranges (struct dwarf_section *section, | |
6805 | void *file ATTRIBUTE_UNUSED) | |
6806 | { | |
6807 | unsigned char *start = section->start; | |
a2ff7a4b | 6808 | unsigned char *last_start = start; |
f6f0e17b | 6809 | unsigned long bytes = section->size; |
19e6b90e | 6810 | unsigned char *section_begin = start; |
f6f0e17b | 6811 | unsigned char *finish = start + bytes; |
01a8f077 JK |
6812 | unsigned int num_range_list, i; |
6813 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
6814 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
6815 | /* Initialize it due to a false compiler warning. */ | |
6816 | unsigned char address_size = 0; | |
19e6b90e | 6817 | |
19e6b90e L |
6818 | if (bytes == 0) |
6819 | { | |
6820 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6821 | return 0; | |
6822 | } | |
6823 | ||
77145576 JK |
6824 | if (is_rnglists) |
6825 | { | |
6826 | dwarf_vma initial_length; | |
6827 | unsigned int initial_length_size; | |
6828 | unsigned char segment_selector_size; | |
6829 | unsigned int offset_size, offset_entry_count; | |
6830 | unsigned short version; | |
6831 | ||
6832 | /* Get and check the length of the block. */ | |
6833 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
6834 | ||
6835 | if (initial_length == 0xffffffff) | |
6836 | { | |
6837 | /* This section is 64-bit DWARF 3. */ | |
6838 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
6839 | offset_size = 8; | |
6840 | initial_length_size = 12; | |
6841 | } | |
6842 | else | |
6843 | { | |
6844 | offset_size = 4; | |
6845 | initial_length_size = 4; | |
6846 | } | |
6847 | ||
6848 | if (initial_length + initial_length_size > section->size) | |
6849 | { | |
6850 | /* If the length field has a relocation against it, then we should | |
6851 | not complain if it is inaccurate (and probably negative). | |
6852 | It is copied from .debug_line handling code. */ | |
6853 | if (reloc_at (section, (start - section->start) - offset_size)) | |
6854 | { | |
6855 | initial_length = (finish - start) - initial_length_size; | |
6856 | } | |
6857 | else | |
6858 | { | |
6859 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
6860 | (long) initial_length); | |
6861 | return 0; | |
6862 | } | |
6863 | } | |
6864 | ||
6865 | /* Get and check the version number. */ | |
6866 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
6867 | ||
6868 | if (version != 5) | |
6869 | { | |
6870 | warn (_("Only DWARF version 5 debug_rnglists info " | |
6871 | "is currently supported.\n")); | |
6872 | return 0; | |
6873 | } | |
6874 | ||
6875 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
6876 | ||
6877 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
6878 | if (segment_selector_size != 0) | |
6879 | { | |
6880 | warn (_("The %s section contains " | |
6881 | "unsupported segment selector size: %d.\n"), | |
6882 | section->name, segment_selector_size); | |
6883 | return 0; | |
6884 | } | |
6885 | ||
6886 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
6887 | if (offset_entry_count != 0) | |
6888 | { | |
6889 | warn (_("The %s section contains " | |
6890 | "unsupported offset entry count: %u.\n"), | |
6891 | section->name, offset_entry_count); | |
6892 | return 0; | |
6893 | } | |
6894 | } | |
6895 | ||
1febe64d NC |
6896 | if (load_debug_info (file) == 0) |
6897 | { | |
6898 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6899 | section->name); | |
6900 | return 0; | |
6901 | } | |
19e6b90e | 6902 | |
01a8f077 | 6903 | num_range_list = 0; |
19e6b90e | 6904 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 6905 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 6906 | |
01a8f077 | 6907 | if (num_range_list == 0) |
4723351a CC |
6908 | { |
6909 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 6910 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
6911 | printf (_("No range lists in .debug_info section.\n")); |
6912 | return 1; | |
6913 | } | |
19e6b90e | 6914 | |
3f5e193b NC |
6915 | range_entries = (struct range_entry *) |
6916 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 6917 | range_entry_fill = range_entries; |
19e6b90e | 6918 | |
01a8f077 JK |
6919 | for (i = 0; i < num_debug_info_entries; i++) |
6920 | { | |
6921 | debug_info *debug_info_p = &debug_information[i]; | |
6922 | unsigned int j; | |
6923 | ||
6924 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
6925 | { | |
6926 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
6927 | range_entry_fill->debug_info_p = debug_info_p; | |
6928 | range_entry_fill++; | |
19e6b90e L |
6929 | } |
6930 | } | |
6931 | ||
01a8f077 JK |
6932 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
6933 | range_entry_compar); | |
19e6b90e | 6934 | |
d493b283 | 6935 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 6936 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 6937 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 6938 | |
dda8d76d NC |
6939 | introduce (section, FALSE); |
6940 | ||
19e6b90e L |
6941 | printf (_(" Offset Begin End\n")); |
6942 | ||
01a8f077 | 6943 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 6944 | { |
01a8f077 JK |
6945 | struct range_entry *range_entry = &range_entries[i]; |
6946 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 6947 | unsigned int pointer_size; |
359ca075 | 6948 | dwarf_vma offset; |
01a8f077 | 6949 | unsigned char *next; |
359ca075 | 6950 | dwarf_vma base_address; |
19e6b90e | 6951 | |
77145576 | 6952 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 6953 | offset = range_entry->ranges_offset; |
01a8f077 JK |
6954 | next = section_begin + offset; |
6955 | base_address = debug_info_p->base_address; | |
cecf136e | 6956 | |
f41e4712 NC |
6957 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
6958 | if (pointer_size < 2 || pointer_size > 8) | |
6959 | { | |
6960 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 6961 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
6962 | continue; |
6963 | } | |
b4eb7656 | 6964 | |
d11ae95e NC |
6965 | if (next < section_begin || next >= finish) |
6966 | { | |
6967 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
6968 | (unsigned long) offset, i); | |
6969 | continue; | |
6970 | } | |
6971 | ||
4723351a | 6972 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 6973 | { |
01a8f077 JK |
6974 | if (start < next) |
6975 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
6976 | (unsigned long) (start - section_begin), | |
6977 | (unsigned long) (next - section_begin), section->name); | |
6978 | else if (start > next) | |
a2ff7a4b AM |
6979 | { |
6980 | if (next == last_start) | |
6981 | continue; | |
6982 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
6983 | (unsigned long) (start - section_begin), | |
6984 | (unsigned long) (next - section_begin), section->name); | |
6985 | } | |
01a8f077 | 6986 | } |
d11ae95e | 6987 | |
01a8f077 | 6988 | start = next; |
a2ff7a4b | 6989 | last_start = next; |
19e6b90e | 6990 | |
77145576 JK |
6991 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
6992 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
6993 | } |
6994 | putchar ('\n'); | |
01a8f077 JK |
6995 | |
6996 | free (range_entries); | |
6997 | ||
19e6b90e L |
6998 | return 1; |
6999 | } | |
7000 | ||
7001 | typedef struct Frame_Chunk | |
7002 | { | |
7003 | struct Frame_Chunk *next; | |
7004 | unsigned char *chunk_start; | |
a1165289 | 7005 | unsigned int ncols; |
19e6b90e L |
7006 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
7007 | short int *col_type; | |
7008 | int *col_offset; | |
7009 | char *augmentation; | |
7010 | unsigned int code_factor; | |
7011 | int data_factor; | |
bf5117e3 NC |
7012 | dwarf_vma pc_begin; |
7013 | dwarf_vma pc_range; | |
32ef3000 | 7014 | unsigned int cfa_reg; |
c8071705 | 7015 | dwarf_vma cfa_offset; |
a1165289 | 7016 | unsigned int ra; |
19e6b90e L |
7017 | unsigned char fde_encoding; |
7018 | unsigned char cfa_exp; | |
604282a7 JJ |
7019 | unsigned char ptr_size; |
7020 | unsigned char segment_size; | |
19e6b90e L |
7021 | } |
7022 | Frame_Chunk; | |
7023 | ||
665ce1f6 L |
7024 | static const char *const *dwarf_regnames; |
7025 | static unsigned int dwarf_regnames_count; | |
7026 | ||
19e6b90e L |
7027 | /* A marker for a col_type that means this column was never referenced |
7028 | in the frame info. */ | |
7029 | #define DW_CFA_unreferenced (-1) | |
7030 | ||
a1165289 | 7031 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
7032 | -1 for invalid reg. */ |
7033 | ||
7034 | static int | |
7035 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 7036 | { |
a1165289 | 7037 | unsigned int prev = fc->ncols; |
19e6b90e | 7038 | |
665ce1f6 L |
7039 | if (reg < (unsigned int) fc->ncols) |
7040 | return 0; | |
7041 | ||
7042 | if (dwarf_regnames_count | |
7043 | && reg > dwarf_regnames_count) | |
7044 | return -1; | |
19e6b90e L |
7045 | |
7046 | fc->ncols = reg + 1; | |
a1165289 NC |
7047 | /* PR 17512: file: 10450-2643-0.004. |
7048 | If reg == -1 then this can happen... */ | |
7049 | if (fc->ncols == 0) | |
7050 | return -1; | |
7051 | ||
06614111 NC |
7052 | /* PR 17512: file: 2844a11d. */ |
7053 | if (fc->ncols > 1024) | |
7054 | { | |
7055 | error (_("Unfeasibly large register number: %u\n"), reg); | |
7056 | fc->ncols = 0; | |
7057 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
7058 | we ever encounter a valid binary that exceeds it. */ | |
7059 | return -1; | |
7060 | } | |
7061 | ||
3f5e193b | 7062 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 7063 | sizeof (short int)); |
3f5e193b | 7064 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 7065 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
7066 | if (fc->col_type == NULL || fc->col_offset == NULL) |
7067 | { | |
7068 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
7069 | fc->ncols); | |
7070 | fc->ncols = 0; | |
7071 | return -1; | |
7072 | } | |
19e6b90e L |
7073 | |
7074 | while (prev < fc->ncols) | |
7075 | { | |
7076 | fc->col_type[prev] = DW_CFA_unreferenced; | |
7077 | fc->col_offset[prev] = 0; | |
7078 | prev++; | |
7079 | } | |
665ce1f6 | 7080 | return 1; |
19e6b90e L |
7081 | } |
7082 | ||
2dc4cec1 L |
7083 | static const char *const dwarf_regnames_i386[] = |
7084 | { | |
43234a1e L |
7085 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
7086 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7087 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7088 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
7089 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
7090 | NULL, NULL, /* 19 - 20 */ | |
7091 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
7092 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
7093 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
7094 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
7095 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
7096 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7097 | "tr", "ldtr", /* 48 - 49 */ | |
7098 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7099 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7100 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7101 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7102 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7103 | NULL, NULL, NULL, /* 90 - 92 */ | |
7104 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
7105 | }; |
7106 | ||
3d875af5 L |
7107 | static const char *const dwarf_regnames_iamcu[] = |
7108 | { | |
7109 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
7110 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7111 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7112 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
7113 | NULL, NULL, /* 19 - 20 */ | |
7114 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
7115 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
7116 | NULL, NULL, NULL, /* 37 - 39 */ | |
7117 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7118 | "tr", "ldtr", /* 48 - 49 */ | |
7119 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7120 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7121 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7122 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7123 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7124 | NULL, NULL, NULL, /* 90 - 92 */ | |
7125 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
7126 | }; | |
7127 | ||
b129eb0e RH |
7128 | void |
7129 | init_dwarf_regnames_i386 (void) | |
7130 | { | |
7131 | dwarf_regnames = dwarf_regnames_i386; | |
7132 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
7133 | } | |
7134 | ||
3d875af5 L |
7135 | void |
7136 | init_dwarf_regnames_iamcu (void) | |
7137 | { | |
7138 | dwarf_regnames = dwarf_regnames_iamcu; | |
7139 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
7140 | } | |
7141 | ||
2dc4cec1 L |
7142 | static const char *const dwarf_regnames_x86_64[] = |
7143 | { | |
7144 | "rax", "rdx", "rcx", "rbx", | |
7145 | "rsi", "rdi", "rbp", "rsp", | |
7146 | "r8", "r9", "r10", "r11", | |
7147 | "r12", "r13", "r14", "r15", | |
7148 | "rip", | |
7149 | "xmm0", "xmm1", "xmm2", "xmm3", | |
7150 | "xmm4", "xmm5", "xmm6", "xmm7", | |
7151 | "xmm8", "xmm9", "xmm10", "xmm11", | |
7152 | "xmm12", "xmm13", "xmm14", "xmm15", | |
7153 | "st0", "st1", "st2", "st3", | |
7154 | "st4", "st5", "st6", "st7", | |
7155 | "mm0", "mm1", "mm2", "mm3", | |
7156 | "mm4", "mm5", "mm6", "mm7", | |
7157 | "rflags", | |
7158 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
7159 | "fs.base", "gs.base", NULL, NULL, | |
7160 | "tr", "ldtr", | |
43234a1e L |
7161 | "mxcsr", "fcw", "fsw", |
7162 | "xmm16", "xmm17", "xmm18", "xmm19", | |
7163 | "xmm20", "xmm21", "xmm22", "xmm23", | |
7164 | "xmm24", "xmm25", "xmm26", "xmm27", | |
7165 | "xmm28", "xmm29", "xmm30", "xmm31", | |
7166 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
7167 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
7168 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
7169 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
7170 | NULL, NULL, NULL, /* 115 - 117 */ | |
7171 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
7172 | }; |
7173 | ||
b129eb0e RH |
7174 | void |
7175 | init_dwarf_regnames_x86_64 (void) | |
7176 | { | |
7177 | dwarf_regnames = dwarf_regnames_x86_64; | |
7178 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
7179 | } | |
7180 | ||
4ee22035 RH |
7181 | static const char *const dwarf_regnames_aarch64[] = |
7182 | { | |
b4eb7656 AM |
7183 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
7184 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
7185 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
7186 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
7187 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
fab7c86e TC |
7188 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
7189 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
7190 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
b4eb7656 AM |
7191 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
7192 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
7193 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
7194 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
fab7c86e TC |
7195 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
7196 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
7197 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
7198 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
4ee22035 RH |
7199 | }; |
7200 | ||
7201 | void | |
7202 | init_dwarf_regnames_aarch64 (void) | |
7203 | { | |
7204 | dwarf_regnames = dwarf_regnames_aarch64; | |
7205 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
7206 | } | |
7207 | ||
d6bb17b0 AA |
7208 | static const char *const dwarf_regnames_s390[] = |
7209 | { | |
7210 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
7211 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7212 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7213 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
7214 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
7215 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
7216 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
7217 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
7218 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
7219 | "pswm", "pswa", | |
7220 | NULL, NULL, | |
7221 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
7222 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
7223 | }; | |
7224 | ||
7225 | void | |
7226 | init_dwarf_regnames_s390 (void) | |
7227 | { | |
7228 | dwarf_regnames = dwarf_regnames_s390; | |
7229 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
7230 | } | |
7231 | ||
5bb0830d AB |
7232 | static const char *const dwarf_regnames_riscv[] = |
7233 | { | |
7234 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
7235 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
7236 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
7237 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
7238 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
7239 | "fs0", "fs1", /* 40 - 41 */ | |
7240 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
7241 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
7242 | "fs10", "fs11", /* 58 - 59 */ | |
7243 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
7244 | }; | |
7245 | ||
7246 | void | |
7247 | init_dwarf_regnames_riscv (void) | |
7248 | { | |
7249 | dwarf_regnames = dwarf_regnames_riscv; | |
7250 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_riscv); | |
7251 | } | |
7252 | ||
2dc4cec1 L |
7253 | void |
7254 | init_dwarf_regnames (unsigned int e_machine) | |
7255 | { | |
7256 | switch (e_machine) | |
7257 | { | |
7258 | case EM_386: | |
b129eb0e | 7259 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
7260 | break; |
7261 | ||
3d875af5 L |
7262 | case EM_IAMCU: |
7263 | init_dwarf_regnames_iamcu (); | |
7264 | break; | |
7265 | ||
2dc4cec1 | 7266 | case EM_X86_64: |
7f502d6c | 7267 | case EM_L1OM: |
7a9068fe | 7268 | case EM_K1OM: |
b129eb0e | 7269 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
7270 | break; |
7271 | ||
4ee22035 RH |
7272 | case EM_AARCH64: |
7273 | init_dwarf_regnames_aarch64 (); | |
7274 | break; | |
7275 | ||
d6bb17b0 AA |
7276 | case EM_S390: |
7277 | init_dwarf_regnames_s390 (); | |
7278 | break; | |
7279 | ||
5bb0830d AB |
7280 | case EM_RISCV: |
7281 | init_dwarf_regnames_riscv (); | |
7282 | break; | |
7283 | ||
2dc4cec1 L |
7284 | default: |
7285 | break; | |
7286 | } | |
7287 | } | |
7288 | ||
7289 | static const char * | |
7290 | regname (unsigned int regno, int row) | |
7291 | { | |
7292 | static char reg[64]; | |
7f2c8a1d | 7293 | |
2dc4cec1 L |
7294 | if (dwarf_regnames |
7295 | && regno < dwarf_regnames_count | |
7296 | && dwarf_regnames [regno] != NULL) | |
7297 | { | |
7298 | if (row) | |
7299 | return dwarf_regnames [regno]; | |
7300 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, | |
7301 | dwarf_regnames [regno]); | |
7302 | } | |
7303 | else | |
7304 | snprintf (reg, sizeof (reg), "r%d", regno); | |
7305 | return reg; | |
7306 | } | |
7307 | ||
19e6b90e | 7308 | static void |
a1165289 | 7309 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 7310 | { |
a1165289 | 7311 | unsigned int r; |
19e6b90e L |
7312 | char tmp[100]; |
7313 | ||
d8024a91 | 7314 | if (*max_regs != fc->ncols) |
19e6b90e L |
7315 | *max_regs = fc->ncols; |
7316 | ||
7317 | if (*need_col_headers) | |
7318 | { | |
91d6fa6a | 7319 | static const char *sloc = " LOC"; |
2dc4cec1 | 7320 | |
19e6b90e L |
7321 | *need_col_headers = 0; |
7322 | ||
91d6fa6a | 7323 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
7324 | |
7325 | for (r = 0; r < *max_regs; r++) | |
7326 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7327 | { | |
7328 | if (r == fc->ra) | |
50751e18 | 7329 | printf ("ra "); |
19e6b90e | 7330 | else |
2dc4cec1 | 7331 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
7332 | } |
7333 | ||
7334 | printf ("\n"); | |
7335 | } | |
7336 | ||
bf5117e3 | 7337 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
7338 | if (fc->cfa_exp) |
7339 | strcpy (tmp, "exp"); | |
7340 | else | |
c8071705 | 7341 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
7342 | printf ("%-8s ", tmp); |
7343 | ||
7344 | for (r = 0; r < fc->ncols; r++) | |
7345 | { | |
7346 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7347 | { | |
7348 | switch (fc->col_type[r]) | |
7349 | { | |
7350 | case DW_CFA_undefined: | |
7351 | strcpy (tmp, "u"); | |
7352 | break; | |
7353 | case DW_CFA_same_value: | |
7354 | strcpy (tmp, "s"); | |
7355 | break; | |
7356 | case DW_CFA_offset: | |
7357 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
7358 | break; | |
12eae2d3 JJ |
7359 | case DW_CFA_val_offset: |
7360 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
7361 | break; | |
19e6b90e | 7362 | case DW_CFA_register: |
2dc4cec1 | 7363 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
7364 | break; |
7365 | case DW_CFA_expression: | |
7366 | strcpy (tmp, "exp"); | |
7367 | break; | |
12eae2d3 JJ |
7368 | case DW_CFA_val_expression: |
7369 | strcpy (tmp, "vexp"); | |
7370 | break; | |
19e6b90e L |
7371 | default: |
7372 | strcpy (tmp, "n/a"); | |
7373 | break; | |
7374 | } | |
2dc4cec1 | 7375 | printf ("%-5s ", tmp); |
19e6b90e L |
7376 | } |
7377 | } | |
7378 | printf ("\n"); | |
7379 | } | |
7380 | ||
49727e46 | 7381 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 7382 | |
49727e46 AM |
7383 | static unsigned char * |
7384 | read_cie (unsigned char *start, unsigned char *end, | |
7385 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 7386 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
7387 | { |
7388 | int version; | |
7389 | Frame_Chunk *fc; | |
7390 | unsigned int length_return; | |
7391 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 7392 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 7393 | |
041830e0 | 7394 | * p_cie = NULL; |
f41e4712 NC |
7395 | /* PR 17512: file: 001-228113-0.004. */ |
7396 | if (start >= end) | |
7397 | return end; | |
7398 | ||
49727e46 AM |
7399 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
7400 | memset (fc, 0, sizeof (Frame_Chunk)); | |
7401 | ||
7402 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
7403 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
7404 | ||
7405 | version = *start++; | |
7406 | ||
7407 | fc->augmentation = (char *) start; | |
f41e4712 NC |
7408 | /* PR 17512: file: 001-228113-0.004. |
7409 | Skip past augmentation name, but avoid running off the end of the data. */ | |
7410 | while (start < end) | |
7411 | if (* start ++ == '\0') | |
7412 | break; | |
7413 | if (start == end) | |
7414 | { | |
7415 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 7416 | goto fail; |
f41e4712 | 7417 | } |
49727e46 AM |
7418 | |
7419 | if (strcmp (fc->augmentation, "eh") == 0) | |
7420 | start += eh_addr_size; | |
7421 | ||
7422 | if (version >= 4) | |
7423 | { | |
7424 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
7425 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
7426 | { | |
7427 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 7428 | goto fail; |
77ef8654 NC |
7429 | } |
7430 | ||
49727e46 | 7431 | GET (fc->segment_size, 1); |
77ef8654 NC |
7432 | /* PR 17512: file: e99d2804. */ |
7433 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
7434 | { | |
7435 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 7436 | goto fail; |
77ef8654 NC |
7437 | } |
7438 | ||
49727e46 AM |
7439 | eh_addr_size = fc->ptr_size; |
7440 | } | |
7441 | else | |
7442 | { | |
7443 | fc->ptr_size = eh_addr_size; | |
7444 | fc->segment_size = 0; | |
7445 | } | |
442a6ce8 | 7446 | |
7f2c8a1d NC |
7447 | READ_ULEB (fc->code_factor); |
7448 | READ_SLEB (fc->data_factor); | |
442a6ce8 | 7449 | |
49727e46 AM |
7450 | if (version == 1) |
7451 | { | |
7452 | GET (fc->ra, 1); | |
7453 | } | |
7454 | else | |
7455 | { | |
7f2c8a1d | 7456 | READ_ULEB (fc->ra); |
49727e46 AM |
7457 | } |
7458 | ||
7459 | if (fc->augmentation[0] == 'z') | |
7460 | { | |
7f2c8a1d | 7461 | READ_ULEB (augmentation_data_len); |
49727e46 | 7462 | augmentation_data = start; |
a1165289 | 7463 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 7464 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 7465 | { |
bf59c5d5 NC |
7466 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
7467 | dwarf_vmatoa ("x", augmentation_data_len), | |
7468 | (unsigned long) (end - start)); | |
442a6ce8 | 7469 | goto fail; |
a1165289 | 7470 | } |
9c0f3d3f | 7471 | start += augmentation_data_len; |
49727e46 AM |
7472 | } |
7473 | ||
7474 | if (augmentation_data_len) | |
7475 | { | |
058037d3 NC |
7476 | unsigned char *p; |
7477 | unsigned char *q; | |
7478 | unsigned char *qend; | |
b4eb7656 | 7479 | |
49727e46 AM |
7480 | p = (unsigned char *) fc->augmentation + 1; |
7481 | q = augmentation_data; | |
058037d3 NC |
7482 | qend = q + augmentation_data_len; |
7483 | ||
9c0f3d3f | 7484 | while (p < end && q < qend) |
49727e46 AM |
7485 | { |
7486 | if (*p == 'L') | |
7487 | q++; | |
7488 | else if (*p == 'P') | |
7489 | q += 1 + size_of_encoded_value (*q); | |
7490 | else if (*p == 'R') | |
7491 | fc->fde_encoding = *q++; | |
7492 | else if (*p == 'S') | |
7493 | ; | |
09038062 ST |
7494 | else if (*p == 'B') |
7495 | ; | |
49727e46 AM |
7496 | else |
7497 | break; | |
7498 | p++; | |
7499 | } | |
c361b9ac NC |
7500 | /* Note - it is OK if this loop terminates with q < qend. |
7501 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
7502 | } |
7503 | ||
7504 | *p_cie = fc; | |
7505 | if (p_version) | |
7506 | *p_version = version; | |
7507 | if (p_aug_len) | |
7508 | { | |
7509 | *p_aug_len = augmentation_data_len; | |
7510 | *p_aug = augmentation_data; | |
7511 | } | |
7512 | return start; | |
442a6ce8 NC |
7513 | |
7514 | fail: | |
7515 | free (fc->col_offset); | |
7516 | free (fc->col_type); | |
7517 | free (fc); | |
7518 | return end; | |
49727e46 AM |
7519 | } |
7520 | ||
d85bf2ba NC |
7521 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
7522 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
7523 | PRINTED contains the number of characters already written to the current | |
7524 | output line. */ | |
bf59c5d5 NC |
7525 | |
7526 | static void | |
d85bf2ba NC |
7527 | display_data (bfd_size_type printed, |
7528 | const unsigned char * data, | |
7529 | const bfd_size_type len) | |
bf59c5d5 | 7530 | { |
d85bf2ba NC |
7531 | if (do_wide || len < ((80 - printed) / 3)) |
7532 | for (printed = 0; printed < len; ++printed) | |
7533 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
7534 | else |
7535 | { | |
d85bf2ba | 7536 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 7537 | { |
d85bf2ba | 7538 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 7539 | putchar ('\n'); |
d85bf2ba | 7540 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
7541 | } |
7542 | } | |
d85bf2ba NC |
7543 | } |
7544 | ||
7545 | /* Prints out the contents on the augmentation data array. | |
7546 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
7547 | ||
7548 | static void | |
7549 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
7550 | { | |
7551 | bfd_size_type i; | |
7552 | ||
7553 | i = printf (_(" Augmentation data: ")); | |
7554 | display_data (i, data, len); | |
bf59c5d5 NC |
7555 | } |
7556 | ||
19e6b90e L |
7557 | static int |
7558 | display_debug_frames (struct dwarf_section *section, | |
7559 | void *file ATTRIBUTE_UNUSED) | |
7560 | { | |
7561 | unsigned char *start = section->start; | |
7562 | unsigned char *end = start + section->size; | |
7563 | unsigned char *section_start = start; | |
3391569f NC |
7564 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
7565 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 7566 | Frame_Chunk *rs; |
3391569f | 7567 | bfd_boolean is_eh = strcmp (section->name, ".eh_frame") == 0; |
19e6b90e | 7568 | unsigned int length_return; |
a1165289 | 7569 | unsigned int max_regs = 0; |
665ce1f6 | 7570 | const char *bad_reg = _("bad register: "); |
77ef8654 | 7571 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 7572 | |
dda8d76d | 7573 | introduce (section, FALSE); |
19e6b90e L |
7574 | |
7575 | while (start < end) | |
7576 | { | |
7577 | unsigned char *saved_start; | |
7578 | unsigned char *block_end; | |
bf5117e3 NC |
7579 | dwarf_vma length; |
7580 | dwarf_vma cie_id; | |
19e6b90e L |
7581 | Frame_Chunk *fc; |
7582 | Frame_Chunk *cie; | |
7583 | int need_col_headers = 1; | |
7584 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 7585 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
7586 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
7587 | unsigned int offset_size; | |
7588 | unsigned int initial_length_size; | |
5b6312fd | 7589 | bfd_boolean all_nops; |
19e6b90e L |
7590 | |
7591 | saved_start = start; | |
19e6b90e | 7592 | |
0c588247 | 7593 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 7594 | |
19e6b90e L |
7595 | if (length == 0) |
7596 | { | |
7597 | printf ("\n%08lx ZERO terminator\n\n", | |
7598 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
7599 | /* Skip any zero terminators that directly follow. |
7600 | A corrupt section size could have loaded a whole | |
7601 | slew of zero filled memory bytes. eg | |
7602 | PR 17512: file: 070-19381-0.004. */ | |
7603 | while (start < end && * start == 0) | |
7604 | ++ start; | |
b758e50f | 7605 | continue; |
19e6b90e L |
7606 | } |
7607 | ||
7608 | if (length == 0xffffffff) | |
7609 | { | |
0c588247 | 7610 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
7611 | offset_size = 8; |
7612 | initial_length_size = 12; | |
7613 | } | |
7614 | else | |
7615 | { | |
7616 | offset_size = 4; | |
7617 | initial_length_size = 4; | |
7618 | } | |
7619 | ||
7620 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 7621 | if (block_end > end || block_end < start) |
53b8873b | 7622 | { |
bf5117e3 NC |
7623 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
7624 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
7625 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
7626 | block_end = end; |
7627 | } | |
0c588247 NC |
7628 | |
7629 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 7630 | |
846a11e4 NC |
7631 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
7632 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
7633 | { |
7634 | int version; | |
a1165289 | 7635 | unsigned int mreg; |
19e6b90e | 7636 | |
49727e46 AM |
7637 | start = read_cie (start, end, &cie, &version, |
7638 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
7639 | /* PR 17512: file: 027-135133-0.005. */ |
7640 | if (cie == NULL) | |
7641 | break; | |
a1165289 | 7642 | |
49727e46 | 7643 | fc = cie; |
19e6b90e L |
7644 | fc->next = chunks; |
7645 | chunks = fc; | |
7646 | fc->chunk_start = saved_start; | |
a1165289 | 7647 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
7648 | if (mreg < fc->ra) |
7649 | mreg = fc->ra; | |
06614111 NC |
7650 | if (frame_need_space (fc, mreg) < 0) |
7651 | break; | |
49727e46 AM |
7652 | if (fc->fde_encoding) |
7653 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 7654 | |
bf5117e3 NC |
7655 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
7656 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 7657 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 7658 | |
19e6b90e | 7659 | if (do_debug_frames_interp) |
bf5117e3 NC |
7660 | { |
7661 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
7662 | fc->code_factor, fc->data_factor, fc->ra); | |
7663 | } | |
19e6b90e L |
7664 | else |
7665 | { | |
bf5117e3 | 7666 | printf ("CIE\n"); |
19e6b90e L |
7667 | printf (" Version: %d\n", version); |
7668 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
7669 | if (version >= 4) |
7670 | { | |
7671 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
7672 | printf (" Segment Size: %u\n", fc->segment_size); | |
7673 | } | |
19e6b90e L |
7674 | printf (" Code alignment factor: %u\n", fc->code_factor); |
7675 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
7676 | printf (" Return address column: %d\n", fc->ra); | |
7677 | ||
7678 | if (augmentation_data_len) | |
bf59c5d5 | 7679 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 7680 | |
19e6b90e L |
7681 | putchar ('\n'); |
7682 | } | |
19e6b90e L |
7683 | } |
7684 | else | |
7685 | { | |
7686 | unsigned char *look_for; | |
7687 | static Frame_Chunk fde_fc; | |
604282a7 | 7688 | unsigned long segment_selector; |
19e6b90e | 7689 | |
49727e46 AM |
7690 | if (is_eh) |
7691 | { | |
7692 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
7693 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
7694 | } | |
7695 | else | |
7696 | look_for = section_start + cie_id; | |
19e6b90e | 7697 | |
49727e46 AM |
7698 | if (look_for <= saved_start) |
7699 | { | |
7700 | for (cie = chunks; cie ; cie = cie->next) | |
7701 | if (cie->chunk_start == look_for) | |
7702 | break; | |
7703 | } | |
7704 | else | |
7705 | { | |
7706 | for (cie = forward_refs; cie ; cie = cie->next) | |
7707 | if (cie->chunk_start == look_for) | |
7708 | break; | |
7709 | if (!cie) | |
7710 | { | |
7711 | unsigned int off_size; | |
7712 | unsigned char *cie_scan; | |
19e6b90e | 7713 | |
49727e46 AM |
7714 | cie_scan = look_for; |
7715 | off_size = 4; | |
7716 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
7717 | if (length == 0xffffffff) | |
7718 | { | |
7719 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
7720 | off_size = 8; | |
7721 | } | |
7722 | if (length != 0) | |
7723 | { | |
7724 | dwarf_vma c_id; | |
7725 | ||
7726 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
7727 | if (is_eh | |
7728 | ? c_id == 0 | |
7729 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
7730 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
7731 | { | |
7732 | int version; | |
a1165289 | 7733 | unsigned int mreg; |
49727e46 AM |
7734 | |
7735 | read_cie (cie_scan, end, &cie, &version, | |
7736 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
7737 | /* PR 17512: file: 3450-2098-0.004. */ |
7738 | if (cie == NULL) | |
7739 | { | |
7740 | warn (_("Failed to read CIE information\n")); | |
7741 | break; | |
7742 | } | |
49727e46 AM |
7743 | cie->next = forward_refs; |
7744 | forward_refs = cie; | |
7745 | cie->chunk_start = look_for; | |
a1165289 | 7746 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
7747 | if (mreg < cie->ra) |
7748 | mreg = cie->ra; | |
06614111 NC |
7749 | if (frame_need_space (cie, mreg) < 0) |
7750 | { | |
7751 | warn (_("Invalid max register\n")); | |
7752 | break; | |
7753 | } | |
49727e46 AM |
7754 | if (cie->fde_encoding) |
7755 | encoded_ptr_size | |
7756 | = size_of_encoded_value (cie->fde_encoding); | |
7757 | } | |
7758 | } | |
7759 | } | |
7760 | } | |
7761 | ||
7762 | fc = &fde_fc; | |
7763 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
7764 | |
7765 | if (!cie) | |
7766 | { | |
bf5117e3 NC |
7767 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
7768 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
7769 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 7770 | fc->ncols = 0; |
3f5e193b NC |
7771 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
7772 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
7773 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
7774 | { | |
7775 | warn (_("Invalid max register\n")); | |
7776 | break; | |
7777 | } | |
19e6b90e L |
7778 | cie = fc; |
7779 | fc->augmentation = ""; | |
7780 | fc->fde_encoding = 0; | |
604282a7 JJ |
7781 | fc->ptr_size = eh_addr_size; |
7782 | fc->segment_size = 0; | |
19e6b90e L |
7783 | } |
7784 | else | |
7785 | { | |
7786 | fc->ncols = cie->ncols; | |
3f5e193b NC |
7787 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
7788 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
7789 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
7790 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
7791 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
7792 | fc->ptr_size = cie->ptr_size; |
7793 | eh_addr_size = cie->ptr_size; | |
7794 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
7795 | fc->code_factor = cie->code_factor; |
7796 | fc->data_factor = cie->data_factor; | |
7797 | fc->cfa_reg = cie->cfa_reg; | |
7798 | fc->cfa_offset = cie->cfa_offset; | |
7799 | fc->ra = cie->ra; | |
06614111 NC |
7800 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
7801 | { | |
7802 | warn (_("Invalid max register\n")); | |
7803 | break; | |
7804 | } | |
19e6b90e L |
7805 | fc->fde_encoding = cie->fde_encoding; |
7806 | } | |
7807 | ||
7808 | if (fc->fde_encoding) | |
7809 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
7810 | ||
604282a7 JJ |
7811 | segment_selector = 0; |
7812 | if (fc->segment_size) | |
c8071705 NC |
7813 | { |
7814 | if (fc->segment_size > sizeof (segment_selector)) | |
7815 | { | |
7816 | /* PR 17512: file: 9e196b3e. */ | |
7817 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
7818 | fc->segment_size = 4; | |
7819 | } | |
7820 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
7821 | } | |
041830e0 NC |
7822 | |
7823 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 7824 | |
0c588247 NC |
7825 | /* FIXME: It appears that sometimes the final pc_range value is |
7826 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
7827 | run of the "objcopy on compressed debug sections" test for an | |
7828 | example of this. */ | |
7829 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 7830 | |
19e6b90e L |
7831 | if (cie->augmentation[0] == 'z') |
7832 | { | |
7f2c8a1d | 7833 | READ_ULEB (augmentation_data_len); |
19e6b90e | 7834 | augmentation_data = start; |
bf59c5d5 | 7835 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
d292364e | 7836 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
0a9d414a | 7837 | { |
d292364e AM |
7838 | warn (_("Augmentation data too long: 0x%s, " |
7839 | "expected at most %#lx\n"), | |
7840 | dwarf_vmatoa ("x", augmentation_data_len), | |
7841 | (unsigned long) (end - start)); | |
0a9d414a NC |
7842 | start = end; |
7843 | augmentation_data = NULL; | |
7844 | augmentation_data_len = 0; | |
7845 | } | |
d292364e | 7846 | start += augmentation_data_len; |
19e6b90e L |
7847 | } |
7848 | ||
bf5117e3 NC |
7849 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
7850 | (unsigned long)(saved_start - section_start), | |
7851 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 7852 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 7853 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 7854 | |
604282a7 JJ |
7855 | if (fc->segment_size) |
7856 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
7857 | |
7858 | printf ("%s..%s\n", | |
7859 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
7860 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
7861 | ||
19e6b90e L |
7862 | if (! do_debug_frames_interp && augmentation_data_len) |
7863 | { | |
bf59c5d5 | 7864 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
7865 | putchar ('\n'); |
7866 | } | |
7867 | } | |
7868 | ||
7869 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
7870 | we're about to interpret instructions for the chunk. */ | |
7871 | /* ??? At present we need to do this always, since this sizes the | |
7872 | fc->col_type and fc->col_offset arrays, which we write into always. | |
7873 | We should probably split the interpreted and non-interpreted bits | |
7874 | into two different routines, since there's so much that doesn't | |
7875 | really overlap between them. */ | |
7876 | if (1 || do_debug_frames_interp) | |
7877 | { | |
7878 | /* Start by making a pass over the chunk, allocating storage | |
7879 | and taking note of what registers are used. */ | |
7880 | unsigned char *tmp = start; | |
7881 | ||
7882 | while (start < block_end) | |
7883 | { | |
041830e0 NC |
7884 | unsigned int reg, op, opa; |
7885 | unsigned long temp; | |
5929c344 | 7886 | unsigned char * new_start; |
19e6b90e L |
7887 | |
7888 | op = *start++; | |
7889 | opa = op & 0x3f; | |
7890 | if (op & 0xc0) | |
7891 | op &= 0xc0; | |
7892 | ||
7893 | /* Warning: if you add any more cases to this switch, be | |
7894 | sure to add them to the corresponding switch below. */ | |
7895 | switch (op) | |
7896 | { | |
7897 | case DW_CFA_advance_loc: | |
7898 | break; | |
7899 | case DW_CFA_offset: | |
7f2c8a1d | 7900 | SKIP_ULEB (); |
665ce1f6 L |
7901 | if (frame_need_space (fc, opa) >= 0) |
7902 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
7903 | break; |
7904 | case DW_CFA_restore: | |
665ce1f6 L |
7905 | if (frame_need_space (fc, opa) >= 0) |
7906 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
7907 | break; |
7908 | case DW_CFA_set_loc: | |
7909 | start += encoded_ptr_size; | |
7910 | break; | |
7911 | case DW_CFA_advance_loc1: | |
7912 | start += 1; | |
7913 | break; | |
7914 | case DW_CFA_advance_loc2: | |
7915 | start += 2; | |
7916 | break; | |
7917 | case DW_CFA_advance_loc4: | |
7918 | start += 4; | |
7919 | break; | |
7920 | case DW_CFA_offset_extended: | |
12eae2d3 | 7921 | case DW_CFA_val_offset: |
7f2c8a1d NC |
7922 | READ_ULEB (reg); |
7923 | SKIP_ULEB (); | |
665ce1f6 L |
7924 | if (frame_need_space (fc, reg) >= 0) |
7925 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7926 | break; |
7927 | case DW_CFA_restore_extended: | |
7f2c8a1d | 7928 | READ_ULEB (reg); |
665ce1f6 L |
7929 | if (frame_need_space (fc, reg) >= 0) |
7930 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7931 | break; |
7932 | case DW_CFA_undefined: | |
7f2c8a1d | 7933 | READ_ULEB (reg); |
665ce1f6 L |
7934 | if (frame_need_space (fc, reg) >= 0) |
7935 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7936 | break; |
7937 | case DW_CFA_same_value: | |
7f2c8a1d | 7938 | READ_ULEB (reg); |
665ce1f6 L |
7939 | if (frame_need_space (fc, reg) >= 0) |
7940 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7941 | break; |
7942 | case DW_CFA_register: | |
7f2c8a1d NC |
7943 | READ_ULEB (reg); |
7944 | SKIP_ULEB (); | |
665ce1f6 L |
7945 | if (frame_need_space (fc, reg) >= 0) |
7946 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7947 | break; |
7948 | case DW_CFA_def_cfa: | |
7f2c8a1d NC |
7949 | SKIP_ULEB (); |
7950 | SKIP_ULEB (); | |
19e6b90e L |
7951 | break; |
7952 | case DW_CFA_def_cfa_register: | |
7f2c8a1d | 7953 | SKIP_ULEB (); |
19e6b90e L |
7954 | break; |
7955 | case DW_CFA_def_cfa_offset: | |
7f2c8a1d | 7956 | SKIP_ULEB (); |
19e6b90e L |
7957 | break; |
7958 | case DW_CFA_def_cfa_expression: | |
7f2c8a1d | 7959 | READ_ULEB (temp); |
5929c344 NC |
7960 | new_start = start + temp; |
7961 | if (new_start < start) | |
041830e0 NC |
7962 | { |
7963 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
7964 | start = block_end; | |
7965 | } | |
7966 | else | |
5929c344 | 7967 | start = new_start; |
19e6b90e L |
7968 | break; |
7969 | case DW_CFA_expression: | |
12eae2d3 | 7970 | case DW_CFA_val_expression: |
7f2c8a1d NC |
7971 | READ_ULEB (reg); |
7972 | READ_ULEB (temp); | |
5929c344 NC |
7973 | new_start = start + temp; |
7974 | if (new_start < start) | |
041830e0 | 7975 | { |
b4eb7656 | 7976 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
7977 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
7978 | start = block_end; | |
7979 | } | |
7980 | else | |
5929c344 | 7981 | start = new_start; |
665ce1f6 L |
7982 | if (frame_need_space (fc, reg) >= 0) |
7983 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7984 | break; |
7985 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 7986 | case DW_CFA_val_offset_sf: |
7f2c8a1d NC |
7987 | READ_ULEB (reg); |
7988 | SKIP_SLEB (); | |
665ce1f6 L |
7989 | if (frame_need_space (fc, reg) >= 0) |
7990 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7991 | break; |
7992 | case DW_CFA_def_cfa_sf: | |
7f2c8a1d NC |
7993 | SKIP_ULEB (); |
7994 | SKIP_SLEB (); | |
19e6b90e L |
7995 | break; |
7996 | case DW_CFA_def_cfa_offset_sf: | |
7f2c8a1d | 7997 | SKIP_SLEB (); |
19e6b90e L |
7998 | break; |
7999 | case DW_CFA_MIPS_advance_loc8: | |
8000 | start += 8; | |
8001 | break; | |
8002 | case DW_CFA_GNU_args_size: | |
7f2c8a1d | 8003 | SKIP_ULEB (); |
19e6b90e L |
8004 | break; |
8005 | case DW_CFA_GNU_negative_offset_extended: | |
7f2c8a1d NC |
8006 | READ_ULEB (reg); |
8007 | SKIP_ULEB (); | |
665ce1f6 L |
8008 | if (frame_need_space (fc, reg) >= 0) |
8009 | fc->col_type[reg] = DW_CFA_undefined; | |
8010 | break; | |
19e6b90e L |
8011 | default: |
8012 | break; | |
8013 | } | |
8014 | } | |
8015 | start = tmp; | |
8016 | } | |
8017 | ||
5b6312fd NC |
8018 | all_nops = TRUE; |
8019 | ||
19e6b90e L |
8020 | /* Now we know what registers are used, make a second pass over |
8021 | the chunk, this time actually printing out the info. */ | |
8022 | ||
8023 | while (start < block_end) | |
8024 | { | |
362beea4 | 8025 | unsigned char * tmp; |
19e6b90e | 8026 | unsigned op, opa; |
7f2c8a1d NC |
8027 | unsigned long ul, roffs; |
8028 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
8029 | are various functions, notably frame_space_needed() that assume that | |
8030 | reg is an unsigned int. */ | |
8031 | unsigned int reg; | |
8032 | dwarf_signed_vma l; | |
bf5117e3 | 8033 | dwarf_vma ofs; |
19e6b90e | 8034 | dwarf_vma vma; |
665ce1f6 | 8035 | const char *reg_prefix = ""; |
19e6b90e L |
8036 | |
8037 | op = *start++; | |
8038 | opa = op & 0x3f; | |
8039 | if (op & 0xc0) | |
8040 | op &= 0xc0; | |
8041 | ||
5b6312fd NC |
8042 | /* Make a note if something other than DW_CFA_nop happens. */ |
8043 | if (op != DW_CFA_nop) | |
8044 | all_nops = FALSE; | |
8045 | ||
19e6b90e L |
8046 | /* Warning: if you add any more cases to this switch, be |
8047 | sure to add them to the corresponding switch above. */ | |
8048 | switch (op) | |
8049 | { | |
8050 | case DW_CFA_advance_loc: | |
8051 | if (do_debug_frames_interp) | |
8052 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8053 | else | |
bf5117e3 | 8054 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 8055 | opa * fc->code_factor, |
b4eb7656 | 8056 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
8057 | fc->pc_begin + opa * fc->code_factor, |
8058 | fc->ptr_size)); | |
19e6b90e L |
8059 | fc->pc_begin += opa * fc->code_factor; |
8060 | break; | |
8061 | ||
8062 | case DW_CFA_offset: | |
7f2c8a1d | 8063 | READ_ULEB (roffs); |
665ce1f6 L |
8064 | if (opa >= (unsigned int) fc->ncols) |
8065 | reg_prefix = bad_reg; | |
8066 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8067 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
8068 | reg_prefix, regname (opa, 0), | |
8069 | roffs * fc->data_factor); | |
8070 | if (*reg_prefix == '\0') | |
8071 | { | |
8072 | fc->col_type[opa] = DW_CFA_offset; | |
8073 | fc->col_offset[opa] = roffs * fc->data_factor; | |
8074 | } | |
19e6b90e L |
8075 | break; |
8076 | ||
8077 | case DW_CFA_restore: | |
50751e18 | 8078 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
8079 | reg_prefix = bad_reg; |
8080 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8081 | printf (" DW_CFA_restore: %s%s\n", | |
8082 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
8083 | if (*reg_prefix != '\0') |
8084 | break; | |
8085 | ||
8086 | if (opa >= (unsigned int) cie->ncols | |
8087 | || (do_debug_frames_interp | |
8088 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
8089 | { | |
8090 | fc->col_type[opa] = DW_CFA_undefined; | |
8091 | fc->col_offset[opa] = 0; | |
8092 | } | |
8093 | else | |
665ce1f6 L |
8094 | { |
8095 | fc->col_type[opa] = cie->col_type[opa]; | |
8096 | fc->col_offset[opa] = cie->col_offset[opa]; | |
8097 | } | |
19e6b90e L |
8098 | break; |
8099 | ||
8100 | case DW_CFA_set_loc: | |
6937bb54 | 8101 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
8102 | if (do_debug_frames_interp) |
8103 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8104 | else | |
bf5117e3 NC |
8105 | printf (" DW_CFA_set_loc: %s\n", |
8106 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
8107 | fc->pc_begin = vma; |
8108 | break; | |
8109 | ||
8110 | case DW_CFA_advance_loc1: | |
0c588247 | 8111 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
8112 | if (do_debug_frames_interp) |
8113 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8114 | else | |
bf5117e3 NC |
8115 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
8116 | (unsigned long) (ofs * fc->code_factor), | |
8117 | dwarf_vmatoa_1 (NULL, | |
8118 | fc->pc_begin + ofs * fc->code_factor, | |
8119 | fc->ptr_size)); | |
19e6b90e L |
8120 | fc->pc_begin += ofs * fc->code_factor; |
8121 | break; | |
8122 | ||
8123 | case DW_CFA_advance_loc2: | |
6937bb54 | 8124 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
8125 | if (do_debug_frames_interp) |
8126 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8127 | else | |
bf5117e3 NC |
8128 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
8129 | (unsigned long) (ofs * fc->code_factor), | |
8130 | dwarf_vmatoa_1 (NULL, | |
8131 | fc->pc_begin + ofs * fc->code_factor, | |
8132 | fc->ptr_size)); | |
19e6b90e L |
8133 | fc->pc_begin += ofs * fc->code_factor; |
8134 | break; | |
8135 | ||
8136 | case DW_CFA_advance_loc4: | |
6937bb54 | 8137 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
8138 | if (do_debug_frames_interp) |
8139 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8140 | else | |
bf5117e3 NC |
8141 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
8142 | (unsigned long) (ofs * fc->code_factor), | |
8143 | dwarf_vmatoa_1 (NULL, | |
8144 | fc->pc_begin + ofs * fc->code_factor, | |
8145 | fc->ptr_size)); | |
19e6b90e L |
8146 | fc->pc_begin += ofs * fc->code_factor; |
8147 | break; | |
8148 | ||
8149 | case DW_CFA_offset_extended: | |
7f2c8a1d NC |
8150 | READ_ULEB (reg); |
8151 | READ_ULEB (roffs); | |
665ce1f6 L |
8152 | if (reg >= (unsigned int) fc->ncols) |
8153 | reg_prefix = bad_reg; | |
8154 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8155 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
8156 | reg_prefix, regname (reg, 0), | |
8157 | roffs * fc->data_factor); | |
8158 | if (*reg_prefix == '\0') | |
8159 | { | |
8160 | fc->col_type[reg] = DW_CFA_offset; | |
8161 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8162 | } | |
19e6b90e L |
8163 | break; |
8164 | ||
12eae2d3 | 8165 | case DW_CFA_val_offset: |
7f2c8a1d NC |
8166 | READ_ULEB (reg); |
8167 | READ_ULEB (roffs); | |
665ce1f6 L |
8168 | if (reg >= (unsigned int) fc->ncols) |
8169 | reg_prefix = bad_reg; | |
8170 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8171 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
8172 | reg_prefix, regname (reg, 0), |
8173 | roffs * fc->data_factor); | |
8174 | if (*reg_prefix == '\0') | |
8175 | { | |
8176 | fc->col_type[reg] = DW_CFA_val_offset; | |
8177 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8178 | } | |
12eae2d3 JJ |
8179 | break; |
8180 | ||
19e6b90e | 8181 | case DW_CFA_restore_extended: |
7f2c8a1d | 8182 | READ_ULEB (reg); |
50751e18 | 8183 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
8184 | reg_prefix = bad_reg; |
8185 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8186 | printf (" DW_CFA_restore_extended: %s%s\n", | |
8187 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
8188 | if (*reg_prefix != '\0') |
8189 | break; | |
8190 | ||
8191 | if (reg >= (unsigned int) cie->ncols) | |
8192 | { | |
8193 | fc->col_type[reg] = DW_CFA_undefined; | |
8194 | fc->col_offset[reg] = 0; | |
8195 | } | |
8196 | else | |
665ce1f6 L |
8197 | { |
8198 | fc->col_type[reg] = cie->col_type[reg]; | |
8199 | fc->col_offset[reg] = cie->col_offset[reg]; | |
8200 | } | |
19e6b90e L |
8201 | break; |
8202 | ||
8203 | case DW_CFA_undefined: | |
7f2c8a1d | 8204 | READ_ULEB (reg); |
665ce1f6 L |
8205 | if (reg >= (unsigned int) fc->ncols) |
8206 | reg_prefix = bad_reg; | |
8207 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8208 | printf (" DW_CFA_undefined: %s%s\n", | |
8209 | reg_prefix, regname (reg, 0)); | |
8210 | if (*reg_prefix == '\0') | |
8211 | { | |
8212 | fc->col_type[reg] = DW_CFA_undefined; | |
8213 | fc->col_offset[reg] = 0; | |
8214 | } | |
19e6b90e L |
8215 | break; |
8216 | ||
8217 | case DW_CFA_same_value: | |
7f2c8a1d | 8218 | READ_ULEB (reg); |
665ce1f6 L |
8219 | if (reg >= (unsigned int) fc->ncols) |
8220 | reg_prefix = bad_reg; | |
8221 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8222 | printf (" DW_CFA_same_value: %s%s\n", | |
8223 | reg_prefix, regname (reg, 0)); | |
8224 | if (*reg_prefix == '\0') | |
8225 | { | |
8226 | fc->col_type[reg] = DW_CFA_same_value; | |
8227 | fc->col_offset[reg] = 0; | |
8228 | } | |
19e6b90e L |
8229 | break; |
8230 | ||
8231 | case DW_CFA_register: | |
7f2c8a1d NC |
8232 | READ_ULEB (reg); |
8233 | READ_ULEB (roffs); | |
665ce1f6 L |
8234 | if (reg >= (unsigned int) fc->ncols) |
8235 | reg_prefix = bad_reg; | |
8236 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 8237 | { |
665ce1f6 L |
8238 | printf (" DW_CFA_register: %s%s in ", |
8239 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
8240 | puts (regname (roffs, 0)); |
8241 | } | |
665ce1f6 L |
8242 | if (*reg_prefix == '\0') |
8243 | { | |
8244 | fc->col_type[reg] = DW_CFA_register; | |
8245 | fc->col_offset[reg] = roffs; | |
8246 | } | |
19e6b90e L |
8247 | break; |
8248 | ||
8249 | case DW_CFA_remember_state: | |
8250 | if (! do_debug_frames_interp) | |
8251 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 8252 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 8253 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
8254 | rs->cfa_reg = fc->cfa_reg; |
8255 | rs->ra = fc->ra; | |
8256 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 8257 | rs->ncols = fc->ncols; |
3f5e193b | 8258 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 8259 | sizeof (* rs->col_type)); |
d71ad7fc RC |
8260 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
8261 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
8262 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
8263 | rs->next = remembered_state; |
8264 | remembered_state = rs; | |
8265 | break; | |
8266 | ||
8267 | case DW_CFA_restore_state: | |
8268 | if (! do_debug_frames_interp) | |
8269 | printf (" DW_CFA_restore_state\n"); | |
8270 | rs = remembered_state; | |
8271 | if (rs) | |
8272 | { | |
8273 | remembered_state = rs->next; | |
d71ad7fc RC |
8274 | fc->cfa_offset = rs->cfa_offset; |
8275 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
8276 | fc->ra = rs->ra; |
8277 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
8278 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
8279 | { | |
1306a742 | 8280 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
8281 | fc->ncols = 0; |
8282 | break; | |
8283 | } | |
d71ad7fc | 8284 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 8285 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 8286 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
8287 | free (rs->col_type); |
8288 | free (rs->col_offset); | |
8289 | free (rs); | |
8290 | } | |
8291 | else if (do_debug_frames_interp) | |
8292 | printf ("Mismatched DW_CFA_restore_state\n"); | |
8293 | break; | |
8294 | ||
8295 | case DW_CFA_def_cfa: | |
32ef3000 | 8296 | READ_ULEB (fc->cfa_reg); |
7f2c8a1d | 8297 | READ_ULEB (fc->cfa_offset); |
19e6b90e L |
8298 | fc->cfa_exp = 0; |
8299 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8300 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 8301 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8302 | break; |
8303 | ||
8304 | case DW_CFA_def_cfa_register: | |
32ef3000 | 8305 | READ_ULEB (fc->cfa_reg); |
19e6b90e L |
8306 | fc->cfa_exp = 0; |
8307 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
8308 | printf (" DW_CFA_def_cfa_register: %s\n", |
8309 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
8310 | break; |
8311 | ||
8312 | case DW_CFA_def_cfa_offset: | |
7f2c8a1d | 8313 | READ_ULEB (fc->cfa_offset); |
19e6b90e | 8314 | if (! do_debug_frames_interp) |
c8071705 | 8315 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8316 | break; |
8317 | ||
8318 | case DW_CFA_nop: | |
8319 | if (! do_debug_frames_interp) | |
8320 | printf (" DW_CFA_nop\n"); | |
8321 | break; | |
8322 | ||
8323 | case DW_CFA_def_cfa_expression: | |
7f2c8a1d | 8324 | READ_ULEB (ul); |
7460c0ab | 8325 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 8326 | { |
a1165289 | 8327 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8328 | break; |
8329 | } | |
19e6b90e L |
8330 | if (! do_debug_frames_interp) |
8331 | { | |
8332 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
8333 | decode_location_expression (start, eh_addr_size, 0, -1, |
8334 | ul, 0, section); | |
19e6b90e L |
8335 | printf (")\n"); |
8336 | } | |
8337 | fc->cfa_exp = 1; | |
8338 | start += ul; | |
8339 | break; | |
8340 | ||
8341 | case DW_CFA_expression: | |
7f2c8a1d NC |
8342 | READ_ULEB (reg); |
8343 | READ_ULEB (ul); | |
665ce1f6 L |
8344 | if (reg >= (unsigned int) fc->ncols) |
8345 | reg_prefix = bad_reg; | |
6937bb54 | 8346 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 8347 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
8348 | tmp = start + ul; |
8349 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8350 | { |
a1165289 | 8351 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8352 | break; |
8353 | } | |
665ce1f6 | 8354 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 8355 | { |
665ce1f6 L |
8356 | printf (" DW_CFA_expression: %s%s (", |
8357 | reg_prefix, regname (reg, 0)); | |
b7807392 | 8358 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 8359 | ul, 0, section); |
19e6b90e L |
8360 | printf (")\n"); |
8361 | } | |
665ce1f6 L |
8362 | if (*reg_prefix == '\0') |
8363 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 8364 | start = tmp; |
19e6b90e L |
8365 | break; |
8366 | ||
12eae2d3 | 8367 | case DW_CFA_val_expression: |
7f2c8a1d NC |
8368 | READ_ULEB (reg); |
8369 | READ_ULEB (ul); | |
665ce1f6 L |
8370 | if (reg >= (unsigned int) fc->ncols) |
8371 | reg_prefix = bad_reg; | |
362beea4 NC |
8372 | tmp = start + ul; |
8373 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8374 | { |
a1165289 | 8375 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
8376 | break; |
8377 | } | |
665ce1f6 | 8378 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 8379 | { |
665ce1f6 L |
8380 | printf (" DW_CFA_val_expression: %s%s (", |
8381 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
8382 | decode_location_expression (start, eh_addr_size, 0, -1, |
8383 | ul, 0, section); | |
12eae2d3 JJ |
8384 | printf (")\n"); |
8385 | } | |
665ce1f6 L |
8386 | if (*reg_prefix == '\0') |
8387 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 8388 | start = tmp; |
12eae2d3 JJ |
8389 | break; |
8390 | ||
19e6b90e | 8391 | case DW_CFA_offset_extended_sf: |
7f2c8a1d NC |
8392 | READ_ULEB (reg); |
8393 | READ_SLEB (l); | |
665ce1f6 L |
8394 | if (frame_need_space (fc, reg) < 0) |
8395 | reg_prefix = bad_reg; | |
8396 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8397 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
8398 | reg_prefix, regname (reg, 0), | |
c8071705 | 8399 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8400 | if (*reg_prefix == '\0') |
8401 | { | |
8402 | fc->col_type[reg] = DW_CFA_offset; | |
8403 | fc->col_offset[reg] = l * fc->data_factor; | |
8404 | } | |
19e6b90e L |
8405 | break; |
8406 | ||
12eae2d3 | 8407 | case DW_CFA_val_offset_sf: |
7f2c8a1d NC |
8408 | READ_ULEB (reg); |
8409 | READ_SLEB (l); | |
665ce1f6 L |
8410 | if (frame_need_space (fc, reg) < 0) |
8411 | reg_prefix = bad_reg; | |
8412 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8413 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 8414 | reg_prefix, regname (reg, 0), |
c8071705 | 8415 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8416 | if (*reg_prefix == '\0') |
8417 | { | |
8418 | fc->col_type[reg] = DW_CFA_val_offset; | |
8419 | fc->col_offset[reg] = l * fc->data_factor; | |
8420 | } | |
12eae2d3 JJ |
8421 | break; |
8422 | ||
19e6b90e | 8423 | case DW_CFA_def_cfa_sf: |
32ef3000 | 8424 | READ_ULEB (fc->cfa_reg); |
7f2c8a1d | 8425 | READ_ULEB (fc->cfa_offset); |
19e6b90e L |
8426 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
8427 | fc->cfa_exp = 0; | |
8428 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8429 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 8430 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8431 | break; |
8432 | ||
8433 | case DW_CFA_def_cfa_offset_sf: | |
7f2c8a1d | 8434 | READ_ULEB (fc->cfa_offset); |
c8071705 | 8435 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 8436 | if (! do_debug_frames_interp) |
c8071705 | 8437 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8438 | break; |
8439 | ||
8440 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 8441 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
8442 | if (do_debug_frames_interp) |
8443 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8444 | else | |
bf5117e3 NC |
8445 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
8446 | (unsigned long) (ofs * fc->code_factor), | |
8447 | dwarf_vmatoa_1 (NULL, | |
8448 | fc->pc_begin + ofs * fc->code_factor, | |
8449 | fc->ptr_size)); | |
19e6b90e L |
8450 | fc->pc_begin += ofs * fc->code_factor; |
8451 | break; | |
8452 | ||
8453 | case DW_CFA_GNU_window_save: | |
8454 | if (! do_debug_frames_interp) | |
8455 | printf (" DW_CFA_GNU_window_save\n"); | |
8456 | break; | |
8457 | ||
8458 | case DW_CFA_GNU_args_size: | |
7f2c8a1d | 8459 | READ_ULEB (ul); |
19e6b90e L |
8460 | if (! do_debug_frames_interp) |
8461 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
8462 | break; | |
8463 | ||
8464 | case DW_CFA_GNU_negative_offset_extended: | |
7f2c8a1d NC |
8465 | READ_ULEB (reg); |
8466 | READ_SLEB (l); | |
8467 | l = - l; | |
665ce1f6 L |
8468 | if (frame_need_space (fc, reg) < 0) |
8469 | reg_prefix = bad_reg; | |
8470 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8471 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
8472 | reg_prefix, regname (reg, 0), | |
c8071705 | 8473 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8474 | if (*reg_prefix == '\0') |
8475 | { | |
8476 | fc->col_type[reg] = DW_CFA_offset; | |
8477 | fc->col_offset[reg] = l * fc->data_factor; | |
8478 | } | |
19e6b90e L |
8479 | break; |
8480 | ||
8481 | default: | |
53b8873b NC |
8482 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
8483 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
8484 | else | |
f41e4712 | 8485 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
8486 | start = block_end; |
8487 | } | |
8488 | } | |
8489 | ||
5b6312fd NC |
8490 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
8491 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
8492 | frame_display_row (fc, &need_col_headers, &max_regs); |
8493 | ||
8494 | start = block_end; | |
604282a7 | 8495 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
8496 | } |
8497 | ||
8498 | printf ("\n"); | |
8499 | ||
3391569f NC |
8500 | while (remembered_state != NULL) |
8501 | { | |
8502 | rs = remembered_state; | |
8503 | remembered_state = rs->next; | |
8504 | free (rs->col_type); | |
8505 | free (rs->col_offset); | |
8506 | rs->next = NULL; /* Paranoia. */ | |
8507 | free (rs); | |
8508 | } | |
8509 | ||
8510 | while (chunks != NULL) | |
8511 | { | |
8512 | rs = chunks; | |
8513 | chunks = rs->next; | |
8514 | free (rs->col_type); | |
8515 | free (rs->col_offset); | |
8516 | rs->next = NULL; /* Paranoia. */ | |
8517 | free (rs); | |
8518 | } | |
8519 | ||
8520 | while (forward_refs != NULL) | |
8521 | { | |
8522 | rs = forward_refs; | |
8523 | forward_refs = rs->next; | |
8524 | free (rs->col_type); | |
8525 | free (rs->col_offset); | |
8526 | rs->next = NULL; /* Paranoia. */ | |
8527 | free (rs); | |
8528 | } | |
8529 | ||
19e6b90e L |
8530 | return 1; |
8531 | } | |
8532 | ||
8533 | #undef GET | |
19e6b90e | 8534 | |
61364358 JK |
8535 | static int |
8536 | display_debug_names (struct dwarf_section *section, void *file) | |
8537 | { | |
8538 | unsigned char *hdrptr = section->start; | |
8539 | dwarf_vma unit_length; | |
8540 | unsigned char *unit_start; | |
8541 | const unsigned char *const section_end = section->start + section->size; | |
8542 | unsigned char *unit_end; | |
8543 | ||
dda8d76d | 8544 | introduce (section, FALSE); |
61364358 | 8545 | |
dda8d76d | 8546 | load_debug_section_with_follow (str, file); |
61364358 JK |
8547 | |
8548 | for (; hdrptr < section_end; hdrptr = unit_end) | |
8549 | { | |
8550 | unsigned int offset_size; | |
8551 | uint16_t dwarf_version, padding; | |
8552 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
8553 | uint32_t bucket_count, name_count, abbrev_table_size; | |
8554 | uint32_t augmentation_string_size; | |
8555 | unsigned int i; | |
e98fdf1a | 8556 | unsigned long sec_off; |
48467cb9 TV |
8557 | bfd_boolean augmentation_printable; |
8558 | const char *augmentation_string; | |
61364358 JK |
8559 | |
8560 | unit_start = hdrptr; | |
8561 | ||
8562 | /* Get and check the length of the block. */ | |
8563 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
8564 | ||
8565 | if (unit_length == 0xffffffff) | |
8566 | { | |
8567 | /* This section is 64-bit DWARF. */ | |
8568 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
8569 | offset_size = 8; | |
8570 | } | |
8571 | else | |
8572 | offset_size = 4; | |
8573 | unit_end = hdrptr + unit_length; | |
8574 | ||
e98fdf1a AM |
8575 | sec_off = hdrptr - section->start; |
8576 | if (sec_off + unit_length < sec_off | |
8577 | || sec_off + unit_length > section->size) | |
61364358 | 8578 | { |
e98fdf1a AM |
8579 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
8580 | section->name, | |
8581 | (unsigned long) (unit_start - section->start), | |
8582 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
8583 | return 0; |
8584 | } | |
8585 | ||
8586 | /* Get and check the version number. */ | |
8587 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
8588 | printf (_("Version %ld\n"), (long) dwarf_version); | |
8589 | ||
8590 | /* Prior versions did not exist, and future versions may not be | |
8591 | backwards compatible. */ | |
8592 | if (dwarf_version != 5) | |
8593 | { | |
8594 | warn (_("Only DWARF version 5 .debug_names " | |
8595 | "is currently supported.\n")); | |
8596 | return 0; | |
8597 | } | |
8598 | ||
8599 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
8600 | if (padding != 0) | |
8601 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
8602 | padding); | |
8603 | ||
8604 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
8605 | if (comp_unit_count == 0) | |
8606 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
8607 | ||
8608 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
8609 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
8610 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
8611 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
8612 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
8613 | ||
8614 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
8615 | if (augmentation_string_size % 4 != 0) | |
8616 | { | |
8617 | warn (_("Augmentation string length %u must be rounded up " | |
8618 | "to a multiple of 4 in .debug_names.\n"), | |
8619 | augmentation_string_size); | |
8620 | augmentation_string_size += (-augmentation_string_size) & 3; | |
8621 | } | |
48467cb9 | 8622 | |
61364358 | 8623 | printf (_("Augmentation string:")); |
48467cb9 TV |
8624 | |
8625 | augmentation_printable = TRUE; | |
8626 | augmentation_string = (const char *) hdrptr; | |
8627 | ||
61364358 JK |
8628 | for (i = 0; i < augmentation_string_size; i++) |
8629 | { | |
8630 | unsigned char uc; | |
8631 | ||
8632 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
8633 | printf (" %02x", uc); | |
48467cb9 TV |
8634 | |
8635 | if (uc != 0 && !ISPRINT (uc)) | |
8636 | augmentation_printable = FALSE; | |
8637 | } | |
8638 | ||
8639 | if (augmentation_printable) | |
8640 | { | |
8641 | printf (" (\""); | |
8642 | for (i = 0; | |
8643 | i < augmentation_string_size && augmentation_string[i]; | |
8644 | ++i) | |
8645 | putchar (augmentation_string[i]); | |
8646 | printf ("\")"); | |
61364358 | 8647 | } |
61364358 JK |
8648 | putchar ('\n'); |
8649 | ||
8650 | printf (_("CU table:\n")); | |
8651 | for (i = 0; i < comp_unit_count; i++) | |
8652 | { | |
8653 | uint64_t cu_offset; | |
8654 | ||
8655 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
8656 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
8657 | } | |
8658 | putchar ('\n'); | |
8659 | ||
8660 | printf (_("TU table:\n")); | |
8661 | for (i = 0; i < local_type_unit_count; i++) | |
8662 | { | |
8663 | uint64_t tu_offset; | |
8664 | ||
8665 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
8666 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
8667 | } | |
8668 | putchar ('\n'); | |
8669 | ||
8670 | printf (_("Foreign TU table:\n")); | |
8671 | for (i = 0; i < foreign_type_unit_count; i++) | |
8672 | { | |
8673 | uint64_t signature; | |
8674 | ||
8675 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
8676 | printf (_("[%3u] "), i); | |
8677 | print_dwarf_vma (signature, 8); | |
8678 | putchar ('\n'); | |
8679 | } | |
8680 | putchar ('\n'); | |
8681 | ||
8682 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
8683 | hdrptr += bucket_count * sizeof (uint32_t); | |
8684 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
8685 | hdrptr += name_count * sizeof (uint32_t); | |
8686 | unsigned char *const name_table_string_offsets = hdrptr; | |
8687 | hdrptr += name_count * offset_size; | |
8688 | unsigned char *const name_table_entry_offsets = hdrptr; | |
8689 | hdrptr += name_count * offset_size; | |
8690 | unsigned char *const abbrev_table = hdrptr; | |
8691 | hdrptr += abbrev_table_size; | |
8692 | const unsigned char *const abbrev_table_end = hdrptr; | |
8693 | unsigned char *const entry_pool = hdrptr; | |
8694 | if (hdrptr > unit_end) | |
8695 | { | |
8696 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
8697 | "for unit 0x%lx in the debug_names\n"), | |
8698 | (long) (hdrptr - section->start), | |
8699 | (long) (unit_end - section->start), | |
8700 | (long) (unit_start - section->start)); | |
8701 | return 0; | |
8702 | } | |
8703 | ||
8704 | size_t buckets_filled = 0; | |
8705 | size_t bucketi; | |
8706 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
8707 | { | |
8708 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
8709 | ||
8710 | if (bucket != 0) | |
8711 | ++buckets_filled; | |
8712 | } | |
d3a49aa8 AM |
8713 | printf (ngettext ("Used %zu of %lu bucket.\n", |
8714 | "Used %zu of %lu buckets.\n", | |
8715 | bucket_count), | |
8716 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 8717 | |
0a79bef4 | 8718 | uint32_t hash_prev = 0; |
61364358 JK |
8719 | size_t hash_clash_count = 0; |
8720 | size_t longest_clash = 0; | |
8721 | size_t this_length = 0; | |
8722 | size_t hashi; | |
8723 | for (hashi = 0; hashi < name_count; hashi++) | |
8724 | { | |
8725 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
8726 | ||
8727 | if (hashi > 0) | |
8728 | { | |
8729 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
8730 | { | |
8731 | ++hash_clash_count; | |
8732 | ++this_length; | |
8733 | longest_clash = MAX (longest_clash, this_length); | |
8734 | } | |
8735 | else | |
8736 | this_length = 0; | |
8737 | } | |
8738 | hash_prev = hash_this; | |
8739 | } | |
8740 | printf (_("Out of %lu items there are %zu bucket clashes" | |
8741 | " (longest of %zu entries).\n"), | |
8742 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
8743 | assert (name_count == buckets_filled + hash_clash_count); | |
8744 | ||
8745 | struct abbrev_lookup_entry | |
8746 | { | |
8747 | dwarf_vma abbrev_tag; | |
8748 | unsigned char *abbrev_lookup_ptr; | |
8749 | }; | |
8750 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
8751 | size_t abbrev_lookup_used = 0; | |
8752 | size_t abbrev_lookup_allocated = 0; | |
8753 | ||
8754 | unsigned char *abbrevptr = abbrev_table; | |
8755 | for (;;) | |
8756 | { | |
8757 | unsigned int bytes_read; | |
8758 | const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read, | |
8759 | abbrev_table_end); | |
8760 | abbrevptr += bytes_read; | |
8761 | if (abbrev_tag == 0) | |
8762 | break; | |
8763 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
8764 | { | |
8765 | abbrev_lookup_allocated = MAX (0x100, | |
8766 | abbrev_lookup_allocated * 2); | |
8767 | abbrev_lookup = xrealloc (abbrev_lookup, | |
8768 | (abbrev_lookup_allocated | |
8769 | * sizeof (*abbrev_lookup))); | |
8770 | } | |
8771 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
8772 | struct abbrev_lookup_entry *entry; | |
8773 | for (entry = abbrev_lookup; | |
8774 | entry < abbrev_lookup + abbrev_lookup_used; | |
8775 | entry++) | |
8776 | if (entry->abbrev_tag == abbrev_tag) | |
8777 | { | |
8778 | warn (_("Duplicate abbreviation tag %lu " | |
8779 | "in unit 0x%lx in the debug_names\n"), | |
8780 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
8781 | break; | |
8782 | } | |
8783 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
8784 | entry->abbrev_tag = abbrev_tag; | |
8785 | entry->abbrev_lookup_ptr = abbrevptr; | |
8786 | ||
8787 | /* Skip DWARF tag. */ | |
8788 | read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end); | |
8789 | abbrevptr += bytes_read; | |
8790 | for (;;) | |
8791 | { | |
1d827a72 L |
8792 | const dwarf_vma xindex = read_uleb128 (abbrevptr, |
8793 | &bytes_read, | |
8794 | abbrev_table_end); | |
61364358 JK |
8795 | abbrevptr += bytes_read; |
8796 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, | |
8797 | abbrev_table_end); | |
8798 | abbrevptr += bytes_read; | |
1d827a72 | 8799 | if (xindex == 0 && form == 0) |
61364358 JK |
8800 | break; |
8801 | } | |
8802 | } | |
8803 | ||
8804 | printf (_("\nSymbol table:\n")); | |
8805 | uint32_t namei; | |
8806 | for (namei = 0; namei < name_count; ++namei) | |
8807 | { | |
8808 | uint64_t string_offset, entry_offset; | |
8809 | ||
8810 | SAFE_BYTE_GET (string_offset, | |
8811 | name_table_string_offsets + namei * offset_size, | |
8812 | offset_size, unit_end); | |
8813 | SAFE_BYTE_GET (entry_offset, | |
8814 | name_table_entry_offsets + namei * offset_size, | |
8815 | offset_size, unit_end); | |
8816 | ||
8817 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
8818 | fetch_indirect_string (string_offset)); | |
8819 | ||
8820 | unsigned char *entryptr = entry_pool + entry_offset; | |
8821 | ||
8822 | // We need to scan first whether there is a single or multiple | |
8823 | // entries. TAGNO is -2 for the first entry, it is -1 for the | |
8824 | // initial tag read of the second entry, then it becomes 0 for the | |
8825 | // first entry for real printing etc. | |
8826 | int tagno = -2; | |
8827 | /* Initialize it due to a false compiler warning. */ | |
8828 | dwarf_vma second_abbrev_tag = -1; | |
8829 | for (;;) | |
8830 | { | |
8831 | unsigned int bytes_read; | |
8832 | const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read, | |
8833 | unit_end); | |
8834 | entryptr += bytes_read; | |
8835 | if (tagno == -1) | |
8836 | { | |
8837 | second_abbrev_tag = abbrev_tag; | |
8838 | tagno = 0; | |
8839 | entryptr = entry_pool + entry_offset; | |
8840 | continue; | |
8841 | } | |
8842 | if (abbrev_tag == 0) | |
8843 | break; | |
8844 | if (tagno >= 0) | |
8845 | printf ("%s<%lu>", | |
8846 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
8847 | (unsigned long) abbrev_tag); | |
8848 | ||
8849 | const struct abbrev_lookup_entry *entry; | |
8850 | for (entry = abbrev_lookup; | |
8851 | entry < abbrev_lookup + abbrev_lookup_used; | |
8852 | entry++) | |
8853 | if (entry->abbrev_tag == abbrev_tag) | |
8854 | break; | |
8855 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
8856 | { | |
8857 | warn (_("Undefined abbreviation tag %lu " | |
8858 | "in unit 0x%lx in the debug_names\n"), | |
8859 | (long) abbrev_tag, | |
8860 | (long) (unit_start - section->start)); | |
8861 | break; | |
8862 | } | |
8863 | abbrevptr = entry->abbrev_lookup_ptr; | |
8864 | const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read, | |
8865 | abbrev_table_end); | |
8866 | abbrevptr += bytes_read; | |
8867 | if (tagno >= 0) | |
8868 | printf (" %s", get_TAG_name (dwarf_tag)); | |
8869 | for (;;) | |
8870 | { | |
1d827a72 L |
8871 | const dwarf_vma xindex = read_uleb128 (abbrevptr, |
8872 | &bytes_read, | |
8873 | abbrev_table_end); | |
61364358 JK |
8874 | abbrevptr += bytes_read; |
8875 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, | |
8876 | abbrev_table_end); | |
8877 | abbrevptr += bytes_read; | |
1d827a72 | 8878 | if (xindex == 0 && form == 0) |
61364358 JK |
8879 | break; |
8880 | ||
8881 | if (tagno >= 0) | |
1d827a72 | 8882 | printf (" %s", get_IDX_name (xindex)); |
61364358 JK |
8883 | entryptr = read_and_display_attr_value (0, form, 0, entryptr, |
8884 | unit_end, 0, 0, | |
8885 | offset_size, | |
8886 | dwarf_version, NULL, | |
8887 | (tagno < 0), NULL, | |
8888 | NULL, '='); | |
8889 | } | |
8890 | ++tagno; | |
8891 | } | |
8892 | if (tagno <= 0) | |
8893 | printf (_(" <no entries>")); | |
8894 | putchar ('\n'); | |
8895 | } | |
8896 | ||
8897 | free (abbrev_lookup); | |
8898 | } | |
8899 | ||
8900 | return 1; | |
8901 | } | |
8902 | ||
dda8d76d | 8903 | static int |
d85bf2ba NC |
8904 | display_debug_links (struct dwarf_section * section, |
8905 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
8906 | { |
8907 | const unsigned char * filename; | |
8908 | unsigned int filelen; | |
8909 | ||
8910 | introduce (section, FALSE); | |
8911 | ||
8912 | /* The .gnu_debuglink section is formatted as: | |
8913 | (c-string) Filename. | |
8914 | (padding) If needed to reach a 4 byte boundary. | |
8915 | (uint32_t) CRC32 value. | |
8916 | ||
8917 | The .gun_debugaltlink section is formatted as: | |
8918 | (c-string) Filename. | |
8919 | (binary) Build-ID. */ | |
8920 | ||
8921 | filename = section->start; | |
8922 | filelen = strnlen ((const char *) filename, section->size); | |
8923 | if (filelen == section->size) | |
8924 | { | |
8925 | warn (_("The debuglink filename is corrupt/missing\n")); | |
8926 | return 0; | |
8927 | } | |
8928 | ||
8929 | printf (_(" Separate debug info file: %s\n"), filename); | |
8930 | ||
8931 | if (const_strneq (section->name, ".gnu_debuglink")) | |
8932 | { | |
8933 | unsigned int crc32; | |
8934 | unsigned int crc_offset; | |
8935 | ||
8936 | crc_offset = filelen + 1; | |
8937 | crc_offset = (crc_offset + 3) & ~3; | |
8938 | if (crc_offset + 4 > section->size) | |
8939 | { | |
8940 | warn (_("CRC offset missing/truncated\n")); | |
8941 | return 0; | |
8942 | } | |
8943 | ||
8944 | crc32 = byte_get (filename + crc_offset, 4); | |
8945 | ||
8946 | printf (_(" CRC value: %#x\n"), crc32); | |
8947 | ||
8948 | if (crc_offset + 4 < section->size) | |
8949 | { | |
8950 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
8951 | (long)(section->size - (crc_offset + 4))); | |
8952 | return 0; | |
8953 | } | |
8954 | } | |
8955 | else /* const_strneq (section->name, ".gnu_debugaltlink") */ | |
8956 | { | |
8957 | const unsigned char * build_id = section->start + filelen + 1; | |
8958 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
8959 | bfd_size_type printed; | |
8960 | ||
8961 | /* FIXME: Should we support smaller build-id notes ? */ | |
8962 | if (build_id_len < 0x14) | |
8963 | { | |
8964 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
8965 | return 0; | |
8966 | } | |
8967 | ||
8968 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 8969 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
8970 | putchar ('\n'); |
8971 | } | |
8972 | ||
8973 | putchar ('\n'); | |
8974 | return 1; | |
8975 | } | |
8976 | ||
5bbdf3d5 DE |
8977 | static int |
8978 | display_gdb_index (struct dwarf_section *section, | |
8979 | void *file ATTRIBUTE_UNUSED) | |
8980 | { | |
8981 | unsigned char *start = section->start; | |
8982 | uint32_t version; | |
8983 | uint32_t cu_list_offset, tu_list_offset; | |
8984 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
8985 | unsigned int cu_list_elements, tu_list_elements; | |
8986 | unsigned int address_table_size, symbol_table_slots; | |
8987 | unsigned char *cu_list, *tu_list; | |
8988 | unsigned char *address_table, *symbol_table, *constant_pool; | |
8989 | unsigned int i; | |
8990 | ||
8991 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
8992 | ||
dda8d76d | 8993 | introduce (section, FALSE); |
5bbdf3d5 DE |
8994 | |
8995 | if (section->size < 6 * sizeof (uint32_t)) | |
8996 | { | |
8997 | warn (_("Truncated header in the %s section.\n"), section->name); | |
8998 | return 0; | |
8999 | } | |
9000 | ||
9001 | version = byte_get_little_endian (start, 4); | |
da88a764 | 9002 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
9003 | |
9004 | /* Prior versions are obsolete, and future versions may not be | |
9005 | backwards compatible. */ | |
aa170720 | 9006 | if (version < 3 || version > 8) |
5bbdf3d5 | 9007 | { |
da88a764 | 9008 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
9009 | return 0; |
9010 | } | |
8d6eee87 TT |
9011 | if (version < 4) |
9012 | warn (_("The address table data in version 3 may be wrong.\n")); | |
9013 | if (version < 5) | |
9014 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
9015 | if (version < 6) | |
9016 | warn (_("Version 5 does not include inlined functions.\n")); | |
9017 | if (version < 7) | |
9018 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
9019 | /* Version 7 indices generated by Gold have bad type unit references, |
9020 | PR binutils/15021. But we don't know if the index was generated by | |
9021 | Gold or not, so to avoid worrying users with gdb-generated indices | |
9022 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
9023 | |
9024 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
9025 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
9026 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
9027 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
9028 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
9029 | ||
9030 | if (cu_list_offset > section->size | |
9031 | || tu_list_offset > section->size | |
9032 | || address_table_offset > section->size | |
9033 | || symbol_table_offset > section->size | |
9034 | || constant_pool_offset > section->size) | |
9035 | { | |
9036 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
9037 | return 0; | |
9038 | } | |
9039 | ||
53774b7e NC |
9040 | /* PR 17531: file: 418d0a8a. */ |
9041 | if (tu_list_offset < cu_list_offset) | |
9042 | { | |
9043 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
9044 | tu_list_offset, cu_list_offset); | |
9045 | return 0; | |
9046 | } | |
9047 | ||
5bbdf3d5 | 9048 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
9049 | |
9050 | if (address_table_offset < tu_list_offset) | |
9051 | { | |
9052 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
9053 | address_table_offset, tu_list_offset); | |
9054 | return 0; | |
9055 | } | |
9056 | ||
5bbdf3d5 | 9057 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
9058 | |
9059 | /* PR 17531: file: 18a47d3d. */ | |
9060 | if (symbol_table_offset < address_table_offset) | |
9061 | { | |
13bace4a | 9062 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
9063 | symbol_table_offset, address_table_offset); |
9064 | return 0; | |
9065 | } | |
9066 | ||
5bbdf3d5 | 9067 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
9068 | |
9069 | if (constant_pool_offset < symbol_table_offset) | |
9070 | { | |
9071 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
9072 | constant_pool_offset, symbol_table_offset); | |
9073 | return 0; | |
9074 | } | |
9075 | ||
5bbdf3d5 DE |
9076 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
9077 | ||
9078 | cu_list = start + cu_list_offset; | |
9079 | tu_list = start + tu_list_offset; | |
9080 | address_table = start + address_table_offset; | |
9081 | symbol_table = start + symbol_table_offset; | |
9082 | constant_pool = start + constant_pool_offset; | |
9083 | ||
28d909e5 | 9084 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 9085 | { |
1306a742 | 9086 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
9087 | return 0; |
9088 | } | |
b4eb7656 | 9089 | |
5bbdf3d5 DE |
9090 | printf (_("\nCU table:\n")); |
9091 | for (i = 0; i < cu_list_elements; i += 2) | |
9092 | { | |
9093 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
9094 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
9095 | ||
9096 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
9097 | (unsigned long) cu_offset, | |
9098 | (unsigned long) (cu_offset + cu_length - 1)); | |
9099 | } | |
9100 | ||
9101 | printf (_("\nTU table:\n")); | |
9102 | for (i = 0; i < tu_list_elements; i += 3) | |
9103 | { | |
9104 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
9105 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
9106 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
9107 | ||
9108 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
9109 | (unsigned long) tu_offset, | |
9110 | (unsigned long) type_offset); | |
9111 | print_dwarf_vma (signature, 8); | |
9112 | printf ("\n"); | |
9113 | } | |
9114 | ||
9115 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
9116 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
9117 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
9118 | { |
9119 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
9120 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
9121 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
9122 | ||
9123 | print_dwarf_vma (low, 8); | |
9124 | print_dwarf_vma (high, 8); | |
da88a764 | 9125 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
9126 | } |
9127 | ||
9128 | printf (_("\nSymbol table:\n")); | |
9129 | for (i = 0; i < symbol_table_slots; ++i) | |
9130 | { | |
9131 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
9132 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
9133 | uint32_t num_cus, cu; | |
9134 | ||
9135 | if (name_offset != 0 | |
9136 | || cu_vector_offset != 0) | |
9137 | { | |
9138 | unsigned int j; | |
362beea4 | 9139 | unsigned char * adr; |
5bbdf3d5 | 9140 | |
362beea4 | 9141 | adr = constant_pool + name_offset; |
53774b7e | 9142 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 9143 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
9144 | { |
9145 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
9146 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
9147 | name_offset, i); | |
9148 | } | |
9149 | else | |
acff9664 NC |
9150 | printf ("[%3u] %.*s:", i, |
9151 | (int) (section->size - (constant_pool_offset + name_offset)), | |
9152 | constant_pool + name_offset); | |
53774b7e | 9153 | |
362beea4 NC |
9154 | adr = constant_pool + cu_vector_offset; |
9155 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
9156 | { |
9157 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
9158 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
9159 | cu_vector_offset, i); | |
9160 | continue; | |
9161 | } | |
57028622 | 9162 | |
362beea4 | 9163 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 9164 | |
362beea4 | 9165 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 9166 | if (num_cus * 4 < num_cus |
362beea4 NC |
9167 | || adr >= section->start + section->size |
9168 | || adr < constant_pool) | |
53774b7e NC |
9169 | { |
9170 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 9171 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
9172 | num_cus, i); |
9173 | continue; | |
9174 | } | |
9175 | ||
8d6eee87 TT |
9176 | if (num_cus > 1) |
9177 | printf ("\n"); | |
f3853b34 | 9178 | |
5bbdf3d5 DE |
9179 | for (j = 0; j < num_cus; ++j) |
9180 | { | |
7c1cef97 | 9181 | int is_static; |
8d6eee87 TT |
9182 | gdb_index_symbol_kind kind; |
9183 | ||
5bbdf3d5 | 9184 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 9185 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
9186 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
9187 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 9188 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 9189 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
9190 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
9191 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 9192 | else |
8d6eee87 TT |
9193 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
9194 | ||
459d52c8 DE |
9195 | printf (" [%s, %s]", |
9196 | is_static ? _("static") : _("global"), | |
9197 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
9198 | if (num_cus > 1) |
9199 | printf ("\n"); | |
5bbdf3d5 | 9200 | } |
8d6eee87 TT |
9201 | if (num_cus <= 1) |
9202 | printf ("\n"); | |
5bbdf3d5 DE |
9203 | } |
9204 | } | |
9205 | ||
9206 | return 1; | |
9207 | } | |
9208 | ||
657d0d47 CC |
9209 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
9210 | ||
9211 | static void | |
9212 | prealloc_cu_tu_list (unsigned int nshndx) | |
9213 | { | |
9214 | if (shndx_pool == NULL) | |
9215 | { | |
9216 | shndx_pool_size = nshndx; | |
9217 | shndx_pool_used = 0; | |
9218 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
9219 | sizeof (unsigned int)); | |
9220 | } | |
9221 | else | |
9222 | { | |
9223 | shndx_pool_size = shndx_pool_used + nshndx; | |
9224 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
9225 | sizeof (unsigned int)); | |
9226 | } | |
9227 | } | |
9228 | ||
9229 | static void | |
9230 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
9231 | { | |
9232 | if (shndx_pool_used >= shndx_pool_size) | |
9233 | { | |
9234 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9235 | return; | |
9236 | } | |
9237 | shndx_pool [shndx_pool_used++] = shndx; | |
9238 | } | |
9239 | ||
9240 | static void | |
9241 | end_cu_tu_entry (void) | |
9242 | { | |
9243 | if (shndx_pool_used >= shndx_pool_size) | |
9244 | { | |
9245 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9246 | return; | |
9247 | } | |
9248 | shndx_pool [shndx_pool_used++] = 0; | |
9249 | } | |
9250 | ||
341f9135 CC |
9251 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
9252 | ||
9253 | static const char * | |
9254 | get_DW_SECT_short_name (unsigned int dw_sect) | |
9255 | { | |
9256 | static char buf[16]; | |
9257 | ||
9258 | switch (dw_sect) | |
9259 | { | |
9260 | case DW_SECT_INFO: | |
9261 | return "info"; | |
9262 | case DW_SECT_TYPES: | |
9263 | return "types"; | |
9264 | case DW_SECT_ABBREV: | |
9265 | return "abbrev"; | |
9266 | case DW_SECT_LINE: | |
9267 | return "line"; | |
9268 | case DW_SECT_LOC: | |
9269 | return "loc"; | |
9270 | case DW_SECT_STR_OFFSETS: | |
9271 | return "str_off"; | |
9272 | case DW_SECT_MACINFO: | |
9273 | return "macinfo"; | |
9274 | case DW_SECT_MACRO: | |
9275 | return "macro"; | |
9276 | default: | |
b4eb7656 | 9277 | break; |
341f9135 CC |
9278 | } |
9279 | ||
9280 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
9281 | return buf; | |
9282 | } | |
9283 | ||
9284 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
9285 | These sections are extensions for Fission. | |
9286 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
9287 | |
9288 | static int | |
9289 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
9290 | { | |
9291 | unsigned char *phdr = section->start; | |
9292 | unsigned char *limit = phdr + section->size; | |
9293 | unsigned char *phash; | |
9294 | unsigned char *pindex; | |
9295 | unsigned char *ppool; | |
9296 | unsigned int version; | |
341f9135 | 9297 | unsigned int ncols = 0; |
657d0d47 CC |
9298 | unsigned int nused; |
9299 | unsigned int nslots; | |
9300 | unsigned int i; | |
341f9135 CC |
9301 | unsigned int j; |
9302 | dwarf_vma signature_high; | |
9303 | dwarf_vma signature_low; | |
9304 | char buf[64]; | |
657d0d47 | 9305 | |
6937bb54 NC |
9306 | /* PR 17512: file: 002-168123-0.004. */ |
9307 | if (phdr == NULL) | |
9308 | { | |
9309 | warn (_("Section %s is empty\n"), section->name); | |
9310 | return 0; | |
9311 | } | |
9312 | /* PR 17512: file: 002-376-0.004. */ | |
9313 | if (section->size < 24) | |
9314 | { | |
72c61a0d | 9315 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
9316 | section->name); |
9317 | return 0; | |
9318 | } | |
9319 | ||
9320 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 9321 | if (version >= 2) |
6937bb54 NC |
9322 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
9323 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
9324 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
9325 | ||
657d0d47 | 9326 | phash = phdr + 16; |
8e2e3c6c AM |
9327 | pindex = phash + (size_t) nslots * 8; |
9328 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 9329 | |
657d0d47 CC |
9330 | if (do_display) |
9331 | { | |
dda8d76d NC |
9332 | introduce (section, FALSE); |
9333 | ||
8e2e3c6c | 9334 | printf (_(" Version: %u\n"), version); |
341f9135 | 9335 | if (version >= 2) |
8e2e3c6c AM |
9336 | printf (_(" Number of columns: %u\n"), ncols); |
9337 | printf (_(" Number of used entries: %u\n"), nused); | |
9338 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
9339 | } |
9340 | ||
8e2e3c6c AM |
9341 | /* PR 17531: file: 45d69832. */ |
9342 | if ((size_t) nslots * 8 / 8 != nslots | |
9343 | || phash < phdr || phash > limit | |
9344 | || pindex < phash || pindex > limit | |
9345 | || ppool < pindex || ppool > limit) | |
657d0d47 | 9346 | { |
8e2e3c6c AM |
9347 | warn (ngettext ("Section %s is too small for %u slot\n", |
9348 | "Section %s is too small for %u slots\n", | |
9349 | nslots), | |
657d0d47 CC |
9350 | section->name, nslots); |
9351 | return 0; | |
9352 | } | |
9353 | ||
341f9135 | 9354 | if (version == 1) |
657d0d47 | 9355 | { |
341f9135 CC |
9356 | if (!do_display) |
9357 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
9358 | for (i = 0; i < nslots; i++) | |
657d0d47 | 9359 | { |
341f9135 CC |
9360 | unsigned char *shndx_list; |
9361 | unsigned int shndx; | |
9362 | ||
6937bb54 | 9363 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 9364 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 9365 | { |
6937bb54 | 9366 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 9367 | shndx_list = ppool + j * 4; |
f3853b34 NC |
9368 | /* PR 17531: file: 705e010d. */ |
9369 | if (shndx_list < ppool) | |
9370 | { | |
9371 | warn (_("Section index pool located before start of section\n")); | |
9372 | return 0; | |
9373 | } | |
9374 | ||
341f9135 CC |
9375 | if (do_display) |
9376 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
9377 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9378 | buf, sizeof (buf))); | |
9379 | for (;;) | |
657d0d47 | 9380 | { |
341f9135 CC |
9381 | if (shndx_list >= limit) |
9382 | { | |
9383 | warn (_("Section %s too small for shndx pool\n"), | |
9384 | section->name); | |
9385 | return 0; | |
9386 | } | |
6937bb54 | 9387 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
9388 | if (shndx == 0) |
9389 | break; | |
9390 | if (do_display) | |
9391 | printf (" %d", shndx); | |
9392 | else | |
9393 | add_shndx_to_cu_tu_entry (shndx); | |
9394 | shndx_list += 4; | |
657d0d47 | 9395 | } |
657d0d47 | 9396 | if (do_display) |
341f9135 | 9397 | printf ("\n"); |
657d0d47 | 9398 | else |
341f9135 CC |
9399 | end_cu_tu_entry (); |
9400 | } | |
9401 | phash += 8; | |
9402 | pindex += 4; | |
9403 | } | |
9404 | } | |
9405 | else if (version == 2) | |
9406 | { | |
9407 | unsigned int val; | |
9408 | unsigned int dw_sect; | |
9409 | unsigned char *ph = phash; | |
9410 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
9411 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
9412 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
9413 | unsigned char *pend = psizes + (size_t) nused * ncols * 4; | |
341f9135 CC |
9414 | bfd_boolean is_tu_index; |
9415 | struct cu_tu_set *this_set = NULL; | |
9416 | unsigned int row; | |
9417 | unsigned char *prow; | |
9418 | ||
9419 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
9420 | ||
362beea4 | 9421 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
9422 | Check for integer overflow (can occur when size_t is 32-bit) |
9423 | with overlarge ncols or nused values. */ | |
4ac948a0 NC |
9424 | if (ncols > 0 |
9425 | && ((size_t) ncols * 4 / 4 != ncols | |
9426 | || (size_t) nused * ncols * 4 / ((size_t) ncols * 4) != nused | |
9427 | || poffsets < ppool || poffsets > limit | |
9428 | || psizes < poffsets || psizes > limit | |
9429 | || pend < psizes || pend > limit)) | |
341f9135 CC |
9430 | { |
9431 | warn (_("Section %s too small for offset and size tables\n"), | |
9432 | section->name); | |
9433 | return 0; | |
9434 | } | |
9435 | ||
9436 | if (do_display) | |
9437 | { | |
9438 | printf (_(" Offset table\n")); | |
9439 | printf (" slot %-16s ", | |
9440 | is_tu_index ? _("signature") : _("dwo_id")); | |
9441 | } | |
9442 | else | |
9443 | { | |
9444 | if (is_tu_index) | |
9445 | { | |
9446 | tu_count = nused; | |
72c61a0d | 9447 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 9448 | this_set = tu_sets; |
657d0d47 | 9449 | } |
657d0d47 | 9450 | else |
341f9135 CC |
9451 | { |
9452 | cu_count = nused; | |
72c61a0d | 9453 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
9454 | this_set = cu_sets; |
9455 | } | |
9456 | } | |
6937bb54 | 9457 | |
341f9135 CC |
9458 | if (do_display) |
9459 | { | |
9460 | for (j = 0; j < ncols; j++) | |
9461 | { | |
6937bb54 | 9462 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
9463 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
9464 | } | |
9465 | printf ("\n"); | |
9466 | } | |
6937bb54 | 9467 | |
341f9135 CC |
9468 | for (i = 0; i < nslots; i++) |
9469 | { | |
6937bb54 NC |
9470 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9471 | ||
9472 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9473 | if (row != 0) |
9474 | { | |
591f7597 | 9475 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 9476 | if (row > nused) |
591f7597 NC |
9477 | { |
9478 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
9479 | row, nused); | |
9480 | return 0; | |
9481 | } | |
9482 | ||
341f9135 | 9483 | if (!do_display) |
6aea08d9 NC |
9484 | { |
9485 | size_t num_copy = sizeof (uint64_t); | |
9486 | ||
9487 | /* PR 23064: Beware of buffer overflow. */ | |
9488 | if (ph + num_copy < limit) | |
9489 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
9490 | else | |
9491 | { | |
9492 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); | |
9493 | return 0; | |
9494 | } | |
9495 | } | |
6937bb54 | 9496 | |
341f9135 | 9497 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
9498 | /* PR 17531: file: b8ce60a8. */ |
9499 | if (prow < poffsets || prow > limit) | |
9500 | { | |
9501 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
9502 | row, ncols); | |
9503 | return 0; | |
9504 | } | |
3aade688 | 9505 | |
341f9135 CC |
9506 | if (do_display) |
9507 | printf (_(" [%3d] 0x%s"), | |
9508 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9509 | buf, sizeof (buf))); | |
9510 | for (j = 0; j < ncols; j++) | |
9511 | { | |
6937bb54 | 9512 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9513 | if (do_display) |
9514 | printf (" %8d", val); | |
9515 | else | |
9516 | { | |
6937bb54 | 9517 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9518 | |
9519 | /* PR 17531: file: 10796eb3. */ | |
9520 | if (dw_sect >= DW_SECT_MAX) | |
9521 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9522 | else | |
9523 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
9524 | } |
9525 | } | |
6937bb54 | 9526 | |
341f9135 CC |
9527 | if (do_display) |
9528 | printf ("\n"); | |
9529 | } | |
9530 | ph += 8; | |
9531 | pi += 4; | |
9532 | } | |
9533 | ||
9534 | ph = phash; | |
9535 | pi = pindex; | |
9536 | if (do_display) | |
b4eb7656 | 9537 | { |
341f9135 CC |
9538 | printf ("\n"); |
9539 | printf (_(" Size table\n")); | |
9540 | printf (" slot %-16s ", | |
9541 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 9542 | } |
6937bb54 | 9543 | |
341f9135 CC |
9544 | for (j = 0; j < ncols; j++) |
9545 | { | |
6937bb54 | 9546 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
9547 | if (do_display) |
9548 | printf (" %8s", get_DW_SECT_short_name (val)); | |
9549 | } | |
6937bb54 | 9550 | |
341f9135 CC |
9551 | if (do_display) |
9552 | printf ("\n"); | |
6937bb54 | 9553 | |
341f9135 CC |
9554 | for (i = 0; i < nslots; i++) |
9555 | { | |
6937bb54 NC |
9556 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9557 | ||
9558 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9559 | if (row != 0) |
9560 | { | |
9561 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 9562 | |
341f9135 CC |
9563 | if (do_display) |
9564 | printf (_(" [%3d] 0x%s"), | |
9565 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9566 | buf, sizeof (buf))); | |
6937bb54 | 9567 | |
341f9135 CC |
9568 | for (j = 0; j < ncols; j++) |
9569 | { | |
6937bb54 | 9570 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9571 | if (do_display) |
9572 | printf (" %8d", val); | |
9573 | else | |
9574 | { | |
6937bb54 | 9575 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9576 | if (dw_sect >= DW_SECT_MAX) |
9577 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9578 | else | |
341f9135 CC |
9579 | this_set [row - 1].section_sizes [dw_sect] = val; |
9580 | } | |
9581 | } | |
6937bb54 | 9582 | |
341f9135 CC |
9583 | if (do_display) |
9584 | printf ("\n"); | |
9585 | } | |
6937bb54 | 9586 | |
341f9135 CC |
9587 | ph += 8; |
9588 | pi += 4; | |
657d0d47 | 9589 | } |
657d0d47 | 9590 | } |
341f9135 | 9591 | else if (do_display) |
6937bb54 | 9592 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
9593 | |
9594 | if (do_display) | |
9595 | printf ("\n"); | |
9596 | ||
9597 | return 1; | |
9598 | } | |
9599 | ||
9600 | /* Load the CU and TU indexes if present. This will build a list of | |
9601 | section sets that we can use to associate a .debug_info.dwo section | |
9602 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
9603 | ||
43a444f9 | 9604 | static bfd_boolean |
657d0d47 CC |
9605 | load_cu_tu_indexes (void *file) |
9606 | { | |
43a444f9 NC |
9607 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
9608 | ||
657d0d47 CC |
9609 | /* If we have already loaded (or tried to load) the CU and TU indexes |
9610 | then do not bother to repeat the task. */ | |
43a444f9 NC |
9611 | if (cu_tu_indexes_read == -1) |
9612 | { | |
9613 | cu_tu_indexes_read = TRUE; | |
9614 | ||
dda8d76d | 9615 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 NC |
9616 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
9617 | cu_tu_indexes_read = FALSE; | |
9618 | ||
dda8d76d | 9619 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 NC |
9620 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
9621 | cu_tu_indexes_read = FALSE; | |
9622 | } | |
657d0d47 | 9623 | |
43a444f9 | 9624 | return (bfd_boolean) cu_tu_indexes_read; |
657d0d47 CC |
9625 | } |
9626 | ||
9627 | /* Find the set of sections that includes section SHNDX. */ | |
9628 | ||
9629 | unsigned int * | |
9630 | find_cu_tu_set (void *file, unsigned int shndx) | |
9631 | { | |
9632 | unsigned int i; | |
9633 | ||
43a444f9 NC |
9634 | if (! load_cu_tu_indexes (file)) |
9635 | return NULL; | |
657d0d47 CC |
9636 | |
9637 | /* Find SHNDX in the shndx pool. */ | |
9638 | for (i = 0; i < shndx_pool_used; i++) | |
9639 | if (shndx_pool [i] == shndx) | |
9640 | break; | |
9641 | ||
9642 | if (i >= shndx_pool_used) | |
9643 | return NULL; | |
9644 | ||
9645 | /* Now backup to find the first entry in the set. */ | |
9646 | while (i > 0 && shndx_pool [i - 1] != 0) | |
9647 | i--; | |
9648 | ||
9649 | return shndx_pool + i; | |
9650 | } | |
9651 | ||
9652 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
9653 | ||
9654 | static int | |
9655 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
9656 | { | |
9657 | return process_cu_tu_index (section, 1); | |
9658 | } | |
9659 | ||
19e6b90e L |
9660 | static int |
9661 | display_debug_not_supported (struct dwarf_section *section, | |
9662 | void *file ATTRIBUTE_UNUSED) | |
9663 | { | |
9664 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
9665 | section->name); | |
9666 | ||
9667 | return 1; | |
9668 | } | |
9669 | ||
1306a742 NC |
9670 | /* Like malloc, but takes two parameters like calloc. |
9671 | Verifies that the first parameter is not too large. | |
82b1b41b | 9672 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 9673 | |
19e6b90e L |
9674 | void * |
9675 | cmalloc (size_t nmemb, size_t size) | |
9676 | { | |
9677 | /* Check for overflow. */ | |
9678 | if (nmemb >= ~(size_t) 0 / size) | |
9679 | return NULL; | |
82b1b41b NC |
9680 | |
9681 | return xmalloc (nmemb * size); | |
19e6b90e L |
9682 | } |
9683 | ||
1306a742 NC |
9684 | /* Like xmalloc, but takes two parameters like calloc. |
9685 | Verifies that the first parameter is not too large. | |
9686 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 9687 | |
72c61a0d | 9688 | void * |
1306a742 | 9689 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
9690 | { |
9691 | /* Check for overflow. */ | |
9692 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
9693 | { |
9694 | fprintf (stderr, | |
9695 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
9696 | (long) nmemb); | |
9697 | xexit (1); | |
9698 | } | |
72c61a0d | 9699 | |
1306a742 | 9700 | return xmalloc (nmemb * size); |
72c61a0d NC |
9701 | } |
9702 | ||
1306a742 NC |
9703 | /* Like xrealloc, but takes three parameters. |
9704 | Verifies that the second parameter is not too large. | |
9705 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 9706 | |
19e6b90e | 9707 | void * |
1306a742 | 9708 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
9709 | { |
9710 | /* Check for overflow. */ | |
9711 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 9712 | { |
dda8d76d NC |
9713 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
9714 | (long) nmemb); | |
8490fb40 NC |
9715 | xexit (1); |
9716 | } | |
82b1b41b | 9717 | |
1306a742 | 9718 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
9719 | } |
9720 | ||
1306a742 | 9721 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 9722 | |
19e6b90e | 9723 | void * |
1306a742 | 9724 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
9725 | { |
9726 | /* Check for overflow. */ | |
9727 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 9728 | { |
dda8d76d NC |
9729 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
9730 | (long) nmemb); | |
8490fb40 NC |
9731 | xexit (1); |
9732 | } | |
82b1b41b | 9733 | |
1306a742 | 9734 | return xcalloc (nmemb, size); |
19e6b90e L |
9735 | } |
9736 | ||
dda8d76d NC |
9737 | static unsigned long |
9738 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
9739 | const unsigned char * buf, | |
9740 | bfd_size_type len) | |
9741 | { | |
9742 | static const unsigned long crc32_table[256] = | |
9743 | { | |
9744 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
9745 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
9746 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
9747 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
9748 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
9749 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
9750 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
9751 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
9752 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
9753 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
9754 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
9755 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
9756 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
9757 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
9758 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
9759 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
9760 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
9761 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
9762 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
9763 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
9764 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
9765 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
9766 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
9767 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
9768 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
9769 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
9770 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
9771 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
9772 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
9773 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
9774 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
9775 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
9776 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
9777 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
9778 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
9779 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
9780 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
9781 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
9782 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
9783 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
9784 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
9785 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
9786 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
9787 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
9788 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
9789 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
9790 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
9791 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
9792 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
9793 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
9794 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
9795 | 0x2d02ef8d | |
9796 | }; | |
9797 | const unsigned char *end; | |
9798 | ||
9799 | crc = ~crc & 0xffffffff; | |
9800 | for (end = buf + len; buf < end; ++ buf) | |
9801 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
9802 | return ~crc & 0xffffffff; | |
9803 | } | |
9804 | ||
9805 | typedef bfd_boolean (* check_func_type) (const char *, void *); | |
9806 | typedef const char * (* parse_func_type) (struct dwarf_section *, void *); | |
9807 | ||
9808 | static bfd_boolean | |
9809 | check_gnu_debuglink (const char * pathname, void * crc_pointer) | |
9810 | { | |
9811 | static unsigned char buffer [8 * 1024]; | |
9812 | FILE * f; | |
9813 | bfd_size_type count; | |
9814 | unsigned long crc = 0; | |
9815 | void * sep_data; | |
9816 | ||
9817 | sep_data = open_debug_file (pathname); | |
9818 | if (sep_data == NULL) | |
9819 | return FALSE; | |
9820 | ||
9821 | /* Yes - we are opening the file twice... */ | |
9822 | f = fopen (pathname, "rb"); | |
9823 | if (f == NULL) | |
9824 | { | |
9825 | /* Paranoia: This should never happen. */ | |
9826 | close_debug_file (sep_data); | |
9827 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
9828 | return FALSE; | |
9829 | } | |
9830 | ||
9831 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
9832 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
9833 | ||
9834 | fclose (f); | |
9835 | ||
9836 | if (crc != * (unsigned long *) crc_pointer) | |
9837 | { | |
9838 | close_debug_file (sep_data); | |
9839 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
9840 | pathname); | |
9841 | return FALSE; | |
9842 | } | |
9843 | ||
9844 | return TRUE; | |
9845 | } | |
9846 | ||
9847 | static const char * | |
9848 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
9849 | { | |
9850 | const char * name; | |
9851 | unsigned int crc_offset; | |
9852 | unsigned long * crc32 = (unsigned long *) data; | |
9853 | ||
9854 | /* The name is first. | |
9855 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
9856 | name = (const char *) section->start; | |
9857 | ||
39f0547e | 9858 | |
dda8d76d NC |
9859 | crc_offset = strnlen (name, section->size) + 1; |
9860 | crc_offset = (crc_offset + 3) & ~3; | |
9861 | if (crc_offset + 4 > section->size) | |
9862 | return NULL; | |
9863 | ||
9864 | * crc32 = byte_get (section->start + crc_offset, 4); | |
9865 | return name; | |
9866 | } | |
9867 | ||
9868 | static bfd_boolean | |
9869 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) | |
9870 | { | |
9871 | void * sep_data = open_debug_file (filename); | |
9872 | ||
9873 | if (sep_data == NULL) | |
9874 | return FALSE; | |
9875 | ||
9876 | /* FIXME: We should now extract the build-id in the separate file | |
9877 | and check it... */ | |
9878 | ||
9879 | return TRUE; | |
9880 | } | |
9881 | ||
9882 | typedef struct build_id_data | |
9883 | { | |
9884 | bfd_size_type len; | |
9885 | const unsigned char * data; | |
9886 | } Build_id_data; | |
9887 | ||
9888 | static const char * | |
9889 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
9890 | { | |
9891 | const char * name; | |
9892 | bfd_size_type namelen; | |
9893 | bfd_size_type id_len; | |
9894 | Build_id_data * build_id_data; | |
9895 | ||
9896 | /* The name is first. | |
9897 | The build-id follows immediately, with no padding, up to the section's end. */ | |
9898 | ||
9899 | name = (const char *) section->start; | |
9900 | namelen = strnlen (name, section->size) + 1; | |
9901 | if (namelen >= section->size) | |
9902 | return NULL; | |
9903 | ||
9904 | id_len = section->size - namelen; | |
9905 | if (id_len < 0x14) | |
9906 | return NULL; | |
9907 | ||
9908 | build_id_data = calloc (1, sizeof * build_id_data); | |
9909 | if (build_id_data == NULL) | |
9910 | return NULL; | |
9911 | ||
9912 | build_id_data->len = id_len; | |
9913 | build_id_data->data = section->start + namelen; | |
9914 | ||
9915 | * (Build_id_data **) data = build_id_data; | |
9916 | ||
9917 | return name; | |
9918 | } | |
9919 | ||
24841daa NC |
9920 | static void |
9921 | add_separate_debug_file (const char * filename, void * handle) | |
9922 | { | |
9923 | separate_info * i = xmalloc (sizeof * i); | |
9924 | ||
9925 | i->filename = filename; | |
9926 | i->handle = handle; | |
9927 | i->next = first_separate_info; | |
9928 | first_separate_info = i; | |
9929 | } | |
9930 | ||
dda8d76d NC |
9931 | static void * |
9932 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 9933 | struct dwarf_section * xlink, |
dda8d76d NC |
9934 | parse_func_type parse_func, |
9935 | check_func_type check_func, | |
9936 | void * func_data) | |
9937 | { | |
9938 | const char * separate_filename; | |
24841daa | 9939 | char * debug_filename; |
dda8d76d NC |
9940 | char * canon_dir; |
9941 | size_t canon_dirlen; | |
9942 | size_t dirlen; | |
9943 | ||
2b63c337 | 9944 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
9945 | { |
9946 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 9947 | xlink->name ? xlink->name : xlink->uncompressed_name); |
dda8d76d NC |
9948 | return FALSE; |
9949 | } | |
9950 | ||
9951 | /* Attempt to locate the separate file. | |
9952 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
9953 | ||
9954 | canon_dir = lrealpath (main_filename); | |
9955 | ||
9956 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) | |
9957 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
9958 | break; | |
9959 | canon_dir[canon_dirlen] = '\0'; | |
9960 | ||
9961 | #ifndef DEBUGDIR | |
9962 | #define DEBUGDIR "/lib/debug" | |
9963 | #endif | |
9964 | #ifndef EXTRA_DEBUG_ROOT1 | |
9965 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
9966 | #endif | |
9967 | #ifndef EXTRA_DEBUG_ROOT2 | |
9968 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
9969 | #endif | |
9970 | ||
24841daa NC |
9971 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
9972 | + canon_dirlen | |
9973 | + strlen (".debug/") | |
dda8d76d | 9974 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 9975 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
9976 | #endif |
9977 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 9978 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 9979 | #endif |
24841daa NC |
9980 | + strlen (separate_filename) |
9981 | + 1); | |
9982 | if (debug_filename == NULL) | |
dda8d76d NC |
9983 | { |
9984 | warn (_("Out of memory")); | |
3391569f | 9985 | free (canon_dir); |
dda8d76d NC |
9986 | return NULL; |
9987 | } | |
9988 | ||
9989 | /* First try in the current directory. */ | |
24841daa NC |
9990 | sprintf (debug_filename, "%s", separate_filename); |
9991 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
9992 | goto found; |
9993 | ||
9994 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
9995 | sprintf (debug_filename, ".debug/%s", separate_filename); |
9996 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
9997 | goto found; |
9998 | ||
9999 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
10000 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10001 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10002 | goto found; |
10003 | ||
10004 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
10005 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10006 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10007 | goto found; |
10008 | ||
10009 | #ifdef EXTRA_DEBUG_ROOT1 | |
10010 | /* Try the first extra debug file root. */ | |
24841daa NC |
10011 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10012 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 10013 | goto found; |
39f0547e NC |
10014 | |
10015 | /* Try the first extra debug file root. */ | |
10016 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
10017 | if (check_func (debug_filename, func_data)) | |
10018 | goto found; | |
dda8d76d NC |
10019 | #endif |
10020 | ||
10021 | #ifdef EXTRA_DEBUG_ROOT2 | |
10022 | /* Try the second extra debug file root. */ | |
24841daa NC |
10023 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10024 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10025 | goto found; |
10026 | #endif | |
10027 | ||
24841daa NC |
10028 | /* Then try in the global debug_filename directory. */ |
10029 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
10030 | dirlen = strlen (DEBUGDIR) - 1; |
10031 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
10032 | strcat (debug_filename, "/"); |
10033 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 10034 | |
24841daa | 10035 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
10036 | goto found; |
10037 | ||
10038 | /* Failed to find the file. */ | |
10039 | warn (_("could not find separate debug file '%s'\n"), separate_filename); | |
24841daa | 10040 | warn (_("tried: %s\n"), debug_filename); |
dda8d76d NC |
10041 | |
10042 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa NC |
10043 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10044 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10045 | #endif |
10046 | ||
10047 | #ifdef EXTRA_DEBUG_ROOT1 | |
39f0547e NC |
10048 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
10049 | warn (_("tried: %s\n"), debug_filename); | |
10050 | ||
24841daa NC |
10051 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10052 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10053 | #endif |
10054 | ||
24841daa NC |
10055 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10056 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10057 | |
24841daa NC |
10058 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10059 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10060 | |
24841daa NC |
10061 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10062 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10063 | |
24841daa NC |
10064 | sprintf (debug_filename, "%s", separate_filename); |
10065 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10066 | |
10067 | free (canon_dir); | |
24841daa | 10068 | free (debug_filename); |
dda8d76d NC |
10069 | return NULL; |
10070 | ||
10071 | found: | |
10072 | free (canon_dir); | |
10073 | ||
24841daa NC |
10074 | void * debug_handle; |
10075 | ||
dda8d76d | 10076 | /* Now open the file.... */ |
24841daa | 10077 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 10078 | { |
24841daa NC |
10079 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
10080 | free (debug_filename); | |
dda8d76d NC |
10081 | return FALSE; |
10082 | } | |
10083 | ||
10084 | /* FIXME: We do not check to see if there are any other separate debug info | |
10085 | files that would also match. */ | |
10086 | ||
24841daa NC |
10087 | printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debug_filename); |
10088 | add_separate_debug_file (debug_filename, debug_handle); | |
dda8d76d | 10089 | |
24841daa | 10090 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 10091 | the structure returned by open_debug_file(). */ |
24841daa | 10092 | return debug_handle; |
dda8d76d NC |
10093 | } |
10094 | ||
d85bf2ba NC |
10095 | /* Attempt to load a separate dwarf object file. */ |
10096 | ||
10097 | static void * | |
24841daa | 10098 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 10099 | { |
24841daa NC |
10100 | char * separate_filename; |
10101 | void * separate_handle; | |
d85bf2ba NC |
10102 | |
10103 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
24841daa NC |
10104 | separate_filename = concat (dir, "/", name, NULL); |
10105 | if (separate_filename == NULL) | |
d85bf2ba NC |
10106 | { |
10107 | warn (_("Out of memory allocating dwo filename\n")); | |
10108 | return NULL; | |
10109 | } | |
10110 | ||
24841daa | 10111 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 10112 | { |
24841daa NC |
10113 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
10114 | free (separate_filename); | |
d85bf2ba NC |
10115 | return NULL; |
10116 | } | |
10117 | ||
10118 | /* FIXME: We should check the dwo_id. */ | |
10119 | ||
24841daa NC |
10120 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
10121 | add_separate_debug_file (separate_filename, separate_handle); | |
10122 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
10123 | return separate_handle; | |
d85bf2ba NC |
10124 | } |
10125 | ||
24841daa NC |
10126 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
10127 | Returns TRUE if any were found, FALSE otherwise. | |
10128 | If TRUE is returned then the linked list starting at first_separate_info | |
10129 | will be populated with open file handles. */ | |
dda8d76d | 10130 | |
24841daa NC |
10131 | bfd_boolean |
10132 | load_separate_debug_files (void * file, const char * filename) | |
dda8d76d | 10133 | { |
8de3a6e2 NC |
10134 | /* Skip this operation if we are not interested in debug links. */ |
10135 | if (! do_follow_links && ! do_debug_links) | |
24841daa | 10136 | return FALSE; |
8de3a6e2 | 10137 | |
24841daa | 10138 | /* See if there are any dwo links. */ |
d85bf2ba NC |
10139 | if (load_debug_section (str, file) |
10140 | && load_debug_section (abbrev, file) | |
10141 | && load_debug_section (info, file)) | |
10142 | { | |
24841daa | 10143 | free_dwo_info (); |
d85bf2ba NC |
10144 | |
10145 | if (process_debug_info (& debug_displays[info].section, file, abbrev, TRUE, FALSE)) | |
10146 | { | |
24841daa NC |
10147 | bfd_boolean introduced = FALSE; |
10148 | dwo_info * dwinfo; | |
10149 | const char * dir = NULL; | |
10150 | const char * id = NULL; | |
10151 | ||
10152 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 10153 | { |
24841daa | 10154 | switch (dwinfo->type) |
d85bf2ba | 10155 | { |
24841daa NC |
10156 | case DWO_NAME: |
10157 | if (do_debug_links) | |
10158 | { | |
10159 | if (! introduced) | |
10160 | { | |
10161 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
10162 | debug_displays [info].section.uncompressed_name); | |
10163 | introduced = TRUE; | |
10164 | } | |
d85bf2ba | 10165 | |
24841daa NC |
10166 | printf (_(" Name: %s\n"), dwinfo->value); |
10167 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); | |
10168 | if (id != NULL) | |
10169 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
10170 | else | |
10171 | printf (_(" ID: <unknown>\n")); | |
10172 | printf ("\n\n"); | |
10173 | } | |
10174 | ||
10175 | if (do_follow_links) | |
10176 | load_dwo_file (filename, dwinfo->value, dir, id); | |
10177 | break; | |
10178 | ||
10179 | case DWO_DIR: | |
10180 | dir = dwinfo->value; | |
10181 | break; | |
10182 | ||
10183 | case DWO_ID: | |
10184 | id = dwinfo->value; | |
10185 | break; | |
10186 | ||
10187 | default: | |
10188 | error (_("Unexpected DWO INFO type")); | |
10189 | break; | |
10190 | } | |
d85bf2ba NC |
10191 | } |
10192 | } | |
10193 | } | |
10194 | ||
dda8d76d | 10195 | if (! do_follow_links) |
8de3a6e2 NC |
10196 | /* The other debug links will be displayed by display_debug_links() |
10197 | so we do not need to do any further processing here. */ | |
24841daa | 10198 | return FALSE; |
dda8d76d NC |
10199 | |
10200 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
10201 | /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */ | |
10202 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ | |
d85bf2ba | 10203 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 10204 | |
dda8d76d NC |
10205 | if (load_debug_section (gnu_debugaltlink, file)) |
10206 | { | |
10207 | Build_id_data * build_id_data; | |
10208 | ||
24841daa NC |
10209 | load_separate_debug_info (filename, |
10210 | & debug_displays[gnu_debugaltlink].section, | |
10211 | parse_gnu_debugaltlink, | |
10212 | check_gnu_debugaltlink, | |
10213 | & build_id_data); | |
dda8d76d NC |
10214 | } |
10215 | ||
10216 | if (load_debug_section (gnu_debuglink, file)) | |
10217 | { | |
10218 | unsigned long crc32; | |
10219 | ||
24841daa NC |
10220 | load_separate_debug_info (filename, |
10221 | & debug_displays[gnu_debuglink].section, | |
10222 | parse_gnu_debuglink, | |
10223 | check_gnu_debuglink, | |
10224 | & crc32); | |
dda8d76d NC |
10225 | } |
10226 | ||
24841daa NC |
10227 | if (first_separate_info != NULL) |
10228 | return TRUE; | |
10229 | ||
dda8d76d | 10230 | do_follow_links = 0; |
24841daa | 10231 | return FALSE; |
dda8d76d NC |
10232 | } |
10233 | ||
19e6b90e L |
10234 | void |
10235 | free_debug_memory (void) | |
10236 | { | |
3f5e193b | 10237 | unsigned int i; |
19e6b90e L |
10238 | |
10239 | free_abbrevs (); | |
10240 | ||
10241 | for (i = 0; i < max; i++) | |
3f5e193b | 10242 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 10243 | |
cc86f28f | 10244 | if (debug_information != NULL) |
19e6b90e | 10245 | { |
cc86f28f | 10246 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
19e6b90e | 10247 | { |
cc86f28f | 10248 | for (i = 0; i < num_debug_info_entries; i++) |
19e6b90e | 10249 | { |
cc86f28f NC |
10250 | if (!debug_information [i].max_loc_offsets) |
10251 | { | |
10252 | free (debug_information [i].loc_offsets); | |
10253 | free (debug_information [i].have_frame_base); | |
10254 | } | |
10255 | if (!debug_information [i].max_range_lists) | |
10256 | free (debug_information [i].range_lists); | |
19e6b90e | 10257 | } |
19e6b90e L |
10258 | } |
10259 | free (debug_information); | |
10260 | debug_information = NULL; | |
82b1b41b | 10261 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 10262 | } |
dda8d76d | 10263 | |
24841daa NC |
10264 | separate_info * d; |
10265 | separate_info * next; | |
dda8d76d | 10266 | |
24841daa NC |
10267 | for (d = first_separate_info; d != NULL; d = next) |
10268 | { | |
10269 | close_debug_file (d->handle); | |
10270 | free ((void *) d->filename); | |
10271 | next = d->next; | |
10272 | free ((void *) d); | |
dda8d76d | 10273 | } |
24841daa NC |
10274 | first_separate_info = NULL; |
10275 | ||
10276 | free_dwo_info (); | |
19e6b90e L |
10277 | } |
10278 | ||
4cb93e3b TG |
10279 | void |
10280 | dwarf_select_sections_by_names (const char *names) | |
10281 | { | |
10282 | typedef struct | |
10283 | { | |
10284 | const char * option; | |
10285 | int * variable; | |
f9f0e732 | 10286 | int val; |
4cb93e3b TG |
10287 | } |
10288 | debug_dump_long_opts; | |
10289 | ||
10290 | static const debug_dump_long_opts opts_table [] = | |
10291 | { | |
10292 | /* Please keep this table alpha- sorted. */ | |
10293 | { "Ranges", & do_debug_ranges, 1 }, | |
10294 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 10295 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 10296 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
10297 | { "cu_index", & do_debug_cu_index, 1 }, |
10298 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 10299 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
10300 | { "frames", & do_debug_frames, 1 }, |
10301 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
10302 | /* The special .gdb_index section. */ |
10303 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
10304 | { "info", & do_debug_info, 1 }, |
10305 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 10306 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
10307 | { "loc", & do_debug_loc, 1 }, |
10308 | { "macro", & do_debug_macinfo, 1 }, | |
10309 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 10310 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 10311 | /* This entry is for compatibility |
4cb93e3b TG |
10312 | with earlier versions of readelf. */ |
10313 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 10314 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 10315 | { "str", & do_debug_str, 1 }, |
6f875884 TG |
10316 | /* These trace_* sections are used by Itanium VMS. */ |
10317 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
10318 | { "trace_aranges", & do_trace_aranges, 1 }, | |
10319 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
10320 | { NULL, NULL, 0 } |
10321 | }; | |
10322 | ||
10323 | const char *p; | |
467c65bc | 10324 | |
4cb93e3b TG |
10325 | p = names; |
10326 | while (*p) | |
10327 | { | |
10328 | const debug_dump_long_opts * entry; | |
467c65bc | 10329 | |
4cb93e3b TG |
10330 | for (entry = opts_table; entry->option; entry++) |
10331 | { | |
10332 | size_t len = strlen (entry->option); | |
467c65bc | 10333 | |
4cb93e3b TG |
10334 | if (strncmp (p, entry->option, len) == 0 |
10335 | && (p[len] == ',' || p[len] == '\0')) | |
10336 | { | |
10337 | * entry->variable |= entry->val; | |
467c65bc | 10338 | |
4cb93e3b TG |
10339 | /* The --debug-dump=frames-interp option also |
10340 | enables the --debug-dump=frames option. */ | |
10341 | if (do_debug_frames_interp) | |
10342 | do_debug_frames = 1; | |
10343 | ||
10344 | p += len; | |
10345 | break; | |
10346 | } | |
10347 | } | |
467c65bc | 10348 | |
4cb93e3b TG |
10349 | if (entry->option == NULL) |
10350 | { | |
10351 | warn (_("Unrecognized debug option '%s'\n"), p); | |
10352 | p = strchr (p, ','); | |
10353 | if (p == NULL) | |
10354 | break; | |
10355 | } | |
467c65bc | 10356 | |
4cb93e3b TG |
10357 | if (*p == ',') |
10358 | p++; | |
10359 | } | |
10360 | } | |
10361 | ||
10362 | void | |
10363 | dwarf_select_sections_by_letters (const char *letters) | |
10364 | { | |
91d6fa6a | 10365 | unsigned int lindex = 0; |
4cb93e3b | 10366 | |
91d6fa6a NC |
10367 | while (letters[lindex]) |
10368 | switch (letters[lindex++]) | |
4cb93e3b | 10369 | { |
dda8d76d NC |
10370 | case 'A': do_debug_addr = 1; break; |
10371 | case 'a': do_debug_abbrevs = 1; break; | |
10372 | case 'c': do_debug_cu_index = 1; break; | |
10373 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
10374 | case 'f': do_debug_frames = 1; break; | |
10375 | case 'g': do_gdb_index = 1; break; | |
10376 | case 'i': do_debug_info = 1; break; | |
10377 | case 'K': do_follow_links = 1; break; | |
10378 | case 'k': do_debug_links = 1; break; | |
10379 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
10380 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
10381 | case 'm': do_debug_macinfo = 1; break; | |
10382 | case 'o': do_debug_loc = 1; break; | |
10383 | case 'p': do_debug_pubnames = 1; break; | |
10384 | case 'R': do_debug_ranges = 1; break; | |
10385 | case 'r': do_debug_aranges = 1; break; | |
10386 | case 's': do_debug_str = 1; break; | |
10387 | case 'T': do_trace_aranges = 1; break; | |
10388 | case 't': do_debug_pubtypes = 1; break; | |
10389 | case 'U': do_trace_info = 1; break; | |
10390 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 10391 | |
4cb93e3b | 10392 | default: |
7cc78d07 | 10393 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
10394 | break; |
10395 | } | |
10396 | } | |
10397 | ||
10398 | void | |
10399 | dwarf_select_sections_all (void) | |
10400 | { | |
10401 | do_debug_info = 1; | |
10402 | do_debug_abbrevs = 1; | |
10403 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
10404 | do_debug_pubnames = 1; | |
f9f0e732 | 10405 | do_debug_pubtypes = 1; |
4cb93e3b TG |
10406 | do_debug_aranges = 1; |
10407 | do_debug_ranges = 1; | |
10408 | do_debug_frames = 1; | |
10409 | do_debug_macinfo = 1; | |
10410 | do_debug_str = 1; | |
10411 | do_debug_loc = 1; | |
5bbdf3d5 | 10412 | do_gdb_index = 1; |
6f875884 TG |
10413 | do_trace_info = 1; |
10414 | do_trace_abbrevs = 1; | |
10415 | do_trace_aranges = 1; | |
657d0d47 CC |
10416 | do_debug_addr = 1; |
10417 | do_debug_cu_index = 1; | |
dda8d76d NC |
10418 | do_follow_links = 1; |
10419 | do_debug_links = 1; | |
4cb93e3b TG |
10420 | } |
10421 | ||
dda8d76d NC |
10422 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL |
10423 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL | |
10424 | ||
10425 | /* N.B. The order here must match the order in section_display_enum. */ | |
10426 | ||
19e6b90e L |
10427 | struct dwarf_section_display debug_displays[] = |
10428 | { | |
dda8d76d NC |
10429 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, |
10430 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE }, | |
10431 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10432 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE }, | |
10433 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10434 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
10435 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
10436 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10437 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10438 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10439 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10440 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10441 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10442 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10443 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
10444 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
10445 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10446 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10447 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10448 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10449 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE }, | |
10450 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10451 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE }, | |
10452 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE }, | |
10453 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE }, | |
10454 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
10455 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE }, | |
10456 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE }, | |
10457 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
10458 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE }, | |
10459 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10460 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10461 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10462 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10463 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE }, | |
10464 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10465 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10466 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE }, | |
10467 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10468 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10469 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10470 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10471 | /* Separate debug info files can containt their own .debug_str section, | |
10472 | and this might be in *addition* to a .debug_str section already present | |
10473 | in the main file. Hence we need to have two entries for .debug_str. */ | |
10474 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
19e6b90e | 10475 | }; |
b451e98a JK |
10476 | |
10477 | /* A static assertion. */ | |
10478 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |