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" |
61364358 JK |
32 | #include <assert.h> |
33 | ||
34 | #undef MAX | |
35 | #undef MIN | |
36 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) | |
37 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
19e6b90e | 38 | |
18464d4d JK |
39 | static const char *regname (unsigned int regno, int row); |
40 | ||
19e6b90e L |
41 | static int have_frame_base; |
42 | static int need_base_address; | |
43 | ||
19e6b90e | 44 | static unsigned int num_debug_info_entries = 0; |
82b1b41b | 45 | static unsigned int alloc_num_debug_info_entries = 0; |
19e6b90e | 46 | static debug_info *debug_information = NULL; |
cc86f28f NC |
47 | /* Special value for num_debug_info_entries to indicate |
48 | that the .debug_info section could not be loaded/parsed. */ | |
49 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
19e6b90e | 50 | |
24841daa NC |
51 | /* A .debug_info section can contain multiple links to separate |
52 | DWO object files. We use these structures to record these links. */ | |
53 | typedef enum dwo_type | |
54 | { | |
55 | DWO_NAME, | |
56 | DWO_DIR, | |
57 | DWO_ID | |
58 | } dwo_type; | |
59 | ||
60 | typedef struct dwo_info | |
61 | { | |
62 | dwo_type type; | |
63 | const char * value; | |
64 | struct dwo_info * next; | |
65 | } dwo_info; | |
66 | ||
67 | static dwo_info * first_dwo_info = NULL; | |
68 | static bfd_boolean need_dwo_info; | |
69 | ||
70 | separate_info * first_separate_info = NULL; | |
d85bf2ba | 71 | |
77ef8654 | 72 | unsigned int eh_addr_size; |
19e6b90e L |
73 | |
74 | int do_debug_info; | |
75 | int do_debug_abbrevs; | |
76 | int do_debug_lines; | |
77 | int do_debug_pubnames; | |
f9f0e732 | 78 | int do_debug_pubtypes; |
19e6b90e L |
79 | int do_debug_aranges; |
80 | int do_debug_ranges; | |
81 | int do_debug_frames; | |
82 | int do_debug_frames_interp; | |
83 | int do_debug_macinfo; | |
84 | int do_debug_str; | |
85 | int do_debug_loc; | |
5bbdf3d5 | 86 | int do_gdb_index; |
6f875884 TG |
87 | int do_trace_info; |
88 | int do_trace_abbrevs; | |
89 | int do_trace_aranges; | |
657d0d47 CC |
90 | int do_debug_addr; |
91 | int do_debug_cu_index; | |
a262ae96 | 92 | int do_wide; |
dda8d76d NC |
93 | int do_debug_links; |
94 | int do_follow_links; | |
19e6b90e | 95 | |
fd2f0033 TT |
96 | int dwarf_cutoff_level = -1; |
97 | unsigned long dwarf_start_die; | |
98 | ||
4723351a CC |
99 | int dwarf_check = 0; |
100 | ||
9f272209 AO |
101 | /* Convenient constant, to avoid having to cast -1 to dwarf_vma when |
102 | testing whether e.g. a locview list is present. */ | |
103 | static const dwarf_vma vm1 = -1; | |
104 | ||
341f9135 CC |
105 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
106 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
107 | as a zero-terminated list of section indexes comprising one set of debug | |
108 | sections from a .dwo file. */ | |
109 | ||
341f9135 CC |
110 | static unsigned int *shndx_pool = NULL; |
111 | static unsigned int shndx_pool_size = 0; | |
112 | static unsigned int shndx_pool_used = 0; | |
113 | ||
114 | /* For version 2 package files, each set contains an array of section offsets | |
115 | and an array of section sizes, giving the offset and size of the | |
116 | contribution from a CU or TU within one of the debug sections. | |
117 | When displaying debug info from a package file, we need to use these | |
118 | tables to locate the corresponding contributions to each section. */ | |
119 | ||
120 | struct cu_tu_set | |
121 | { | |
122 | uint64_t signature; | |
123 | dwarf_vma section_offsets[DW_SECT_MAX]; | |
124 | size_t section_sizes[DW_SECT_MAX]; | |
125 | }; | |
126 | ||
127 | static int cu_count = 0; | |
128 | static int tu_count = 0; | |
129 | static struct cu_tu_set *cu_sets = NULL; | |
130 | static struct cu_tu_set *tu_sets = NULL; | |
131 | ||
43a444f9 | 132 | static bfd_boolean load_cu_tu_indexes (void *); |
341f9135 | 133 | |
4cb93e3b TG |
134 | /* Values for do_debug_lines. */ |
135 | #define FLAG_DEBUG_LINES_RAW 1 | |
136 | #define FLAG_DEBUG_LINES_DECODED 2 | |
137 | ||
77ef8654 | 138 | static unsigned int |
f1c4cc75 RH |
139 | size_of_encoded_value (int encoding) |
140 | { | |
141 | switch (encoding & 0x7) | |
142 | { | |
143 | default: /* ??? */ | |
144 | case 0: return eh_addr_size; | |
145 | case 2: return 2; | |
146 | case 3: return 4; | |
147 | case 4: return 8; | |
148 | } | |
149 | } | |
150 | ||
151 | static dwarf_vma | |
041830e0 | 152 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 153 | int encoding, |
041830e0 NC |
154 | struct dwarf_section *section, |
155 | unsigned char * end) | |
f1c4cc75 | 156 | { |
041830e0 | 157 | unsigned char * data = * pdata; |
6937bb54 | 158 | unsigned int size = size_of_encoded_value (encoding); |
bad62cf5 | 159 | dwarf_vma val; |
f1c4cc75 | 160 | |
041830e0 NC |
161 | if (data + size >= end) |
162 | { | |
163 | warn (_("Encoded value extends past end of section\n")); | |
164 | * pdata = end; | |
165 | return 0; | |
166 | } | |
167 | ||
6937bb54 NC |
168 | /* PR 17512: file: 002-829853-0.004. */ |
169 | if (size > 8) | |
170 | { | |
171 | warn (_("Encoded size of %d is too large to read\n"), size); | |
172 | * pdata = end; | |
173 | return 0; | |
174 | } | |
175 | ||
0a9d414a NC |
176 | /* PR 17512: file: 1085-5603-0.004. */ |
177 | if (size == 0) | |
178 | { | |
179 | warn (_("Encoded size of 0 is too small to read\n")); | |
180 | * pdata = end; | |
181 | return 0; | |
182 | } | |
183 | ||
f1c4cc75 | 184 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 185 | val = byte_get_signed (data, size); |
f1c4cc75 | 186 | else |
bad62cf5 AM |
187 | val = byte_get (data, size); |
188 | ||
189 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
190 | val += section->address + (data - section->start); | |
041830e0 NC |
191 | |
192 | * pdata = data + size; | |
bad62cf5 | 193 | return val; |
f1c4cc75 RH |
194 | } |
195 | ||
4c219c2e AM |
196 | #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
197 | # ifndef __MINGW32__ | |
198 | # define DWARF_VMA_FMT "ll" | |
199 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
200 | # else | |
201 | # define DWARF_VMA_FMT "I64" | |
202 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
203 | # endif | |
2e14fae2 | 204 | #else |
4c219c2e AM |
205 | # define DWARF_VMA_FMT "l" |
206 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
207 | #endif |
208 | ||
bf5117e3 NC |
209 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
210 | buffer containing the converted VALUE. The value is converted according | |
211 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
212 | it specifies the maximum number of bytes to be displayed in the converted | |
213 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 214 | |
47704ddf | 215 | static const char * |
bf5117e3 | 216 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
217 | { |
218 | /* As dwarf_vmatoa is used more then once in a printf call | |
219 | for output, we are cycling through an fixed array of pointers | |
220 | for return address. */ | |
221 | static int buf_pos = 0; | |
467c65bc NC |
222 | static struct dwarf_vmatoa_buf |
223 | { | |
47704ddf KT |
224 | char place[64]; |
225 | } buf[16]; | |
47704ddf KT |
226 | char *ret; |
227 | ||
47704ddf | 228 | ret = buf[buf_pos++].place; |
467c65bc | 229 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 230 | |
bf5117e3 NC |
231 | if (num_bytes) |
232 | { | |
222c2bf0 | 233 | /* Printf does not have a way of specifying a maximum field width for an |
bf5117e3 NC |
234 | integer value, so we print the full value into a buffer and then select |
235 | the precision we need. */ | |
236 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
237 | if (num_bytes > 8) | |
238 | num_bytes = 8; | |
239 | return ret + (16 - 2 * num_bytes); | |
240 | } | |
241 | else | |
242 | { | |
243 | char fmt[32]; | |
244 | ||
0bae9e9e NC |
245 | if (fmtch) |
246 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
247 | else | |
248 | sprintf (fmt, "%%%s", DWARF_VMA_FMT); | |
bf5117e3 NC |
249 | snprintf (ret, sizeof (buf[0].place), fmt, value); |
250 | return ret; | |
251 | } | |
252 | } | |
47704ddf | 253 | |
bf5117e3 NC |
254 | static inline const char * |
255 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
256 | { | |
257 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
258 | } | |
259 | ||
260 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
261 | hexadecimal format, followed by a space. The length of the VALUE (and | |
262 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
263 | ||
264 | static void | |
265 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
266 | { | |
267 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
268 | } |
269 | ||
9f272209 AO |
270 | /* Print a view number in hexadecimal value, with the same width |
271 | print_dwarf_vma would have printed it with the same num_bytes. | |
272 | Print blanks for zero view, unless force is nonzero. */ | |
273 | ||
274 | static void | |
275 | print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force) | |
276 | { | |
277 | int len; | |
278 | if (!num_bytes) | |
279 | len = 4; | |
280 | else | |
281 | len = num_bytes * 2; | |
282 | ||
283 | assert (value == (unsigned long) value); | |
284 | if (value || force) | |
285 | printf ("v%0*lx ", len - 1, (unsigned long) value); | |
286 | else | |
287 | printf ("%*s", len + 1, ""); | |
288 | } | |
289 | ||
74bc6052 CC |
290 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
291 | For reentrancy, this uses a buffer provided by the caller. */ | |
292 | ||
293 | static const char * | |
294 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, | |
295 | unsigned int buf_len) | |
296 | { | |
297 | int len = 0; | |
298 | ||
299 | if (hvalue == 0) | |
300 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); | |
301 | else | |
302 | { | |
303 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); | |
304 | snprintf (buf + len, buf_len - len, | |
305 | "%08" DWARF_VMA_FMT "x", lvalue); | |
306 | } | |
307 | ||
308 | return buf; | |
309 | } | |
310 | ||
f6f0e17b NC |
311 | /* Read in a LEB128 encoded value starting at address DATA. |
312 | If SIGN is true, return a signed LEB128 value. | |
313 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
314 | No bytes will be read at address END or beyond. */ | |
315 | ||
467c65bc | 316 | dwarf_vma |
f6f0e17b NC |
317 | read_leb128 (unsigned char *data, |
318 | unsigned int *length_return, | |
319 | bfd_boolean sign, | |
320 | const unsigned char * const end) | |
19e6b90e | 321 | { |
467c65bc | 322 | dwarf_vma result = 0; |
19e6b90e L |
323 | unsigned int num_read = 0; |
324 | unsigned int shift = 0; | |
f6f0e17b | 325 | unsigned char byte = 0; |
19e6b90e | 326 | |
f6f0e17b | 327 | while (data < end) |
19e6b90e L |
328 | { |
329 | byte = *data++; | |
330 | num_read++; | |
331 | ||
467c65bc | 332 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; |
19e6b90e L |
333 | |
334 | shift += 7; | |
f6f0e17b NC |
335 | if ((byte & 0x80) == 0) |
336 | break; | |
77ef8654 NC |
337 | |
338 | /* PR 17512: file: 0ca183b8. | |
339 | FIXME: Should we signal this error somehow ? */ | |
f641dd96 | 340 | if (shift >= sizeof (result) * 8) |
77ef8654 | 341 | break; |
19e6b90e | 342 | } |
19e6b90e L |
343 | |
344 | if (length_return != NULL) | |
345 | *length_return = num_read; | |
346 | ||
347 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
c4e0beac | 348 | result |= -((dwarf_vma) 1 << shift); |
19e6b90e L |
349 | |
350 | return result; | |
351 | } | |
352 | ||
467c65bc | 353 | /* Create a signed version to avoid painful typecasts. */ |
f6f0e17b NC |
354 | static inline dwarf_signed_vma |
355 | read_sleb128 (unsigned char * data, | |
356 | unsigned int * length_return, | |
357 | const unsigned char * const end) | |
358 | { | |
359 | return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end); | |
360 | } | |
361 | ||
362 | static inline dwarf_vma | |
363 | read_uleb128 (unsigned char * data, | |
364 | unsigned int * length_return, | |
365 | const unsigned char * const end) | |
467c65bc | 366 | { |
f6f0e17b | 367 | return read_leb128 (data, length_return, FALSE, end); |
467c65bc NC |
368 | } |
369 | ||
7f2c8a1d NC |
370 | #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return |
371 | #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return | |
372 | ||
373 | #define READ_ULEB(var) \ | |
374 | do \ | |
375 | { \ | |
376 | dwarf_vma _val; \ | |
377 | \ | |
378 | (var) = _val = read_uleb128 (start, &length_return, end); \ | |
379 | if ((var) != _val) \ | |
66cfc0fd AM |
380 | error (_("Internal error: %s:%d: LEB value (%s) " \ |
381 | "too large for containing variable\n"), \ | |
382 | __FILE__, __LINE__, dwarf_vmatoa ("u", _val)); \ | |
7f2c8a1d NC |
383 | start += length_return; \ |
384 | } \ | |
385 | while (0) | |
386 | ||
387 | #define READ_SLEB(var) \ | |
388 | do \ | |
389 | { \ | |
390 | dwarf_signed_vma _val; \ | |
391 | \ | |
392 | (var) = _val = read_sleb128 (start, &length_return, end); \ | |
393 | if ((var) != _val) \ | |
66cfc0fd AM |
394 | error (_("Internal error: %s:%d: LEB value (%s) " \ |
395 | "too large for containing variable\n"), \ | |
396 | __FILE__, __LINE__, dwarf_vmatoa ("d", _val)); \ | |
7f2c8a1d NC |
397 | start += length_return; \ |
398 | } \ | |
399 | while (0) | |
400 | ||
d11ae95e NC |
401 | /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value. |
402 | Checks to make sure that the read will not reach or pass END | |
403 | and that VAL is big enough to hold AMOUNT bytes. */ | |
0c588247 NC |
404 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
405 | do \ | |
406 | { \ | |
407 | unsigned int amount = (AMOUNT); \ | |
34b9f729 NC |
408 | if (sizeof (VAL) < amount) \ |
409 | { \ | |
d3a49aa8 AM |
410 | error (ngettext ("internal error: attempt to read %d byte " \ |
411 | "of data in to %d sized variable", \ | |
412 | "internal error: attempt to read %d bytes " \ | |
413 | "of data in to %d sized variable", \ | |
414 | amount), \ | |
34b9f729 NC |
415 | amount, (int) sizeof (VAL)); \ |
416 | amount = sizeof (VAL); \ | |
417 | } \ | |
0c588247 NC |
418 | if (((PTR) + amount) >= (END)) \ |
419 | { \ | |
420 | if ((PTR) < (END)) \ | |
421 | amount = (END) - (PTR); \ | |
422 | else \ | |
423 | amount = 0; \ | |
424 | } \ | |
6937bb54 | 425 | if (amount == 0 || amount > 8) \ |
0c588247 | 426 | VAL = 0; \ |
6937bb54 NC |
427 | else \ |
428 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
429 | } \ |
430 | while (0) | |
431 | ||
d11ae95e | 432 | /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
433 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
434 | do \ | |
435 | { \ | |
436 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
437 | PTR += AMOUNT; \ | |
438 | } \ | |
439 | while (0) | |
440 | ||
d11ae95e | 441 | /* Like SAFE_BYTE_GET, but reads a signed value. */ |
0c588247 NC |
442 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
443 | do \ | |
444 | { \ | |
445 | unsigned int amount = (AMOUNT); \ | |
446 | if (((PTR) + amount) >= (END)) \ | |
447 | { \ | |
448 | if ((PTR) < (END)) \ | |
449 | amount = (END) - (PTR); \ | |
450 | else \ | |
451 | amount = 0; \ | |
452 | } \ | |
453 | if (amount) \ | |
454 | VAL = byte_get_signed ((PTR), amount); \ | |
455 | else \ | |
456 | VAL = 0; \ | |
457 | } \ | |
458 | while (0) | |
459 | ||
d11ae95e | 460 | /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
461 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
462 | do \ | |
463 | { \ | |
464 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
465 | PTR += AMOUNT; \ | |
466 | } \ | |
467 | while (0) | |
468 | ||
469 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
470 | do \ | |
471 | { \ | |
87bc83b3 | 472 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
473 | { \ |
474 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
475 | } \ | |
476 | else \ | |
477 | { \ | |
0c588247 NC |
478 | * (LOW) = * (HIGH) = 0; \ |
479 | } \ | |
480 | } \ | |
481 | while (0) | |
482 | ||
19e6b90e L |
483 | typedef struct State_Machine_Registers |
484 | { | |
467c65bc | 485 | dwarf_vma address; |
ba8826a8 | 486 | unsigned int view; |
19e6b90e L |
487 | unsigned int file; |
488 | unsigned int line; | |
489 | unsigned int column; | |
490 | int is_stmt; | |
491 | int basic_block; | |
a233b20c JJ |
492 | unsigned char op_index; |
493 | unsigned char end_sequence; | |
ba8826a8 AO |
494 | /* This variable hold the number of the last entry seen |
495 | in the File Table. */ | |
19e6b90e L |
496 | unsigned int last_file_entry; |
497 | } SMR; | |
498 | ||
499 | static SMR state_machine_regs; | |
500 | ||
501 | static void | |
502 | reset_state_machine (int is_stmt) | |
503 | { | |
504 | state_machine_regs.address = 0; | |
ba8826a8 | 505 | state_machine_regs.view = 0; |
a233b20c | 506 | state_machine_regs.op_index = 0; |
19e6b90e L |
507 | state_machine_regs.file = 1; |
508 | state_machine_regs.line = 1; | |
509 | state_machine_regs.column = 0; | |
510 | state_machine_regs.is_stmt = is_stmt; | |
511 | state_machine_regs.basic_block = 0; | |
512 | state_machine_regs.end_sequence = 0; | |
513 | state_machine_regs.last_file_entry = 0; | |
514 | } | |
515 | ||
516 | /* Handled an extend line op. | |
517 | Returns the number of bytes read. */ | |
518 | ||
519 | static int | |
f6f0e17b NC |
520 | process_extended_line_op (unsigned char * data, |
521 | int is_stmt, | |
522 | unsigned char * end) | |
19e6b90e L |
523 | { |
524 | unsigned char op_code; | |
525 | unsigned int bytes_read; | |
526 | unsigned int len; | |
527 | unsigned char *name; | |
143a3db0 | 528 | unsigned char *orig_data = data; |
f6f0e17b | 529 | dwarf_vma adr; |
19e6b90e | 530 | |
f6f0e17b | 531 | len = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
532 | data += bytes_read; |
533 | ||
e44c58ce | 534 | if (len == 0 || data == end || len > (uintptr_t) (end - data)) |
19e6b90e | 535 | { |
f41e4712 | 536 | warn (_("Badly formed extended line op encountered!\n")); |
19e6b90e L |
537 | return bytes_read; |
538 | } | |
539 | ||
540 | len += bytes_read; | |
541 | op_code = *data++; | |
542 | ||
543 | printf (_(" Extended opcode %d: "), op_code); | |
544 | ||
545 | switch (op_code) | |
546 | { | |
547 | case DW_LNE_end_sequence: | |
548 | printf (_("End of Sequence\n\n")); | |
549 | reset_state_machine (is_stmt); | |
550 | break; | |
551 | ||
552 | case DW_LNE_set_address: | |
6937bb54 NC |
553 | /* PR 17512: file: 002-100480-0.004. */ |
554 | if (len - bytes_read - 1 > 8) | |
77ef8654 NC |
555 | { |
556 | warn (_("Length (%d) of DW_LNE_set_address op is too long\n"), | |
557 | len - bytes_read - 1); | |
558 | adr = 0; | |
559 | } | |
560 | else | |
561 | SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end); | |
47704ddf | 562 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 563 | state_machine_regs.address = adr; |
ba8826a8 | 564 | state_machine_regs.view = 0; |
a233b20c | 565 | state_machine_regs.op_index = 0; |
19e6b90e L |
566 | break; |
567 | ||
568 | case DW_LNE_define_file: | |
143a3db0 | 569 | printf (_("define new File Table entry\n")); |
19e6b90e | 570 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 571 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 572 | |
d949ff56 NC |
573 | { |
574 | size_t l; | |
575 | ||
576 | name = data; | |
577 | l = strnlen ((char *) data, end - data); | |
578 | data += len + 1; | |
579 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
580 | data += bytes_read; | |
581 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
582 | data += bytes_read; | |
583 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
584 | data += bytes_read; | |
585 | printf ("%.*s\n\n", (int) l, name); | |
586 | } | |
f6f0e17b NC |
587 | |
588 | if (((unsigned int) (data - orig_data) != len) || data == end) | |
b4eb7656 | 589 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
590 | break; |
591 | ||
ed4a4bdf | 592 | case DW_LNE_set_discriminator: |
47704ddf | 593 | printf (_("set Discriminator to %s\n"), |
f6f0e17b | 594 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
ed4a4bdf CC |
595 | break; |
596 | ||
e2a0d921 NC |
597 | /* HP extensions. */ |
598 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 599 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
600 | break; |
601 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 602 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
603 | break; |
604 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 605 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
606 | break; |
607 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 608 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
609 | break; |
610 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 611 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
612 | break; |
613 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 614 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
615 | break; |
616 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 617 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
618 | break; |
619 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 620 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
621 | break; |
622 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 623 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
624 | break; |
625 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 626 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 627 | break; |
43294ab7 TG |
628 | case DW_LNE_HP_source_file_correlation: |
629 | { | |
b4eb7656 AM |
630 | unsigned char *edata = data + len - bytes_read - 1; |
631 | ||
632 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
633 | ||
634 | while (data < edata) | |
635 | { | |
636 | unsigned int opc; | |
637 | ||
638 | opc = read_uleb128 (data, & bytes_read, edata); | |
639 | data += bytes_read; | |
640 | ||
641 | switch (opc) | |
642 | { | |
643 | case DW_LNE_HP_SFC_formfeed: | |
644 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
645 | break; | |
646 | case DW_LNE_HP_SFC_set_listing_line: | |
647 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", | |
648 | dwarf_vmatoa ("u", | |
649 | read_uleb128 (data, & bytes_read, edata))); | |
650 | data += bytes_read; | |
651 | break; | |
652 | case DW_LNE_HP_SFC_associate: | |
653 | printf (" DW_LNE_HP_SFC_associate "); | |
654 | printf ("(%s", | |
655 | dwarf_vmatoa ("u", | |
656 | read_uleb128 (data, & bytes_read, edata))); | |
657 | data += bytes_read; | |
658 | printf (",%s", | |
659 | dwarf_vmatoa ("u", | |
660 | read_uleb128 (data, & bytes_read, edata))); | |
661 | data += bytes_read; | |
662 | printf (",%s)\n", | |
663 | dwarf_vmatoa ("u", | |
664 | read_uleb128 (data, & bytes_read, edata))); | |
665 | data += bytes_read; | |
666 | break; | |
667 | default: | |
668 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
669 | data = edata; | |
670 | break; | |
671 | } | |
672 | } | |
43294ab7 TG |
673 | } |
674 | break; | |
cecf136e | 675 | |
19e6b90e | 676 | default: |
7e665af3 | 677 | { |
b4eb7656 AM |
678 | unsigned int rlen = len - bytes_read - 1; |
679 | ||
680 | if (op_code >= DW_LNE_lo_user | |
681 | /* The test against DW_LNW_hi_user is redundant due to | |
682 | the limited range of the unsigned char data type used | |
683 | for op_code. */ | |
684 | /*&& op_code <= DW_LNE_hi_user*/) | |
685 | printf (_("user defined: ")); | |
686 | else | |
687 | printf (_("UNKNOWN: ")); | |
688 | printf (_("length %d ["), rlen); | |
689 | for (; rlen; rlen--) | |
690 | printf (" %02x", *data++); | |
691 | printf ("]\n"); | |
7e665af3 | 692 | } |
19e6b90e L |
693 | break; |
694 | } | |
695 | ||
696 | return len; | |
697 | } | |
698 | ||
0c588247 | 699 | static const unsigned char * |
467c65bc | 700 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
701 | { |
702 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 703 | const unsigned char * ret; |
19e6b90e L |
704 | |
705 | if (section->start == NULL) | |
0c588247 | 706 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 707 | |
d949ff56 | 708 | if (offset >= section->size) |
19e6b90e | 709 | { |
467c65bc NC |
710 | warn (_("DW_FORM_strp offset too big: %s\n"), |
711 | dwarf_vmatoa ("x", offset)); | |
0c588247 | 712 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
713 | } |
714 | ||
d949ff56 NC |
715 | ret = section->start + offset; |
716 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
717 | NUL byte. Since our caller is expecting to receive a well formed C | |
718 | string we test for the lack of a terminating byte here. */ | |
719 | if (strnlen ((const char *) ret, section->size - offset) | |
720 | == section->size - offset) | |
721 | ret = (const unsigned char *) | |
722 | _("<no NUL byte at end of .debug_str section>"); | |
723 | ||
724 | return ret; | |
19e6b90e L |
725 | } |
726 | ||
77145576 JK |
727 | static const unsigned char * |
728 | fetch_indirect_line_string (dwarf_vma offset) | |
729 | { | |
730 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 731 | const unsigned char * ret; |
77145576 JK |
732 | |
733 | if (section->start == NULL) | |
734 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
735 | ||
d949ff56 | 736 | if (offset >= section->size) |
77145576 JK |
737 | { |
738 | warn (_("DW_FORM_line_strp offset too big: %s\n"), | |
739 | dwarf_vmatoa ("x", offset)); | |
740 | return (const unsigned char *) _("<offset is too big>"); | |
741 | } | |
742 | ||
d949ff56 NC |
743 | ret = section->start + offset; |
744 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
745 | with a NUL byte. Since our caller is expecting to receive a well formed | |
746 | C string we test for the lack of a terminating byte here. */ | |
747 | if (strnlen ((const char *) ret, section->size - offset) | |
748 | == section->size - offset) | |
749 | ret = (const unsigned char *) | |
750 | _("<no NUL byte at end of .debug_line_str section>"); | |
751 | ||
752 | return ret; | |
77145576 JK |
753 | } |
754 | ||
4723351a | 755 | static const char * |
341f9135 | 756 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
d85bf2ba | 757 | dwarf_vma offset_size, bfd_boolean dwo) |
4723351a CC |
758 | { |
759 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
760 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
761 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
762 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
763 | dwarf_vma index_offset = idx * offset_size; | |
764 | dwarf_vma str_offset; | |
d949ff56 | 765 | const char * ret; |
4723351a CC |
766 | |
767 | if (index_section->start == NULL) | |
768 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
769 | : _("<no .debug_str_offsets section>")); | |
770 | ||
341f9135 CC |
771 | if (this_set != NULL) |
772 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
d949ff56 | 773 | if (index_offset >= index_section->size) |
4723351a CC |
774 | { |
775 | warn (_("DW_FORM_GNU_str_index offset too big: %s\n"), | |
776 | dwarf_vmatoa ("x", index_offset)); | |
777 | return _("<index offset is too big>"); | |
778 | } | |
779 | ||
780 | if (str_section->start == NULL) | |
781 | return (dwo ? _("<no .debug_str.dwo section>") | |
782 | : _("<no .debug_str section>")); | |
783 | ||
784 | str_offset = byte_get (index_section->start + index_offset, offset_size); | |
785 | str_offset -= str_section->address; | |
d949ff56 | 786 | if (str_offset >= str_section->size) |
4723351a CC |
787 | { |
788 | warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), | |
789 | dwarf_vmatoa ("x", str_offset)); | |
790 | return _("<indirect index offset is too big>"); | |
791 | } | |
792 | ||
d949ff56 NC |
793 | ret = (const char *) str_section->start + str_offset; |
794 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
795 | Since our caller is expecting to receive a well formed C string we test | |
796 | for the lack of a terminating byte here. */ | |
797 | if (strnlen (ret, str_section->size - str_offset) | |
798 | == str_section->size - str_offset) | |
799 | ret = (const char *) _("<no NUL byte at end of section>"); | |
800 | ||
801 | return ret; | |
4723351a CC |
802 | } |
803 | ||
804 | static const char * | |
805 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
806 | { | |
807 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
808 | ||
809 | if (section->start == NULL) | |
810 | return (_("<no .debug_addr section>")); | |
811 | ||
812 | if (offset + bytes > section->size) | |
813 | { | |
814 | warn (_("Offset into section %s too big: %s\n"), | |
b4eb7656 | 815 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
816 | return "<offset too big>"; |
817 | } | |
818 | ||
819 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
820 | } | |
821 | ||
822 | ||
19e6b90e L |
823 | /* FIXME: There are better and more efficient ways to handle |
824 | these structures. For now though, I just want something that | |
825 | is simple to implement. */ | |
826 | typedef struct abbrev_attr | |
827 | { | |
828 | unsigned long attribute; | |
829 | unsigned long form; | |
77145576 | 830 | bfd_signed_vma implicit_const; |
19e6b90e L |
831 | struct abbrev_attr *next; |
832 | } | |
833 | abbrev_attr; | |
834 | ||
835 | typedef struct abbrev_entry | |
836 | { | |
837 | unsigned long entry; | |
838 | unsigned long tag; | |
839 | int children; | |
840 | struct abbrev_attr *first_attr; | |
841 | struct abbrev_attr *last_attr; | |
842 | struct abbrev_entry *next; | |
843 | } | |
844 | abbrev_entry; | |
845 | ||
846 | static abbrev_entry *first_abbrev = NULL; | |
847 | static abbrev_entry *last_abbrev = NULL; | |
848 | ||
849 | static void | |
850 | free_abbrevs (void) | |
851 | { | |
91d6fa6a | 852 | abbrev_entry *abbrv; |
19e6b90e | 853 | |
91d6fa6a | 854 | for (abbrv = first_abbrev; abbrv;) |
19e6b90e | 855 | { |
91d6fa6a | 856 | abbrev_entry *next_abbrev = abbrv->next; |
19e6b90e L |
857 | abbrev_attr *attr; |
858 | ||
91d6fa6a | 859 | for (attr = abbrv->first_attr; attr;) |
19e6b90e | 860 | { |
91d6fa6a | 861 | abbrev_attr *next_attr = attr->next; |
19e6b90e L |
862 | |
863 | free (attr); | |
91d6fa6a | 864 | attr = next_attr; |
19e6b90e L |
865 | } |
866 | ||
91d6fa6a NC |
867 | free (abbrv); |
868 | abbrv = next_abbrev; | |
19e6b90e L |
869 | } |
870 | ||
871 | last_abbrev = first_abbrev = NULL; | |
872 | } | |
873 | ||
874 | static void | |
875 | add_abbrev (unsigned long number, unsigned long tag, int children) | |
876 | { | |
877 | abbrev_entry *entry; | |
878 | ||
3f5e193b | 879 | entry = (abbrev_entry *) malloc (sizeof (*entry)); |
19e6b90e L |
880 | if (entry == NULL) |
881 | /* ugg */ | |
882 | return; | |
883 | ||
884 | entry->entry = number; | |
885 | entry->tag = tag; | |
886 | entry->children = children; | |
887 | entry->first_attr = NULL; | |
888 | entry->last_attr = NULL; | |
889 | entry->next = NULL; | |
890 | ||
891 | if (first_abbrev == NULL) | |
892 | first_abbrev = entry; | |
893 | else | |
894 | last_abbrev->next = entry; | |
895 | ||
896 | last_abbrev = entry; | |
897 | } | |
898 | ||
899 | static void | |
77145576 JK |
900 | add_abbrev_attr (unsigned long attribute, unsigned long form, |
901 | bfd_signed_vma implicit_const) | |
19e6b90e L |
902 | { |
903 | abbrev_attr *attr; | |
904 | ||
3f5e193b | 905 | attr = (abbrev_attr *) malloc (sizeof (*attr)); |
19e6b90e L |
906 | if (attr == NULL) |
907 | /* ugg */ | |
908 | return; | |
909 | ||
910 | attr->attribute = attribute; | |
911 | attr->form = form; | |
77145576 | 912 | attr->implicit_const = implicit_const; |
19e6b90e L |
913 | attr->next = NULL; |
914 | ||
915 | if (last_abbrev->first_attr == NULL) | |
916 | last_abbrev->first_attr = attr; | |
917 | else | |
918 | last_abbrev->last_attr->next = attr; | |
919 | ||
920 | last_abbrev->last_attr = attr; | |
921 | } | |
922 | ||
923 | /* Processes the (partial) contents of a .debug_abbrev section. | |
924 | Returns NULL if the end of the section was encountered. | |
925 | Returns the address after the last byte read if the end of | |
926 | an abbreviation set was found. */ | |
927 | ||
928 | static unsigned char * | |
929 | process_abbrev_section (unsigned char *start, unsigned char *end) | |
930 | { | |
931 | if (first_abbrev != NULL) | |
932 | return NULL; | |
933 | ||
934 | while (start < end) | |
935 | { | |
936 | unsigned int bytes_read; | |
937 | unsigned long entry; | |
938 | unsigned long tag; | |
939 | unsigned long attribute; | |
940 | int children; | |
941 | ||
f6f0e17b | 942 | entry = read_uleb128 (start, & bytes_read, end); |
19e6b90e L |
943 | start += bytes_read; |
944 | ||
945 | /* A single zero is supposed to end the section according | |
946 | to the standard. If there's more, then signal that to | |
947 | the caller. */ | |
f6f0e17b NC |
948 | if (start == end) |
949 | return NULL; | |
19e6b90e | 950 | if (entry == 0) |
f6f0e17b | 951 | return start; |
19e6b90e | 952 | |
f6f0e17b | 953 | tag = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 954 | start += bytes_read; |
f6f0e17b NC |
955 | if (start == end) |
956 | return NULL; | |
19e6b90e L |
957 | |
958 | children = *start++; | |
959 | ||
960 | add_abbrev (entry, tag, children); | |
961 | ||
962 | do | |
963 | { | |
964 | unsigned long form; | |
77145576 JK |
965 | /* Initialize it due to a false compiler warning. */ |
966 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 967 | |
f6f0e17b | 968 | attribute = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 969 | start += bytes_read; |
f6f0e17b NC |
970 | if (start == end) |
971 | break; | |
19e6b90e | 972 | |
f6f0e17b | 973 | form = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 974 | start += bytes_read; |
f6f0e17b NC |
975 | if (start == end) |
976 | break; | |
19e6b90e | 977 | |
77145576 JK |
978 | if (form == DW_FORM_implicit_const) |
979 | { | |
980 | implicit_const = read_sleb128 (start, & bytes_read, end); | |
981 | start += bytes_read; | |
982 | if (start == end) | |
983 | break; | |
984 | } | |
985 | ||
986 | add_abbrev_attr (attribute, form, implicit_const); | |
19e6b90e L |
987 | } |
988 | while (attribute != 0); | |
989 | } | |
990 | ||
399c99f7 L |
991 | /* Report the missing single zero which ends the section. */ |
992 | error (_(".debug_abbrev section not zero terminated\n")); | |
993 | ||
19e6b90e L |
994 | return NULL; |
995 | } | |
996 | ||
a19c41a7 | 997 | static const char * |
19e6b90e L |
998 | get_TAG_name (unsigned long tag) |
999 | { | |
04914e37 | 1000 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
a19c41a7 TT |
1001 | |
1002 | if (name == NULL) | |
19e6b90e | 1003 | { |
a19c41a7 | 1004 | static char buffer[100]; |
19e6b90e | 1005 | |
04914e37 NC |
1006 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
1007 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); | |
1008 | else | |
1009 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); | |
a19c41a7 | 1010 | return buffer; |
19e6b90e | 1011 | } |
a19c41a7 TT |
1012 | |
1013 | return name; | |
19e6b90e L |
1014 | } |
1015 | ||
a19c41a7 | 1016 | static const char * |
19e6b90e L |
1017 | get_FORM_name (unsigned long form) |
1018 | { | |
399c99f7 | 1019 | const char *name; |
bf5117e3 | 1020 | |
399c99f7 L |
1021 | if (form == 0) |
1022 | return "DW_FORM value: 0"; | |
a19c41a7 | 1023 | |
399c99f7 | 1024 | name = get_DW_FORM_name (form); |
a19c41a7 | 1025 | if (name == NULL) |
19e6b90e | 1026 | { |
a19c41a7 | 1027 | static char buffer[100]; |
19e6b90e | 1028 | |
a19c41a7 TT |
1029 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
1030 | return buffer; | |
19e6b90e | 1031 | } |
a19c41a7 TT |
1032 | |
1033 | return name; | |
19e6b90e L |
1034 | } |
1035 | ||
61364358 JK |
1036 | static const char * |
1037 | get_IDX_name (unsigned long idx) | |
1038 | { | |
1039 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
1040 | ||
1041 | if (name == NULL) | |
1042 | { | |
1043 | static char buffer[100]; | |
1044 | ||
1045 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1046 | return buffer; | |
1047 | } | |
1048 | ||
1049 | return name; | |
1050 | } | |
1051 | ||
19e6b90e | 1052 | static unsigned char * |
0c588247 NC |
1053 | display_block (unsigned char *data, |
1054 | dwarf_vma length, | |
ef0b5f1c | 1055 | const unsigned char * const end, char delimiter) |
19e6b90e | 1056 | { |
0c588247 NC |
1057 | dwarf_vma maxlen; |
1058 | ||
ef0b5f1c | 1059 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1060 | if (data > end) |
1061 | return (unsigned char *) end; | |
19e6b90e | 1062 | |
0c588247 NC |
1063 | maxlen = (dwarf_vma) (end - data); |
1064 | length = length > maxlen ? maxlen : length; | |
1065 | ||
19e6b90e L |
1066 | while (length --) |
1067 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1068 | ||
1069 | return data; | |
1070 | } | |
1071 | ||
1072 | static int | |
1073 | decode_location_expression (unsigned char * data, | |
1074 | unsigned int pointer_size, | |
b7807392 JJ |
1075 | unsigned int offset_size, |
1076 | int dwarf_version, | |
467c65bc NC |
1077 | dwarf_vma length, |
1078 | dwarf_vma cu_offset, | |
f1c4cc75 | 1079 | struct dwarf_section * section) |
19e6b90e L |
1080 | { |
1081 | unsigned op; | |
1082 | unsigned int bytes_read; | |
467c65bc | 1083 | dwarf_vma uvalue; |
0c588247 | 1084 | dwarf_signed_vma svalue; |
19e6b90e L |
1085 | unsigned char *end = data + length; |
1086 | int need_frame_base = 0; | |
1087 | ||
1088 | while (data < end) | |
1089 | { | |
1090 | op = *data++; | |
1091 | ||
1092 | switch (op) | |
1093 | { | |
1094 | case DW_OP_addr: | |
0c588247 NC |
1095 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1096 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1097 | break; |
1098 | case DW_OP_deref: | |
1099 | printf ("DW_OP_deref"); | |
1100 | break; | |
1101 | case DW_OP_const1u: | |
0c588247 NC |
1102 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1103 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1104 | break; |
1105 | case DW_OP_const1s: | |
0c588247 NC |
1106 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1107 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1108 | break; |
1109 | case DW_OP_const2u: | |
87bc83b3 | 1110 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1111 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1112 | break; |
1113 | case DW_OP_const2s: | |
0c588247 NC |
1114 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1115 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1116 | break; |
1117 | case DW_OP_const4u: | |
0c588247 NC |
1118 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1119 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1120 | break; |
1121 | case DW_OP_const4s: | |
0c588247 NC |
1122 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1123 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1124 | break; |
1125 | case DW_OP_const8u: | |
0c588247 NC |
1126 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1127 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1128 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1129 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1130 | break; |
1131 | case DW_OP_const8s: | |
0c588247 NC |
1132 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1133 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1134 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1135 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1136 | break; |
1137 | case DW_OP_constu: | |
467c65bc | 1138 | printf ("DW_OP_constu: %s", |
f6f0e17b | 1139 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1140 | data += bytes_read; |
1141 | break; | |
1142 | case DW_OP_consts: | |
467c65bc | 1143 | printf ("DW_OP_consts: %s", |
f6f0e17b | 1144 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1145 | data += bytes_read; |
1146 | break; | |
1147 | case DW_OP_dup: | |
1148 | printf ("DW_OP_dup"); | |
1149 | break; | |
1150 | case DW_OP_drop: | |
1151 | printf ("DW_OP_drop"); | |
1152 | break; | |
1153 | case DW_OP_over: | |
1154 | printf ("DW_OP_over"); | |
1155 | break; | |
1156 | case DW_OP_pick: | |
0c588247 NC |
1157 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1158 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1159 | break; |
1160 | case DW_OP_swap: | |
1161 | printf ("DW_OP_swap"); | |
1162 | break; | |
1163 | case DW_OP_rot: | |
1164 | printf ("DW_OP_rot"); | |
1165 | break; | |
1166 | case DW_OP_xderef: | |
1167 | printf ("DW_OP_xderef"); | |
1168 | break; | |
1169 | case DW_OP_abs: | |
1170 | printf ("DW_OP_abs"); | |
1171 | break; | |
1172 | case DW_OP_and: | |
1173 | printf ("DW_OP_and"); | |
1174 | break; | |
1175 | case DW_OP_div: | |
1176 | printf ("DW_OP_div"); | |
1177 | break; | |
1178 | case DW_OP_minus: | |
1179 | printf ("DW_OP_minus"); | |
1180 | break; | |
1181 | case DW_OP_mod: | |
1182 | printf ("DW_OP_mod"); | |
1183 | break; | |
1184 | case DW_OP_mul: | |
1185 | printf ("DW_OP_mul"); | |
1186 | break; | |
1187 | case DW_OP_neg: | |
1188 | printf ("DW_OP_neg"); | |
1189 | break; | |
1190 | case DW_OP_not: | |
1191 | printf ("DW_OP_not"); | |
1192 | break; | |
1193 | case DW_OP_or: | |
1194 | printf ("DW_OP_or"); | |
1195 | break; | |
1196 | case DW_OP_plus: | |
1197 | printf ("DW_OP_plus"); | |
1198 | break; | |
1199 | case DW_OP_plus_uconst: | |
467c65bc | 1200 | printf ("DW_OP_plus_uconst: %s", |
f6f0e17b | 1201 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1202 | data += bytes_read; |
1203 | break; | |
1204 | case DW_OP_shl: | |
1205 | printf ("DW_OP_shl"); | |
1206 | break; | |
1207 | case DW_OP_shr: | |
1208 | printf ("DW_OP_shr"); | |
1209 | break; | |
1210 | case DW_OP_shra: | |
1211 | printf ("DW_OP_shra"); | |
1212 | break; | |
1213 | case DW_OP_xor: | |
1214 | printf ("DW_OP_xor"); | |
1215 | break; | |
1216 | case DW_OP_bra: | |
0c588247 NC |
1217 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1218 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1219 | break; |
1220 | case DW_OP_eq: | |
1221 | printf ("DW_OP_eq"); | |
1222 | break; | |
1223 | case DW_OP_ge: | |
1224 | printf ("DW_OP_ge"); | |
1225 | break; | |
1226 | case DW_OP_gt: | |
1227 | printf ("DW_OP_gt"); | |
1228 | break; | |
1229 | case DW_OP_le: | |
1230 | printf ("DW_OP_le"); | |
1231 | break; | |
1232 | case DW_OP_lt: | |
1233 | printf ("DW_OP_lt"); | |
1234 | break; | |
1235 | case DW_OP_ne: | |
1236 | printf ("DW_OP_ne"); | |
1237 | break; | |
1238 | case DW_OP_skip: | |
0c588247 NC |
1239 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1240 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1241 | break; |
1242 | ||
1243 | case DW_OP_lit0: | |
1244 | case DW_OP_lit1: | |
1245 | case DW_OP_lit2: | |
1246 | case DW_OP_lit3: | |
1247 | case DW_OP_lit4: | |
1248 | case DW_OP_lit5: | |
1249 | case DW_OP_lit6: | |
1250 | case DW_OP_lit7: | |
1251 | case DW_OP_lit8: | |
1252 | case DW_OP_lit9: | |
1253 | case DW_OP_lit10: | |
1254 | case DW_OP_lit11: | |
1255 | case DW_OP_lit12: | |
1256 | case DW_OP_lit13: | |
1257 | case DW_OP_lit14: | |
1258 | case DW_OP_lit15: | |
1259 | case DW_OP_lit16: | |
1260 | case DW_OP_lit17: | |
1261 | case DW_OP_lit18: | |
1262 | case DW_OP_lit19: | |
1263 | case DW_OP_lit20: | |
1264 | case DW_OP_lit21: | |
1265 | case DW_OP_lit22: | |
1266 | case DW_OP_lit23: | |
1267 | case DW_OP_lit24: | |
1268 | case DW_OP_lit25: | |
1269 | case DW_OP_lit26: | |
1270 | case DW_OP_lit27: | |
1271 | case DW_OP_lit28: | |
1272 | case DW_OP_lit29: | |
1273 | case DW_OP_lit30: | |
1274 | case DW_OP_lit31: | |
1275 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1276 | break; | |
1277 | ||
1278 | case DW_OP_reg0: | |
1279 | case DW_OP_reg1: | |
1280 | case DW_OP_reg2: | |
1281 | case DW_OP_reg3: | |
1282 | case DW_OP_reg4: | |
1283 | case DW_OP_reg5: | |
1284 | case DW_OP_reg6: | |
1285 | case DW_OP_reg7: | |
1286 | case DW_OP_reg8: | |
1287 | case DW_OP_reg9: | |
1288 | case DW_OP_reg10: | |
1289 | case DW_OP_reg11: | |
1290 | case DW_OP_reg12: | |
1291 | case DW_OP_reg13: | |
1292 | case DW_OP_reg14: | |
1293 | case DW_OP_reg15: | |
1294 | case DW_OP_reg16: | |
1295 | case DW_OP_reg17: | |
1296 | case DW_OP_reg18: | |
1297 | case DW_OP_reg19: | |
1298 | case DW_OP_reg20: | |
1299 | case DW_OP_reg21: | |
1300 | case DW_OP_reg22: | |
1301 | case DW_OP_reg23: | |
1302 | case DW_OP_reg24: | |
1303 | case DW_OP_reg25: | |
1304 | case DW_OP_reg26: | |
1305 | case DW_OP_reg27: | |
1306 | case DW_OP_reg28: | |
1307 | case DW_OP_reg29: | |
1308 | case DW_OP_reg30: | |
1309 | case DW_OP_reg31: | |
18464d4d JK |
1310 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1311 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1312 | break; |
1313 | ||
1314 | case DW_OP_breg0: | |
1315 | case DW_OP_breg1: | |
1316 | case DW_OP_breg2: | |
1317 | case DW_OP_breg3: | |
1318 | case DW_OP_breg4: | |
1319 | case DW_OP_breg5: | |
1320 | case DW_OP_breg6: | |
1321 | case DW_OP_breg7: | |
1322 | case DW_OP_breg8: | |
1323 | case DW_OP_breg9: | |
1324 | case DW_OP_breg10: | |
1325 | case DW_OP_breg11: | |
1326 | case DW_OP_breg12: | |
1327 | case DW_OP_breg13: | |
1328 | case DW_OP_breg14: | |
1329 | case DW_OP_breg15: | |
1330 | case DW_OP_breg16: | |
1331 | case DW_OP_breg17: | |
1332 | case DW_OP_breg18: | |
1333 | case DW_OP_breg19: | |
1334 | case DW_OP_breg20: | |
1335 | case DW_OP_breg21: | |
1336 | case DW_OP_breg22: | |
1337 | case DW_OP_breg23: | |
1338 | case DW_OP_breg24: | |
1339 | case DW_OP_breg25: | |
1340 | case DW_OP_breg26: | |
1341 | case DW_OP_breg27: | |
1342 | case DW_OP_breg28: | |
1343 | case DW_OP_breg29: | |
1344 | case DW_OP_breg30: | |
1345 | case DW_OP_breg31: | |
467c65bc | 1346 | printf ("DW_OP_breg%d (%s): %s", |
47704ddf | 1347 | op - DW_OP_breg0, |
18464d4d | 1348 | regname (op - DW_OP_breg0, 1), |
f6f0e17b | 1349 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1350 | data += bytes_read; |
1351 | break; | |
1352 | ||
1353 | case DW_OP_regx: | |
f6f0e17b | 1354 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1355 | data += bytes_read; |
467c65bc NC |
1356 | printf ("DW_OP_regx: %s (%s)", |
1357 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1358 | break; |
1359 | case DW_OP_fbreg: | |
1360 | need_frame_base = 1; | |
467c65bc | 1361 | printf ("DW_OP_fbreg: %s", |
f6f0e17b | 1362 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1363 | data += bytes_read; |
1364 | break; | |
1365 | case DW_OP_bregx: | |
f6f0e17b | 1366 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1367 | data += bytes_read; |
467c65bc NC |
1368 | printf ("DW_OP_bregx: %s (%s) %s", |
1369 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
f6f0e17b | 1370 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1371 | data += bytes_read; |
1372 | break; | |
1373 | case DW_OP_piece: | |
467c65bc | 1374 | printf ("DW_OP_piece: %s", |
f6f0e17b | 1375 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1376 | data += bytes_read; |
1377 | break; | |
1378 | case DW_OP_deref_size: | |
0c588247 NC |
1379 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1380 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1381 | break; |
1382 | case DW_OP_xderef_size: | |
0c588247 NC |
1383 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1384 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1385 | break; |
1386 | case DW_OP_nop: | |
1387 | printf ("DW_OP_nop"); | |
1388 | break; | |
1389 | ||
1390 | /* DWARF 3 extensions. */ | |
1391 | case DW_OP_push_object_address: | |
1392 | printf ("DW_OP_push_object_address"); | |
1393 | break; | |
1394 | case DW_OP_call2: | |
d85bf2ba | 1395 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1396 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1397 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1398 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1399 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1400 | break; |
1401 | case DW_OP_call4: | |
d85bf2ba | 1402 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1403 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1404 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1405 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1406 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1407 | break; |
1408 | case DW_OP_call_ref: | |
d85bf2ba | 1409 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1410 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1411 | if (dwarf_version == -1) |
1412 | { | |
1413 | printf (_("(DW_OP_call_ref in frame info)")); | |
1414 | /* No way to tell where the next op is, so just bail. */ | |
1415 | return need_frame_base; | |
1416 | } | |
1417 | if (dwarf_version == 2) | |
1418 | { | |
0c588247 | 1419 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1420 | } |
1421 | else | |
1422 | { | |
0c588247 | 1423 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1424 | } |
0c588247 | 1425 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1426 | break; |
a87b0a59 NS |
1427 | case DW_OP_form_tls_address: |
1428 | printf ("DW_OP_form_tls_address"); | |
1429 | break; | |
e2a0d921 NC |
1430 | case DW_OP_call_frame_cfa: |
1431 | printf ("DW_OP_call_frame_cfa"); | |
1432 | break; | |
1433 | case DW_OP_bit_piece: | |
1434 | printf ("DW_OP_bit_piece: "); | |
9cf03b7e | 1435 | printf (_("size: %s "), |
f6f0e17b | 1436 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 | 1437 | data += bytes_read; |
9cf03b7e | 1438 | printf (_("offset: %s "), |
f6f0e17b | 1439 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 NC |
1440 | data += bytes_read; |
1441 | break; | |
19e6b90e | 1442 | |
3244e8f5 JJ |
1443 | /* DWARF 4 extensions. */ |
1444 | case DW_OP_stack_value: | |
1445 | printf ("DW_OP_stack_value"); | |
1446 | break; | |
1447 | ||
1448 | case DW_OP_implicit_value: | |
1449 | printf ("DW_OP_implicit_value"); | |
f6f0e17b | 1450 | uvalue = read_uleb128 (data, &bytes_read, end); |
3244e8f5 | 1451 | data += bytes_read; |
ef0b5f1c | 1452 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1453 | break; |
1454 | ||
19e6b90e L |
1455 | /* GNU extensions. */ |
1456 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1457 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1458 | break; |
1459 | case DW_OP_GNU_uninit: | |
1460 | printf ("DW_OP_GNU_uninit"); | |
1461 | /* FIXME: Is there data associated with this OP ? */ | |
1462 | break; | |
f1c4cc75 RH |
1463 | case DW_OP_GNU_encoded_addr: |
1464 | { | |
6937bb54 | 1465 | int encoding = 0; |
f1c4cc75 | 1466 | dwarf_vma addr; |
467c65bc | 1467 | |
6937bb54 NC |
1468 | if (data < end) |
1469 | encoding = *data++; | |
041830e0 | 1470 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1471 | |
1472 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1473 | print_dwarf_vma (addr, pointer_size); | |
1474 | } | |
1475 | break; | |
bc0a77d2 | 1476 | case DW_OP_implicit_pointer: |
b7807392 | 1477 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1478 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1479 | this ought to be an 8-byte wide computation. */ |
1480 | if (dwarf_version == -1) | |
1481 | { | |
bc0a77d2 JK |
1482 | printf (_("(%s in frame info)"), |
1483 | (op == DW_OP_implicit_pointer | |
1484 | ? "DW_OP_implicit_pointer" | |
1485 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1486 | /* No way to tell where the next op is, so just bail. */ |
1487 | return need_frame_base; | |
1488 | } | |
1489 | if (dwarf_version == 2) | |
1490 | { | |
0c588247 | 1491 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1492 | } |
1493 | else | |
1494 | { | |
0c588247 | 1495 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1496 | } |
bc0a77d2 JK |
1497 | printf ("%s: <0x%s> %s", |
1498 | (op == DW_OP_implicit_pointer | |
1499 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 NC |
1500 | dwarf_vmatoa ("x", uvalue), |
1501 | dwarf_vmatoa ("d", read_sleb128 (data, | |
1502 | &bytes_read, end))); | |
1503 | data += bytes_read; | |
b7807392 | 1504 | break; |
77145576 | 1505 | case DW_OP_entry_value: |
0892011d | 1506 | case DW_OP_GNU_entry_value: |
f6f0e17b | 1507 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1508 | data += bytes_read; |
058037d3 NC |
1509 | /* PR 17531: file: 0cc9cd00. */ |
1510 | if (uvalue > (dwarf_vma) (end - data)) | |
1511 | uvalue = end - data; | |
77145576 JK |
1512 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1513 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1514 | if (decode_location_expression (data, pointer_size, offset_size, |
1515 | dwarf_version, uvalue, | |
1516 | cu_offset, section)) | |
1517 | need_frame_base = 1; | |
1518 | putchar (')'); | |
1519 | data += uvalue; | |
6937bb54 NC |
1520 | if (data > end) |
1521 | data = end; | |
0892011d | 1522 | break; |
bc0a77d2 | 1523 | case DW_OP_const_type: |
0892011d | 1524 | case DW_OP_GNU_const_type: |
f6f0e17b | 1525 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1526 | data += bytes_read; |
bc0a77d2 JK |
1527 | printf ("%s: <0x%s> ", |
1528 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1529 | : "DW_OP_GNU_const_type"), | |
0892011d | 1530 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1531 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1532 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1533 | break; |
bc0a77d2 | 1534 | case DW_OP_regval_type: |
0892011d | 1535 | case DW_OP_GNU_regval_type: |
f6f0e17b | 1536 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1537 | data += bytes_read; |
bc0a77d2 JK |
1538 | printf ("%s: %s (%s)", |
1539 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1540 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1541 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
f6f0e17b | 1542 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1543 | data += bytes_read; |
1544 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1545 | break; | |
bc0a77d2 | 1546 | case DW_OP_deref_type: |
0892011d | 1547 | case DW_OP_GNU_deref_type: |
0c588247 | 1548 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1549 | printf ("%s: %ld", |
1550 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1551 | : "DW_OP_GNU_deref_type"), | |
1552 | (long) uvalue); | |
f6f0e17b | 1553 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1554 | data += bytes_read; |
1555 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1556 | break; | |
bc0a77d2 | 1557 | case DW_OP_convert: |
0892011d | 1558 | case DW_OP_GNU_convert: |
f6f0e17b | 1559 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1560 | data += bytes_read; |
bc0a77d2 JK |
1561 | printf ("%s <0x%s>", |
1562 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1563 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1564 | break; |
bc0a77d2 | 1565 | case DW_OP_reinterpret: |
0892011d | 1566 | case DW_OP_GNU_reinterpret: |
f6f0e17b | 1567 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1568 | data += bytes_read; |
bc0a77d2 JK |
1569 | printf ("%s <0x%s>", |
1570 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1571 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1572 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1573 | break; | |
1574 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1575 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1576 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1577 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1578 | break; |
b4eb7656 AM |
1579 | case DW_OP_GNU_addr_index: |
1580 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1581 | data += bytes_read; | |
1582 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1583 | break; | |
1584 | case DW_OP_GNU_const_index: | |
1585 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1586 | data += bytes_read; | |
1587 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1588 | break; | |
f384a1f0 KB |
1589 | case DW_OP_GNU_variable_value: |
1590 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1591 | this ought to be an 8-byte wide computation. */ | |
1592 | if (dwarf_version == -1) | |
1593 | { | |
1594 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1595 | /* No way to tell where the next op is, so just bail. */ | |
1596 | return need_frame_base; | |
1597 | } | |
1598 | if (dwarf_version == 2) | |
1599 | { | |
1600 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1601 | } | |
1602 | else | |
1603 | { | |
1604 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1605 | } | |
1606 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1607 | break; | |
e2a0d921 NC |
1608 | |
1609 | /* HP extensions. */ | |
1610 | case DW_OP_HP_is_value: | |
1611 | printf ("DW_OP_HP_is_value"); | |
1612 | /* FIXME: Is there data associated with this OP ? */ | |
1613 | break; | |
1614 | case DW_OP_HP_fltconst4: | |
1615 | printf ("DW_OP_HP_fltconst4"); | |
1616 | /* FIXME: Is there data associated with this OP ? */ | |
1617 | break; | |
1618 | case DW_OP_HP_fltconst8: | |
1619 | printf ("DW_OP_HP_fltconst8"); | |
1620 | /* FIXME: Is there data associated with this OP ? */ | |
1621 | break; | |
1622 | case DW_OP_HP_mod_range: | |
1623 | printf ("DW_OP_HP_mod_range"); | |
1624 | /* FIXME: Is there data associated with this OP ? */ | |
1625 | break; | |
1626 | case DW_OP_HP_unmod_range: | |
1627 | printf ("DW_OP_HP_unmod_range"); | |
1628 | /* FIXME: Is there data associated with this OP ? */ | |
1629 | break; | |
1630 | case DW_OP_HP_tls: | |
1631 | printf ("DW_OP_HP_tls"); | |
1632 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1633 | break; |
1634 | ||
35d60fe4 NC |
1635 | /* PGI (STMicroelectronics) extensions. */ |
1636 | case DW_OP_PGI_omp_thread_num: | |
1637 | /* Pushes the thread number for the current thread as it would be | |
1638 | returned by the standard OpenMP library function: | |
1639 | omp_get_thread_num(). The "current thread" is the thread for | |
1640 | which the expression is being evaluated. */ | |
1641 | printf ("DW_OP_PGI_omp_thread_num"); | |
1642 | break; | |
1643 | ||
19e6b90e L |
1644 | default: |
1645 | if (op >= DW_OP_lo_user | |
1646 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1647 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1648 | else |
0502a2b4 | 1649 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1650 | /* No way to tell where the next op is, so just bail. */ |
1651 | return need_frame_base; | |
1652 | } | |
1653 | ||
1654 | /* Separate the ops. */ | |
1655 | if (data < end) | |
1656 | printf ("; "); | |
1657 | } | |
1658 | ||
1659 | return need_frame_base; | |
1660 | } | |
1661 | ||
341f9135 CC |
1662 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1663 | This is used for DWARF package files. */ | |
1664 | ||
1665 | static struct cu_tu_set * | |
1666 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1667 | { | |
1668 | struct cu_tu_set *p; | |
1669 | unsigned int nsets; | |
1670 | unsigned int dw_sect; | |
1671 | ||
1672 | if (do_types) | |
1673 | { | |
1674 | p = tu_sets; | |
1675 | nsets = tu_count; | |
1676 | dw_sect = DW_SECT_TYPES; | |
1677 | } | |
1678 | else | |
1679 | { | |
1680 | p = cu_sets; | |
1681 | nsets = cu_count; | |
1682 | dw_sect = DW_SECT_INFO; | |
1683 | } | |
1684 | while (nsets > 0) | |
1685 | { | |
1686 | if (p->section_offsets [dw_sect] == cu_offset) | |
1687 | return p; | |
1688 | p++; | |
1689 | nsets--; | |
1690 | } | |
1691 | return NULL; | |
1692 | } | |
1693 | ||
a69c4772 NC |
1694 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1695 | static void | |
1696 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1697 | { | |
1698 | dwarf_vma tmp = * low_bits; | |
1699 | ||
1700 | tmp += inc; | |
1701 | ||
1702 | /* FIXME: There is probably a better way of handling this: | |
1703 | ||
1704 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1705 | type. Plus regardless of its size LOW_BITS is meant to | |
1706 | only hold 32-bits, so if there is overflow or wrap around | |
1707 | we must propagate into HIGH_BITS. */ | |
1708 | if (tmp < * low_bits) | |
1709 | { | |
1710 | ++ * high_bits; | |
1711 | } | |
1712 | else if (sizeof (tmp) > 8 | |
1713 | && (tmp >> 31) > 1) | |
1714 | { | |
1715 | ++ * high_bits; | |
1716 | tmp &= 0xFFFFFFFF; | |
1717 | } | |
1718 | ||
1719 | * low_bits = tmp; | |
1720 | } | |
1721 | ||
dda8d76d NC |
1722 | static const char * |
1723 | fetch_alt_indirect_string (dwarf_vma offset) | |
1724 | { | |
24841daa | 1725 | separate_info * i; |
dda8d76d NC |
1726 | |
1727 | if (! do_follow_links) | |
1728 | return ""; | |
1729 | ||
24841daa NC |
1730 | if (first_separate_info == NULL) |
1731 | return _("<no links available>"); | |
dda8d76d | 1732 | |
24841daa NC |
1733 | for (i = first_separate_info; i != NULL; i = i->next) |
1734 | { | |
1735 | struct dwarf_section * section; | |
1736 | const char * ret; | |
dda8d76d | 1737 | |
24841daa NC |
1738 | if (! load_debug_section (separate_debug_str, i->handle)) |
1739 | continue; | |
dda8d76d | 1740 | |
24841daa | 1741 | section = &debug_displays [separate_debug_str].section; |
dda8d76d | 1742 | |
24841daa NC |
1743 | if (section->start == NULL) |
1744 | continue; | |
dda8d76d | 1745 | |
24841daa NC |
1746 | if (offset >= section->size) |
1747 | continue; | |
1748 | ||
1749 | ret = (const char *) (section->start + offset); | |
1750 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1751 | NUL byte. Since our caller is expecting to receive a well formed C | |
1752 | string we test for the lack of a terminating byte here. */ | |
1753 | if (strnlen ((const char *) ret, section->size - offset) | |
1754 | == section->size - offset) | |
1755 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1756 | ||
1757 | return ret; | |
1758 | } | |
1759 | ||
1760 | warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"), | |
1761 | dwarf_vmatoa ("x", offset)); | |
1762 | return _("<offset is too big>"); | |
dda8d76d NC |
1763 | } |
1764 | ||
d85bf2ba NC |
1765 | static const char * |
1766 | get_AT_name (unsigned long attribute) | |
1767 | { | |
1768 | const char *name; | |
1769 | ||
1770 | if (attribute == 0) | |
1771 | return "DW_AT value: 0"; | |
1772 | ||
1773 | /* One value is shared by the MIPS and HP extensions: */ | |
1774 | if (attribute == DW_AT_MIPS_fde) | |
1775 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1776 | ||
1777 | name = get_DW_AT_name (attribute); | |
1778 | ||
1779 | if (name == NULL) | |
1780 | { | |
1781 | static char buffer[100]; | |
1782 | ||
1783 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1784 | attribute); | |
1785 | return buffer; | |
1786 | } | |
1787 | ||
1788 | return name; | |
1789 | } | |
1790 | ||
24841daa NC |
1791 | static void |
1792 | add_dwo_info (const char * field, dwo_type type) | |
1793 | { | |
1794 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1795 | ||
1796 | dwinfo->type = type; | |
1797 | dwinfo->value = field; | |
1798 | dwinfo->next = first_dwo_info; | |
1799 | first_dwo_info = dwinfo; | |
1800 | } | |
1801 | ||
1802 | static void | |
1803 | add_dwo_name (const char * name) | |
1804 | { | |
1805 | add_dwo_info (name, DWO_NAME); | |
1806 | } | |
1807 | ||
1808 | static void | |
1809 | add_dwo_dir (const char * dir) | |
1810 | { | |
1811 | add_dwo_info (dir, DWO_DIR); | |
1812 | } | |
1813 | ||
1814 | static void | |
1815 | add_dwo_id (const char * id) | |
1816 | { | |
1817 | add_dwo_info (id, DWO_ID); | |
1818 | } | |
1819 | ||
1820 | static void | |
1821 | free_dwo_info (void) | |
1822 | { | |
1823 | dwo_info * dwinfo; | |
1824 | dwo_info * next; | |
1825 | ||
1826 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1827 | { | |
1828 | next = dwinfo->next; | |
1829 | free (dwinfo); | |
1830 | } | |
1831 | first_dwo_info = NULL; | |
1832 | } | |
1833 | ||
19e6b90e | 1834 | static unsigned char * |
dda8d76d NC |
1835 | read_and_display_attr_value (unsigned long attribute, |
1836 | unsigned long form, | |
1837 | dwarf_signed_vma implicit_const, | |
1838 | unsigned char * data, | |
1839 | unsigned char * end, | |
1840 | dwarf_vma cu_offset, | |
1841 | dwarf_vma pointer_size, | |
1842 | dwarf_vma offset_size, | |
1843 | int dwarf_version, | |
1844 | debug_info * debug_info_p, | |
1845 | int do_loc, | |
1846 | struct dwarf_section * section, | |
1847 | struct cu_tu_set * this_set, | |
1848 | char delimiter) | |
19e6b90e | 1849 | { |
467c65bc | 1850 | dwarf_vma uvalue = 0; |
19e6b90e | 1851 | unsigned char *block_start = NULL; |
6e3d6dc1 | 1852 | unsigned char * orig_data = data; |
19e6b90e L |
1853 | unsigned int bytes_read; |
1854 | ||
f41e4712 | 1855 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 1856 | { |
f41e4712 | 1857 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
1858 | return data; |
1859 | } | |
1860 | ||
19e6b90e L |
1861 | switch (form) |
1862 | { | |
1863 | default: | |
1864 | break; | |
1865 | ||
1866 | case DW_FORM_ref_addr: | |
1867 | if (dwarf_version == 2) | |
0c588247 | 1868 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
932fd279 | 1869 | else if (dwarf_version == 3 || dwarf_version == 4) |
0c588247 | 1870 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 1871 | else |
467c65bc NC |
1872 | error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); |
1873 | ||
19e6b90e L |
1874 | break; |
1875 | ||
1876 | case DW_FORM_addr: | |
0c588247 | 1877 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
1878 | break; |
1879 | ||
1880 | case DW_FORM_strp: | |
77145576 | 1881 | case DW_FORM_line_strp: |
932fd279 | 1882 | case DW_FORM_sec_offset: |
a081f3cd JJ |
1883 | case DW_FORM_GNU_ref_alt: |
1884 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 1885 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
1886 | break; |
1887 | ||
932fd279 JJ |
1888 | case DW_FORM_flag_present: |
1889 | uvalue = 1; | |
1890 | break; | |
1891 | ||
19e6b90e L |
1892 | case DW_FORM_ref1: |
1893 | case DW_FORM_flag: | |
1894 | case DW_FORM_data1: | |
0c588247 | 1895 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
1896 | break; |
1897 | ||
1898 | case DW_FORM_ref2: | |
1899 | case DW_FORM_data2: | |
0c588247 | 1900 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
1901 | break; |
1902 | ||
1903 | case DW_FORM_ref4: | |
1904 | case DW_FORM_data4: | |
0c588247 | 1905 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
1906 | break; |
1907 | ||
1908 | case DW_FORM_sdata: | |
f6f0e17b | 1909 | uvalue = read_sleb128 (data, & bytes_read, end); |
19e6b90e L |
1910 | data += bytes_read; |
1911 | break; | |
1912 | ||
4723351a | 1913 | case DW_FORM_GNU_str_index: |
f6f0e17b | 1914 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
1915 | data += bytes_read; |
1916 | break; | |
1917 | ||
19e6b90e L |
1918 | case DW_FORM_ref_udata: |
1919 | case DW_FORM_udata: | |
f6f0e17b | 1920 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
1921 | data += bytes_read; |
1922 | break; | |
1923 | ||
1924 | case DW_FORM_indirect: | |
f6f0e17b | 1925 | form = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
1926 | data += bytes_read; |
1927 | if (!do_loc) | |
ef0b5f1c | 1928 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 JK |
1929 | if (form == DW_FORM_implicit_const) |
1930 | { | |
1931 | implicit_const = read_sleb128 (data, & bytes_read, end); | |
1932 | data += bytes_read; | |
1933 | } | |
1934 | return read_and_display_attr_value (attribute, form, implicit_const, data, | |
1935 | end, cu_offset, pointer_size, | |
19e6b90e | 1936 | offset_size, dwarf_version, |
ec4d4525 | 1937 | debug_info_p, do_loc, |
ef0b5f1c | 1938 | section, this_set, delimiter); |
4723351a | 1939 | case DW_FORM_GNU_addr_index: |
f6f0e17b | 1940 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
1941 | data += bytes_read; |
1942 | break; | |
19e6b90e L |
1943 | } |
1944 | ||
1945 | switch (form) | |
1946 | { | |
1947 | case DW_FORM_ref_addr: | |
1948 | if (!do_loc) | |
ef0b5f1c | 1949 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
1950 | break; |
1951 | ||
a081f3cd JJ |
1952 | case DW_FORM_GNU_ref_alt: |
1953 | if (!do_loc) | |
ef0b5f1c | 1954 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
dda8d76d | 1955 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
1956 | break; |
1957 | ||
19e6b90e L |
1958 | case DW_FORM_ref1: |
1959 | case DW_FORM_ref2: | |
1960 | case DW_FORM_ref4: | |
1961 | case DW_FORM_ref_udata: | |
1962 | if (!do_loc) | |
ef0b5f1c | 1963 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
1964 | break; |
1965 | ||
1966 | case DW_FORM_data4: | |
1967 | case DW_FORM_addr: | |
932fd279 | 1968 | case DW_FORM_sec_offset: |
19e6b90e | 1969 | if (!do_loc) |
ef0b5f1c | 1970 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
1971 | break; |
1972 | ||
932fd279 | 1973 | case DW_FORM_flag_present: |
19e6b90e L |
1974 | case DW_FORM_flag: |
1975 | case DW_FORM_data1: | |
1976 | case DW_FORM_data2: | |
1977 | case DW_FORM_sdata: | |
1978 | case DW_FORM_udata: | |
1979 | if (!do_loc) | |
ef0b5f1c | 1980 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
1981 | break; |
1982 | ||
77145576 JK |
1983 | case DW_FORM_implicit_const: |
1984 | if (!do_loc) | |
1985 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
1986 | break; | |
1987 | ||
19e6b90e L |
1988 | case DW_FORM_ref8: |
1989 | case DW_FORM_data8: | |
2bc8690c | 1990 | if (!do_loc) |
19e6b90e | 1991 | { |
74bc6052 | 1992 | dwarf_vma high_bits; |
a69c4772 | 1993 | dwarf_vma utmp; |
74bc6052 CC |
1994 | char buf[64]; |
1995 | ||
0c588247 | 1996 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
1997 | utmp = uvalue; |
1998 | if (form == DW_FORM_ref8) | |
1999 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 2000 | printf ("%c0x%s", delimiter, |
a69c4772 | 2001 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 2002 | } |
0c588247 | 2003 | |
19e6b90e L |
2004 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2005 | && num_debug_info_entries == 0) | |
2006 | { | |
2007 | if (sizeof (uvalue) == 8) | |
0c588247 | 2008 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 2009 | else |
467c65bc | 2010 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 2011 | } |
0c588247 | 2012 | |
19e6b90e L |
2013 | data += 8; |
2014 | break; | |
2015 | ||
2f6cd591 JK |
2016 | case DW_FORM_data16: |
2017 | if (!do_loc) | |
2018 | { | |
2019 | dwarf_vma left_high_bits, left_low_bits; | |
2020 | dwarf_vma right_high_bits, right_low_bits; | |
2021 | ||
2022 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
2023 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
2024 | if (byte_get == byte_get_little_endian) | |
2025 | { | |
2026 | /* Swap them. */ | |
2027 | left_high_bits ^= right_high_bits; | |
2028 | right_high_bits ^= left_high_bits; | |
2029 | left_high_bits ^= right_high_bits; | |
2030 | left_low_bits ^= right_low_bits; | |
2031 | right_low_bits ^= left_low_bits; | |
2032 | left_low_bits ^= right_low_bits; | |
2033 | } | |
2034 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
2035 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
2036 | left_high_bits, left_low_bits, right_high_bits, | |
2037 | right_low_bits); | |
2038 | } | |
2039 | data += 16; | |
2040 | break; | |
2041 | ||
19e6b90e L |
2042 | case DW_FORM_string: |
2043 | if (!do_loc) | |
ef0b5f1c | 2044 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 2045 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
2046 | break; |
2047 | ||
2048 | case DW_FORM_block: | |
932fd279 | 2049 | case DW_FORM_exprloc: |
f6f0e17b | 2050 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e | 2051 | block_start = data + bytes_read; |
a1165289 NC |
2052 | if (block_start >= end) |
2053 | { | |
2054 | warn (_("Block ends prematurely\n")); | |
2055 | uvalue = 0; | |
2056 | block_start = end; | |
2057 | } | |
f3853b34 NC |
2058 | /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with |
2059 | gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute | |
2060 | block_start + uvalue here. */ | |
2061 | data = block_start + uvalue; | |
f41e4712 | 2062 | /* PR 17512: file: 008-103549-0.001:0.1. */ |
f3853b34 | 2063 | if (block_start + uvalue > end || data < block_start) |
f41e4712 NC |
2064 | { |
2065 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
2066 | uvalue = end - block_start; | |
2067 | } | |
19e6b90e L |
2068 | if (do_loc) |
2069 | data = block_start + uvalue; | |
2070 | else | |
ef0b5f1c | 2071 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2072 | break; |
2073 | ||
2074 | case DW_FORM_block1: | |
0c588247 | 2075 | SAFE_BYTE_GET (uvalue, data, 1, end); |
19e6b90e | 2076 | block_start = data + 1; |
a1165289 NC |
2077 | if (block_start >= end) |
2078 | { | |
2079 | warn (_("Block ends prematurely\n")); | |
2080 | uvalue = 0; | |
2081 | block_start = end; | |
2082 | } | |
f3853b34 NC |
2083 | data = block_start + uvalue; |
2084 | if (block_start + uvalue > end || data < block_start) | |
f41e4712 NC |
2085 | { |
2086 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
2087 | uvalue = end - block_start; | |
2088 | } | |
19e6b90e L |
2089 | if (do_loc) |
2090 | data = block_start + uvalue; | |
2091 | else | |
ef0b5f1c | 2092 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2093 | break; |
2094 | ||
2095 | case DW_FORM_block2: | |
0c588247 | 2096 | SAFE_BYTE_GET (uvalue, data, 2, end); |
19e6b90e | 2097 | block_start = data + 2; |
a1165289 NC |
2098 | if (block_start >= end) |
2099 | { | |
2100 | warn (_("Block ends prematurely\n")); | |
2101 | uvalue = 0; | |
2102 | block_start = end; | |
2103 | } | |
f3853b34 NC |
2104 | data = block_start + uvalue; |
2105 | if (block_start + uvalue > end || data < block_start) | |
f41e4712 NC |
2106 | { |
2107 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
2108 | uvalue = end - block_start; | |
2109 | } | |
19e6b90e L |
2110 | if (do_loc) |
2111 | data = block_start + uvalue; | |
2112 | else | |
ef0b5f1c | 2113 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2114 | break; |
2115 | ||
2116 | case DW_FORM_block4: | |
0c588247 | 2117 | SAFE_BYTE_GET (uvalue, data, 4, end); |
19e6b90e | 2118 | block_start = data + 4; |
a1165289 NC |
2119 | /* PR 17512: file: 3371-3907-0.004. */ |
2120 | if (block_start >= end) | |
2121 | { | |
2122 | warn (_("Block ends prematurely\n")); | |
2123 | uvalue = 0; | |
2124 | block_start = end; | |
2125 | } | |
f3853b34 NC |
2126 | data = block_start + uvalue; |
2127 | if (block_start + uvalue > end | |
b4eb7656 | 2128 | /* PR 17531: file: 5b5f0592. */ |
f3853b34 | 2129 | || data < block_start) |
f41e4712 NC |
2130 | { |
2131 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
2132 | uvalue = end - block_start; | |
2133 | } | |
19e6b90e L |
2134 | if (do_loc) |
2135 | data = block_start + uvalue; | |
2136 | else | |
ef0b5f1c | 2137 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2138 | break; |
2139 | ||
2140 | case DW_FORM_strp: | |
2141 | if (!do_loc) | |
ef0b5f1c | 2142 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, |
47704ddf KT |
2143 | dwarf_vmatoa ("x", uvalue), |
2144 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
2145 | break; |
2146 | ||
77145576 JK |
2147 | case DW_FORM_line_strp: |
2148 | if (!do_loc) | |
2149 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2150 | dwarf_vmatoa ("x", uvalue), | |
2151 | fetch_indirect_line_string (uvalue)); | |
2152 | break; | |
2153 | ||
4723351a CC |
2154 | case DW_FORM_GNU_str_index: |
2155 | if (!do_loc) | |
b4eb7656 | 2156 | { |
d85bf2ba NC |
2157 | const char * suffix = strrchr (section->name, '.'); |
2158 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
b4eb7656 | 2159 | |
ef0b5f1c | 2160 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2161 | dwarf_vmatoa ("x", uvalue), |
2162 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2163 | } | |
4723351a CC |
2164 | break; |
2165 | ||
a081f3cd JJ |
2166 | case DW_FORM_GNU_strp_alt: |
2167 | if (!do_loc) | |
dda8d76d NC |
2168 | { |
2169 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2170 | dwarf_vmatoa ("x", uvalue), | |
2171 | fetch_alt_indirect_string (uvalue)); | |
2172 | } | |
a081f3cd JJ |
2173 | break; |
2174 | ||
19e6b90e L |
2175 | case DW_FORM_indirect: |
2176 | /* Handled above. */ | |
2177 | break; | |
2178 | ||
2b6f5997 CC |
2179 | case DW_FORM_ref_sig8: |
2180 | if (!do_loc) | |
2181 | { | |
74bc6052 CC |
2182 | dwarf_vma high_bits; |
2183 | char buf[64]; | |
2184 | ||
0c588247 | 2185 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
ef0b5f1c | 2186 | printf ("%csignature: 0x%s", delimiter, |
74bc6052 | 2187 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); |
2b6f5997 | 2188 | } |
74bc6052 | 2189 | data += 8; |
2b6f5997 CC |
2190 | break; |
2191 | ||
4723351a CC |
2192 | case DW_FORM_GNU_addr_index: |
2193 | if (!do_loc) | |
ef0b5f1c | 2194 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2195 | dwarf_vmatoa ("x", uvalue), |
2196 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
4723351a CC |
2197 | break; |
2198 | ||
19e6b90e L |
2199 | default: |
2200 | warn (_("Unrecognized form: %lu\n"), form); | |
2201 | break; | |
2202 | } | |
2203 | ||
19e6b90e | 2204 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2205 | && num_debug_info_entries == 0 |
2206 | && debug_info_p != NULL) | |
19e6b90e L |
2207 | { |
2208 | switch (attribute) | |
2209 | { | |
2210 | case DW_AT_frame_base: | |
2211 | have_frame_base = 1; | |
1a0670f3 | 2212 | /* Fall through. */ |
19e6b90e | 2213 | case DW_AT_location: |
9f272209 | 2214 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2215 | case DW_AT_string_length: |
2216 | case DW_AT_return_addr: | |
19e6b90e L |
2217 | case DW_AT_data_member_location: |
2218 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2219 | case DW_AT_segment: |
2220 | case DW_AT_static_link: | |
2221 | case DW_AT_use_location: | |
bc0a77d2 | 2222 | case DW_AT_call_value: |
629e7ca8 | 2223 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2224 | case DW_AT_call_data_value: |
629e7ca8 | 2225 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2226 | case DW_AT_call_target: |
629e7ca8 | 2227 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2228 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2229 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2230 | if ((dwarf_version < 4 |
212b6063 | 2231 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2232 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2233 | { |
2234 | /* Process location list. */ | |
91d6fa6a | 2235 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2236 | unsigned int num = debug_info_p->num_loc_offsets; |
2237 | ||
91d6fa6a | 2238 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2239 | { |
91d6fa6a | 2240 | lmax += 1024; |
467c65bc | 2241 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2242 | xcrealloc (debug_info_p->loc_offsets, |
2243 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2244 | debug_info_p->loc_views = (dwarf_vma *) |
2245 | xcrealloc (debug_info_p->loc_views, | |
2246 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2247 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2248 | xcrealloc (debug_info_p->have_frame_base, |
2249 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2250 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2251 | } |
341f9135 | 2252 | if (this_set != NULL) |
b4eb7656 | 2253 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2254 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2255 | if (attribute != DW_AT_GNU_locviews) |
2256 | { | |
a7504f87 NC |
2257 | /* Corrupt DWARF info can produce more offsets than views. |
2258 | See PR 23062 for an example. */ | |
2259 | if (debug_info_p->num_loc_offsets | |
2260 | > debug_info_p->num_loc_views) | |
2261 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2262 | else | |
2263 | { | |
2264 | debug_info_p->loc_offsets [num] = uvalue; | |
2265 | debug_info_p->num_loc_offsets++; | |
2266 | } | |
9f272209 AO |
2267 | } |
2268 | else | |
2269 | { | |
2270 | assert (debug_info_p->num_loc_views <= num); | |
2271 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2272 | if (num > debug_info_p->num_loc_offsets) |
2273 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2274 | else | |
2275 | { | |
2276 | debug_info_p->loc_views [num] = uvalue; | |
2277 | debug_info_p->num_loc_views++; | |
2278 | } | |
9f272209 | 2279 | } |
19e6b90e L |
2280 | } |
2281 | break; | |
e2a0d921 | 2282 | |
19e6b90e L |
2283 | case DW_AT_low_pc: |
2284 | if (need_base_address) | |
2285 | debug_info_p->base_address = uvalue; | |
2286 | break; | |
2287 | ||
4723351a | 2288 | case DW_AT_GNU_addr_base: |
b4eb7656 | 2289 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2290 | break; |
2291 | ||
2292 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2293 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2294 | break; |
2295 | ||
19e6b90e | 2296 | case DW_AT_ranges: |
b4eb7656 | 2297 | if ((dwarf_version < 4 |
212b6063 | 2298 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2299 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2300 | { |
2301 | /* Process range list. */ | |
91d6fa6a | 2302 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2303 | unsigned int num = debug_info_p->num_range_lists; |
2304 | ||
91d6fa6a | 2305 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2306 | { |
91d6fa6a | 2307 | lmax += 1024; |
467c65bc | 2308 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2309 | xcrealloc (debug_info_p->range_lists, |
2310 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2311 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2312 | } |
2313 | debug_info_p->range_lists [num] = uvalue; | |
2314 | debug_info_p->num_range_lists++; | |
2315 | } | |
2316 | break; | |
2317 | ||
d85bf2ba NC |
2318 | case DW_AT_GNU_dwo_name: |
2319 | case DW_AT_dwo_name: | |
2320 | if (need_dwo_info) | |
2321 | switch (form) | |
2322 | { | |
2323 | case DW_FORM_strp: | |
24841daa | 2324 | add_dwo_name ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba NC |
2325 | break; |
2326 | case DW_FORM_GNU_str_index: | |
24841daa | 2327 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2328 | break; |
2329 | case DW_FORM_string: | |
24841daa | 2330 | add_dwo_name ((const char *) orig_data); |
d85bf2ba NC |
2331 | break; |
2332 | default: | |
2333 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2334 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2335 | break; |
2336 | } | |
2337 | break; | |
2338 | ||
2339 | case DW_AT_comp_dir: | |
2340 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2341 | if (need_dwo_info) | |
2342 | switch (form) | |
2343 | { | |
2344 | case DW_FORM_strp: | |
24841daa | 2345 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba NC |
2346 | break; |
2347 | case DW_FORM_line_strp: | |
24841daa | 2348 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue)); |
d85bf2ba NC |
2349 | break; |
2350 | case DW_FORM_GNU_str_index: | |
24841daa | 2351 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2352 | break; |
2353 | case DW_FORM_string: | |
24841daa | 2354 | add_dwo_dir ((const char *) orig_data); |
d85bf2ba NC |
2355 | break; |
2356 | default: | |
2357 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2358 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2359 | break; |
2360 | } | |
2361 | break; | |
2362 | ||
2363 | case DW_AT_GNU_dwo_id: | |
2364 | if (need_dwo_info) | |
2365 | switch (form) | |
2366 | { | |
2367 | case DW_FORM_data8: | |
24841daa NC |
2368 | /* FIXME: Record the length of the ID as well ? */ |
2369 | add_dwo_id ((const char *) (data - 8)); | |
d85bf2ba NC |
2370 | break; |
2371 | default: | |
2372 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2373 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2374 | break; |
2375 | } | |
2376 | break; | |
2377 | ||
19e6b90e L |
2378 | default: |
2379 | break; | |
2380 | } | |
2381 | } | |
2382 | ||
4ccf1e31 | 2383 | if (do_loc || attribute == 0) |
19e6b90e L |
2384 | return data; |
2385 | ||
ec4d4525 | 2386 | /* For some attributes we can display further information. */ |
19e6b90e L |
2387 | switch (attribute) |
2388 | { | |
2389 | case DW_AT_inline: | |
2e9e81a8 | 2390 | printf ("\t"); |
19e6b90e L |
2391 | switch (uvalue) |
2392 | { | |
2393 | case DW_INL_not_inlined: | |
2394 | printf (_("(not inlined)")); | |
2395 | break; | |
2396 | case DW_INL_inlined: | |
2397 | printf (_("(inlined)")); | |
2398 | break; | |
2399 | case DW_INL_declared_not_inlined: | |
2400 | printf (_("(declared as inline but ignored)")); | |
2401 | break; | |
2402 | case DW_INL_declared_inlined: | |
2403 | printf (_("(declared as inline and inlined)")); | |
2404 | break; | |
2405 | default: | |
47704ddf KT |
2406 | printf (_(" (Unknown inline attribute value: %s)"), |
2407 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2408 | break; |
2409 | } | |
2410 | break; | |
2411 | ||
2412 | case DW_AT_language: | |
2e9e81a8 | 2413 | printf ("\t"); |
19e6b90e L |
2414 | switch (uvalue) |
2415 | { | |
4b78141a | 2416 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 2417 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
2418 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
2419 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 2420 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
2421 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
2422 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
2423 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
2424 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 2425 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 2426 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 2427 | /* DWARF 2.1 values. */ |
4b78141a | 2428 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
2429 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
2430 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
2431 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
2432 | /* DWARF 3 values. */ |
2433 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
2434 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
2435 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
2436 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
2437 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
2438 | /* DWARF 4 values. */ |
2439 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 2440 | /* DWARF 5 values. */ |
2008a0db | 2441 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 2442 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
2443 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
2444 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
2445 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 2446 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
2447 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
2448 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 2449 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
2450 | case DW_LANG_Swift: printf ("(Swift)"); break; |
2451 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
2452 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 2453 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
2454 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
2455 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 2456 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
2457 | /* MIPS extension. */ |
2458 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
2459 | /* UPC extension. */ | |
2460 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
2461 | default: | |
4b78141a | 2462 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 2463 | printf (_("(implementation defined: %s)"), |
467c65bc | 2464 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 2465 | else |
9cf03b7e | 2466 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2467 | break; |
2468 | } | |
2469 | break; | |
2470 | ||
2471 | case DW_AT_encoding: | |
2e9e81a8 | 2472 | printf ("\t"); |
19e6b90e L |
2473 | switch (uvalue) |
2474 | { | |
2475 | case DW_ATE_void: printf ("(void)"); break; | |
2476 | case DW_ATE_address: printf ("(machine address)"); break; | |
2477 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
2478 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
2479 | case DW_ATE_float: printf ("(float)"); break; | |
2480 | case DW_ATE_signed: printf ("(signed)"); break; | |
2481 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
2482 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
2483 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 2484 | /* DWARF 2.1 values: */ |
19e6b90e L |
2485 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
2486 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
2487 | /* DWARF 3 values: */ |
2488 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
2489 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
2490 | case DW_ATE_edited: printf ("(edited)"); break; | |
2491 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
2492 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
2493 | /* DWARF 4 values: */ |
2494 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
2495 | /* DWARF 5 values: */ | |
2496 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
2497 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
2498 | ||
e2a0d921 NC |
2499 | /* HP extensions: */ |
2500 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
2501 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
2502 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
2503 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
2504 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
2505 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
2506 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
2507 | ||
19e6b90e L |
2508 | default: |
2509 | if (uvalue >= DW_ATE_lo_user | |
2510 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 2511 | printf (_("(user defined type)")); |
19e6b90e | 2512 | else |
9cf03b7e | 2513 | printf (_("(unknown type)")); |
19e6b90e L |
2514 | break; |
2515 | } | |
2516 | break; | |
2517 | ||
2518 | case DW_AT_accessibility: | |
2e9e81a8 | 2519 | printf ("\t"); |
19e6b90e L |
2520 | switch (uvalue) |
2521 | { | |
2522 | case DW_ACCESS_public: printf ("(public)"); break; | |
2523 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
2524 | case DW_ACCESS_private: printf ("(private)"); break; | |
2525 | default: | |
9cf03b7e | 2526 | printf (_("(unknown accessibility)")); |
19e6b90e L |
2527 | break; |
2528 | } | |
2529 | break; | |
2530 | ||
2531 | case DW_AT_visibility: | |
2e9e81a8 | 2532 | printf ("\t"); |
19e6b90e L |
2533 | switch (uvalue) |
2534 | { | |
2535 | case DW_VIS_local: printf ("(local)"); break; | |
2536 | case DW_VIS_exported: printf ("(exported)"); break; | |
2537 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 2538 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
2539 | } |
2540 | break; | |
2541 | ||
04914e37 NC |
2542 | case DW_AT_endianity: |
2543 | printf ("\t"); | |
2544 | switch (uvalue) | |
2545 | { | |
2546 | case DW_END_default: printf ("(default)"); break; | |
2547 | case DW_END_big: printf ("(big)"); break; | |
2548 | case DW_END_little: printf ("(little)"); break; | |
2549 | default: | |
2550 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
2551 | printf (_("(user specified)")); | |
2552 | else | |
2553 | printf (_("(unknown endianity)")); | |
2554 | break; | |
2555 | } | |
2556 | break; | |
2557 | ||
19e6b90e | 2558 | case DW_AT_virtuality: |
2e9e81a8 | 2559 | printf ("\t"); |
19e6b90e L |
2560 | switch (uvalue) |
2561 | { | |
2562 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
2563 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
2564 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 2565 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
2566 | } |
2567 | break; | |
2568 | ||
2569 | case DW_AT_identifier_case: | |
2e9e81a8 | 2570 | printf ("\t"); |
19e6b90e L |
2571 | switch (uvalue) |
2572 | { | |
2573 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
2574 | case DW_ID_up_case: printf ("(up_case)"); break; | |
2575 | case DW_ID_down_case: printf ("(down_case)"); break; | |
2576 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 2577 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
2578 | } |
2579 | break; | |
2580 | ||
2581 | case DW_AT_calling_convention: | |
2e9e81a8 | 2582 | printf ("\t"); |
19e6b90e L |
2583 | switch (uvalue) |
2584 | { | |
2585 | case DW_CC_normal: printf ("(normal)"); break; | |
2586 | case DW_CC_program: printf ("(program)"); break; | |
2587 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
2588 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
2589 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
2590 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
2591 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
2592 | default: |
2593 | if (uvalue >= DW_CC_lo_user | |
2594 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 2595 | printf (_("(user defined)")); |
19e6b90e | 2596 | else |
9cf03b7e | 2597 | printf (_("(unknown convention)")); |
19e6b90e L |
2598 | } |
2599 | break; | |
2600 | ||
2601 | case DW_AT_ordering: | |
2e9e81a8 | 2602 | printf ("\t"); |
19e6b90e L |
2603 | switch (uvalue) |
2604 | { | |
04914e37 | 2605 | case 255: |
9cf03b7e | 2606 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
2607 | case 0: printf ("(row major)"); break; |
2608 | case 1: printf ("(column major)"); break; | |
2609 | } | |
2610 | break; | |
2611 | ||
04914e37 NC |
2612 | case DW_AT_decimal_sign: |
2613 | printf ("\t"); | |
2614 | switch (uvalue) | |
2615 | { | |
2616 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
2617 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
2618 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
2619 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
2620 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
2621 | default: printf (_("(unrecognised)")); break; | |
2622 | } | |
2623 | break; | |
2624 | ||
2625 | case DW_AT_defaulted: | |
2626 | printf ("\t"); | |
2627 | switch (uvalue) | |
2628 | { | |
2629 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
2630 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
2631 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
2632 | default: printf (_("(unrecognised)")); break; | |
2633 | } | |
2634 | break; | |
2635 | ||
2636 | case DW_AT_discr_list: | |
2637 | printf ("\t"); | |
2638 | switch (uvalue) | |
2639 | { | |
2640 | case DW_DSC_label: printf (_("(label)")); break; | |
2641 | case DW_DSC_range: printf (_("(range)")); break; | |
2642 | default: printf (_("(unrecognised)")); break; | |
2643 | } | |
2644 | break; | |
2645 | ||
19e6b90e L |
2646 | case DW_AT_frame_base: |
2647 | have_frame_base = 1; | |
1a0670f3 | 2648 | /* Fall through. */ |
19e6b90e | 2649 | case DW_AT_location: |
e2a0d921 NC |
2650 | case DW_AT_string_length: |
2651 | case DW_AT_return_addr: | |
19e6b90e L |
2652 | case DW_AT_data_member_location: |
2653 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2654 | case DW_AT_segment: |
2655 | case DW_AT_static_link: | |
2656 | case DW_AT_use_location: | |
bc0a77d2 | 2657 | case DW_AT_call_value: |
629e7ca8 | 2658 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2659 | case DW_AT_call_data_value: |
629e7ca8 | 2660 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2661 | case DW_AT_call_target: |
629e7ca8 | 2662 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2663 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2664 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 2665 | if ((dwarf_version < 4 |
b4eb7656 | 2666 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2667 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 2668 | printf (_(" (location list)")); |
e2a0d921 | 2669 | /* Fall through. */ |
19e6b90e L |
2670 | case DW_AT_allocated: |
2671 | case DW_AT_associated: | |
2672 | case DW_AT_data_location: | |
2673 | case DW_AT_stride: | |
2674 | case DW_AT_upper_bound: | |
cecf136e | 2675 | case DW_AT_lower_bound: |
19e6b90e L |
2676 | if (block_start) |
2677 | { | |
2678 | int need_frame_base; | |
2679 | ||
2e9e81a8 | 2680 | printf ("\t("); |
19e6b90e L |
2681 | need_frame_base = decode_location_expression (block_start, |
2682 | pointer_size, | |
b7807392 JJ |
2683 | offset_size, |
2684 | dwarf_version, | |
19e6b90e | 2685 | uvalue, |
f1c4cc75 | 2686 | cu_offset, section); |
19e6b90e L |
2687 | printf (")"); |
2688 | if (need_frame_base && !have_frame_base) | |
2689 | printf (_(" [without DW_AT_frame_base]")); | |
2690 | } | |
19e6b90e L |
2691 | break; |
2692 | ||
c54207d3 NC |
2693 | case DW_AT_data_bit_offset: |
2694 | case DW_AT_byte_size: | |
2695 | case DW_AT_bit_size: | |
2696 | case DW_AT_string_length_byte_size: | |
2697 | case DW_AT_string_length_bit_size: | |
2698 | case DW_AT_bit_stride: | |
2699 | if (form == DW_FORM_exprloc) | |
2700 | { | |
2701 | printf ("\t("); | |
2702 | (void) decode_location_expression (block_start, pointer_size, | |
2703 | offset_size, dwarf_version, | |
2704 | uvalue, cu_offset, section); | |
2705 | printf (")"); | |
2706 | } | |
2707 | break; | |
2708 | ||
ec4d4525 NC |
2709 | case DW_AT_import: |
2710 | { | |
a081f3cd JJ |
2711 | if (form == DW_FORM_ref_sig8 |
2712 | || form == DW_FORM_GNU_ref_alt) | |
b4eb7656 | 2713 | break; |
2b6f5997 | 2714 | |
ec4d4525 NC |
2715 | if (form == DW_FORM_ref1 |
2716 | || form == DW_FORM_ref2 | |
a7a0b6a5 JK |
2717 | || form == DW_FORM_ref4 |
2718 | || form == DW_FORM_ref_udata) | |
ec4d4525 NC |
2719 | uvalue += cu_offset; |
2720 | ||
6e3d6dc1 | 2721 | if (uvalue >= section->size) |
f3853b34 | 2722 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
47704ddf KT |
2723 | dwarf_vmatoa ("x", uvalue), |
2724 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
2725 | else |
2726 | { | |
2727 | unsigned long abbrev_number; | |
2728 | abbrev_entry * entry; | |
2729 | ||
f6f0e17b | 2730 | abbrev_number = read_uleb128 (section->start + uvalue, NULL, end); |
cecf136e | 2731 | |
2e9e81a8 | 2732 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
afd6e1ff JJ |
2733 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
2734 | use different abbrev table, and we don't track .debug_info chunks | |
2735 | yet. */ | |
2736 | if (form != DW_FORM_ref_addr) | |
2737 | { | |
2738 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
2739 | if (entry->entry == abbrev_number) | |
2740 | break; | |
2741 | if (entry != NULL) | |
2742 | printf (" (%s)", get_TAG_name (entry->tag)); | |
2743 | } | |
6e3d6dc1 NC |
2744 | printf ("]"); |
2745 | } | |
ec4d4525 NC |
2746 | } |
2747 | break; | |
2748 | ||
19e6b90e L |
2749 | default: |
2750 | break; | |
2751 | } | |
2752 | ||
2753 | return data; | |
2754 | } | |
2755 | ||
19e6b90e | 2756 | static unsigned char * |
dda8d76d NC |
2757 | read_and_display_attr (unsigned long attribute, |
2758 | unsigned long form, | |
2759 | dwarf_signed_vma implicit_const, | |
2760 | unsigned char * data, | |
2761 | unsigned char * end, | |
2762 | dwarf_vma cu_offset, | |
2763 | dwarf_vma pointer_size, | |
2764 | dwarf_vma offset_size, | |
2765 | int dwarf_version, | |
2766 | debug_info * debug_info_p, | |
2767 | int do_loc, | |
2768 | struct dwarf_section * section, | |
2769 | struct cu_tu_set * this_set) | |
19e6b90e L |
2770 | { |
2771 | if (!do_loc) | |
750f03b7 | 2772 | printf (" %-18s:", get_AT_name (attribute)); |
77145576 | 2773 | data = read_and_display_attr_value (attribute, form, implicit_const, data, end, |
f6f0e17b | 2774 | cu_offset, pointer_size, offset_size, |
19e6b90e | 2775 | dwarf_version, debug_info_p, |
ef0b5f1c | 2776 | do_loc, section, this_set, ' '); |
19e6b90e L |
2777 | if (!do_loc) |
2778 | printf ("\n"); | |
2779 | return data; | |
2780 | } | |
2781 | ||
dda8d76d | 2782 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
2783 | following debug links, then attempt to load the requested section |
2784 | from one of the separate debug info files. */ | |
dda8d76d NC |
2785 | |
2786 | static bfd_boolean | |
2787 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, | |
24841daa | 2788 | void * handle) |
dda8d76d | 2789 | { |
24841daa | 2790 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 2791 | { |
24841daa NC |
2792 | if (debug_displays[sec_enum].section.filename == NULL) |
2793 | { | |
2794 | /* See if we can associate a filename with this section. */ | |
2795 | separate_info * i; | |
2796 | ||
2797 | for (i = first_separate_info; i != NULL; i = i->next) | |
2798 | if (i->handle == handle) | |
2799 | { | |
2800 | debug_displays[sec_enum].section.filename = i->filename; | |
2801 | break; | |
2802 | } | |
2803 | } | |
2804 | ||
dda8d76d NC |
2805 | return TRUE; |
2806 | } | |
2807 | ||
24841daa NC |
2808 | if (do_follow_links) |
2809 | { | |
2810 | separate_info * i; | |
2811 | ||
2812 | for (i = first_separate_info; i != NULL; i = i->next) | |
2813 | { | |
2814 | if (load_debug_section (sec_enum, i->handle)) | |
2815 | { | |
2816 | debug_displays[sec_enum].section.filename = i->filename; | |
2817 | ||
2818 | /* FIXME: We should check to see if any of the remaining debug info | |
2819 | files also contain this section, and, umm, do something about it. */ | |
2820 | return TRUE; | |
2821 | } | |
2822 | } | |
2823 | } | |
dda8d76d NC |
2824 | |
2825 | return FALSE; | |
2826 | } | |
2827 | ||
2828 | static void | |
2829 | introduce (struct dwarf_section * section, bfd_boolean raw) | |
2830 | { | |
2831 | if (raw) | |
2832 | { | |
2833 | if (do_follow_links && section->filename) | |
2834 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
2835 | section->name, section->filename); | |
2836 | else | |
2837 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
2838 | } | |
2839 | else | |
2840 | { | |
2841 | if (do_follow_links && section->filename) | |
2842 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
2843 | section->name, section->filename); | |
2844 | else | |
2845 | printf (_("Contents of the %s section:\n\n"), section->name); | |
2846 | } | |
2847 | } | |
2848 | ||
d85bf2ba NC |
2849 | /* Process the contents of a .debug_info section. |
2850 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
2851 | and we do not want to display anything to the user. | |
2852 | If do_types is TRUE, we are processing a .debug_types section instead of | |
2853 | a .debug_info section. | |
2854 | The information displayed is restricted by the values in DWARF_START_DIE | |
2855 | and DWARF_CUTOFF_LEVEL. | |
2856 | Returns TRUE upon success. Otherwise an error or warning message is | |
2857 | printed and FALSE is returned. */ | |
19e6b90e | 2858 | |
d85bf2ba NC |
2859 | static bfd_boolean |
2860 | process_debug_info (struct dwarf_section * section, | |
2861 | void * file, | |
2862 | enum dwarf_section_display_enum abbrev_sec, | |
2863 | bfd_boolean do_loc, | |
2864 | bfd_boolean do_types) | |
19e6b90e L |
2865 | { |
2866 | unsigned char *start = section->start; | |
2867 | unsigned char *end = start + section->size; | |
2868 | unsigned char *section_begin; | |
2869 | unsigned int unit; | |
2870 | unsigned int num_units = 0; | |
2871 | ||
2872 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
2873 | && num_debug_info_entries == 0 |
2874 | && ! do_types) | |
19e6b90e | 2875 | { |
767221a9 | 2876 | dwarf_vma length; |
19e6b90e L |
2877 | |
2878 | /* First scan the section to get the number of comp units. */ | |
2879 | for (section_begin = start, num_units = 0; section_begin < end; | |
2880 | num_units ++) | |
2881 | { | |
2882 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
2883 | will be the length. For a 64-bit DWARF section, it'll be | |
2884 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 2885 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
2886 | |
2887 | if (length == 0xffffffff) | |
2888 | { | |
0c588247 | 2889 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
2890 | section_begin += length + 12; |
2891 | } | |
ec4d4525 NC |
2892 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
2893 | { | |
767221a9 NC |
2894 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
2895 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 2896 | return FALSE; |
ec4d4525 | 2897 | } |
19e6b90e L |
2898 | else |
2899 | section_begin += length + 4; | |
aca88567 NC |
2900 | |
2901 | /* Negative values are illegal, they may even cause infinite | |
2902 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
2903 | relocations to an object file, or if the file is corrupt. */ |
2904 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 2905 | { |
767221a9 NC |
2906 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
2907 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 2908 | return FALSE; |
aca88567 | 2909 | } |
19e6b90e L |
2910 | } |
2911 | ||
2912 | if (num_units == 0) | |
2913 | { | |
f41e4712 | 2914 | error (_("No comp units in %s section ?\n"), section->name); |
d85bf2ba | 2915 | return FALSE; |
19e6b90e L |
2916 | } |
2917 | ||
2918 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 2919 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 2920 | sizeof (* debug_information)); |
19e6b90e L |
2921 | if (debug_information == NULL) |
2922 | { | |
f41e4712 | 2923 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 2924 | num_units); |
82b1b41b | 2925 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
d85bf2ba | 2926 | return FALSE; |
19e6b90e | 2927 | } |
d85bf2ba | 2928 | |
03a91817 NC |
2929 | /* PR 17531: file: 92ca3797. |
2930 | We cannot rely upon the debug_information array being initialised | |
2931 | before it is used. A corrupt file could easily contain references | |
2932 | to a unit for which information has not been made available. So | |
2933 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
2934 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
2935 | ||
82b1b41b | 2936 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
2937 | } |
2938 | ||
2939 | if (!do_loc) | |
2940 | { | |
dda8d76d NC |
2941 | load_debug_section_with_follow (str, file); |
2942 | load_debug_section_with_follow (line_str, file); | |
2943 | load_debug_section_with_follow (str_dwo, file); | |
2944 | load_debug_section_with_follow (str_index, file); | |
2945 | load_debug_section_with_follow (str_index_dwo, file); | |
2946 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e L |
2947 | } |
2948 | ||
dda8d76d | 2949 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 2950 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
2951 | { |
2952 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 2953 | debug_displays [abbrev_sec].section.uncompressed_name); |
d85bf2ba | 2954 | return FALSE; |
19e6b90e L |
2955 | } |
2956 | ||
dda8d76d NC |
2957 | if (!do_loc && dwarf_start_die == 0) |
2958 | introduce (section, FALSE); | |
2959 | ||
19e6b90e L |
2960 | for (section_begin = start, unit = 0; start < end; unit++) |
2961 | { | |
2962 | DWARF2_Internal_CompUnit compunit; | |
2963 | unsigned char *hdrptr; | |
19e6b90e | 2964 | unsigned char *tags; |
fd2f0033 | 2965 | int level, last_level, saved_level; |
467c65bc | 2966 | dwarf_vma cu_offset; |
e98fdf1a | 2967 | unsigned long sec_off; |
bf5117e3 | 2968 | unsigned int offset_size; |
19485196 | 2969 | unsigned int initial_length_size; |
74bc6052 CC |
2970 | dwarf_vma signature_high = 0; |
2971 | dwarf_vma signature_low = 0; | |
767221a9 | 2972 | dwarf_vma type_offset = 0; |
341f9135 CC |
2973 | struct cu_tu_set *this_set; |
2974 | dwarf_vma abbrev_base; | |
2975 | size_t abbrev_size; | |
19e6b90e L |
2976 | |
2977 | hdrptr = start; | |
2978 | ||
0c588247 | 2979 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
2980 | |
2981 | if (compunit.cu_length == 0xffffffff) | |
2982 | { | |
0c588247 | 2983 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
2984 | offset_size = 8; |
2985 | initial_length_size = 12; | |
2986 | } | |
2987 | else | |
2988 | { | |
2989 | offset_size = 4; | |
2990 | initial_length_size = 4; | |
2991 | } | |
2992 | ||
0c588247 | 2993 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
2994 | |
2995 | cu_offset = start - section_begin; | |
19e6b90e | 2996 | |
341f9135 CC |
2997 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
2998 | ||
77145576 JK |
2999 | if (compunit.cu_version < 5) |
3000 | { | |
3001 | compunit.cu_unit_type = DW_UT_compile; | |
3002 | /* Initialize it due to a false compiler warning. */ | |
3003 | compunit.cu_pointer_size = -1; | |
3004 | } | |
3005 | else | |
3006 | { | |
3007 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3008 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3009 | ||
3010 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3011 | } | |
3012 | ||
0c588247 | 3013 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 3014 | |
341f9135 CC |
3015 | if (this_set == NULL) |
3016 | { | |
3017 | abbrev_base = 0; | |
3018 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3019 | } | |
3020 | else | |
3021 | { | |
3022 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3023 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3024 | } | |
3025 | ||
77145576 JK |
3026 | if (compunit.cu_version < 5) |
3027 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3028 | ||
f41e4712 NC |
3029 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3030 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3031 | { | |
3032 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3033 | compunit.cu_pointer_size, offset_size); | |
3034 | compunit.cu_pointer_size = offset_size; | |
3035 | } | |
2b6f5997 CC |
3036 | |
3037 | if (do_types) | |
b4eb7656 | 3038 | { |
0c588247 | 3039 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 3040 | hdrptr += 8; |
0c588247 | 3041 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 3042 | } |
2b6f5997 | 3043 | |
ae7e7825 NC |
3044 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
3045 | + initial_length_size)) | |
3046 | { | |
3047 | start = section_begin + cu_offset + compunit.cu_length | |
3048 | + initial_length_size; | |
3049 | continue; | |
3050 | } | |
3051 | ||
19e6b90e | 3052 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 CC |
3053 | && num_debug_info_entries == 0 |
3054 | && ! do_types) | |
19e6b90e L |
3055 | { |
3056 | debug_information [unit].cu_offset = cu_offset; | |
3057 | debug_information [unit].pointer_size | |
3058 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3059 | debug_information [unit].offset_size = offset_size; |
3060 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3061 | debug_information [unit].base_address = 0; |
4723351a CC |
3062 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3063 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3064 | debug_information [unit].loc_offsets = NULL; |
3065 | debug_information [unit].have_frame_base = NULL; | |
3066 | debug_information [unit].max_loc_offsets = 0; | |
3067 | debug_information [unit].num_loc_offsets = 0; | |
3068 | debug_information [unit].range_lists = NULL; | |
3069 | debug_information [unit].max_range_lists= 0; | |
3070 | debug_information [unit].num_range_lists = 0; | |
3071 | } | |
3072 | ||
fd2f0033 | 3073 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3074 | { |
47704ddf KT |
3075 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3076 | dwarf_vmatoa ("x", cu_offset)); | |
3077 | printf (_(" Length: 0x%s (%s)\n"), | |
3078 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3079 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3080 | printf (_(" Version: %d\n"), compunit.cu_version); |
7282333f AM |
3081 | printf (_(" Abbrev Offset: 0x%s\n"), |
3082 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3083 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3084 | if (do_types) |
3085 | { | |
74bc6052 CC |
3086 | char buf[64]; |
3087 | ||
3088 | printf (_(" Signature: 0x%s\n"), | |
3089 | dwarf_vmatoa64 (signature_high, signature_low, | |
3090 | buf, sizeof (buf))); | |
3091 | printf (_(" Type Offset: 0x%s\n"), | |
3092 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3093 | } |
341f9135 CC |
3094 | if (this_set != NULL) |
3095 | { | |
3096 | dwarf_vma *offsets = this_set->section_offsets; | |
3097 | size_t *sizes = this_set->section_sizes; | |
3098 | ||
3099 | printf (_(" Section contributions:\n")); | |
3100 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3101 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3102 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3103 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3104 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3105 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3106 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3107 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3108 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3109 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3110 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3111 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3112 | } | |
19e6b90e L |
3113 | } |
3114 | ||
e98fdf1a AM |
3115 | sec_off = cu_offset + initial_length_size; |
3116 | if (sec_off + compunit.cu_length < sec_off | |
3117 | || sec_off + compunit.cu_length > section->size) | |
460c89ff | 3118 | { |
e98fdf1a AM |
3119 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
3120 | section->name, | |
3121 | (unsigned long) cu_offset, | |
19485196 NC |
3122 | dwarf_vmatoa ("x", compunit.cu_length)); |
3123 | num_units = unit; | |
3124 | break; | |
3125 | } | |
3126 | ||
460c89ff NS |
3127 | tags = hdrptr; |
3128 | start += compunit.cu_length + initial_length_size; | |
3129 | ||
77145576 | 3130 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3131 | { |
47704ddf KT |
3132 | warn (_("CU at offset %s contains corrupt or " |
3133 | "unsupported version number: %d.\n"), | |
3134 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3135 | continue; |
3136 | } | |
3137 | ||
77145576 JK |
3138 | if (compunit.cu_unit_type != DW_UT_compile |
3139 | && compunit.cu_unit_type != DW_UT_type) | |
3140 | { | |
3141 | warn (_("CU at offset %s contains corrupt or " | |
3142 | "unsupported unit type: %d.\n"), | |
3143 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3144 | continue; | |
3145 | } | |
3146 | ||
19e6b90e L |
3147 | free_abbrevs (); |
3148 | ||
d493b283 | 3149 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 3150 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
3151 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
3152 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 3153 | (unsigned long) abbrev_size); |
b4eb7656 | 3154 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
3155 | else if ((abbrev_base + abbrev_size) |
3156 | > debug_displays [abbrev_sec].section.size) | |
3157 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
3158 | (unsigned long) abbrev_base + abbrev_size, | |
3159 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff NS |
3160 | else |
3161 | process_abbrev_section | |
341f9135 CC |
3162 | (((unsigned char *) debug_displays [abbrev_sec].section.start |
3163 | + abbrev_base + compunit.cu_abbrev_offset), | |
3164 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3165 | + abbrev_base + abbrev_size)); | |
19e6b90e L |
3166 | |
3167 | level = 0; | |
fd2f0033 TT |
3168 | last_level = level; |
3169 | saved_level = -1; | |
19e6b90e L |
3170 | while (tags < start) |
3171 | { | |
3172 | unsigned int bytes_read; | |
3173 | unsigned long abbrev_number; | |
ec4d4525 | 3174 | unsigned long die_offset; |
19e6b90e L |
3175 | abbrev_entry *entry; |
3176 | abbrev_attr *attr; | |
fd2f0033 | 3177 | int do_printing = 1; |
19e6b90e | 3178 | |
ec4d4525 NC |
3179 | die_offset = tags - section_begin; |
3180 | ||
f6f0e17b | 3181 | abbrev_number = read_uleb128 (tags, & bytes_read, start); |
19e6b90e L |
3182 | tags += bytes_read; |
3183 | ||
eb7cc021 JK |
3184 | /* A null DIE marks the end of a list of siblings or it may also be |
3185 | a section padding. */ | |
19e6b90e L |
3186 | if (abbrev_number == 0) |
3187 | { | |
eb7cc021 JK |
3188 | /* Check if it can be a section padding for the last CU. */ |
3189 | if (level == 0 && start == end) | |
3190 | { | |
3191 | unsigned char *chk; | |
3192 | ||
3193 | for (chk = tags; chk < start; chk++) | |
3194 | if (*chk != 0) | |
3195 | break; | |
3196 | if (chk == start) | |
3197 | break; | |
3198 | } | |
3199 | ||
4337774f TT |
3200 | if (!do_loc && die_offset >= dwarf_start_die |
3201 | && (dwarf_cutoff_level == -1 | |
3202 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3203 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3204 | level, die_offset); | |
3205 | ||
19e6b90e | 3206 | --level; |
ec4d4525 NC |
3207 | if (level < 0) |
3208 | { | |
3209 | static unsigned num_bogus_warns = 0; | |
3210 | ||
3211 | if (num_bogus_warns < 3) | |
3212 | { | |
4723351a CC |
3213 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3214 | die_offset, section->name); | |
ec4d4525 NC |
3215 | num_bogus_warns ++; |
3216 | if (num_bogus_warns == 3) | |
3217 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3218 | } | |
3219 | } | |
fd2f0033 | 3220 | if (dwarf_start_die != 0 && level < saved_level) |
d85bf2ba | 3221 | return TRUE; |
19e6b90e L |
3222 | continue; |
3223 | } | |
3224 | ||
4b78141a | 3225 | if (!do_loc) |
fd2f0033 TT |
3226 | { |
3227 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3228 | do_printing = 0; | |
3229 | else | |
3230 | { | |
3231 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3232 | saved_level = level; | |
3233 | do_printing = (dwarf_cutoff_level == -1 | |
3234 | || level < dwarf_cutoff_level); | |
3235 | if (do_printing) | |
3236 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
3237 | level, die_offset, abbrev_number); | |
3238 | else if (dwarf_cutoff_level == -1 | |
3239 | || last_level < dwarf_cutoff_level) | |
3240 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
3241 | last_level = level; | |
3242 | } | |
3243 | } | |
cecf136e | 3244 | |
19e6b90e L |
3245 | /* Scan through the abbreviation list until we reach the |
3246 | correct entry. */ | |
3247 | for (entry = first_abbrev; | |
3248 | entry && entry->entry != abbrev_number; | |
3249 | entry = entry->next) | |
3250 | continue; | |
3251 | ||
3252 | if (entry == NULL) | |
3253 | { | |
fd2f0033 | 3254 | if (!do_loc && do_printing) |
4b78141a NC |
3255 | { |
3256 | printf ("\n"); | |
3257 | fflush (stdout); | |
3258 | } | |
f3853b34 | 3259 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 3260 | die_offset, abbrev_number); |
d85bf2ba | 3261 | return FALSE; |
19e6b90e L |
3262 | } |
3263 | ||
fd2f0033 | 3264 | if (!do_loc && do_printing) |
cc5914eb | 3265 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 3266 | |
19e6b90e L |
3267 | switch (entry->tag) |
3268 | { | |
3269 | default: | |
3270 | need_base_address = 0; | |
3271 | break; | |
3272 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
3273 | need_base_address = 1; |
3274 | need_dwo_info = do_loc; | |
19e6b90e L |
3275 | break; |
3276 | case DW_TAG_entry_point: | |
19e6b90e L |
3277 | case DW_TAG_subprogram: |
3278 | need_base_address = 0; | |
3279 | /* Assuming that there is no DW_AT_frame_base. */ | |
3280 | have_frame_base = 0; | |
3281 | break; | |
3282 | } | |
3283 | ||
9f272209 AO |
3284 | debug_info *debug_info_p = |
3285 | (debug_information && unit < alloc_num_debug_info_entries) | |
3286 | ? debug_information + unit : NULL; | |
3287 | ||
3288 | assert (!debug_info_p | |
3289 | || (debug_info_p->num_loc_offsets | |
3290 | == debug_info_p->num_loc_views)); | |
3291 | ||
399c99f7 L |
3292 | for (attr = entry->first_attr; |
3293 | attr && attr->attribute; | |
3294 | attr = attr->next) | |
4b78141a | 3295 | { |
fd2f0033 | 3296 | if (! do_loc && do_printing) |
4b78141a | 3297 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 TT |
3298 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
3299 | ||
4b78141a NC |
3300 | tags = read_and_display_attr (attr->attribute, |
3301 | attr->form, | |
77145576 | 3302 | attr->implicit_const, |
341f9135 | 3303 | tags, |
f6f0e17b | 3304 | end, |
341f9135 | 3305 | cu_offset, |
4b78141a NC |
3306 | compunit.cu_pointer_size, |
3307 | offset_size, | |
3308 | compunit.cu_version, | |
9f272209 | 3309 | debug_info_p, |
341f9135 CC |
3310 | do_loc || ! do_printing, |
3311 | section, | |
3312 | this_set); | |
4b78141a | 3313 | } |
cecf136e | 3314 | |
9f272209 AO |
3315 | /* If a locview attribute appears before a location one, |
3316 | make sure we don't associate it with an earlier | |
3317 | loclist. */ | |
3318 | if (debug_info_p) | |
3319 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
3320 | { | |
3321 | case 1: | |
3322 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
3323 | debug_info_p->num_loc_views++; | |
3324 | assert (debug_info_p->num_loc_views | |
3325 | == debug_info_p->num_loc_offsets); | |
3326 | break; | |
3327 | ||
3328 | case 0: | |
3329 | break; | |
3330 | ||
3331 | case -1: | |
3332 | warn(_("DIE has locviews without loclist\n")); | |
3333 | debug_info_p->num_loc_views--; | |
3334 | break; | |
3335 | ||
3336 | default: | |
3337 | assert (0); | |
3338 | } | |
3339 | ||
b4eb7656 AM |
3340 | if (entry->children) |
3341 | ++level; | |
3342 | } | |
19e6b90e | 3343 | } |
cecf136e | 3344 | |
19e6b90e L |
3345 | /* Set num_debug_info_entries here so that it can be used to check if |
3346 | we need to process .debug_loc and .debug_ranges sections. */ | |
3347 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3348 | && num_debug_info_entries == 0 |
3349 | && ! do_types) | |
82b1b41b | 3350 | { |
b4eb7656 | 3351 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
3352 | num_debug_info_entries = alloc_num_debug_info_entries; |
3353 | else | |
3354 | num_debug_info_entries = num_units; | |
3355 | } | |
cecf136e | 3356 | |
19e6b90e | 3357 | if (!do_loc) |
467c65bc | 3358 | printf ("\n"); |
cecf136e | 3359 | |
d85bf2ba | 3360 | return TRUE; |
19e6b90e L |
3361 | } |
3362 | ||
3363 | /* Locate and scan the .debug_info section in the file and record the pointer | |
3364 | sizes and offsets for the compilation units in it. Usually an executable | |
3365 | will have just one pointer size, but this is not guaranteed, and so we try | |
3366 | not to make any assumptions. Returns zero upon failure, or the number of | |
3367 | compilation units upon success. */ | |
3368 | ||
3369 | static unsigned int | |
3370 | load_debug_info (void * file) | |
3371 | { | |
1febe64d | 3372 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 3373 | section then do not bother to repeat the task. */ |
cc86f28f | 3374 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
3375 | return 0; |
3376 | ||
19e6b90e L |
3377 | /* If we already have the information there is nothing else to do. */ |
3378 | if (num_debug_info_entries > 0) | |
3379 | return num_debug_info_entries; | |
3380 | ||
341f9135 | 3381 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 3382 | (void) load_cu_tu_indexes (file); |
341f9135 | 3383 | |
dda8d76d | 3384 | if (load_debug_section_with_follow (info, file) |
d85bf2ba | 3385 | && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE)) |
19e6b90e | 3386 | return num_debug_info_entries; |
82b1b41b | 3387 | |
dda8d76d | 3388 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 3389 | && process_debug_info (&debug_displays [info_dwo].section, file, |
d85bf2ba | 3390 | abbrev_dwo, TRUE, FALSE)) |
4723351a | 3391 | return num_debug_info_entries; |
1febe64d | 3392 | |
cc86f28f | 3393 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 3394 | return 0; |
19e6b90e L |
3395 | } |
3396 | ||
b40bf0a2 NC |
3397 | /* Read a DWARF .debug_line section header starting at DATA. |
3398 | Upon success returns an updated DATA pointer and the LINFO | |
3399 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
3400 | Otherwise returns NULL. */ | |
19e6b90e | 3401 | |
b40bf0a2 NC |
3402 | static unsigned char * |
3403 | read_debug_line_header (struct dwarf_section * section, | |
3404 | unsigned char * data, | |
3405 | unsigned char * end, | |
3406 | DWARF2_Internal_LineInfo * linfo, | |
3407 | unsigned char ** end_of_sequence) | |
3408 | { | |
3409 | unsigned char *hdrptr; | |
b40bf0a2 | 3410 | unsigned int initial_length_size; |
77145576 | 3411 | unsigned char address_size, segment_selector_size; |
19e6b90e | 3412 | |
b40bf0a2 NC |
3413 | /* Extract information from the Line Number Program Header. |
3414 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 3415 | hdrptr = data; |
19e6b90e | 3416 | |
b40bf0a2 NC |
3417 | /* Get and check the length of the block. */ |
3418 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 3419 | |
b40bf0a2 | 3420 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
3421 | { |
3422 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 3423 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 3424 | linfo->li_offset_size = 8; |
f41e4712 NC |
3425 | initial_length_size = 12; |
3426 | } | |
3427 | else | |
3428 | { | |
77145576 | 3429 | linfo->li_offset_size = 4; |
f41e4712 NC |
3430 | initial_length_size = 4; |
3431 | } | |
19e6b90e | 3432 | |
b40bf0a2 | 3433 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 3434 | { |
8fcc61b4 NC |
3435 | /* If the length field has a relocation against it, then we should |
3436 | not complain if it is inaccurate (and probably negative). This | |
3437 | happens in object files when the .debug_line section is actually | |
3438 | comprised of several different .debug_line.* sections, (some of | |
3439 | which may be removed by linker garbage collection), and a relocation | |
3440 | is used to compute the correct length once that is done. */ | |
77145576 | 3441 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 3442 | { |
8fcc61b4 | 3443 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
3444 | } |
3445 | else | |
3446 | { | |
8fcc61b4 NC |
3447 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
3448 | (long) linfo->li_length); | |
b40bf0a2 NC |
3449 | return NULL; |
3450 | } | |
f41e4712 | 3451 | } |
19e6b90e | 3452 | |
b40bf0a2 NC |
3453 | /* Get and check the version number. */ |
3454 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
3455 | ||
3456 | if (linfo->li_version != 2 | |
3457 | && linfo->li_version != 3 | |
77145576 JK |
3458 | && linfo->li_version != 4 |
3459 | && linfo->li_version != 5) | |
f41e4712 | 3460 | { |
77145576 JK |
3461 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
3462 | "is currently supported.\n")); | |
b40bf0a2 | 3463 | return NULL; |
f41e4712 | 3464 | } |
19e6b90e | 3465 | |
77145576 JK |
3466 | if (linfo->li_version >= 5) |
3467 | { | |
3468 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
3469 | ||
3470 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
3471 | if (segment_selector_size != 0) | |
3472 | { | |
3473 | warn (_("The %s section contains " | |
3474 | "unsupported segment selector size: %d.\n"), | |
3475 | section->name, segment_selector_size); | |
3476 | return 0; | |
3477 | } | |
3478 | } | |
3479 | ||
3480 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
3481 | linfo->li_offset_size, end); | |
b40bf0a2 | 3482 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 3483 | |
b40bf0a2 | 3484 | if (linfo->li_version >= 4) |
f41e4712 | 3485 | { |
b40bf0a2 | 3486 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 3487 | |
b40bf0a2 | 3488 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
3489 | { |
3490 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 3491 | return NULL; |
a233b20c | 3492 | } |
f41e4712 NC |
3493 | } |
3494 | else | |
b40bf0a2 | 3495 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 3496 | |
b40bf0a2 | 3497 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 3498 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
3499 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
3500 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 3501 | |
b40bf0a2 | 3502 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 3503 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
3504 | if (* end_of_sequence > end) |
3505 | { | |
4c219c2e AM |
3506 | warn (_("Line length %s extends beyond end of section\n"), |
3507 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
3508 | * end_of_sequence = end; |
3509 | return NULL; | |
3510 | } | |
3511 | ||
b40bf0a2 NC |
3512 | return hdrptr; |
3513 | } | |
19e6b90e | 3514 | |
77145576 | 3515 | static unsigned char * |
dda8d76d NC |
3516 | display_formatted_table (unsigned char * data, |
3517 | unsigned char * start, | |
3518 | unsigned char * end, | |
3519 | const DWARF2_Internal_LineInfo * linfo, | |
3520 | struct dwarf_section * section, | |
7b8d9e8c | 3521 | bfd_boolean is_dir) |
77145576 JK |
3522 | { |
3523 | unsigned char *format_start, format_count, *format, formati; | |
3524 | dwarf_vma data_count, datai; | |
3525 | unsigned int bytes_read, namepass, last_entry = 0; | |
3526 | ||
3527 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
3528 | format_start = data; | |
3529 | for (formati = 0; formati < format_count; formati++) | |
3530 | { | |
3531 | read_uleb128 (data, & bytes_read, end); | |
3532 | data += bytes_read; | |
3533 | read_uleb128 (data, & bytes_read, end); | |
3534 | data += bytes_read; | |
3535 | if (data == end) | |
3536 | { | |
7b8d9e8c AM |
3537 | if (is_dir) |
3538 | warn (_("Corrupt directory format table entry\n")); | |
3539 | else | |
3540 | warn (_("Corrupt file name format table entry\n")); | |
77145576 JK |
3541 | return data; |
3542 | } | |
3543 | } | |
3544 | ||
3545 | data_count = read_uleb128 (data, & bytes_read, end); | |
3546 | data += bytes_read; | |
3547 | if (data == end) | |
3548 | { | |
7b8d9e8c AM |
3549 | if (is_dir) |
3550 | warn (_("Corrupt directory list\n")); | |
3551 | else | |
3552 | warn (_("Corrupt file name list\n")); | |
77145576 JK |
3553 | return data; |
3554 | } | |
3555 | ||
3556 | if (data_count == 0) | |
3557 | { | |
7b8d9e8c AM |
3558 | if (is_dir) |
3559 | printf (_("\n The Directory Table is empty.\n")); | |
3560 | else | |
3561 | printf (_("\n The File Name Table is empty.\n")); | |
77145576 JK |
3562 | return data; |
3563 | } | |
3564 | ||
7b8d9e8c AM |
3565 | if (is_dir) |
3566 | printf (_("\n The Directory Table (offset 0x%lx):\n"), | |
3567 | (long) (data - start)); | |
3568 | else | |
3569 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
3570 | (long) (data - start)); | |
77145576 JK |
3571 | |
3572 | printf (_(" Entry")); | |
3573 | /* Delay displaying name as the last entry for better screen layout. */ | |
3574 | for (namepass = 0; namepass < 2; namepass++) | |
3575 | { | |
3576 | format = format_start; | |
3577 | for (formati = 0; formati < format_count; formati++) | |
3578 | { | |
3579 | dwarf_vma content_type; | |
3580 | ||
3581 | content_type = read_uleb128 (format, & bytes_read, end); | |
3582 | format += bytes_read; | |
3583 | if ((content_type == DW_LNCT_path) == (namepass == 1)) | |
3584 | switch (content_type) | |
3585 | { | |
3586 | case DW_LNCT_path: | |
3587 | printf (_("\tName")); | |
3588 | break; | |
3589 | case DW_LNCT_directory_index: | |
3590 | printf (_("\tDir")); | |
3591 | break; | |
3592 | case DW_LNCT_timestamp: | |
3593 | printf (_("\tTime")); | |
3594 | break; | |
3595 | case DW_LNCT_size: | |
3596 | printf (_("\tSize")); | |
3597 | break; | |
3598 | case DW_LNCT_MD5: | |
3599 | printf (_("\tMD5")); | |
3600 | break; | |
3601 | default: | |
3602 | printf (_("\t(Unknown format content type %s)"), | |
3603 | dwarf_vmatoa ("u", content_type)); | |
3604 | } | |
3605 | read_uleb128 (format, & bytes_read, end); | |
3606 | format += bytes_read; | |
3607 | } | |
3608 | } | |
3609 | putchar ('\n'); | |
3610 | ||
3611 | for (datai = 0; datai < data_count; datai++) | |
3612 | { | |
3613 | unsigned char *datapass = data; | |
3614 | ||
3615 | printf (" %d", last_entry++); | |
3616 | /* Delay displaying name as the last entry for better screen layout. */ | |
3617 | for (namepass = 0; namepass < 2; namepass++) | |
3618 | { | |
3619 | format = format_start; | |
3620 | data = datapass; | |
3621 | for (formati = 0; formati < format_count; formati++) | |
3622 | { | |
3623 | dwarf_vma content_type, form; | |
3624 | ||
3625 | content_type = read_uleb128 (format, & bytes_read, end); | |
3626 | format += bytes_read; | |
3627 | form = read_uleb128 (format, & bytes_read, end); | |
3628 | format += bytes_read; | |
3629 | data = read_and_display_attr_value (0, form, 0, data, end, 0, 0, | |
3630 | linfo->li_offset_size, | |
3631 | linfo->li_version, NULL, | |
3632 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
3633 | section, NULL, '\t'); | |
3634 | } | |
3635 | } | |
3636 | if (data == end) | |
3637 | { | |
7b8d9e8c AM |
3638 | if (is_dir) |
3639 | warn (_("Corrupt directory entries list\n")); | |
3640 | else | |
3641 | warn (_("Corrupt file name entries list\n")); | |
77145576 JK |
3642 | return data; |
3643 | } | |
3644 | putchar ('\n'); | |
3645 | } | |
3646 | return data; | |
3647 | } | |
3648 | ||
b40bf0a2 | 3649 | static int |
dda8d76d NC |
3650 | display_debug_lines_raw (struct dwarf_section * section, |
3651 | unsigned char * data, | |
3652 | unsigned char * end, | |
3653 | void * file) | |
b40bf0a2 NC |
3654 | { |
3655 | unsigned char *start = section->start; | |
ba8826a8 | 3656 | int verbose_view = 0; |
19e6b90e | 3657 | |
dda8d76d | 3658 | introduce (section, TRUE); |
19e6b90e | 3659 | |
b40bf0a2 NC |
3660 | while (data < end) |
3661 | { | |
3662 | static DWARF2_Internal_LineInfo saved_linfo; | |
3663 | DWARF2_Internal_LineInfo linfo; | |
3664 | unsigned char *standard_opcodes; | |
3665 | unsigned char *end_of_sequence; | |
fe59e83d | 3666 | int i; |
19e6b90e | 3667 | |
4925cdd7 NC |
3668 | if (const_strneq (section->name, ".debug_line.") |
3669 | /* Note: the following does not apply to .debug_line.dwo sections. | |
3670 | These are full debug_line sections. */ | |
3671 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 3672 | { |
b40bf0a2 NC |
3673 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
3674 | section containing just the Line Number Statements. They are | |
3675 | created by the assembler and intended to be used alongside gcc's | |
3676 | -ffunction-sections command line option. When the linker's | |
3677 | garbage collection decides to discard a .text.<foo> section it | |
3678 | can then also discard the line number information in .debug_line.<foo>. | |
3679 | ||
4925cdd7 | 3680 | Since the section is a fragment it does not have the details |
b40bf0a2 | 3681 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 3682 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
3683 | end_of_sequence = end; |
3684 | standard_opcodes = NULL; | |
3685 | linfo = saved_linfo; | |
058037d3 NC |
3686 | /* PR 17531: file: 0522b371. */ |
3687 | if (linfo.li_line_range == 0) | |
3688 | { | |
1306a742 | 3689 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
3690 | return 0; |
3691 | } | |
b40bf0a2 | 3692 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3693 | } |
19e6b90e L |
3694 | else |
3695 | { | |
b40bf0a2 | 3696 | unsigned char * hdrptr; |
19e6b90e | 3697 | |
b40bf0a2 NC |
3698 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
3699 | & end_of_sequence)) == NULL) | |
3700 | return 0; | |
19e6b90e | 3701 | |
b40bf0a2 NC |
3702 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
3703 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
3704 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
77ef8654 | 3705 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
3706 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
3707 | if (linfo.li_version >= 4) | |
3708 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
3709 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
3710 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
3711 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
3712 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 3713 | |
0a9d414a NC |
3714 | /* PR 17512: file: 1665-6428-0.004. */ |
3715 | if (linfo.li_line_range == 0) | |
3716 | { | |
3717 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
3718 | linfo.li_line_range = 1; | |
3719 | } | |
77ef8654 | 3720 | |
b40bf0a2 | 3721 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3722 | |
b40bf0a2 NC |
3723 | /* Display the contents of the Opcodes table. */ |
3724 | standard_opcodes = hdrptr; | |
19e6b90e | 3725 | |
6937bb54 NC |
3726 | /* PR 17512: file: 002-417945-0.004. */ |
3727 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
3728 | { | |
3729 | warn (_("Line Base extends beyond end of section\n")); | |
3730 | return 0; | |
3731 | } | |
3732 | ||
b40bf0a2 | 3733 | printf (_("\n Opcodes:\n")); |
19e6b90e | 3734 | |
b40bf0a2 | 3735 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
3736 | printf (ngettext (" Opcode %d has %d arg\n", |
3737 | " Opcode %d has %d args\n", | |
3738 | standard_opcodes[i - 1]), | |
3739 | i, standard_opcodes[i - 1]); | |
19e6b90e | 3740 | |
b40bf0a2 NC |
3741 | /* Display the contents of the Directory table. */ |
3742 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 3743 | |
77145576 | 3744 | if (linfo.li_version >= 5) |
b40bf0a2 | 3745 | { |
dda8d76d | 3746 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 3747 | |
77145576 | 3748 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 3749 | TRUE); |
77145576 | 3750 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 3751 | FALSE); |
77145576 JK |
3752 | } |
3753 | else | |
3754 | { | |
3755 | if (*data == 0) | |
3756 | printf (_("\n The Directory Table is empty.\n")); | |
3757 | else | |
a233b20c | 3758 | { |
77145576 | 3759 | unsigned int last_dir_entry = 0; |
6937bb54 | 3760 | |
77145576 JK |
3761 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
3762 | (long)(data - start)); | |
19e6b90e | 3763 | |
77145576 JK |
3764 | while (data < end && *data != 0) |
3765 | { | |
3766 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 3767 | |
77145576 JK |
3768 | data += strnlen ((char *) data, end - data) + 1; |
3769 | } | |
19e6b90e | 3770 | |
77145576 JK |
3771 | /* PR 17512: file: 002-132094-0.004. */ |
3772 | if (data >= end - 1) | |
3773 | break; | |
3774 | } | |
19e6b90e | 3775 | |
77145576 JK |
3776 | /* Skip the NUL at the end of the table. */ |
3777 | data++; | |
19e6b90e | 3778 | |
77145576 JK |
3779 | /* Display the contents of the File Name table. */ |
3780 | if (*data == 0) | |
3781 | printf (_("\n The File Name Table is empty.\n")); | |
3782 | else | |
3783 | { | |
3784 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
3785 | (long)(data - start)); | |
3786 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 3787 | |
77145576 | 3788 | while (data < end && *data != 0) |
b40bf0a2 | 3789 | { |
77145576 JK |
3790 | unsigned char *name; |
3791 | unsigned int bytes_read; | |
3792 | ||
3793 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
3794 | name = data; | |
3795 | data += strnlen ((char *) data, end - data) + 1; | |
3796 | ||
3797 | printf ("%s\t", | |
3798 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
3799 | data += bytes_read; | |
3800 | printf ("%s\t", | |
3801 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
3802 | data += bytes_read; | |
3803 | printf ("%s\t", | |
3804 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
3805 | data += bytes_read; | |
3806 | printf ("%.*s\n", (int)(end - name), name); | |
3807 | ||
3808 | if (data == end) | |
3809 | { | |
3810 | warn (_("Corrupt file name table entry\n")); | |
3811 | break; | |
3812 | } | |
b40bf0a2 | 3813 | } |
a233b20c | 3814 | } |
77145576 JK |
3815 | |
3816 | /* Skip the NUL at the end of the table. */ | |
3817 | data++; | |
b40bf0a2 | 3818 | } |
19e6b90e | 3819 | |
b40bf0a2 NC |
3820 | putchar ('\n'); |
3821 | saved_linfo = linfo; | |
3822 | } | |
19e6b90e | 3823 | |
b40bf0a2 NC |
3824 | /* Now display the statements. */ |
3825 | if (data >= end_of_sequence) | |
3826 | printf (_(" No Line Number Statements.\n")); | |
3827 | else | |
3828 | { | |
3829 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 3830 | |
b40bf0a2 NC |
3831 | while (data < end_of_sequence) |
3832 | { | |
3833 | unsigned char op_code; | |
3834 | dwarf_signed_vma adv; | |
3835 | dwarf_vma uladv; | |
3836 | unsigned int bytes_read; | |
19e6b90e | 3837 | |
fe59e83d CC |
3838 | printf (" [0x%08lx]", (long)(data - start)); |
3839 | ||
b40bf0a2 | 3840 | op_code = *data++; |
19e6b90e | 3841 | |
b40bf0a2 | 3842 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 3843 | { |
b40bf0a2 NC |
3844 | op_code -= linfo.li_opcode_base; |
3845 | uladv = (op_code / linfo.li_line_range); | |
3846 | if (linfo.li_max_ops_per_insn == 1) | |
3847 | { | |
3848 | uladv *= linfo.li_min_insn_length; | |
3849 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
3850 | if (uladv) |
3851 | state_machine_regs.view = 0; | |
b40bf0a2 | 3852 | printf (_(" Special opcode %d: " |
ba8826a8 | 3853 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 3854 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
3855 | dwarf_vmatoa ("x", state_machine_regs.address), |
3856 | verbose_view && uladv | |
3857 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3858 | } |
3859 | else | |
3860 | { | |
ba8826a8 AO |
3861 | unsigned addrdelta |
3862 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
3863 | / linfo.li_max_ops_per_insn) |
3864 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
3865 | |
3866 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
3867 | state_machine_regs.op_index |
3868 | = (state_machine_regs.op_index + uladv) | |
3869 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
3870 | if (addrdelta) |
3871 | state_machine_regs.view = 0; | |
b40bf0a2 | 3872 | printf (_(" Special opcode %d: " |
ba8826a8 | 3873 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
3874 | op_code, dwarf_vmatoa ("u", uladv), |
3875 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
3876 | state_machine_regs.op_index, |
3877 | verbose_view && addrdelta | |
3878 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3879 | } |
3880 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
3881 | state_machine_regs.line += adv; | |
ba8826a8 | 3882 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 3883 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
3884 | if (verbose_view || state_machine_regs.view) |
3885 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
3886 | else | |
3887 | putchar ('\n'); | |
3888 | state_machine_regs.view++; | |
19e6b90e | 3889 | } |
b40bf0a2 NC |
3890 | else switch (op_code) |
3891 | { | |
3892 | case DW_LNS_extended_op: | |
3893 | data += process_extended_line_op (data, linfo.li_default_is_stmt, end); | |
3894 | break; | |
3895 | ||
3896 | case DW_LNS_copy: | |
ba8826a8 AO |
3897 | printf (_(" Copy")); |
3898 | if (verbose_view || state_machine_regs.view) | |
3899 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
3900 | else | |
3901 | putchar ('\n'); | |
3902 | state_machine_regs.view++; | |
b40bf0a2 NC |
3903 | break; |
3904 | ||
3905 | case DW_LNS_advance_pc: | |
3906 | uladv = read_uleb128 (data, & bytes_read, end); | |
3907 | data += bytes_read; | |
3908 | if (linfo.li_max_ops_per_insn == 1) | |
3909 | { | |
3910 | uladv *= linfo.li_min_insn_length; | |
3911 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
3912 | if (uladv) |
3913 | state_machine_regs.view = 0; | |
3914 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
b40bf0a2 | 3915 | dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
3916 | dwarf_vmatoa ("x", state_machine_regs.address), |
3917 | verbose_view && uladv | |
3918 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3919 | } |
3920 | else | |
3921 | { | |
ba8826a8 AO |
3922 | unsigned addrdelta |
3923 | = ((state_machine_regs.op_index + uladv) | |
3924 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 3925 | * linfo.li_min_insn_length; |
ba8826a8 AO |
3926 | state_machine_regs.address |
3927 | += addrdelta; | |
b40bf0a2 NC |
3928 | state_machine_regs.op_index |
3929 | = (state_machine_regs.op_index + uladv) | |
3930 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
3931 | if (addrdelta) |
3932 | state_machine_regs.view = 0; | |
3933 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
b40bf0a2 NC |
3934 | dwarf_vmatoa ("u", uladv), |
3935 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
3936 | state_machine_regs.op_index, |
3937 | verbose_view && addrdelta | |
3938 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3939 | } |
3940 | break; | |
3941 | ||
3942 | case DW_LNS_advance_line: | |
3943 | adv = read_sleb128 (data, & bytes_read, end); | |
3944 | data += bytes_read; | |
3945 | state_machine_regs.line += adv; | |
3946 | printf (_(" Advance Line by %s to %d\n"), | |
3947 | dwarf_vmatoa ("d", adv), | |
3948 | state_machine_regs.line); | |
3949 | break; | |
3950 | ||
3951 | case DW_LNS_set_file: | |
3952 | adv = read_uleb128 (data, & bytes_read, end); | |
3953 | data += bytes_read; | |
3954 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
3955 | dwarf_vmatoa ("d", adv)); | |
3956 | state_machine_regs.file = adv; | |
3957 | break; | |
3958 | ||
3959 | case DW_LNS_set_column: | |
3960 | uladv = read_uleb128 (data, & bytes_read, end); | |
3961 | data += bytes_read; | |
3962 | printf (_(" Set column to %s\n"), | |
3963 | dwarf_vmatoa ("u", uladv)); | |
3964 | state_machine_regs.column = uladv; | |
3965 | break; | |
3966 | ||
3967 | case DW_LNS_negate_stmt: | |
3968 | adv = state_machine_regs.is_stmt; | |
3969 | adv = ! adv; | |
3970 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
3971 | state_machine_regs.is_stmt = adv; | |
3972 | break; | |
3973 | ||
3974 | case DW_LNS_set_basic_block: | |
3975 | printf (_(" Set basic block\n")); | |
3976 | state_machine_regs.basic_block = 1; | |
3977 | break; | |
3978 | ||
3979 | case DW_LNS_const_add_pc: | |
3980 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
3981 | if (linfo.li_max_ops_per_insn) | |
3982 | { | |
3983 | uladv *= linfo.li_min_insn_length; | |
3984 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
3985 | if (uladv) |
3986 | state_machine_regs.view = 0; | |
3987 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
b40bf0a2 | 3988 | dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
3989 | dwarf_vmatoa ("x", state_machine_regs.address), |
3990 | verbose_view && uladv | |
3991 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
3992 | } |
3993 | else | |
3994 | { | |
ba8826a8 AO |
3995 | unsigned addrdelta |
3996 | = ((state_machine_regs.op_index + uladv) | |
3997 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 3998 | * linfo.li_min_insn_length; |
ba8826a8 AO |
3999 | state_machine_regs.address |
4000 | += addrdelta; | |
b40bf0a2 NC |
4001 | state_machine_regs.op_index |
4002 | = (state_machine_regs.op_index + uladv) | |
4003 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4004 | if (addrdelta) |
4005 | state_machine_regs.view = 0; | |
4006 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
b40bf0a2 NC |
4007 | dwarf_vmatoa ("u", uladv), |
4008 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4009 | state_machine_regs.op_index, |
4010 | verbose_view && addrdelta | |
4011 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4012 | } |
4013 | break; | |
4014 | ||
4015 | case DW_LNS_fixed_advance_pc: | |
4016 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4017 | state_machine_regs.address += uladv; | |
4018 | state_machine_regs.op_index = 0; | |
4019 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4020 | dwarf_vmatoa ("u", uladv), | |
4021 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
ba8826a8 | 4022 | /* Do NOT reset view. */ |
b40bf0a2 NC |
4023 | break; |
4024 | ||
4025 | case DW_LNS_set_prologue_end: | |
4026 | printf (_(" Set prologue_end to true\n")); | |
4027 | break; | |
4028 | ||
4029 | case DW_LNS_set_epilogue_begin: | |
4030 | printf (_(" Set epilogue_begin to true\n")); | |
4031 | break; | |
4032 | ||
4033 | case DW_LNS_set_isa: | |
4034 | uladv = read_uleb128 (data, & bytes_read, end); | |
4035 | data += bytes_read; | |
4036 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4037 | break; | |
4038 | ||
4039 | default: | |
4040 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4041 | ||
4042 | if (standard_opcodes != NULL) | |
4043 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4044 | { | |
4045 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
4046 | &bytes_read, end)), | |
4047 | i == 1 ? "" : ", "); | |
4048 | data += bytes_read; | |
4049 | } | |
4050 | putchar ('\n'); | |
4051 | break; | |
4052 | } | |
19e6b90e | 4053 | } |
b40bf0a2 | 4054 | putchar ('\n'); |
19e6b90e | 4055 | } |
19e6b90e L |
4056 | } |
4057 | ||
4058 | return 1; | |
4059 | } | |
4060 | ||
a262ae96 NC |
4061 | typedef struct |
4062 | { | |
467c65bc NC |
4063 | unsigned char *name; |
4064 | unsigned int directory_index; | |
4065 | unsigned int modification_date; | |
4066 | unsigned int length; | |
a262ae96 NC |
4067 | } File_Entry; |
4068 | ||
4069 | /* Output a decoded representation of the .debug_line section. */ | |
4070 | ||
4071 | static int | |
dda8d76d NC |
4072 | display_debug_lines_decoded (struct dwarf_section * section, |
4073 | unsigned char * data, | |
4074 | unsigned char * end, | |
4075 | void * fileptr) | |
a262ae96 | 4076 | { |
b40bf0a2 NC |
4077 | static DWARF2_Internal_LineInfo saved_linfo; |
4078 | ||
dda8d76d | 4079 | introduce (section, FALSE); |
a262ae96 NC |
4080 | |
4081 | while (data < end) | |
4082 | { | |
4083 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4084 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4085 | unsigned char *standard_opcodes; |
4086 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4087 | int i; |
4088 | File_Entry *file_table = NULL; | |
143a3db0 | 4089 | unsigned int n_files = 0; |
a262ae96 | 4090 | unsigned char **directory_table = NULL; |
77145576 | 4091 | dwarf_vma n_directories = 0; |
a262ae96 | 4092 | |
4925cdd7 NC |
4093 | if (const_strneq (section->name, ".debug_line.") |
4094 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4095 | These are full debug_line sections. */ | |
4096 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4097 | { |
4925cdd7 | 4098 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4099 | end_of_sequence = end; |
4100 | standard_opcodes = NULL; | |
4101 | linfo = saved_linfo; | |
058037d3 NC |
4102 | /* PR 17531: file: 0522b371. */ |
4103 | if (linfo.li_line_range == 0) | |
4104 | { | |
1306a742 | 4105 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4106 | return 0; |
4107 | } | |
b40bf0a2 | 4108 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4109 | } |
a262ae96 | 4110 | else |
b4eb7656 | 4111 | { |
b40bf0a2 | 4112 | unsigned char *hdrptr; |
a262ae96 | 4113 | |
b40bf0a2 NC |
4114 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4115 | & end_of_sequence)) == NULL) | |
a233b20c | 4116 | return 0; |
0c588247 | 4117 | |
058037d3 NC |
4118 | /* PR 17531: file: 0522b371. */ |
4119 | if (linfo.li_line_range == 0) | |
4120 | { | |
4121 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4122 | linfo.li_line_range = 1; | |
4123 | } | |
b40bf0a2 | 4124 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4125 | |
b40bf0a2 NC |
4126 | /* Save a pointer to the contents of the Opcodes table. */ |
4127 | standard_opcodes = hdrptr; | |
a262ae96 | 4128 | |
b40bf0a2 NC |
4129 | /* Traverse the Directory table just to count entries. */ |
4130 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4131 | /* PR 20440 */ |
4132 | if (data >= end) | |
4133 | { | |
4134 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4135 | linfo.li_opcode_base); | |
4136 | return 0; | |
4137 | } | |
4138 | ||
77145576 | 4139 | if (linfo.li_version >= 5) |
b40bf0a2 | 4140 | { |
77145576 JK |
4141 | unsigned char *format_start, format_count, *format; |
4142 | dwarf_vma formati, entryi; | |
4143 | unsigned int bytes_read; | |
a262ae96 | 4144 | |
dda8d76d | 4145 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4146 | |
4147 | /* Skip directories format. */ | |
4148 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
4149 | format_start = data; | |
4150 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4151 | { |
77145576 JK |
4152 | read_uleb128 (data, & bytes_read, end); |
4153 | data += bytes_read; | |
4154 | read_uleb128 (data, & bytes_read, end); | |
4155 | data += bytes_read; | |
b40bf0a2 | 4156 | } |
a262ae96 | 4157 | |
77145576 JK |
4158 | n_directories = read_uleb128 (data, & bytes_read, end); |
4159 | data += bytes_read; | |
4160 | if (data == end) | |
d8024a91 | 4161 | { |
77145576 | 4162 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4163 | break; |
4164 | } | |
4165 | ||
b40bf0a2 NC |
4166 | directory_table = (unsigned char **) |
4167 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 4168 | |
77145576 | 4169 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 4170 | { |
77145576 | 4171 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 4172 | |
77145576 JK |
4173 | format = format_start; |
4174 | for (formati = 0; formati < format_count; formati++) | |
4175 | { | |
4176 | dwarf_vma content_type, form; | |
4177 | dwarf_vma uvalue; | |
4178 | ||
4179 | content_type = read_uleb128 (format, & bytes_read, end); | |
4180 | format += bytes_read; | |
4181 | form = read_uleb128 (format, & bytes_read, end); | |
4182 | format += bytes_read; | |
4183 | if (data == end) | |
4184 | { | |
4185 | warn (_("Corrupt directories list\n")); | |
4186 | break; | |
4187 | } | |
4188 | switch (content_type) | |
4189 | { | |
4190 | case DW_LNCT_path: | |
4191 | switch (form) | |
4192 | { | |
4193 | case DW_FORM_string: | |
4194 | *pathp = data; | |
4195 | break; | |
4196 | case DW_FORM_line_strp: | |
4197 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4198 | end); | |
4199 | /* Remove const by the cast. */ | |
4200 | *pathp = (unsigned char *) | |
4201 | fetch_indirect_line_string (uvalue); | |
4202 | break; | |
4203 | } | |
4204 | break; | |
4205 | } | |
4206 | data = read_and_display_attr_value (0, form, 0, data, end, | |
4207 | 0, 0, | |
4208 | linfo.li_offset_size, | |
4209 | linfo.li_version, | |
4210 | NULL, 1, section, | |
4211 | NULL, '\t'); | |
4212 | } | |
4213 | if (data == end) | |
4214 | { | |
4215 | warn (_("Corrupt directories list\n")); | |
4216 | break; | |
4217 | } | |
4218 | } | |
a262ae96 | 4219 | |
77145576 JK |
4220 | /* Skip files format. */ |
4221 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
4222 | format_start = data; | |
4223 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4224 | { |
b40bf0a2 NC |
4225 | read_uleb128 (data, & bytes_read, end); |
4226 | data += bytes_read; | |
4227 | read_uleb128 (data, & bytes_read, end); | |
4228 | data += bytes_read; | |
b40bf0a2 | 4229 | } |
a262ae96 | 4230 | |
77145576 JK |
4231 | n_files = read_uleb128 (data, & bytes_read, end); |
4232 | data += bytes_read; | |
4233 | if (data == end) | |
d8024a91 | 4234 | { |
77145576 | 4235 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
4236 | break; |
4237 | } | |
4238 | ||
77145576 JK |
4239 | file_table = (File_Entry *) xcalloc (1, n_files |
4240 | * sizeof (File_Entry)); | |
a262ae96 | 4241 | |
77145576 | 4242 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 4243 | { |
77145576 | 4244 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 4245 | |
77145576 JK |
4246 | format = format_start; |
4247 | for (formati = 0; formati < format_count; formati++) | |
4248 | { | |
4249 | dwarf_vma content_type, form; | |
4250 | dwarf_vma uvalue; | |
4251 | ||
4252 | content_type = read_uleb128 (format, & bytes_read, end); | |
4253 | format += bytes_read; | |
4254 | form = read_uleb128 (format, & bytes_read, end); | |
4255 | format += bytes_read; | |
4256 | if (data == end) | |
4257 | { | |
4258 | warn (_("Corrupt file name list\n")); | |
4259 | break; | |
4260 | } | |
4261 | switch (content_type) | |
4262 | { | |
4263 | case DW_LNCT_path: | |
4264 | switch (form) | |
4265 | { | |
4266 | case DW_FORM_string: | |
4267 | file->name = data; | |
4268 | break; | |
4269 | case DW_FORM_line_strp: | |
4270 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4271 | end); | |
4272 | /* Remove const by the cast. */ | |
4273 | file->name = (unsigned char *) | |
4274 | fetch_indirect_line_string (uvalue); | |
4275 | break; | |
4276 | } | |
4277 | break; | |
4278 | case DW_LNCT_directory_index: | |
4279 | switch (form) | |
4280 | { | |
4281 | case DW_FORM_data1: | |
4282 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
4283 | end); | |
4284 | break; | |
4285 | case DW_FORM_data2: | |
4286 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
4287 | end); | |
4288 | break; | |
4289 | case DW_FORM_udata: | |
4290 | file->directory_index = read_uleb128 (data, NULL, | |
4291 | end); | |
4292 | break; | |
4293 | } | |
4294 | break; | |
4295 | } | |
4296 | data = read_and_display_attr_value (0, form, 0, data, end, | |
4297 | 0, 0, | |
4298 | linfo.li_offset_size, | |
4299 | linfo.li_version, | |
4300 | NULL, 1, section, | |
4301 | NULL, '\t'); | |
4302 | } | |
4303 | if (data == end) | |
4304 | { | |
4305 | warn (_("Corrupt file name list\n")); | |
4306 | break; | |
4307 | } | |
4308 | } | |
4309 | } | |
4310 | else | |
4311 | { | |
4312 | if (*data != 0) | |
b40bf0a2 | 4313 | { |
77145576 JK |
4314 | unsigned char *ptr_directory_table = data; |
4315 | ||
4316 | while (data < end && *data != 0) | |
4317 | { | |
4318 | data += strnlen ((char *) data, end - data) + 1; | |
4319 | n_directories++; | |
4320 | } | |
4321 | ||
4322 | /* PR 20440 */ | |
4323 | if (data >= end) | |
4324 | { | |
4325 | warn (_("directory table ends unexpectedly\n")); | |
4326 | n_directories = 0; | |
4327 | break; | |
4328 | } | |
4329 | ||
4330 | /* Go through the directory table again to save the directories. */ | |
4331 | directory_table = (unsigned char **) | |
4332 | xmalloc (n_directories * sizeof (unsigned char *)); | |
4333 | ||
4334 | i = 0; | |
4335 | while (*ptr_directory_table != 0) | |
4336 | { | |
4337 | directory_table[i] = ptr_directory_table; | |
4338 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
4339 | ptr_directory_table - end) + 1; | |
4340 | i++; | |
4341 | } | |
b40bf0a2 | 4342 | } |
77145576 JK |
4343 | /* Skip the NUL at the end of the table. */ |
4344 | data++; | |
4345 | ||
4346 | /* Traverse the File Name table just to count the entries. */ | |
4347 | if (data < end && *data != 0) | |
b40bf0a2 | 4348 | { |
77145576 JK |
4349 | unsigned char *ptr_file_name_table = data; |
4350 | ||
4351 | while (data < end && *data != 0) | |
db9537d2 | 4352 | { |
77145576 JK |
4353 | unsigned int bytes_read; |
4354 | ||
4355 | /* Skip Name, directory index, last modification time and length | |
4356 | of file. */ | |
4357 | data += strnlen ((char *) data, end - data) + 1; | |
4358 | read_uleb128 (data, & bytes_read, end); | |
4359 | data += bytes_read; | |
4360 | read_uleb128 (data, & bytes_read, end); | |
4361 | data += bytes_read; | |
4362 | read_uleb128 (data, & bytes_read, end); | |
4363 | data += bytes_read; | |
4364 | ||
4365 | n_files++; | |
db9537d2 | 4366 | } |
a262ae96 | 4367 | |
77145576 JK |
4368 | if (data >= end) |
4369 | { | |
4370 | warn (_("file table ends unexpectedly\n")); | |
4371 | n_files = 0; | |
4372 | break; | |
4373 | } | |
4374 | ||
4375 | /* Go through the file table again to save the strings. */ | |
4376 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 4377 | |
77145576 JK |
4378 | i = 0; |
4379 | while (*ptr_file_name_table != 0) | |
4380 | { | |
4381 | unsigned int bytes_read; | |
4382 | ||
4383 | file_table[i].name = ptr_file_name_table; | |
4384 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
4385 | end - ptr_file_name_table) + 1; | |
4386 | ||
4387 | /* We are not interested in directory, time or size. */ | |
4388 | file_table[i].directory_index = read_uleb128 (ptr_file_name_table, | |
4389 | & bytes_read, end); | |
4390 | ptr_file_name_table += bytes_read; | |
4391 | file_table[i].modification_date = read_uleb128 (ptr_file_name_table, | |
4392 | & bytes_read, end); | |
4393 | ptr_file_name_table += bytes_read; | |
4394 | file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end); | |
4395 | ptr_file_name_table += bytes_read; | |
4396 | i++; | |
4397 | } | |
4398 | i = 0; | |
b40bf0a2 | 4399 | } |
77145576 JK |
4400 | |
4401 | /* Skip the NUL at the end of the table. */ | |
4402 | data++; | |
b40bf0a2 | 4403 | } |
cc5914eb | 4404 | |
77145576 | 4405 | /* Print the Compilation Unit's name and a header. */ |
f082820d AM |
4406 | if (file_table == NULL) |
4407 | ; | |
4408 | else if (directory_table == NULL) | |
4409 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
4410 | else |
4411 | { | |
4412 | unsigned int ix = file_table[0].directory_index; | |
4413 | const char *directory; | |
4414 | ||
4415 | if (ix == 0) | |
4416 | directory = "."; | |
4417 | /* PR 20439 */ | |
4418 | else if (n_directories == 0) | |
4419 | directory = _("<unknown>"); | |
4420 | else if (ix > n_directories) | |
4421 | { | |
4422 | warn (_("directory index %u > number of directories %s\n"), | |
4423 | ix, dwarf_vmatoa ("u", n_directories)); | |
4424 | directory = _("<corrupt>"); | |
4425 | } | |
4426 | else | |
4427 | directory = (char *) directory_table[ix - 1]; | |
4428 | ||
4429 | if (do_wide || strlen (directory) < 76) | |
4430 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
4431 | else | |
4432 | printf ("%s:\n", file_table[0].name); | |
77145576 | 4433 | } |
a262ae96 | 4434 | |
17f6ade2 | 4435 | printf (_("File name Line number Starting address View Stmt\n")); |
b40bf0a2 NC |
4436 | saved_linfo = linfo; |
4437 | } | |
a262ae96 NC |
4438 | |
4439 | /* This loop iterates through the Dwarf Line Number Program. */ | |
4440 | while (data < end_of_sequence) | |
b4eb7656 | 4441 | { |
a262ae96 | 4442 | unsigned char op_code; |
ba8826a8 | 4443 | int xop; |
b4eb7656 AM |
4444 | int adv; |
4445 | unsigned long int uladv; | |
4446 | unsigned int bytes_read; | |
4447 | int is_special_opcode = 0; | |
a262ae96 | 4448 | |
b4eb7656 | 4449 | op_code = *data++; |
ba8826a8 | 4450 | xop = op_code; |
a262ae96 | 4451 | |
b4eb7656 | 4452 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 4453 | { |
91d6fa6a | 4454 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
4455 | uladv = (op_code / linfo.li_line_range); |
4456 | if (linfo.li_max_ops_per_insn == 1) | |
4457 | { | |
4458 | uladv *= linfo.li_min_insn_length; | |
4459 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4460 | if (uladv) |
4461 | state_machine_regs.view = 0; | |
a233b20c JJ |
4462 | } |
4463 | else | |
4464 | { | |
ba8826a8 AO |
4465 | unsigned addrdelta |
4466 | = ((state_machine_regs.op_index + uladv) | |
4467 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4468 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4469 | state_machine_regs.address |
4470 | += addrdelta; | |
a233b20c JJ |
4471 | state_machine_regs.op_index |
4472 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 4473 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
4474 | if (addrdelta) |
4475 | state_machine_regs.view = 0; | |
a233b20c | 4476 | } |
a262ae96 | 4477 | |
b4eb7656 AM |
4478 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
4479 | state_machine_regs.line += adv; | |
4480 | is_special_opcode = 1; | |
ba8826a8 | 4481 | /* Increment view after printing this row. */ |
b4eb7656 AM |
4482 | } |
4483 | else switch (op_code) | |
b40bf0a2 NC |
4484 | { |
4485 | case DW_LNS_extended_op: | |
4486 | { | |
4487 | unsigned int ext_op_code_len; | |
4488 | unsigned char ext_op_code; | |
4489 | unsigned char *op_code_data = data; | |
4490 | ||
4491 | ext_op_code_len = read_uleb128 (op_code_data, &bytes_read, | |
4492 | end_of_sequence); | |
4493 | op_code_data += bytes_read; | |
4494 | ||
4495 | if (ext_op_code_len == 0) | |
4496 | { | |
f41e4712 | 4497 | warn (_("Badly formed extended line op encountered!\n")); |
b40bf0a2 NC |
4498 | break; |
4499 | } | |
4500 | ext_op_code_len += bytes_read; | |
4501 | ext_op_code = *op_code_data++; | |
ba8826a8 AO |
4502 | xop = ext_op_code; |
4503 | xop = -xop; | |
b40bf0a2 NC |
4504 | |
4505 | switch (ext_op_code) | |
4506 | { | |
4507 | case DW_LNE_end_sequence: | |
ba8826a8 | 4508 | /* Reset stuff after printing this row. */ |
b40bf0a2 NC |
4509 | break; |
4510 | case DW_LNE_set_address: | |
4511 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
87bc83b3 CC |
4512 | op_code_data, |
4513 | ext_op_code_len - bytes_read - 1, | |
b40bf0a2 NC |
4514 | end); |
4515 | state_machine_regs.op_index = 0; | |
ba8826a8 | 4516 | state_machine_regs.view = 0; |
b40bf0a2 NC |
4517 | break; |
4518 | case DW_LNE_define_file: | |
4519 | { | |
4520 | file_table = (File_Entry *) xrealloc | |
4521 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
4522 | ||
4523 | ++state_machine_regs.last_file_entry; | |
4524 | /* Source file name. */ | |
4525 | file_table[n_files].name = op_code_data; | |
4526 | op_code_data += strlen ((char *) op_code_data) + 1; | |
4527 | /* Directory index. */ | |
4528 | file_table[n_files].directory_index = | |
4529 | read_uleb128 (op_code_data, & bytes_read, | |
4530 | end_of_sequence); | |
4531 | op_code_data += bytes_read; | |
4532 | /* Last modification time. */ | |
4533 | file_table[n_files].modification_date = | |
4534 | read_uleb128 (op_code_data, & bytes_read, | |
4535 | end_of_sequence); | |
4536 | op_code_data += bytes_read; | |
4537 | /* File length. */ | |
4538 | file_table[n_files].length = | |
4539 | read_uleb128 (op_code_data, & bytes_read, | |
4540 | end_of_sequence); | |
4541 | ||
4542 | n_files++; | |
4543 | break; | |
4544 | } | |
4545 | case DW_LNE_set_discriminator: | |
4546 | case DW_LNE_HP_set_sequence: | |
4547 | /* Simply ignored. */ | |
4548 | break; | |
4549 | ||
4550 | default: | |
4551 | printf (_("UNKNOWN (%u): length %d\n"), | |
4552 | ext_op_code, ext_op_code_len - bytes_read); | |
4553 | break; | |
4554 | } | |
4555 | data += ext_op_code_len; | |
4556 | break; | |
4557 | } | |
4558 | case DW_LNS_copy: | |
ba8826a8 | 4559 | /* Increment view after printing this row. */ |
b40bf0a2 NC |
4560 | break; |
4561 | ||
4562 | case DW_LNS_advance_pc: | |
4563 | uladv = read_uleb128 (data, & bytes_read, end); | |
4564 | data += bytes_read; | |
4565 | if (linfo.li_max_ops_per_insn == 1) | |
4566 | { | |
4567 | uladv *= linfo.li_min_insn_length; | |
4568 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4569 | if (uladv) |
4570 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4571 | } |
4572 | else | |
4573 | { | |
ba8826a8 AO |
4574 | unsigned addrdelta |
4575 | = ((state_machine_regs.op_index + uladv) | |
4576 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4577 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4578 | state_machine_regs.address |
4579 | += addrdelta; | |
b40bf0a2 NC |
4580 | state_machine_regs.op_index |
4581 | = (state_machine_regs.op_index + uladv) | |
4582 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4583 | if (addrdelta) |
4584 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4585 | } |
4586 | break; | |
4587 | ||
4588 | case DW_LNS_advance_line: | |
4589 | adv = read_sleb128 (data, & bytes_read, end); | |
4590 | data += bytes_read; | |
4591 | state_machine_regs.line += adv; | |
4592 | break; | |
4593 | ||
4594 | case DW_LNS_set_file: | |
4595 | adv = read_uleb128 (data, & bytes_read, end); | |
4596 | data += bytes_read; | |
4597 | state_machine_regs.file = adv; | |
4598 | ||
db9537d2 NC |
4599 | { |
4600 | unsigned file = state_machine_regs.file - 1; | |
4601 | unsigned dir; | |
4602 | ||
4603 | if (file_table == NULL || n_files == 0) | |
4604 | printf (_("\n [Use file table entry %d]\n"), file); | |
4605 | /* PR 20439 */ | |
4606 | else if (file >= n_files) | |
4607 | { | |
4608 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
4609 | printf (_("\n <over large file table index %u>"), file); | |
4610 | } | |
4611 | else if ((dir = file_table[file].directory_index) == 0) | |
4612 | /* If directory index is 0, that means current directory. */ | |
4613 | printf ("\n./%s:[++]\n", file_table[file].name); | |
4614 | else if (directory_table == NULL || n_directories == 0) | |
4615 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
4616 | file_table[file].name, dir); | |
4617 | /* PR 20439 */ | |
4618 | else if (dir > n_directories) | |
4619 | { | |
77145576 JK |
4620 | warn (_("directory index %u > number of directories %s\n"), |
4621 | dir, dwarf_vmatoa ("u", n_directories)); | |
db9537d2 NC |
4622 | printf (_("\n <over large directory table entry %u>\n"), dir); |
4623 | } | |
4624 | else | |
4625 | printf ("\n%s/%s:\n", | |
4626 | /* The directory index starts counting at 1. */ | |
4627 | directory_table[dir - 1], file_table[file].name); | |
4628 | } | |
b40bf0a2 NC |
4629 | break; |
4630 | ||
4631 | case DW_LNS_set_column: | |
4632 | uladv = read_uleb128 (data, & bytes_read, end); | |
4633 | data += bytes_read; | |
4634 | state_machine_regs.column = uladv; | |
4635 | break; | |
4636 | ||
4637 | case DW_LNS_negate_stmt: | |
4638 | adv = state_machine_regs.is_stmt; | |
4639 | adv = ! adv; | |
4640 | state_machine_regs.is_stmt = adv; | |
4641 | break; | |
4642 | ||
4643 | case DW_LNS_set_basic_block: | |
4644 | state_machine_regs.basic_block = 1; | |
4645 | break; | |
4646 | ||
4647 | case DW_LNS_const_add_pc: | |
4648 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4649 | if (linfo.li_max_ops_per_insn == 1) | |
4650 | { | |
4651 | uladv *= linfo.li_min_insn_length; | |
4652 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4653 | if (uladv) |
4654 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4655 | } |
4656 | else | |
4657 | { | |
ba8826a8 AO |
4658 | unsigned addrdelta |
4659 | = ((state_machine_regs.op_index + uladv) | |
4660 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4661 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4662 | state_machine_regs.address |
4663 | += addrdelta; | |
b40bf0a2 NC |
4664 | state_machine_regs.op_index |
4665 | = (state_machine_regs.op_index + uladv) | |
4666 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4667 | if (addrdelta) |
4668 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4669 | } |
4670 | break; | |
4671 | ||
4672 | case DW_LNS_fixed_advance_pc: | |
4673 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4674 | state_machine_regs.address += uladv; | |
4675 | state_machine_regs.op_index = 0; | |
ba8826a8 | 4676 | /* Do NOT reset view. */ |
b40bf0a2 NC |
4677 | break; |
4678 | ||
4679 | case DW_LNS_set_prologue_end: | |
4680 | break; | |
4681 | ||
4682 | case DW_LNS_set_epilogue_begin: | |
4683 | break; | |
4684 | ||
4685 | case DW_LNS_set_isa: | |
4686 | uladv = read_uleb128 (data, & bytes_read, end); | |
4687 | data += bytes_read; | |
4688 | printf (_(" Set ISA to %lu\n"), uladv); | |
4689 | break; | |
4690 | ||
4691 | default: | |
4692 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4693 | ||
4694 | if (standard_opcodes != NULL) | |
4695 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4696 | { | |
4697 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
4698 | &bytes_read, end)), | |
4699 | i == 1 ? "" : ", "); | |
4700 | data += bytes_read; | |
4701 | } | |
4702 | putchar ('\n'); | |
4703 | break; | |
4704 | } | |
a262ae96 | 4705 | |
b4eb7656 AM |
4706 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
4707 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
4708 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
4709 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
4710 | { |
4711 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
4712 | char *fileName; | |
4713 | char *newFileName = NULL; | |
4714 | size_t fileNameLength; | |
b40bf0a2 NC |
4715 | |
4716 | if (file_table) | |
db9537d2 NC |
4717 | { |
4718 | unsigned indx = state_machine_regs.file - 1; | |
4719 | /* PR 20439 */ | |
4720 | if (indx >= n_files) | |
4721 | { | |
4722 | warn (_("corrupt file index %u encountered\n"), indx); | |
4723 | fileName = _("<corrupt>"); | |
4724 | } | |
4725 | else | |
4726 | fileName = (char *) file_table[indx].name; | |
4727 | } | |
b40bf0a2 | 4728 | else |
db9537d2 | 4729 | fileName = _("<unknown>"); |
b40bf0a2 NC |
4730 | |
4731 | fileNameLength = strlen (fileName); | |
a262ae96 | 4732 | |
b4eb7656 AM |
4733 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
4734 | { | |
4735 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
4736 | /* Truncate file name */ | |
4737 | strncpy (newFileName, | |
4738 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
4739 | MAX_FILENAME_LENGTH + 1); | |
4740 | } | |
4741 | else | |
4742 | { | |
4743 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
4744 | strncpy (newFileName, fileName, fileNameLength + 1); | |
4745 | } | |
4746 | ||
4747 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) | |
4748 | { | |
a233b20c | 4749 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 4750 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 4751 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4752 | state_machine_regs.address); |
4753 | else | |
ba8826a8 | 4754 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 4755 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4756 | state_machine_regs.address, |
4757 | state_machine_regs.op_index); | |
b4eb7656 AM |
4758 | } |
4759 | else | |
4760 | { | |
a233b20c | 4761 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 4762 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 4763 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4764 | state_machine_regs.address); |
4765 | else | |
ba8826a8 | 4766 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 4767 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4768 | state_machine_regs.address, |
4769 | state_machine_regs.op_index); | |
b4eb7656 | 4770 | } |
a262ae96 | 4771 | |
ba8826a8 | 4772 | if (state_machine_regs.view) |
17f6ade2 | 4773 | printf (" %6u", state_machine_regs.view); |
ba8826a8 | 4774 | else |
17f6ade2 JD |
4775 | printf (" "); |
4776 | ||
4777 | if (state_machine_regs.is_stmt) | |
4778 | printf (" x"); | |
4779 | ||
4780 | putchar ('\n'); | |
ba8826a8 AO |
4781 | state_machine_regs.view++; |
4782 | ||
4783 | if (xop == -DW_LNE_end_sequence) | |
4784 | { | |
4785 | reset_state_machine (linfo.li_default_is_stmt); | |
4786 | putchar ('\n'); | |
4787 | } | |
a262ae96 | 4788 | |
b4eb7656 AM |
4789 | free (newFileName); |
4790 | } | |
4791 | } | |
b40bf0a2 NC |
4792 | |
4793 | if (file_table) | |
4794 | { | |
4795 | free (file_table); | |
4796 | file_table = NULL; | |
4797 | n_files = 0; | |
4798 | } | |
4799 | ||
4800 | if (directory_table) | |
4801 | { | |
4802 | free (directory_table); | |
4803 | directory_table = NULL; | |
4804 | n_directories = 0; | |
4805 | } | |
4806 | ||
a262ae96 NC |
4807 | putchar ('\n'); |
4808 | } | |
4809 | ||
4810 | return 1; | |
4811 | } | |
4812 | ||
4813 | static int | |
77145576 | 4814 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
4815 | { |
4816 | unsigned char *data = section->start; | |
4817 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
4818 | int retValRaw = 1; |
4819 | int retValDecoded = 1; | |
a262ae96 | 4820 | |
008f4c78 NC |
4821 | if (do_debug_lines == 0) |
4822 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
4823 | ||
4cb93e3b | 4824 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 4825 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 4826 | |
4cb93e3b | 4827 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
77145576 | 4828 | retValDecoded = display_debug_lines_decoded (section, data, end, file); |
a262ae96 | 4829 | |
4cb93e3b | 4830 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
4831 | return 0; |
4832 | ||
4833 | return 1; | |
4834 | } | |
4835 | ||
6e3d6dc1 NC |
4836 | static debug_info * |
4837 | find_debug_info_for_offset (unsigned long offset) | |
4838 | { | |
4839 | unsigned int i; | |
4840 | ||
4841 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
4842 | return NULL; | |
4843 | ||
4844 | for (i = 0; i < num_debug_info_entries; i++) | |
4845 | if (debug_information[i].cu_offset == offset) | |
4846 | return debug_information + i; | |
4847 | ||
4848 | return NULL; | |
4849 | } | |
4850 | ||
459d52c8 DE |
4851 | static const char * |
4852 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
4853 | { | |
4854 | /* See gdb/gdb-index.h. */ | |
4855 | static const char * const kinds[] = | |
4856 | { | |
4857 | N_ ("no info"), | |
4858 | N_ ("type"), | |
4859 | N_ ("variable"), | |
4860 | N_ ("function"), | |
4861 | N_ ("other"), | |
4862 | N_ ("unused5"), | |
4863 | N_ ("unused6"), | |
4864 | N_ ("unused7") | |
4865 | }; | |
4866 | ||
4867 | return _ (kinds[kind]); | |
4868 | } | |
4869 | ||
19e6b90e | 4870 | static int |
459d52c8 DE |
4871 | display_debug_pubnames_worker (struct dwarf_section *section, |
4872 | void *file ATTRIBUTE_UNUSED, | |
4873 | int is_gnu) | |
19e6b90e | 4874 | { |
91d6fa6a | 4875 | DWARF2_Internal_PubNames names; |
19e6b90e L |
4876 | unsigned char *start = section->start; |
4877 | unsigned char *end = start + section->size; | |
4878 | ||
6e3d6dc1 NC |
4879 | /* It does not matter if this load fails, |
4880 | we test for that later on. */ | |
4881 | load_debug_info (file); | |
4882 | ||
dda8d76d | 4883 | introduce (section, FALSE); |
19e6b90e L |
4884 | |
4885 | while (start < end) | |
4886 | { | |
4887 | unsigned char *data; | |
e98fdf1a | 4888 | unsigned long sec_off; |
bf5117e3 | 4889 | unsigned int offset_size, initial_length_size; |
19e6b90e | 4890 | |
e98fdf1a | 4891 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 4892 | if (names.pn_length == 0xffffffff) |
19e6b90e | 4893 | { |
e98fdf1a | 4894 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e L |
4895 | offset_size = 8; |
4896 | initial_length_size = 12; | |
4897 | } | |
4898 | else | |
4899 | { | |
4900 | offset_size = 4; | |
4901 | initial_length_size = 4; | |
4902 | } | |
4903 | ||
e98fdf1a AM |
4904 | sec_off = start - section->start; |
4905 | if (sec_off + names.pn_length < sec_off | |
4906 | || sec_off + names.pn_length > section->size) | |
4907 | { | |
4908 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
4909 | section->name, | |
4910 | sec_off - initial_length_size, | |
4911 | dwarf_vmatoa ("x", names.pn_length)); | |
4912 | break; | |
4913 | } | |
4914 | ||
4915 | data = start; | |
4916 | start += names.pn_length; | |
4917 | ||
0c588247 NC |
4918 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
4919 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
4920 | |
4921 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
4922 | && num_debug_info_entries > 0 | |
91d6fa6a | 4923 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 4924 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 4925 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 4926 | |
0c588247 | 4927 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 4928 | |
058037d3 NC |
4929 | printf (_(" Length: %ld\n"), |
4930 | (long) names.pn_length); | |
4931 | printf (_(" Version: %d\n"), | |
4932 | names.pn_version); | |
4933 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
4934 | (unsigned long) names.pn_offset); | |
4935 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
4936 | (long) names.pn_size); | |
19e6b90e | 4937 | |
91d6fa6a | 4938 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
4939 | { |
4940 | static int warned = 0; | |
4941 | ||
4942 | if (! warned) | |
4943 | { | |
4944 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
4945 | warned = 1; | |
4946 | } | |
4947 | ||
4948 | continue; | |
4949 | } | |
4950 | ||
459d52c8 DE |
4951 | if (is_gnu) |
4952 | printf (_("\n Offset Kind Name\n")); | |
4953 | else | |
4954 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 4955 | |
e98fdf1a | 4956 | while (1) |
19e6b90e | 4957 | { |
f41e4712 | 4958 | bfd_size_type maxprint; |
e98fdf1a | 4959 | dwarf_vma offset; |
f41e4712 | 4960 | |
0c588247 | 4961 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e | 4962 | |
e98fdf1a AM |
4963 | if (offset == 0) |
4964 | break; | |
b4eb7656 | 4965 | |
e98fdf1a AM |
4966 | data += offset_size; |
4967 | if (data >= end) | |
4968 | break; | |
4969 | maxprint = (end - data) - 1; | |
f41e4712 | 4970 | |
e98fdf1a AM |
4971 | if (is_gnu) |
4972 | { | |
4973 | unsigned int kind_data; | |
4974 | gdb_index_symbol_kind kind; | |
4975 | const char *kind_name; | |
4976 | int is_static; | |
4977 | ||
4978 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
4979 | data++; | |
4980 | maxprint --; | |
4981 | /* GCC computes the kind as the upper byte in the CU index | |
4982 | word, and then right shifts it by the CU index size. | |
4983 | Left shift KIND to where the gdb-index.h accessor macros | |
4984 | can use it. */ | |
4985 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
4986 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
4987 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
4988 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
4989 | printf (" %-6lx %s,%-10s %.*s\n", | |
4990 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
4991 | kind_name, (int) maxprint, data); | |
19e6b90e | 4992 | } |
e98fdf1a AM |
4993 | else |
4994 | printf (" %-6lx\t%.*s\n", | |
4995 | (unsigned long) offset, (int) maxprint, data); | |
4996 | ||
4997 | data += strnlen ((char *) data, maxprint) + 1; | |
4998 | if (data >= end) | |
4999 | break; | |
19e6b90e | 5000 | } |
19e6b90e L |
5001 | } |
5002 | ||
5003 | printf ("\n"); | |
5004 | return 1; | |
5005 | } | |
5006 | ||
459d52c8 DE |
5007 | static int |
5008 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5009 | { | |
5010 | return display_debug_pubnames_worker (section, file, 0); | |
5011 | } | |
5012 | ||
5013 | static int | |
5014 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5015 | { | |
5016 | return display_debug_pubnames_worker (section, file, 1); | |
5017 | } | |
5018 | ||
19e6b90e L |
5019 | static int |
5020 | display_debug_macinfo (struct dwarf_section *section, | |
5021 | void *file ATTRIBUTE_UNUSED) | |
5022 | { | |
5023 | unsigned char *start = section->start; | |
5024 | unsigned char *end = start + section->size; | |
5025 | unsigned char *curr = start; | |
5026 | unsigned int bytes_read; | |
5027 | enum dwarf_macinfo_record_type op; | |
5028 | ||
dda8d76d | 5029 | introduce (section, FALSE); |
19e6b90e L |
5030 | |
5031 | while (curr < end) | |
5032 | { | |
5033 | unsigned int lineno; | |
0c588247 | 5034 | const unsigned char *string; |
19e6b90e | 5035 | |
3f5e193b | 5036 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5037 | curr++; |
5038 | ||
5039 | switch (op) | |
5040 | { | |
5041 | case DW_MACINFO_start_file: | |
5042 | { | |
5043 | unsigned int filenum; | |
5044 | ||
f6f0e17b | 5045 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5046 | curr += bytes_read; |
f6f0e17b | 5047 | filenum = read_uleb128 (curr, & bytes_read, end); |
19e6b90e L |
5048 | curr += bytes_read; |
5049 | ||
5050 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), | |
5051 | lineno, filenum); | |
5052 | } | |
5053 | break; | |
5054 | ||
5055 | case DW_MACINFO_end_file: | |
5056 | printf (_(" DW_MACINFO_end_file\n")); | |
5057 | break; | |
5058 | ||
5059 | case DW_MACINFO_define: | |
f6f0e17b | 5060 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5061 | curr += bytes_read; |
0c588247 NC |
5062 | string = curr; |
5063 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5064 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
5065 | lineno, string); | |
5066 | break; | |
5067 | ||
5068 | case DW_MACINFO_undef: | |
f6f0e17b | 5069 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5070 | curr += bytes_read; |
0c588247 NC |
5071 | string = curr; |
5072 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5073 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
5074 | lineno, string); | |
5075 | break; | |
5076 | ||
5077 | case DW_MACINFO_vendor_ext: | |
5078 | { | |
5079 | unsigned int constant; | |
5080 | ||
f6f0e17b | 5081 | constant = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5082 | curr += bytes_read; |
0c588247 NC |
5083 | string = curr; |
5084 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5085 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
5086 | constant, string); | |
5087 | } | |
5088 | break; | |
5089 | } | |
5090 | } | |
5091 | ||
5092 | return 1; | |
5093 | } | |
5094 | ||
4ccf1e31 JJ |
5095 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5096 | filename and dirname corresponding to file name table entry with index | |
5097 | FILEIDX. Return NULL on failure. */ | |
5098 | ||
5099 | static unsigned char * | |
f6f0e17b NC |
5100 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5101 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5102 | unsigned char **dir_name) |
5103 | { | |
5104 | struct dwarf_section *section = &debug_displays [line].section; | |
5105 | unsigned char *hdrptr, *dirtable, *file_name; | |
5106 | unsigned int offset_size, initial_length_size; | |
5107 | unsigned int version, opcode_base, bytes_read; | |
5108 | dwarf_vma length, diridx; | |
f6f0e17b | 5109 | const unsigned char * end; |
4ccf1e31 JJ |
5110 | |
5111 | *dir_name = NULL; | |
5112 | if (section->start == NULL | |
5113 | || line_offset >= section->size | |
5114 | || fileidx == 0) | |
5115 | return NULL; | |
5116 | ||
5117 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5118 | end = section->start + section->size; |
0c588247 NC |
5119 | |
5120 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5121 | if (length == 0xffffffff) |
5122 | { | |
5123 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5124 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
5125 | offset_size = 8; |
5126 | initial_length_size = 12; | |
5127 | } | |
5128 | else | |
5129 | { | |
5130 | offset_size = 4; | |
5131 | initial_length_size = 4; | |
5132 | } | |
e98fdf1a AM |
5133 | if (length + initial_length_size < length |
5134 | || length + initial_length_size > section->size) | |
4ccf1e31 | 5135 | return NULL; |
0c588247 NC |
5136 | |
5137 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5138 | if (version != 2 && version != 3 && version != 4) |
5139 | return NULL; | |
5140 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5141 | if (version >= 4) | |
5142 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5143 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5144 | |
5145 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
5146 | if (opcode_base == 0) |
5147 | return NULL; | |
0c588247 | 5148 | |
4ccf1e31 | 5149 | hdrptr += opcode_base - 1; |
5c1c468d NC |
5150 | if (hdrptr >= end) |
5151 | return NULL; | |
5152 | ||
4ccf1e31 JJ |
5153 | dirtable = hdrptr; |
5154 | /* Skip over dirname table. */ | |
5155 | while (*hdrptr != '\0') | |
5c1c468d NC |
5156 | { |
5157 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; | |
5158 | if (hdrptr >= end) | |
5159 | return NULL; | |
5160 | } | |
4ccf1e31 | 5161 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 5162 | |
4ccf1e31 | 5163 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 5164 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 5165 | { |
0c588247 | 5166 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
f6f0e17b | 5167 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 5168 | hdrptr += bytes_read; |
f6f0e17b | 5169 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 5170 | hdrptr += bytes_read; |
f6f0e17b | 5171 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
5172 | hdrptr += bytes_read; |
5173 | } | |
5c1c468d | 5174 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 5175 | return NULL; |
5c1c468d | 5176 | |
4ccf1e31 | 5177 | file_name = hdrptr; |
0c588247 | 5178 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
5c1c468d NC |
5179 | if (hdrptr >= end) |
5180 | return NULL; | |
f6f0e17b | 5181 | diridx = read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
5182 | if (diridx == 0) |
5183 | return file_name; | |
5c1c468d | 5184 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
0c588247 | 5185 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
5c1c468d | 5186 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
5187 | return NULL; |
5188 | *dir_name = dirtable; | |
5189 | return file_name; | |
5190 | } | |
5191 | ||
5192 | static int | |
5193 | display_debug_macro (struct dwarf_section *section, | |
5194 | void *file) | |
5195 | { | |
5196 | unsigned char *start = section->start; | |
5197 | unsigned char *end = start + section->size; | |
5198 | unsigned char *curr = start; | |
5199 | unsigned char *extended_op_buf[256]; | |
5200 | unsigned int bytes_read; | |
5201 | ||
dda8d76d NC |
5202 | load_debug_section_with_follow (str, file); |
5203 | load_debug_section_with_follow (line, file); | |
4ccf1e31 | 5204 | |
dda8d76d | 5205 | introduce (section, FALSE); |
4ccf1e31 JJ |
5206 | |
5207 | while (curr < end) | |
5208 | { | |
5209 | unsigned int lineno, version, flags; | |
5210 | unsigned int offset_size = 4; | |
0c588247 | 5211 | const unsigned char *string; |
4ccf1e31 JJ |
5212 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
5213 | unsigned char **extended_ops = NULL; | |
5214 | ||
0c588247 | 5215 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 5216 | if (version != 4 && version != 5) |
4ccf1e31 | 5217 | { |
7a7e1061 | 5218 | error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"), |
4ccf1e31 JJ |
5219 | section->name); |
5220 | return 0; | |
5221 | } | |
5222 | ||
0c588247 | 5223 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
5224 | if (flags & 1) |
5225 | offset_size = 8; | |
5226 | printf (_(" Offset: 0x%lx\n"), | |
5227 | (unsigned long) sec_offset); | |
5228 | printf (_(" Version: %d\n"), version); | |
5229 | printf (_(" Offset size: %d\n"), offset_size); | |
5230 | if (flags & 2) | |
5231 | { | |
0c588247 | 5232 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
5233 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
5234 | (unsigned long) line_offset); | |
5235 | } | |
5236 | if (flags & 4) | |
5237 | { | |
0c588247 | 5238 | unsigned int i, count, op; |
4ccf1e31 | 5239 | dwarf_vma nargs, n; |
0c588247 NC |
5240 | |
5241 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 5242 | |
4ccf1e31 JJ |
5243 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
5244 | extended_ops = extended_op_buf; | |
5245 | if (count) | |
5246 | { | |
5247 | printf (_(" Extension opcode arguments:\n")); | |
5248 | for (i = 0; i < count; i++) | |
5249 | { | |
0c588247 | 5250 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 5251 | extended_ops[op] = curr; |
f6f0e17b | 5252 | nargs = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
5253 | curr += bytes_read; |
5254 | if (nargs == 0) | |
7a7e1061 | 5255 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
5256 | else |
5257 | { | |
7a7e1061 | 5258 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
5259 | for (n = 0; n < nargs; n++) |
5260 | { | |
0c588247 NC |
5261 | unsigned int form; |
5262 | ||
5263 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
5264 | printf ("%s%s", get_FORM_name (form), |
5265 | n == nargs - 1 ? "\n" : ", "); | |
5266 | switch (form) | |
5267 | { | |
5268 | case DW_FORM_data1: | |
5269 | case DW_FORM_data2: | |
5270 | case DW_FORM_data4: | |
5271 | case DW_FORM_data8: | |
5272 | case DW_FORM_sdata: | |
5273 | case DW_FORM_udata: | |
5274 | case DW_FORM_block: | |
5275 | case DW_FORM_block1: | |
5276 | case DW_FORM_block2: | |
5277 | case DW_FORM_block4: | |
5278 | case DW_FORM_flag: | |
5279 | case DW_FORM_string: | |
5280 | case DW_FORM_strp: | |
5281 | case DW_FORM_sec_offset: | |
5282 | break; | |
5283 | default: | |
5284 | error (_("Invalid extension opcode form %s\n"), | |
5285 | get_FORM_name (form)); | |
5286 | return 0; | |
5287 | } | |
5288 | } | |
5289 | } | |
5290 | } | |
5291 | } | |
5292 | } | |
5293 | printf ("\n"); | |
5294 | ||
5295 | while (1) | |
5296 | { | |
5297 | unsigned int op; | |
5298 | ||
5299 | if (curr >= end) | |
5300 | { | |
5301 | error (_(".debug_macro section not zero terminated\n")); | |
5302 | return 0; | |
5303 | } | |
5304 | ||
0c588247 | 5305 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
5306 | if (op == 0) |
5307 | break; | |
5308 | ||
5309 | switch (op) | |
5310 | { | |
7a7e1061 | 5311 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
5312 | { |
5313 | unsigned int filenum; | |
5314 | unsigned char *file_name = NULL, *dir_name = NULL; | |
5315 | ||
f6f0e17b | 5316 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5317 | curr += bytes_read; |
f6f0e17b | 5318 | filenum = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
5319 | curr += bytes_read; |
5320 | ||
5321 | if ((flags & 2) == 0) | |
7a7e1061 | 5322 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
5323 | else |
5324 | file_name | |
5325 | = get_line_filename_and_dirname (line_offset, filenum, | |
5326 | &dir_name); | |
5327 | if (file_name == NULL) | |
7a7e1061 | 5328 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
5329 | lineno, filenum); |
5330 | else | |
7a7e1061 | 5331 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
5332 | lineno, filenum, |
5333 | dir_name != NULL ? (const char *) dir_name : "", | |
5334 | dir_name != NULL ? "/" : "", file_name); | |
5335 | } | |
5336 | break; | |
5337 | ||
7a7e1061 JK |
5338 | case DW_MACRO_end_file: |
5339 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
5340 | break; |
5341 | ||
7a7e1061 | 5342 | case DW_MACRO_define: |
f6f0e17b | 5343 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5344 | curr += bytes_read; |
0c588247 NC |
5345 | string = curr; |
5346 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5347 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5348 | lineno, string); |
5349 | break; | |
5350 | ||
7a7e1061 | 5351 | case DW_MACRO_undef: |
f6f0e17b | 5352 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5353 | curr += bytes_read; |
0c588247 NC |
5354 | string = curr; |
5355 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5356 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5357 | lineno, string); |
5358 | break; | |
5359 | ||
7a7e1061 | 5360 | case DW_MACRO_define_strp: |
f6f0e17b | 5361 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5362 | curr += bytes_read; |
0c588247 | 5363 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5364 | string = fetch_indirect_string (offset); |
7a7e1061 | 5365 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5366 | lineno, string); |
5367 | break; | |
5368 | ||
7a7e1061 | 5369 | case DW_MACRO_undef_strp: |
f6f0e17b | 5370 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5371 | curr += bytes_read; |
0c588247 | 5372 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5373 | string = fetch_indirect_string (offset); |
7a7e1061 | 5374 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5375 | lineno, string); |
5376 | break; | |
5377 | ||
7a7e1061 | 5378 | case DW_MACRO_import: |
0c588247 | 5379 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5380 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
5381 | (unsigned long) offset); |
5382 | break; | |
5383 | ||
7a7e1061 | 5384 | case DW_MACRO_define_sup: |
f6f0e17b | 5385 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 5386 | curr += bytes_read; |
0c588247 | 5387 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5388 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5389 | lineno, (unsigned long) offset); |
5390 | break; | |
5391 | ||
7a7e1061 | 5392 | case DW_MACRO_undef_sup: |
f6f0e17b | 5393 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 5394 | curr += bytes_read; |
0c588247 | 5395 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5396 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5397 | lineno, (unsigned long) offset); |
5398 | break; | |
5399 | ||
7a7e1061 | 5400 | case DW_MACRO_import_sup: |
0c588247 | 5401 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5402 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
5403 | (unsigned long) offset); |
5404 | break; | |
5405 | ||
4ccf1e31 JJ |
5406 | default: |
5407 | if (extended_ops == NULL || extended_ops[op] == NULL) | |
5408 | { | |
5409 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
5410 | return 0; | |
5411 | } | |
5412 | else | |
5413 | { | |
5414 | /* Skip over unhandled opcodes. */ | |
5415 | dwarf_vma nargs, n; | |
5416 | unsigned char *desc = extended_ops[op]; | |
f6f0e17b | 5417 | nargs = read_uleb128 (desc, &bytes_read, end); |
4ccf1e31 JJ |
5418 | desc += bytes_read; |
5419 | if (nargs == 0) | |
5420 | { | |
7a7e1061 | 5421 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
5422 | break; |
5423 | } | |
7a7e1061 | 5424 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
5425 | for (n = 0; n < nargs; n++) |
5426 | { | |
0c588247 NC |
5427 | int val; |
5428 | ||
77145576 | 5429 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 5430 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 5431 | curr |
77145576 | 5432 | = read_and_display_attr_value (0, val, 0, |
f6f0e17b | 5433 | curr, end, 0, 0, offset_size, |
341f9135 | 5434 | version, NULL, 0, NULL, |
ef0b5f1c | 5435 | NULL, ' '); |
4ccf1e31 JJ |
5436 | if (n != nargs - 1) |
5437 | printf (","); | |
5438 | } | |
5439 | printf ("\n"); | |
5440 | } | |
5441 | break; | |
5442 | } | |
5443 | } | |
5444 | ||
5445 | printf ("\n"); | |
b4eb7656 | 5446 | } |
4ccf1e31 JJ |
5447 | |
5448 | return 1; | |
5449 | } | |
5450 | ||
19e6b90e L |
5451 | static int |
5452 | display_debug_abbrev (struct dwarf_section *section, | |
5453 | void *file ATTRIBUTE_UNUSED) | |
5454 | { | |
5455 | abbrev_entry *entry; | |
5456 | unsigned char *start = section->start; | |
5457 | unsigned char *end = start + section->size; | |
5458 | ||
dda8d76d | 5459 | introduce (section, FALSE); |
19e6b90e L |
5460 | |
5461 | do | |
5462 | { | |
7282333f AM |
5463 | unsigned char *last; |
5464 | ||
19e6b90e L |
5465 | free_abbrevs (); |
5466 | ||
7282333f | 5467 | last = start; |
19e6b90e L |
5468 | start = process_abbrev_section (start, end); |
5469 | ||
5470 | if (first_abbrev == NULL) | |
5471 | continue; | |
5472 | ||
7282333f | 5473 | printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); |
19e6b90e L |
5474 | |
5475 | for (entry = first_abbrev; entry; entry = entry->next) | |
5476 | { | |
5477 | abbrev_attr *attr; | |
5478 | ||
cc5914eb | 5479 | printf (" %ld %s [%s]\n", |
19e6b90e L |
5480 | entry->entry, |
5481 | get_TAG_name (entry->tag), | |
5482 | entry->children ? _("has children") : _("no children")); | |
5483 | ||
5484 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
5485 | { |
5486 | printf (" %-18s %s", | |
5487 | get_AT_name (attr->attribute), | |
5488 | get_FORM_name (attr->form)); | |
5489 | if (attr->form == DW_FORM_implicit_const) | |
5490 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
5491 | putchar ('\n'); | |
5492 | } | |
19e6b90e L |
5493 | } |
5494 | } | |
5495 | while (start); | |
5496 | ||
5497 | printf ("\n"); | |
5498 | ||
5499 | return 1; | |
5500 | } | |
5501 | ||
42bcef4a AB |
5502 | /* Return true when ADDR is the maximum address, when addresses are |
5503 | POINTER_SIZE bytes long. */ | |
5504 | ||
5505 | static bfd_boolean | |
5506 | is_max_address (dwarf_vma addr, unsigned int pointer_size) | |
5507 | { | |
5508 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
5509 | return ((addr & mask) == mask); | |
5510 | } | |
5511 | ||
9f272209 AO |
5512 | /* Display a view pair list starting at *VSTART_PTR and ending at |
5513 | VLISTEND within SECTION. */ | |
5514 | ||
5515 | static void | |
5516 | display_view_pair_list (struct dwarf_section *section, | |
5517 | unsigned char **vstart_ptr, | |
5518 | unsigned int debug_info_entry, | |
5519 | unsigned char *vlistend) | |
5520 | { | |
5521 | unsigned char *vstart = *vstart_ptr; | |
5522 | unsigned char *section_end = section->start + section->size; | |
5523 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
5524 | ||
5525 | if (vlistend < section_end) | |
5526 | section_end = vlistend; | |
5527 | ||
5528 | putchar ('\n'); | |
5529 | ||
5530 | while (vstart < section_end) | |
5531 | { | |
5532 | dwarf_vma off = vstart - section->start; | |
5533 | dwarf_vma vbegin, vend; | |
5534 | ||
5535 | unsigned int bytes_read; | |
5536 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
5537 | vstart += bytes_read; | |
5538 | if (vstart == section_end) | |
5539 | { | |
5540 | vstart -= bytes_read; | |
5541 | break; | |
5542 | } | |
5543 | ||
5544 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
5545 | vstart += bytes_read; | |
5546 | ||
5547 | printf (" %8.8lx ", (unsigned long) off); | |
5548 | ||
5549 | print_dwarf_view (vbegin, pointer_size, 1); | |
5550 | print_dwarf_view (vend, pointer_size, 1); | |
5551 | printf (_("location view pair\n")); | |
5552 | } | |
5553 | ||
5554 | putchar ('\n'); | |
5555 | *vstart_ptr = vstart; | |
5556 | } | |
5557 | ||
4723351a CC |
5558 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
5559 | ||
5560 | static void | |
5561 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
5562 | unsigned char **start_ptr, |
5563 | unsigned int debug_info_entry, | |
359ca075 JK |
5564 | dwarf_vma offset, |
5565 | dwarf_vma base_address, | |
9f272209 | 5566 | unsigned char **vstart_ptr, |
b4eb7656 | 5567 | int has_frame_base) |
4723351a | 5568 | { |
9f272209 | 5569 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 5570 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
5571 | unsigned long cu_offset; |
5572 | unsigned int pointer_size; | |
5573 | unsigned int offset_size; | |
5574 | int dwarf_version; | |
4723351a CC |
5575 | |
5576 | dwarf_vma begin; | |
5577 | dwarf_vma end; | |
5578 | unsigned short length; | |
5579 | int need_frame_base; | |
5580 | ||
82b1b41b NC |
5581 | if (debug_info_entry >= num_debug_info_entries) |
5582 | { | |
5583 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
5584 | debug_info_entry); | |
5585 | return; | |
5586 | } | |
b4eb7656 | 5587 | |
82b1b41b NC |
5588 | cu_offset = debug_information [debug_info_entry].cu_offset; |
5589 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5590 | offset_size = debug_information [debug_info_entry].offset_size; | |
5591 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 5592 | |
f41e4712 NC |
5593 | if (pointer_size < 2 || pointer_size > 8) |
5594 | { | |
5595 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5596 | pointer_size, debug_info_entry); | |
5597 | return; | |
5598 | } | |
5599 | ||
4723351a CC |
5600 | while (1) |
5601 | { | |
359ca075 | 5602 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 5603 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 5604 | |
4723351a | 5605 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
5606 | { |
5607 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5608 | (unsigned long) offset); |
b4eb7656 AM |
5609 | break; |
5610 | } | |
4723351a | 5611 | |
359ca075 | 5612 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 5613 | |
0c588247 NC |
5614 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
5615 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 5616 | |
4723351a | 5617 | if (begin == 0 && end == 0) |
b4eb7656 | 5618 | { |
d1c4b12b NC |
5619 | /* PR 18374: In a object file we can have a location list that |
5620 | starts with a begin and end of 0 because there are relocations | |
5621 | that need to be applied to the addresses. Actually applying | |
5622 | the relocations now does not help as they will probably resolve | |
5623 | to 0, since the object file has not been fully linked. Real | |
5624 | end of list markers will not have any relocations against them. */ | |
5625 | if (! reloc_at (section, off) | |
5626 | && ! reloc_at (section, off + pointer_size)) | |
5627 | { | |
5628 | printf (_("<End of list>\n")); | |
5629 | break; | |
5630 | } | |
b4eb7656 | 5631 | } |
4723351a CC |
5632 | |
5633 | /* Check base address specifiers. */ | |
42bcef4a AB |
5634 | if (is_max_address (begin, pointer_size) |
5635 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
5636 | { |
5637 | base_address = end; | |
5638 | print_dwarf_vma (begin, pointer_size); | |
5639 | print_dwarf_vma (end, pointer_size); | |
5640 | printf (_("(base address)\n")); | |
5641 | continue; | |
5642 | } | |
4723351a | 5643 | |
9f272209 AO |
5644 | if (vstart) |
5645 | { | |
5646 | unsigned int bytes_read; | |
5647 | ||
5648 | off = offset + (vstart - *start_ptr); | |
5649 | ||
5650 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
5651 | vstart += bytes_read; | |
5652 | print_dwarf_view (vbegin, pointer_size, 1); | |
5653 | ||
5654 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
5655 | vstart += bytes_read; | |
5656 | print_dwarf_view (vend, pointer_size, 1); | |
5657 | ||
5658 | printf (_("views at %8.8lx for:\n %*s "), | |
5659 | (unsigned long) off, 8, ""); | |
5660 | } | |
5661 | ||
4723351a | 5662 | if (start + 2 > section_end) |
b4eb7656 AM |
5663 | { |
5664 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5665 | (unsigned long) offset); |
b4eb7656 AM |
5666 | break; |
5667 | } | |
4723351a | 5668 | |
0c588247 | 5669 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
5670 | |
5671 | if (start + length > section_end) | |
b4eb7656 AM |
5672 | { |
5673 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5674 | (unsigned long) offset); |
b4eb7656 AM |
5675 | break; |
5676 | } | |
4723351a CC |
5677 | |
5678 | print_dwarf_vma (begin + base_address, pointer_size); | |
5679 | print_dwarf_vma (end + base_address, pointer_size); | |
5680 | ||
5681 | putchar ('('); | |
5682 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
5683 | pointer_size, |
5684 | offset_size, | |
5685 | dwarf_version, | |
5686 | length, | |
5687 | cu_offset, section); | |
4723351a CC |
5688 | putchar (')'); |
5689 | ||
5690 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 5691 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 5692 | |
9f272209 | 5693 | if (begin == end && vbegin == vend) |
b4eb7656 | 5694 | fputs (_(" (start == end)"), stdout); |
9f272209 | 5695 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 5696 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
5697 | |
5698 | putchar ('\n'); | |
5699 | ||
5700 | start += length; | |
5701 | } | |
5702 | ||
5703 | *start_ptr = start; | |
9f272209 | 5704 | *vstart_ptr = vstart; |
4723351a CC |
5705 | } |
5706 | ||
77145576 JK |
5707 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
5708 | ||
5709 | static void | |
5710 | display_loclists_list (struct dwarf_section *section, | |
5711 | unsigned char **start_ptr, | |
5712 | unsigned int debug_info_entry, | |
5713 | dwarf_vma offset, | |
5714 | dwarf_vma base_address, | |
9f272209 | 5715 | unsigned char **vstart_ptr, |
77145576 JK |
5716 | int has_frame_base) |
5717 | { | |
9f272209 | 5718 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
5719 | unsigned char *section_end = section->start + section->size; |
5720 | unsigned long cu_offset; | |
5721 | unsigned int pointer_size; | |
5722 | unsigned int offset_size; | |
5723 | int dwarf_version; | |
5724 | unsigned int bytes_read; | |
5725 | ||
9dfd0db9 | 5726 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
5727 | dwarf_vma begin = -1, vbegin = -1; |
5728 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
5729 | dwarf_vma length; |
5730 | int need_frame_base; | |
5731 | ||
5732 | if (debug_info_entry >= num_debug_info_entries) | |
5733 | { | |
5734 | warn (_("No debug information available for " | |
5735 | "loclists lists of entry: %u\n"), | |
5736 | debug_info_entry); | |
5737 | return; | |
5738 | } | |
5739 | ||
5740 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
5741 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5742 | offset_size = debug_information [debug_info_entry].offset_size; | |
5743 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
5744 | ||
5745 | if (pointer_size < 2 || pointer_size > 8) | |
5746 | { | |
5747 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5748 | pointer_size, debug_info_entry); | |
5749 | return; | |
5750 | } | |
5751 | ||
5752 | while (1) | |
5753 | { | |
5754 | dwarf_vma off = offset + (start - *start_ptr); | |
5755 | enum dwarf_location_list_entry_type llet; | |
5756 | ||
5757 | if (start + 1 > section_end) | |
5758 | { | |
5759 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5760 | (unsigned long) offset); | |
5761 | break; | |
5762 | } | |
5763 | ||
5764 | printf (" %8.8lx ", (unsigned long) off); | |
5765 | ||
5766 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
5767 | ||
9f272209 AO |
5768 | if (vstart && llet == DW_LLE_offset_pair) |
5769 | { | |
5770 | off = offset + (vstart - *start_ptr); | |
5771 | ||
5772 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
5773 | vstart += bytes_read; | |
5774 | print_dwarf_view (vbegin, pointer_size, 1); | |
5775 | ||
5776 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
5777 | vstart += bytes_read; | |
5778 | print_dwarf_view (vend, pointer_size, 1); | |
5779 | ||
5780 | printf (_("views at %8.8lx for:\n %*s "), | |
5781 | (unsigned long) off, 8, ""); | |
5782 | } | |
5783 | ||
77145576 JK |
5784 | switch (llet) |
5785 | { | |
5786 | case DW_LLE_end_of_list: | |
5787 | printf (_("<End of list>\n")); | |
5788 | break; | |
5789 | case DW_LLE_offset_pair: | |
5790 | begin = read_uleb128 (start, &bytes_read, section_end); | |
5791 | start += bytes_read; | |
5792 | end = read_uleb128 (start, &bytes_read, section_end); | |
5793 | start += bytes_read; | |
5794 | break; | |
5795 | case DW_LLE_base_address: | |
5796 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
5797 | section_end); | |
5798 | print_dwarf_vma (base_address, pointer_size); | |
5799 | printf (_("(base address)\n")); | |
5800 | break; | |
9f272209 AO |
5801 | #ifdef DW_LLE_view_pair |
5802 | case DW_LLE_view_pair: | |
5803 | if (vstart) | |
5804 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
5805 | vbegin = read_uleb128 (start, &bytes_read, section_end); | |
5806 | start += bytes_read; | |
5807 | print_dwarf_view (vbegin, pointer_size, 1); | |
5808 | ||
5809 | vend = read_uleb128 (start, &bytes_read, section_end); | |
5810 | start += bytes_read; | |
5811 | print_dwarf_view (vend, pointer_size, 1); | |
5812 | ||
5813 | printf (_("views for:\n")); | |
5814 | continue; | |
5815 | #endif | |
77145576 JK |
5816 | default: |
5817 | error (_("Invalid location list entry type %d\n"), llet); | |
5818 | return; | |
5819 | } | |
5820 | if (llet == DW_LLE_end_of_list) | |
5821 | break; | |
5822 | if (llet != DW_LLE_offset_pair) | |
5823 | continue; | |
5824 | ||
5825 | if (start + 2 > section_end) | |
5826 | { | |
5827 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5828 | (unsigned long) offset); | |
5829 | break; | |
5830 | } | |
5831 | ||
5832 | length = read_uleb128 (start, &bytes_read, section_end); | |
5833 | start += bytes_read; | |
5834 | ||
5835 | print_dwarf_vma (begin + base_address, pointer_size); | |
5836 | print_dwarf_vma (end + base_address, pointer_size); | |
5837 | ||
5838 | putchar ('('); | |
5839 | need_frame_base = decode_location_expression (start, | |
5840 | pointer_size, | |
5841 | offset_size, | |
5842 | dwarf_version, | |
5843 | length, | |
5844 | cu_offset, section); | |
5845 | putchar (')'); | |
5846 | ||
5847 | if (need_frame_base && !has_frame_base) | |
5848 | printf (_(" [without DW_AT_frame_base]")); | |
5849 | ||
9f272209 | 5850 | if (begin == end && vbegin == vend) |
77145576 | 5851 | fputs (_(" (start == end)"), stdout); |
9f272209 | 5852 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
5853 | fputs (_(" (start > end)"), stdout); |
5854 | ||
5855 | putchar ('\n'); | |
5856 | ||
5857 | start += length; | |
9f272209 | 5858 | vbegin = vend = -1; |
77145576 JK |
5859 | } |
5860 | ||
9f272209 AO |
5861 | if (vbegin != vm1 || vend != vm1) |
5862 | printf (_("Trailing view pair not used in a range")); | |
5863 | ||
77145576 | 5864 | *start_ptr = start; |
9f272209 | 5865 | *vstart_ptr = vstart; |
77145576 JK |
5866 | } |
5867 | ||
fab128ef CC |
5868 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
5869 | right-adjusted in a field of length LEN, and followed by a space. */ | |
5870 | ||
5871 | static void | |
5872 | print_addr_index (unsigned int idx, unsigned int len) | |
5873 | { | |
5874 | static char buf[15]; | |
5875 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 5876 | printf ("%*s ", len, buf); |
fab128ef CC |
5877 | } |
5878 | ||
4723351a CC |
5879 | /* Display a location list from a .dwo section. It uses address indexes rather |
5880 | than embedded addresses. This code closely follows display_loc_list, but the | |
5881 | two are sufficiently different that combining things is very ugly. */ | |
5882 | ||
5883 | static void | |
5884 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
5885 | unsigned char **start_ptr, |
5886 | unsigned int debug_info_entry, | |
359ca075 | 5887 | dwarf_vma offset, |
9f272209 | 5888 | unsigned char **vstart_ptr, |
b4eb7656 | 5889 | int has_frame_base) |
4723351a | 5890 | { |
9f272209 | 5891 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 5892 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
5893 | unsigned long cu_offset; |
5894 | unsigned int pointer_size; | |
5895 | unsigned int offset_size; | |
5896 | int dwarf_version; | |
4723351a CC |
5897 | int entry_type; |
5898 | unsigned short length; | |
5899 | int need_frame_base; | |
fab128ef | 5900 | unsigned int idx; |
4723351a CC |
5901 | unsigned int bytes_read; |
5902 | ||
82b1b41b NC |
5903 | if (debug_info_entry >= num_debug_info_entries) |
5904 | { | |
5905 | warn (_("No debug information for loc lists of entry: %u\n"), | |
5906 | debug_info_entry); | |
5907 | return; | |
5908 | } | |
5909 | ||
5910 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
5911 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5912 | offset_size = debug_information [debug_info_entry].offset_size; | |
5913 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
5914 | ||
f41e4712 NC |
5915 | if (pointer_size < 2 || pointer_size > 8) |
5916 | { | |
5917 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5918 | pointer_size, debug_info_entry); | |
5919 | return; | |
5920 | } | |
5921 | ||
4723351a CC |
5922 | while (1) |
5923 | { | |
359ca075 | 5924 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 5925 | |
fab128ef | 5926 | if (start >= section_end) |
b4eb7656 AM |
5927 | { |
5928 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5929 | (unsigned long) offset); |
b4eb7656 AM |
5930 | break; |
5931 | } | |
4723351a | 5932 | |
0c588247 | 5933 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
5934 | |
5935 | if (vstart) | |
5936 | switch (entry_type) | |
5937 | { | |
5938 | default: | |
5939 | break; | |
5940 | ||
5941 | case 2: | |
5942 | case 3: | |
5943 | case 4: | |
5944 | { | |
5945 | dwarf_vma view; | |
5946 | dwarf_vma off = offset + (vstart - *start_ptr); | |
5947 | ||
5948 | view = read_uleb128 (vstart, &bytes_read, section_end); | |
5949 | vstart += bytes_read; | |
5950 | print_dwarf_view (view, 8, 1); | |
5951 | ||
5952 | view = read_uleb128 (vstart, &bytes_read, section_end); | |
5953 | vstart += bytes_read; | |
5954 | print_dwarf_view (view, 8, 1); | |
5955 | ||
5956 | printf (_("views at %8.8lx for:\n %*s "), | |
5957 | (unsigned long) off, 8, ""); | |
5958 | ||
5959 | } | |
5960 | break; | |
5961 | } | |
5962 | ||
4723351a | 5963 | switch (entry_type) |
b4eb7656 AM |
5964 | { |
5965 | case 0: /* A terminating entry. */ | |
5966 | *start_ptr = start; | |
9f272209 | 5967 | *vstart_ptr = vstart; |
b4eb7656 AM |
5968 | printf (_("<End of list>\n")); |
5969 | return; | |
5970 | case 1: /* A base-address entry. */ | |
5971 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5972 | start += bytes_read; | |
5973 | print_addr_index (idx, 8); | |
9f272209 | 5974 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
5975 | printf (_("(base address selection entry)\n")); |
5976 | continue; | |
5977 | case 2: /* A start/end entry. */ | |
5978 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5979 | start += bytes_read; | |
5980 | print_addr_index (idx, 8); | |
5981 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5982 | start += bytes_read; | |
5983 | print_addr_index (idx, 8); | |
5984 | break; | |
5985 | case 3: /* A start/length entry. */ | |
5986 | idx = read_uleb128 (start, &bytes_read, section_end); | |
5987 | start += bytes_read; | |
5988 | print_addr_index (idx, 8); | |
5989 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
5990 | printf ("%08x ", idx); | |
5991 | break; | |
5992 | case 4: /* An offset pair entry. */ | |
5993 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
5994 | printf ("%08x ", idx); | |
5995 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
5996 | printf ("%08x ", idx); | |
5997 | break; | |
5998 | default: | |
5999 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6000 | *start_ptr = start; | |
9f272209 | 6001 | *vstart_ptr = vstart; |
b4eb7656 AM |
6002 | return; |
6003 | } | |
4723351a CC |
6004 | |
6005 | if (start + 2 > section_end) | |
b4eb7656 AM |
6006 | { |
6007 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6008 | (unsigned long) offset); |
b4eb7656 AM |
6009 | break; |
6010 | } | |
4723351a | 6011 | |
0c588247 | 6012 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6013 | if (start + length > section_end) |
b4eb7656 AM |
6014 | { |
6015 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6016 | (unsigned long) offset); |
b4eb7656 AM |
6017 | break; |
6018 | } | |
4723351a CC |
6019 | |
6020 | putchar ('('); | |
6021 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6022 | pointer_size, |
6023 | offset_size, | |
6024 | dwarf_version, | |
6025 | length, | |
6026 | cu_offset, section); | |
4723351a CC |
6027 | putchar (')'); |
6028 | ||
6029 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6030 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6031 | |
6032 | putchar ('\n'); | |
6033 | ||
6034 | start += length; | |
6035 | } | |
6036 | ||
6037 | *start_ptr = start; | |
9f272209 | 6038 | *vstart_ptr = vstart; |
4723351a CC |
6039 | } |
6040 | ||
9f272209 AO |
6041 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6042 | loc_views. */ | |
51d0d03f | 6043 | |
9f272209 | 6044 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6045 | |
6046 | static int | |
6047 | loc_offsets_compar (const void *ap, const void *bp) | |
6048 | { | |
6049 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6050 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6051 | ||
9f272209 AO |
6052 | int ret = (a > b) - (b > a); |
6053 | if (ret) | |
6054 | return ret; | |
6055 | ||
6056 | a = loc_views[*(const unsigned int *) ap]; | |
6057 | b = loc_views[*(const unsigned int *) bp]; | |
6058 | ||
6059 | ret = (a > b) - (b > a); | |
6060 | ||
6061 | return ret; | |
51d0d03f JJ |
6062 | } |
6063 | ||
19e6b90e L |
6064 | static int |
6065 | display_debug_loc (struct dwarf_section *section, void *file) | |
6066 | { | |
9f272209 | 6067 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6068 | unsigned long bytes; |
6069 | unsigned char *section_begin = start; | |
6070 | unsigned int num_loc_list = 0; | |
6071 | unsigned long last_offset = 0; | |
9f272209 | 6072 | unsigned long last_view = 0; |
19e6b90e L |
6073 | unsigned int first = 0; |
6074 | unsigned int i; | |
6075 | unsigned int j; | |
6076 | int seen_first_offset = 0; | |
51d0d03f | 6077 | int locs_sorted = 1; |
9f272209 | 6078 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6079 | unsigned int *array = NULL; |
4723351a | 6080 | const char *suffix = strrchr (section->name, '.'); |
24841daa | 6081 | bfd_boolean is_dwo = FALSE; |
77145576 JK |
6082 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6083 | dwarf_vma expected_start = 0; | |
4723351a CC |
6084 | |
6085 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
24841daa | 6086 | is_dwo = TRUE; |
19e6b90e L |
6087 | |
6088 | bytes = section->size; | |
19e6b90e L |
6089 | |
6090 | if (bytes == 0) | |
6091 | { | |
6092 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6093 | return 0; | |
6094 | } | |
6095 | ||
77145576 JK |
6096 | if (is_loclists) |
6097 | { | |
6098 | unsigned char *hdrptr = section_begin; | |
6099 | dwarf_vma ll_length; | |
6100 | unsigned short ll_version; | |
6101 | unsigned char *end = section_begin + section->size; | |
6102 | unsigned char address_size, segment_selector_size; | |
6103 | uint32_t offset_entry_count; | |
6104 | ||
6105 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6106 | if (ll_length == 0xffffffff) | |
6107 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6108 | ||
6109 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6110 | if (ll_version != 5) | |
6111 | { | |
6112 | warn (_("The %s section contains corrupt or " | |
6113 | "unsupported version number: %d.\n"), | |
6114 | section->name, ll_version); | |
6115 | return 0; | |
6116 | } | |
6117 | ||
6118 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6119 | ||
6120 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6121 | if (segment_selector_size != 0) | |
6122 | { | |
6123 | warn (_("The %s section contains " | |
6124 | "unsupported segment selector size: %d.\n"), | |
6125 | section->name, segment_selector_size); | |
6126 | return 0; | |
6127 | } | |
6128 | ||
6129 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6130 | if (offset_entry_count != 0) | |
6131 | { | |
6132 | warn (_("The %s section contains " | |
6133 | "unsupported offset entry count: %d.\n"), | |
6134 | section->name, offset_entry_count); | |
6135 | return 0; | |
6136 | } | |
6137 | ||
6138 | expected_start = hdrptr - section_begin; | |
6139 | } | |
6140 | ||
1febe64d NC |
6141 | if (load_debug_info (file) == 0) |
6142 | { | |
6143 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6144 | section->name); | |
6145 | return 0; | |
6146 | } | |
19e6b90e L |
6147 | |
6148 | /* Check the order of location list in .debug_info section. If | |
6149 | offsets of location lists are in the ascending order, we can | |
6150 | use `debug_information' directly. */ | |
6151 | for (i = 0; i < num_debug_info_entries; i++) | |
6152 | { | |
6153 | unsigned int num; | |
6154 | ||
6155 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
6156 | if (num > num_loc_list) |
6157 | num_loc_list = num; | |
19e6b90e L |
6158 | |
6159 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 6160 | if (locs_sorted && num != 0) |
19e6b90e L |
6161 | { |
6162 | if (!seen_first_offset) | |
6163 | { | |
6164 | /* This is the first location list. */ | |
6165 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 6166 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
6167 | first = i; |
6168 | seen_first_offset = 1; | |
6169 | j = 1; | |
6170 | } | |
6171 | else | |
6172 | j = 0; | |
6173 | ||
6174 | for (; j < num; j++) | |
6175 | { | |
6176 | if (last_offset > | |
9f272209 AO |
6177 | debug_information [i].loc_offsets [j] |
6178 | || (last_offset == debug_information [i].loc_offsets [j] | |
6179 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 6180 | { |
51d0d03f | 6181 | locs_sorted = 0; |
19e6b90e L |
6182 | break; |
6183 | } | |
6184 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 6185 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
6186 | } |
6187 | } | |
6188 | } | |
6189 | ||
19e6b90e L |
6190 | if (!seen_first_offset) |
6191 | error (_("No location lists in .debug_info section!\n")); | |
6192 | ||
d4bfc77b | 6193 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
6194 | && debug_information [first].loc_offsets [0] != expected_start |
6195 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
6196 | warn (_("Location lists in %s section start at 0x%s\n"), |
6197 | section->name, | |
6198 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 6199 | |
51d0d03f JJ |
6200 | if (!locs_sorted) |
6201 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d NC |
6202 | |
6203 | introduce (section, FALSE); | |
6204 | ||
d1c4b12b NC |
6205 | if (reloc_at (section, 0)) |
6206 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 6207 | |
d1c4b12b | 6208 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
6209 | |
6210 | seen_first_offset = 0; | |
6211 | for (i = first; i < num_debug_info_entries; i++) | |
6212 | { | |
9f272209 | 6213 | dwarf_vma offset, voffset; |
359ca075 | 6214 | dwarf_vma base_address; |
d1c4b12b | 6215 | unsigned int k; |
19e6b90e L |
6216 | int has_frame_base; |
6217 | ||
51d0d03f JJ |
6218 | if (!locs_sorted) |
6219 | { | |
6220 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
6221 | array[k] = k; | |
6222 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 6223 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
6224 | qsort (array, debug_information [i].num_loc_offsets, |
6225 | sizeof (*array), loc_offsets_compar); | |
6226 | } | |
19e6b90e | 6227 | |
9f272209 | 6228 | int adjacent_view_loclists = 1; |
51d0d03f | 6229 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 6230 | { |
51d0d03f JJ |
6231 | j = locs_sorted ? k : array[k]; |
6232 | if (k | |
9f272209 | 6233 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 6234 | ? k - 1 : array [k - 1]] |
9f272209 AO |
6235 | == debug_information [i].loc_offsets [j]) |
6236 | && (debug_information [i].loc_views [locs_sorted | |
6237 | ? k - 1 : array [k - 1]] | |
6238 | == debug_information [i].loc_views [j])) | |
51d0d03f | 6239 | continue; |
19e6b90e | 6240 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 6241 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 6242 | next = section_begin + offset; |
9f272209 AO |
6243 | voffset = debug_information [i].loc_views [j]; |
6244 | if (voffset != vm1) | |
6245 | vnext = section_begin + voffset; | |
6246 | else | |
6247 | vnext = NULL; | |
19e6b90e L |
6248 | base_address = debug_information [i].base_address; |
6249 | ||
9f272209 AO |
6250 | if (vnext && vnext < next) |
6251 | { | |
6252 | vstart = vnext; | |
6253 | display_view_pair_list (section, &vstart, i, next); | |
6254 | if (start == vnext) | |
6255 | start = vstart; | |
6256 | } | |
6257 | ||
6258 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
6259 | seen_first_offset = 1; |
6260 | else | |
6261 | { | |
6262 | if (start < next) | |
6263 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6264 | (unsigned long) (start - section_begin), |
c8071705 | 6265 | (unsigned long) offset); |
19e6b90e L |
6266 | else if (start > next) |
6267 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6268 | (unsigned long) (start - section_begin), |
c8071705 | 6269 | (unsigned long) offset); |
19e6b90e L |
6270 | } |
6271 | start = next; | |
9f272209 | 6272 | vstart = vnext; |
19e6b90e L |
6273 | |
6274 | if (offset >= bytes) | |
6275 | { | |
6276 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 6277 | (unsigned long) offset); |
19e6b90e L |
6278 | continue; |
6279 | } | |
6280 | ||
9f272209 AO |
6281 | if (vnext && voffset >= bytes) |
6282 | { | |
6283 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
6284 | (unsigned long) voffset); | |
6285 | continue; | |
6286 | } | |
6287 | ||
77145576 JK |
6288 | if (!is_loclists) |
6289 | { | |
6290 | if (is_dwo) | |
6291 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 6292 | &vstart, has_frame_base); |
77145576 JK |
6293 | else |
6294 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 6295 | &vstart, has_frame_base); |
77145576 | 6296 | } |
b4eb7656 | 6297 | else |
77145576 JK |
6298 | { |
6299 | if (is_dwo) | |
6300 | warn (_("DWO is not yet supported.\n")); | |
6301 | else | |
6302 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
6303 | &vstart, has_frame_base); |
6304 | } | |
6305 | ||
6306 | /* FIXME: this arrangement is quite simplistic. Nothing | |
6307 | requires locview lists to be adjacent to corresponding | |
6308 | loclists, and a single loclist could be augmented by | |
6309 | different locview lists, and vice-versa, unlikely as it | |
6310 | is that it would make sense to do so. Hopefully we'll | |
6311 | have view pair support built into loclists before we ever | |
6312 | need to address all these possibilities. */ | |
6313 | if (adjacent_view_loclists && vnext | |
6314 | && vnext != start && vstart != next) | |
6315 | { | |
6316 | adjacent_view_loclists = 0; | |
6317 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 6318 | } |
9f272209 AO |
6319 | |
6320 | if (vnext && vnext == start) | |
6321 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
6322 | } |
6323 | } | |
031cd65f | 6324 | |
4723351a | 6325 | if (start < section->start + section->size) |
d3a49aa8 AM |
6326 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
6327 | "There are %ld unused bytes at the end of section %s\n", | |
6328 | (long) (section->start + section->size - start)), | |
4723351a | 6329 | (long) (section->start + section->size - start), section->name); |
98fb390a | 6330 | putchar ('\n'); |
51d0d03f | 6331 | free (array); |
19e6b90e L |
6332 | return 1; |
6333 | } | |
6334 | ||
6335 | static int | |
6336 | display_debug_str (struct dwarf_section *section, | |
6337 | void *file ATTRIBUTE_UNUSED) | |
6338 | { | |
6339 | unsigned char *start = section->start; | |
6340 | unsigned long bytes = section->size; | |
6341 | dwarf_vma addr = section->address; | |
6342 | ||
6343 | if (bytes == 0) | |
6344 | { | |
6345 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6346 | return 0; | |
6347 | } | |
6348 | ||
dda8d76d | 6349 | introduce (section, FALSE); |
19e6b90e L |
6350 | |
6351 | while (bytes) | |
6352 | { | |
6353 | int j; | |
6354 | int k; | |
6355 | int lbytes; | |
6356 | ||
6357 | lbytes = (bytes > 16 ? 16 : bytes); | |
6358 | ||
6359 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
6360 | ||
6361 | for (j = 0; j < 16; j++) | |
6362 | { | |
6363 | if (j < lbytes) | |
6364 | printf ("%2.2x", start[j]); | |
6365 | else | |
6366 | printf (" "); | |
6367 | ||
6368 | if ((j & 3) == 3) | |
6369 | printf (" "); | |
6370 | } | |
6371 | ||
6372 | for (j = 0; j < lbytes; j++) | |
6373 | { | |
6374 | k = start[j]; | |
6375 | if (k >= ' ' && k < 0x80) | |
6376 | printf ("%c", k); | |
6377 | else | |
6378 | printf ("."); | |
6379 | } | |
6380 | ||
6381 | putchar ('\n'); | |
6382 | ||
6383 | start += lbytes; | |
6384 | addr += lbytes; | |
6385 | bytes -= lbytes; | |
6386 | } | |
6387 | ||
6388 | putchar ('\n'); | |
6389 | ||
6390 | return 1; | |
6391 | } | |
6392 | ||
19e6b90e L |
6393 | static int |
6394 | display_debug_info (struct dwarf_section *section, void *file) | |
6395 | { | |
d85bf2ba | 6396 | return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE); |
19e6b90e L |
6397 | } |
6398 | ||
2b6f5997 CC |
6399 | static int |
6400 | display_debug_types (struct dwarf_section *section, void *file) | |
6401 | { | |
d85bf2ba | 6402 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
6f875884 TG |
6403 | } |
6404 | ||
6405 | static int | |
6406 | display_trace_info (struct dwarf_section *section, void *file) | |
6407 | { | |
d85bf2ba | 6408 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
2b6f5997 | 6409 | } |
19e6b90e L |
6410 | |
6411 | static int | |
6412 | display_debug_aranges (struct dwarf_section *section, | |
6413 | void *file ATTRIBUTE_UNUSED) | |
6414 | { | |
6415 | unsigned char *start = section->start; | |
6416 | unsigned char *end = start + section->size; | |
6417 | ||
dda8d76d | 6418 | introduce (section, FALSE); |
19e6b90e | 6419 | |
6e3d6dc1 NC |
6420 | /* It does not matter if this load fails, |
6421 | we test for that later on. */ | |
6422 | load_debug_info (file); | |
6423 | ||
19e6b90e L |
6424 | while (start < end) |
6425 | { | |
6426 | unsigned char *hdrptr; | |
6427 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 6428 | unsigned char *addr_ranges; |
2d9472a2 NC |
6429 | dwarf_vma length; |
6430 | dwarf_vma address; | |
e98fdf1a | 6431 | unsigned long sec_off; |
53b8873b | 6432 | unsigned char address_size; |
19e6b90e | 6433 | int excess; |
bf5117e3 NC |
6434 | unsigned int offset_size; |
6435 | unsigned int initial_length_size; | |
19e6b90e L |
6436 | |
6437 | hdrptr = start; | |
6438 | ||
0c588247 | 6439 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
6440 | if (arange.ar_length == 0xffffffff) |
6441 | { | |
0c588247 | 6442 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
6443 | offset_size = 8; |
6444 | initial_length_size = 12; | |
6445 | } | |
6446 | else | |
6447 | { | |
6448 | offset_size = 4; | |
6449 | initial_length_size = 4; | |
6450 | } | |
6451 | ||
e98fdf1a AM |
6452 | sec_off = hdrptr - section->start; |
6453 | if (sec_off + arange.ar_length < sec_off | |
6454 | || sec_off + arange.ar_length > section->size) | |
6455 | { | |
6456 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
6457 | section->name, | |
6458 | sec_off - initial_length_size, | |
6459 | dwarf_vmatoa ("x", arange.ar_length)); | |
6460 | break; | |
6461 | } | |
6462 | ||
0c588247 NC |
6463 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
6464 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 6465 | |
6e3d6dc1 NC |
6466 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
6467 | && num_debug_info_entries > 0 | |
6468 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
6469 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 6470 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 6471 | |
0c588247 NC |
6472 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
6473 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
6474 | |
6475 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
6476 | { | |
67f101ee NC |
6477 | /* PR 19872: A version number of 0 probably means that there is |
6478 | padding at the end of the .debug_aranges section. Gold puts | |
6479 | it there when performing an incremental link, for example. | |
6480 | So do not generate a warning in this case. */ | |
6481 | if (arange.ar_version) | |
6482 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
6483 | break; |
6484 | } | |
6485 | ||
47704ddf KT |
6486 | printf (_(" Length: %ld\n"), |
6487 | (long) arange.ar_length); | |
19e6b90e | 6488 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
6489 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
6490 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
6491 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
6492 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
6493 | ||
53b8873b NC |
6494 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
6495 | ||
f41e4712 NC |
6496 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
6497 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
6498 | { |
6499 | error (_("Invalid address size in %s section!\n"), | |
6500 | section->name); | |
6501 | break; | |
6502 | } | |
6503 | ||
53b8873b NC |
6504 | /* The DWARF spec does not require that the address size be a power |
6505 | of two, but we do. This will have to change if we ever encounter | |
6506 | an uneven architecture. */ | |
6507 | if ((address_size & (address_size - 1)) != 0) | |
6508 | { | |
6509 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
6510 | break; | |
6511 | } | |
cecf136e | 6512 | |
209c9a13 NC |
6513 | if (address_size > 4) |
6514 | printf (_("\n Address Length\n")); | |
6515 | else | |
6516 | printf (_("\n Address Length\n")); | |
19e6b90e | 6517 | |
91d6fa6a | 6518 | addr_ranges = hdrptr; |
19e6b90e | 6519 | |
53b8873b NC |
6520 | /* Must pad to an alignment boundary that is twice the address size. */ |
6521 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 6522 | if (excess) |
91d6fa6a | 6523 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 6524 | |
e98fdf1a | 6525 | start += arange.ar_length + initial_length_size; |
1617e571 | 6526 | |
91d6fa6a | 6527 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 6528 | { |
0c588247 NC |
6529 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
6530 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 6531 | |
80c35038 | 6532 | printf (" "); |
2d9472a2 NC |
6533 | print_dwarf_vma (address, address_size); |
6534 | print_dwarf_vma (length, address_size); | |
6535 | putchar ('\n'); | |
19e6b90e | 6536 | } |
19e6b90e L |
6537 | } |
6538 | ||
6539 | printf ("\n"); | |
6540 | ||
6541 | return 1; | |
6542 | } | |
6543 | ||
4723351a CC |
6544 | /* Comparison function for qsort. */ |
6545 | static int | |
6546 | comp_addr_base (const void * v0, const void * v1) | |
6547 | { | |
6548 | debug_info * info0 = (debug_info *) v0; | |
6549 | debug_info * info1 = (debug_info *) v1; | |
6550 | return info0->addr_base - info1->addr_base; | |
6551 | } | |
6552 | ||
6553 | /* Display the debug_addr section. */ | |
6554 | static int | |
6555 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 6556 | void *file) |
4723351a CC |
6557 | { |
6558 | debug_info **debug_addr_info; | |
6559 | unsigned char *entry; | |
6560 | unsigned char *end; | |
6561 | unsigned int i; | |
6562 | unsigned int count; | |
6563 | ||
6564 | if (section->size == 0) | |
6565 | { | |
6566 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6567 | return 0; | |
6568 | } | |
6569 | ||
6570 | if (load_debug_info (file) == 0) | |
6571 | { | |
6572 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6573 | section->name); | |
6574 | return 0; | |
6575 | } | |
6576 | ||
dda8d76d | 6577 | introduce (section, FALSE); |
4723351a | 6578 | |
1306a742 NC |
6579 | /* PR 17531: file: cf38d01b. |
6580 | We use xcalloc because a corrupt file may not have initialised all of the | |
6581 | fields in the debug_info structure, which means that the sort below might | |
6582 | try to move uninitialised data. */ | |
6583 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 6584 | sizeof (debug_info *)); |
4723351a CC |
6585 | |
6586 | count = 0; | |
6587 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 6588 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
6589 | { |
6590 | /* PR 17531: file: cf38d01b. */ | |
6591 | if (debug_information[i].addr_base >= section->size) | |
6592 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
6593 | (unsigned long) debug_information[i].addr_base, i); | |
6594 | else | |
6595 | debug_addr_info [count++] = debug_information + i; | |
6596 | } | |
4723351a CC |
6597 | |
6598 | /* Add a sentinel to make iteration convenient. */ | |
6599 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
6600 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 6601 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 6602 | |
4723351a CC |
6603 | for (i = 0; i < count; i++) |
6604 | { | |
6605 | unsigned int idx; | |
fab128ef | 6606 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
6607 | |
6608 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 6609 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 6610 | |
fab128ef | 6611 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
6612 | entry = section->start + debug_addr_info [i]->addr_base; |
6613 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
6614 | idx = 0; | |
6615 | while (entry < end) | |
b4eb7656 AM |
6616 | { |
6617 | dwarf_vma base = byte_get (entry, address_size); | |
6618 | printf (_("\t%d:\t"), idx); | |
6619 | print_dwarf_vma (base, address_size); | |
6620 | printf ("\n"); | |
6621 | entry += address_size; | |
6622 | idx++; | |
6623 | } | |
4723351a CC |
6624 | } |
6625 | printf ("\n"); | |
6626 | ||
6627 | free (debug_addr_info); | |
6628 | return 1; | |
6629 | } | |
6630 | ||
6631 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 6632 | |
4723351a CC |
6633 | static int |
6634 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 6635 | void *file ATTRIBUTE_UNUSED) |
4723351a CC |
6636 | { |
6637 | if (section->size == 0) | |
6638 | { | |
6639 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6640 | return 0; | |
6641 | } | |
6642 | /* TODO: Dump the contents. This is made somewhat difficult by not knowing | |
6643 | what the offset size is for this section. */ | |
6644 | return 1; | |
6645 | } | |
6646 | ||
01a8f077 JK |
6647 | /* Each debug_information[x].range_lists[y] gets this representation for |
6648 | sorting purposes. */ | |
6649 | ||
6650 | struct range_entry | |
467c65bc NC |
6651 | { |
6652 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 6653 | dwarf_vma ranges_offset; |
01a8f077 | 6654 | |
467c65bc NC |
6655 | /* Original debug_information to find parameters of the data. */ |
6656 | debug_info *debug_info_p; | |
6657 | }; | |
01a8f077 JK |
6658 | |
6659 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
6660 | ||
6661 | static int | |
6662 | range_entry_compar (const void *ap, const void *bp) | |
6663 | { | |
3f5e193b NC |
6664 | const struct range_entry *a_re = (const struct range_entry *) ap; |
6665 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
6666 | const dwarf_vma a = a_re->ranges_offset; |
6667 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
6668 | |
6669 | return (a > b) - (b > a); | |
6670 | } | |
6671 | ||
77145576 JK |
6672 | static void |
6673 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
6674 | unsigned int pointer_size, unsigned long offset, | |
6675 | unsigned long base_address) | |
6676 | { | |
6677 | while (start < finish) | |
6678 | { | |
6679 | dwarf_vma begin; | |
6680 | dwarf_vma end; | |
6681 | ||
6682 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6683 | if (start >= finish) | |
6684 | break; | |
6685 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
6686 | ||
d11ae95e | 6687 | |
77145576 JK |
6688 | printf (" %8.8lx ", offset); |
6689 | ||
6690 | if (begin == 0 && end == 0) | |
6691 | { | |
6692 | printf (_("<End of list>\n")); | |
6693 | break; | |
6694 | } | |
6695 | ||
6696 | /* Check base address specifiers. */ | |
6697 | if (is_max_address (begin, pointer_size) | |
6698 | && !is_max_address (end, pointer_size)) | |
6699 | { | |
6700 | base_address = end; | |
6701 | print_dwarf_vma (begin, pointer_size); | |
6702 | print_dwarf_vma (end, pointer_size); | |
6703 | printf ("(base address)\n"); | |
6704 | continue; | |
6705 | } | |
6706 | ||
6707 | print_dwarf_vma (begin + base_address, pointer_size); | |
6708 | print_dwarf_vma (end + base_address, pointer_size); | |
6709 | ||
6710 | if (begin == end) | |
6711 | fputs (_("(start == end)"), stdout); | |
6712 | else if (begin > end) | |
6713 | fputs (_("(start > end)"), stdout); | |
6714 | ||
6715 | putchar ('\n'); | |
6716 | } | |
6717 | } | |
6718 | ||
6719 | static void | |
6720 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
6721 | unsigned int pointer_size, unsigned long offset, | |
6722 | unsigned long base_address) | |
6723 | { | |
6724 | unsigned char *next = start; | |
6725 | ||
6726 | while (1) | |
6727 | { | |
6728 | unsigned long off = offset + (start - next); | |
6729 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
6730 | /* Initialize it due to a false compiler warning. */ |
6731 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
6732 | unsigned int bytes_read; |
6733 | ||
6734 | if (start + 1 > finish) | |
6735 | { | |
6736 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
6737 | offset); | |
6738 | break; | |
6739 | } | |
6740 | ||
6741 | printf (" %8.8lx ", off); | |
6742 | ||
6743 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
6744 | ||
6745 | switch (rlet) | |
6746 | { | |
6747 | case DW_RLE_end_of_list: | |
6748 | printf (_("<End of list>\n")); | |
6749 | break; | |
6750 | case DW_RLE_base_address: | |
6751 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
6752 | print_dwarf_vma (base_address, pointer_size); | |
6753 | printf (_("(base address)\n")); | |
6754 | break; | |
6755 | case DW_RLE_start_length: | |
6756 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6757 | length = read_uleb128 (start, &bytes_read, finish); | |
6758 | start += bytes_read; | |
6759 | end = begin + length; | |
6760 | break; | |
6761 | case DW_RLE_offset_pair: | |
6762 | begin = read_uleb128 (start, &bytes_read, finish); | |
6763 | start += bytes_read; | |
6764 | end = read_uleb128 (start, &bytes_read, finish); | |
6765 | start += bytes_read; | |
6766 | break; | |
6767 | case DW_RLE_start_end: | |
6768 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6769 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
6770 | break; | |
6771 | default: | |
6772 | error (_("Invalid range list entry type %d\n"), rlet); | |
6773 | rlet = DW_RLE_end_of_list; | |
6774 | break; | |
6775 | } | |
6776 | if (rlet == DW_RLE_end_of_list) | |
6777 | break; | |
6778 | if (rlet == DW_RLE_base_address) | |
6779 | continue; | |
6780 | ||
6781 | print_dwarf_vma (begin + base_address, pointer_size); | |
6782 | print_dwarf_vma (end + base_address, pointer_size); | |
6783 | ||
6784 | if (begin == end) | |
6785 | fputs (_("(start == end)"), stdout); | |
6786 | else if (begin > end) | |
6787 | fputs (_("(start > end)"), stdout); | |
6788 | ||
6789 | putchar ('\n'); | |
6790 | } | |
6791 | } | |
6792 | ||
19e6b90e L |
6793 | static int |
6794 | display_debug_ranges (struct dwarf_section *section, | |
6795 | void *file ATTRIBUTE_UNUSED) | |
6796 | { | |
6797 | unsigned char *start = section->start; | |
a2ff7a4b | 6798 | unsigned char *last_start = start; |
f6f0e17b | 6799 | unsigned long bytes = section->size; |
19e6b90e | 6800 | unsigned char *section_begin = start; |
f6f0e17b | 6801 | unsigned char *finish = start + bytes; |
01a8f077 JK |
6802 | unsigned int num_range_list, i; |
6803 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
6804 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
6805 | /* Initialize it due to a false compiler warning. */ | |
6806 | unsigned char address_size = 0; | |
19e6b90e | 6807 | |
19e6b90e L |
6808 | if (bytes == 0) |
6809 | { | |
6810 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6811 | return 0; | |
6812 | } | |
6813 | ||
77145576 JK |
6814 | if (is_rnglists) |
6815 | { | |
6816 | dwarf_vma initial_length; | |
6817 | unsigned int initial_length_size; | |
6818 | unsigned char segment_selector_size; | |
6819 | unsigned int offset_size, offset_entry_count; | |
6820 | unsigned short version; | |
6821 | ||
6822 | /* Get and check the length of the block. */ | |
6823 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
6824 | ||
6825 | if (initial_length == 0xffffffff) | |
6826 | { | |
6827 | /* This section is 64-bit DWARF 3. */ | |
6828 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
6829 | offset_size = 8; | |
6830 | initial_length_size = 12; | |
6831 | } | |
6832 | else | |
6833 | { | |
6834 | offset_size = 4; | |
6835 | initial_length_size = 4; | |
6836 | } | |
6837 | ||
6838 | if (initial_length + initial_length_size > section->size) | |
6839 | { | |
6840 | /* If the length field has a relocation against it, then we should | |
6841 | not complain if it is inaccurate (and probably negative). | |
6842 | It is copied from .debug_line handling code. */ | |
6843 | if (reloc_at (section, (start - section->start) - offset_size)) | |
6844 | { | |
6845 | initial_length = (finish - start) - initial_length_size; | |
6846 | } | |
6847 | else | |
6848 | { | |
6849 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
6850 | (long) initial_length); | |
6851 | return 0; | |
6852 | } | |
6853 | } | |
6854 | ||
6855 | /* Get and check the version number. */ | |
6856 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
6857 | ||
6858 | if (version != 5) | |
6859 | { | |
6860 | warn (_("Only DWARF version 5 debug_rnglists info " | |
6861 | "is currently supported.\n")); | |
6862 | return 0; | |
6863 | } | |
6864 | ||
6865 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
6866 | ||
6867 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
6868 | if (segment_selector_size != 0) | |
6869 | { | |
6870 | warn (_("The %s section contains " | |
6871 | "unsupported segment selector size: %d.\n"), | |
6872 | section->name, segment_selector_size); | |
6873 | return 0; | |
6874 | } | |
6875 | ||
6876 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
6877 | if (offset_entry_count != 0) | |
6878 | { | |
6879 | warn (_("The %s section contains " | |
6880 | "unsupported offset entry count: %u.\n"), | |
6881 | section->name, offset_entry_count); | |
6882 | return 0; | |
6883 | } | |
6884 | } | |
6885 | ||
1febe64d NC |
6886 | if (load_debug_info (file) == 0) |
6887 | { | |
6888 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6889 | section->name); | |
6890 | return 0; | |
6891 | } | |
19e6b90e | 6892 | |
01a8f077 | 6893 | num_range_list = 0; |
19e6b90e | 6894 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 6895 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 6896 | |
01a8f077 | 6897 | if (num_range_list == 0) |
4723351a CC |
6898 | { |
6899 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 6900 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
6901 | printf (_("No range lists in .debug_info section.\n")); |
6902 | return 1; | |
6903 | } | |
19e6b90e | 6904 | |
3f5e193b NC |
6905 | range_entries = (struct range_entry *) |
6906 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 6907 | range_entry_fill = range_entries; |
19e6b90e | 6908 | |
01a8f077 JK |
6909 | for (i = 0; i < num_debug_info_entries; i++) |
6910 | { | |
6911 | debug_info *debug_info_p = &debug_information[i]; | |
6912 | unsigned int j; | |
6913 | ||
6914 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
6915 | { | |
6916 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
6917 | range_entry_fill->debug_info_p = debug_info_p; | |
6918 | range_entry_fill++; | |
19e6b90e L |
6919 | } |
6920 | } | |
6921 | ||
01a8f077 JK |
6922 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
6923 | range_entry_compar); | |
19e6b90e | 6924 | |
d493b283 | 6925 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 6926 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 6927 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 6928 | |
dda8d76d NC |
6929 | introduce (section, FALSE); |
6930 | ||
19e6b90e L |
6931 | printf (_(" Offset Begin End\n")); |
6932 | ||
01a8f077 | 6933 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 6934 | { |
01a8f077 JK |
6935 | struct range_entry *range_entry = &range_entries[i]; |
6936 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 6937 | unsigned int pointer_size; |
359ca075 | 6938 | dwarf_vma offset; |
01a8f077 | 6939 | unsigned char *next; |
359ca075 | 6940 | dwarf_vma base_address; |
19e6b90e | 6941 | |
77145576 | 6942 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 6943 | offset = range_entry->ranges_offset; |
01a8f077 JK |
6944 | next = section_begin + offset; |
6945 | base_address = debug_info_p->base_address; | |
cecf136e | 6946 | |
f41e4712 NC |
6947 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
6948 | if (pointer_size < 2 || pointer_size > 8) | |
6949 | { | |
6950 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 6951 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
6952 | continue; |
6953 | } | |
b4eb7656 | 6954 | |
d11ae95e NC |
6955 | if (next < section_begin || next >= finish) |
6956 | { | |
6957 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
6958 | (unsigned long) offset, i); | |
6959 | continue; | |
6960 | } | |
6961 | ||
4723351a | 6962 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 6963 | { |
01a8f077 JK |
6964 | if (start < next) |
6965 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
6966 | (unsigned long) (start - section_begin), | |
6967 | (unsigned long) (next - section_begin), section->name); | |
6968 | else if (start > next) | |
a2ff7a4b AM |
6969 | { |
6970 | if (next == last_start) | |
6971 | continue; | |
6972 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
6973 | (unsigned long) (start - section_begin), | |
6974 | (unsigned long) (next - section_begin), section->name); | |
6975 | } | |
01a8f077 | 6976 | } |
d11ae95e | 6977 | |
01a8f077 | 6978 | start = next; |
a2ff7a4b | 6979 | last_start = next; |
19e6b90e | 6980 | |
77145576 JK |
6981 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
6982 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
6983 | } |
6984 | putchar ('\n'); | |
01a8f077 JK |
6985 | |
6986 | free (range_entries); | |
6987 | ||
19e6b90e L |
6988 | return 1; |
6989 | } | |
6990 | ||
6991 | typedef struct Frame_Chunk | |
6992 | { | |
6993 | struct Frame_Chunk *next; | |
6994 | unsigned char *chunk_start; | |
a1165289 | 6995 | unsigned int ncols; |
19e6b90e L |
6996 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
6997 | short int *col_type; | |
6998 | int *col_offset; | |
6999 | char *augmentation; | |
7000 | unsigned int code_factor; | |
7001 | int data_factor; | |
bf5117e3 NC |
7002 | dwarf_vma pc_begin; |
7003 | dwarf_vma pc_range; | |
32ef3000 | 7004 | unsigned int cfa_reg; |
c8071705 | 7005 | dwarf_vma cfa_offset; |
a1165289 | 7006 | unsigned int ra; |
19e6b90e L |
7007 | unsigned char fde_encoding; |
7008 | unsigned char cfa_exp; | |
604282a7 JJ |
7009 | unsigned char ptr_size; |
7010 | unsigned char segment_size; | |
19e6b90e L |
7011 | } |
7012 | Frame_Chunk; | |
7013 | ||
665ce1f6 L |
7014 | static const char *const *dwarf_regnames; |
7015 | static unsigned int dwarf_regnames_count; | |
7016 | ||
19e6b90e L |
7017 | /* A marker for a col_type that means this column was never referenced |
7018 | in the frame info. */ | |
7019 | #define DW_CFA_unreferenced (-1) | |
7020 | ||
a1165289 | 7021 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
7022 | -1 for invalid reg. */ |
7023 | ||
7024 | static int | |
7025 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 7026 | { |
a1165289 | 7027 | unsigned int prev = fc->ncols; |
19e6b90e | 7028 | |
665ce1f6 L |
7029 | if (reg < (unsigned int) fc->ncols) |
7030 | return 0; | |
7031 | ||
7032 | if (dwarf_regnames_count | |
7033 | && reg > dwarf_regnames_count) | |
7034 | return -1; | |
19e6b90e L |
7035 | |
7036 | fc->ncols = reg + 1; | |
a1165289 NC |
7037 | /* PR 17512: file: 10450-2643-0.004. |
7038 | If reg == -1 then this can happen... */ | |
7039 | if (fc->ncols == 0) | |
7040 | return -1; | |
7041 | ||
06614111 NC |
7042 | /* PR 17512: file: 2844a11d. */ |
7043 | if (fc->ncols > 1024) | |
7044 | { | |
7045 | error (_("Unfeasibly large register number: %u\n"), reg); | |
7046 | fc->ncols = 0; | |
7047 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
7048 | we ever encounter a valid binary that exceeds it. */ | |
7049 | return -1; | |
7050 | } | |
7051 | ||
3f5e193b | 7052 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 7053 | sizeof (short int)); |
3f5e193b | 7054 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 7055 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
7056 | if (fc->col_type == NULL || fc->col_offset == NULL) |
7057 | { | |
7058 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
7059 | fc->ncols); | |
7060 | fc->ncols = 0; | |
7061 | return -1; | |
7062 | } | |
19e6b90e L |
7063 | |
7064 | while (prev < fc->ncols) | |
7065 | { | |
7066 | fc->col_type[prev] = DW_CFA_unreferenced; | |
7067 | fc->col_offset[prev] = 0; | |
7068 | prev++; | |
7069 | } | |
665ce1f6 | 7070 | return 1; |
19e6b90e L |
7071 | } |
7072 | ||
2dc4cec1 L |
7073 | static const char *const dwarf_regnames_i386[] = |
7074 | { | |
43234a1e L |
7075 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
7076 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7077 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7078 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
7079 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
7080 | NULL, NULL, /* 19 - 20 */ | |
7081 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
7082 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
7083 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
7084 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
7085 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
7086 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7087 | "tr", "ldtr", /* 48 - 49 */ | |
7088 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7089 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7090 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7091 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7092 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7093 | NULL, NULL, NULL, /* 90 - 92 */ | |
7094 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
7095 | }; |
7096 | ||
3d875af5 L |
7097 | static const char *const dwarf_regnames_iamcu[] = |
7098 | { | |
7099 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
7100 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7101 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7102 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
7103 | NULL, NULL, /* 19 - 20 */ | |
7104 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
7105 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
7106 | NULL, NULL, NULL, /* 37 - 39 */ | |
7107 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7108 | "tr", "ldtr", /* 48 - 49 */ | |
7109 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7110 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7111 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7112 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7113 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7114 | NULL, NULL, NULL, /* 90 - 92 */ | |
7115 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
7116 | }; | |
7117 | ||
b129eb0e RH |
7118 | void |
7119 | init_dwarf_regnames_i386 (void) | |
7120 | { | |
7121 | dwarf_regnames = dwarf_regnames_i386; | |
7122 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
7123 | } | |
7124 | ||
3d875af5 L |
7125 | void |
7126 | init_dwarf_regnames_iamcu (void) | |
7127 | { | |
7128 | dwarf_regnames = dwarf_regnames_iamcu; | |
7129 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
7130 | } | |
7131 | ||
2dc4cec1 L |
7132 | static const char *const dwarf_regnames_x86_64[] = |
7133 | { | |
7134 | "rax", "rdx", "rcx", "rbx", | |
7135 | "rsi", "rdi", "rbp", "rsp", | |
7136 | "r8", "r9", "r10", "r11", | |
7137 | "r12", "r13", "r14", "r15", | |
7138 | "rip", | |
7139 | "xmm0", "xmm1", "xmm2", "xmm3", | |
7140 | "xmm4", "xmm5", "xmm6", "xmm7", | |
7141 | "xmm8", "xmm9", "xmm10", "xmm11", | |
7142 | "xmm12", "xmm13", "xmm14", "xmm15", | |
7143 | "st0", "st1", "st2", "st3", | |
7144 | "st4", "st5", "st6", "st7", | |
7145 | "mm0", "mm1", "mm2", "mm3", | |
7146 | "mm4", "mm5", "mm6", "mm7", | |
7147 | "rflags", | |
7148 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
7149 | "fs.base", "gs.base", NULL, NULL, | |
7150 | "tr", "ldtr", | |
43234a1e L |
7151 | "mxcsr", "fcw", "fsw", |
7152 | "xmm16", "xmm17", "xmm18", "xmm19", | |
7153 | "xmm20", "xmm21", "xmm22", "xmm23", | |
7154 | "xmm24", "xmm25", "xmm26", "xmm27", | |
7155 | "xmm28", "xmm29", "xmm30", "xmm31", | |
7156 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
7157 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
7158 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
7159 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
7160 | NULL, NULL, NULL, /* 115 - 117 */ | |
7161 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
7162 | }; |
7163 | ||
b129eb0e RH |
7164 | void |
7165 | init_dwarf_regnames_x86_64 (void) | |
7166 | { | |
7167 | dwarf_regnames = dwarf_regnames_x86_64; | |
7168 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
7169 | } | |
7170 | ||
4ee22035 RH |
7171 | static const char *const dwarf_regnames_aarch64[] = |
7172 | { | |
b4eb7656 AM |
7173 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
7174 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
7175 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
7176 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
7177 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
7178 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7179 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7180 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
b4eb7656 AM |
7181 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
7182 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
7183 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
7184 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
7185 | }; | |
7186 | ||
7187 | void | |
7188 | init_dwarf_regnames_aarch64 (void) | |
7189 | { | |
7190 | dwarf_regnames = dwarf_regnames_aarch64; | |
7191 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
7192 | } | |
7193 | ||
d6bb17b0 AA |
7194 | static const char *const dwarf_regnames_s390[] = |
7195 | { | |
7196 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
7197 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7198 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7199 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
7200 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
7201 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
7202 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
7203 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
7204 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
7205 | "pswm", "pswa", | |
7206 | NULL, NULL, | |
7207 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
7208 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
7209 | }; | |
7210 | ||
7211 | void | |
7212 | init_dwarf_regnames_s390 (void) | |
7213 | { | |
7214 | dwarf_regnames = dwarf_regnames_s390; | |
7215 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
7216 | } | |
7217 | ||
5bb0830d AB |
7218 | static const char *const dwarf_regnames_riscv[] = |
7219 | { | |
7220 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
7221 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
7222 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
7223 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
7224 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
7225 | "fs0", "fs1", /* 40 - 41 */ | |
7226 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
7227 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
7228 | "fs10", "fs11", /* 58 - 59 */ | |
7229 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
7230 | }; | |
7231 | ||
7232 | void | |
7233 | init_dwarf_regnames_riscv (void) | |
7234 | { | |
7235 | dwarf_regnames = dwarf_regnames_riscv; | |
7236 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_riscv); | |
7237 | } | |
7238 | ||
2dc4cec1 L |
7239 | void |
7240 | init_dwarf_regnames (unsigned int e_machine) | |
7241 | { | |
7242 | switch (e_machine) | |
7243 | { | |
7244 | case EM_386: | |
b129eb0e | 7245 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
7246 | break; |
7247 | ||
3d875af5 L |
7248 | case EM_IAMCU: |
7249 | init_dwarf_regnames_iamcu (); | |
7250 | break; | |
7251 | ||
2dc4cec1 | 7252 | case EM_X86_64: |
7f502d6c | 7253 | case EM_L1OM: |
7a9068fe | 7254 | case EM_K1OM: |
b129eb0e | 7255 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
7256 | break; |
7257 | ||
4ee22035 RH |
7258 | case EM_AARCH64: |
7259 | init_dwarf_regnames_aarch64 (); | |
7260 | break; | |
7261 | ||
d6bb17b0 AA |
7262 | case EM_S390: |
7263 | init_dwarf_regnames_s390 (); | |
7264 | break; | |
7265 | ||
5bb0830d AB |
7266 | case EM_RISCV: |
7267 | init_dwarf_regnames_riscv (); | |
7268 | break; | |
7269 | ||
2dc4cec1 L |
7270 | default: |
7271 | break; | |
7272 | } | |
7273 | } | |
7274 | ||
7275 | static const char * | |
7276 | regname (unsigned int regno, int row) | |
7277 | { | |
7278 | static char reg[64]; | |
7f2c8a1d | 7279 | |
2dc4cec1 L |
7280 | if (dwarf_regnames |
7281 | && regno < dwarf_regnames_count | |
7282 | && dwarf_regnames [regno] != NULL) | |
7283 | { | |
7284 | if (row) | |
7285 | return dwarf_regnames [regno]; | |
7286 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, | |
7287 | dwarf_regnames [regno]); | |
7288 | } | |
7289 | else | |
7290 | snprintf (reg, sizeof (reg), "r%d", regno); | |
7291 | return reg; | |
7292 | } | |
7293 | ||
19e6b90e | 7294 | static void |
a1165289 | 7295 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 7296 | { |
a1165289 | 7297 | unsigned int r; |
19e6b90e L |
7298 | char tmp[100]; |
7299 | ||
d8024a91 | 7300 | if (*max_regs != fc->ncols) |
19e6b90e L |
7301 | *max_regs = fc->ncols; |
7302 | ||
7303 | if (*need_col_headers) | |
7304 | { | |
91d6fa6a | 7305 | static const char *sloc = " LOC"; |
2dc4cec1 | 7306 | |
19e6b90e L |
7307 | *need_col_headers = 0; |
7308 | ||
91d6fa6a | 7309 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
7310 | |
7311 | for (r = 0; r < *max_regs; r++) | |
7312 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7313 | { | |
7314 | if (r == fc->ra) | |
50751e18 | 7315 | printf ("ra "); |
19e6b90e | 7316 | else |
2dc4cec1 | 7317 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
7318 | } |
7319 | ||
7320 | printf ("\n"); | |
7321 | } | |
7322 | ||
bf5117e3 | 7323 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
7324 | if (fc->cfa_exp) |
7325 | strcpy (tmp, "exp"); | |
7326 | else | |
c8071705 | 7327 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
7328 | printf ("%-8s ", tmp); |
7329 | ||
7330 | for (r = 0; r < fc->ncols; r++) | |
7331 | { | |
7332 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7333 | { | |
7334 | switch (fc->col_type[r]) | |
7335 | { | |
7336 | case DW_CFA_undefined: | |
7337 | strcpy (tmp, "u"); | |
7338 | break; | |
7339 | case DW_CFA_same_value: | |
7340 | strcpy (tmp, "s"); | |
7341 | break; | |
7342 | case DW_CFA_offset: | |
7343 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
7344 | break; | |
12eae2d3 JJ |
7345 | case DW_CFA_val_offset: |
7346 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
7347 | break; | |
19e6b90e | 7348 | case DW_CFA_register: |
2dc4cec1 | 7349 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
7350 | break; |
7351 | case DW_CFA_expression: | |
7352 | strcpy (tmp, "exp"); | |
7353 | break; | |
12eae2d3 JJ |
7354 | case DW_CFA_val_expression: |
7355 | strcpy (tmp, "vexp"); | |
7356 | break; | |
19e6b90e L |
7357 | default: |
7358 | strcpy (tmp, "n/a"); | |
7359 | break; | |
7360 | } | |
2dc4cec1 | 7361 | printf ("%-5s ", tmp); |
19e6b90e L |
7362 | } |
7363 | } | |
7364 | printf ("\n"); | |
7365 | } | |
7366 | ||
49727e46 | 7367 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 7368 | |
49727e46 AM |
7369 | static unsigned char * |
7370 | read_cie (unsigned char *start, unsigned char *end, | |
7371 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 7372 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
7373 | { |
7374 | int version; | |
7375 | Frame_Chunk *fc; | |
7376 | unsigned int length_return; | |
7377 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 7378 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 7379 | |
041830e0 | 7380 | * p_cie = NULL; |
f41e4712 NC |
7381 | /* PR 17512: file: 001-228113-0.004. */ |
7382 | if (start >= end) | |
7383 | return end; | |
7384 | ||
49727e46 AM |
7385 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
7386 | memset (fc, 0, sizeof (Frame_Chunk)); | |
7387 | ||
7388 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
7389 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
7390 | ||
7391 | version = *start++; | |
7392 | ||
7393 | fc->augmentation = (char *) start; | |
f41e4712 NC |
7394 | /* PR 17512: file: 001-228113-0.004. |
7395 | Skip past augmentation name, but avoid running off the end of the data. */ | |
7396 | while (start < end) | |
7397 | if (* start ++ == '\0') | |
7398 | break; | |
7399 | if (start == end) | |
7400 | { | |
7401 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 7402 | goto fail; |
f41e4712 | 7403 | } |
49727e46 AM |
7404 | |
7405 | if (strcmp (fc->augmentation, "eh") == 0) | |
7406 | start += eh_addr_size; | |
7407 | ||
7408 | if (version >= 4) | |
7409 | { | |
7410 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
7411 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
7412 | { | |
7413 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 7414 | goto fail; |
77ef8654 NC |
7415 | } |
7416 | ||
49727e46 | 7417 | GET (fc->segment_size, 1); |
77ef8654 NC |
7418 | /* PR 17512: file: e99d2804. */ |
7419 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
7420 | { | |
7421 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 7422 | goto fail; |
77ef8654 NC |
7423 | } |
7424 | ||
49727e46 AM |
7425 | eh_addr_size = fc->ptr_size; |
7426 | } | |
7427 | else | |
7428 | { | |
7429 | fc->ptr_size = eh_addr_size; | |
7430 | fc->segment_size = 0; | |
7431 | } | |
442a6ce8 | 7432 | |
7f2c8a1d NC |
7433 | READ_ULEB (fc->code_factor); |
7434 | READ_SLEB (fc->data_factor); | |
442a6ce8 | 7435 | |
49727e46 AM |
7436 | if (version == 1) |
7437 | { | |
7438 | GET (fc->ra, 1); | |
7439 | } | |
7440 | else | |
7441 | { | |
7f2c8a1d | 7442 | READ_ULEB (fc->ra); |
49727e46 AM |
7443 | } |
7444 | ||
7445 | if (fc->augmentation[0] == 'z') | |
7446 | { | |
7f2c8a1d | 7447 | READ_ULEB (augmentation_data_len); |
49727e46 | 7448 | augmentation_data = start; |
a1165289 | 7449 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 7450 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 7451 | { |
bf59c5d5 NC |
7452 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
7453 | dwarf_vmatoa ("x", augmentation_data_len), | |
7454 | (unsigned long) (end - start)); | |
442a6ce8 | 7455 | goto fail; |
a1165289 | 7456 | } |
9c0f3d3f | 7457 | start += augmentation_data_len; |
49727e46 AM |
7458 | } |
7459 | ||
7460 | if (augmentation_data_len) | |
7461 | { | |
058037d3 NC |
7462 | unsigned char *p; |
7463 | unsigned char *q; | |
7464 | unsigned char *qend; | |
b4eb7656 | 7465 | |
49727e46 AM |
7466 | p = (unsigned char *) fc->augmentation + 1; |
7467 | q = augmentation_data; | |
058037d3 NC |
7468 | qend = q + augmentation_data_len; |
7469 | ||
9c0f3d3f | 7470 | while (p < end && q < qend) |
49727e46 AM |
7471 | { |
7472 | if (*p == 'L') | |
7473 | q++; | |
7474 | else if (*p == 'P') | |
7475 | q += 1 + size_of_encoded_value (*q); | |
7476 | else if (*p == 'R') | |
7477 | fc->fde_encoding = *q++; | |
7478 | else if (*p == 'S') | |
7479 | ; | |
09038062 ST |
7480 | else if (*p == 'B') |
7481 | ; | |
49727e46 AM |
7482 | else |
7483 | break; | |
7484 | p++; | |
7485 | } | |
c361b9ac NC |
7486 | /* Note - it is OK if this loop terminates with q < qend. |
7487 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
7488 | } |
7489 | ||
7490 | *p_cie = fc; | |
7491 | if (p_version) | |
7492 | *p_version = version; | |
7493 | if (p_aug_len) | |
7494 | { | |
7495 | *p_aug_len = augmentation_data_len; | |
7496 | *p_aug = augmentation_data; | |
7497 | } | |
7498 | return start; | |
442a6ce8 NC |
7499 | |
7500 | fail: | |
7501 | free (fc->col_offset); | |
7502 | free (fc->col_type); | |
7503 | free (fc); | |
7504 | return end; | |
49727e46 AM |
7505 | } |
7506 | ||
d85bf2ba NC |
7507 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
7508 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
7509 | PRINTED contains the number of characters already written to the current | |
7510 | output line. */ | |
bf59c5d5 NC |
7511 | |
7512 | static void | |
d85bf2ba NC |
7513 | display_data (bfd_size_type printed, |
7514 | const unsigned char * data, | |
7515 | const bfd_size_type len) | |
bf59c5d5 | 7516 | { |
d85bf2ba NC |
7517 | if (do_wide || len < ((80 - printed) / 3)) |
7518 | for (printed = 0; printed < len; ++printed) | |
7519 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
7520 | else |
7521 | { | |
d85bf2ba | 7522 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 7523 | { |
d85bf2ba | 7524 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 7525 | putchar ('\n'); |
d85bf2ba | 7526 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
7527 | } |
7528 | } | |
d85bf2ba NC |
7529 | } |
7530 | ||
7531 | /* Prints out the contents on the augmentation data array. | |
7532 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
7533 | ||
7534 | static void | |
7535 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
7536 | { | |
7537 | bfd_size_type i; | |
7538 | ||
7539 | i = printf (_(" Augmentation data: ")); | |
7540 | display_data (i, data, len); | |
bf59c5d5 NC |
7541 | } |
7542 | ||
19e6b90e L |
7543 | static int |
7544 | display_debug_frames (struct dwarf_section *section, | |
7545 | void *file ATTRIBUTE_UNUSED) | |
7546 | { | |
7547 | unsigned char *start = section->start; | |
7548 | unsigned char *end = start + section->size; | |
7549 | unsigned char *section_start = start; | |
3391569f NC |
7550 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
7551 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 7552 | Frame_Chunk *rs; |
3391569f | 7553 | bfd_boolean is_eh = strcmp (section->name, ".eh_frame") == 0; |
19e6b90e | 7554 | unsigned int length_return; |
a1165289 | 7555 | unsigned int max_regs = 0; |
665ce1f6 | 7556 | const char *bad_reg = _("bad register: "); |
77ef8654 | 7557 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 7558 | |
dda8d76d | 7559 | introduce (section, FALSE); |
19e6b90e L |
7560 | |
7561 | while (start < end) | |
7562 | { | |
7563 | unsigned char *saved_start; | |
7564 | unsigned char *block_end; | |
bf5117e3 NC |
7565 | dwarf_vma length; |
7566 | dwarf_vma cie_id; | |
19e6b90e L |
7567 | Frame_Chunk *fc; |
7568 | Frame_Chunk *cie; | |
7569 | int need_col_headers = 1; | |
7570 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 7571 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
7572 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
7573 | unsigned int offset_size; | |
7574 | unsigned int initial_length_size; | |
5b6312fd | 7575 | bfd_boolean all_nops; |
19e6b90e L |
7576 | |
7577 | saved_start = start; | |
19e6b90e | 7578 | |
0c588247 | 7579 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 7580 | |
19e6b90e L |
7581 | if (length == 0) |
7582 | { | |
7583 | printf ("\n%08lx ZERO terminator\n\n", | |
7584 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
7585 | /* Skip any zero terminators that directly follow. |
7586 | A corrupt section size could have loaded a whole | |
7587 | slew of zero filled memory bytes. eg | |
7588 | PR 17512: file: 070-19381-0.004. */ | |
7589 | while (start < end && * start == 0) | |
7590 | ++ start; | |
b758e50f | 7591 | continue; |
19e6b90e L |
7592 | } |
7593 | ||
7594 | if (length == 0xffffffff) | |
7595 | { | |
0c588247 | 7596 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
7597 | offset_size = 8; |
7598 | initial_length_size = 12; | |
7599 | } | |
7600 | else | |
7601 | { | |
7602 | offset_size = 4; | |
7603 | initial_length_size = 4; | |
7604 | } | |
7605 | ||
7606 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 7607 | if (block_end > end || block_end < start) |
53b8873b | 7608 | { |
bf5117e3 NC |
7609 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
7610 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
7611 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
7612 | block_end = end; |
7613 | } | |
0c588247 NC |
7614 | |
7615 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 7616 | |
846a11e4 NC |
7617 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
7618 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
7619 | { |
7620 | int version; | |
a1165289 | 7621 | unsigned int mreg; |
19e6b90e | 7622 | |
49727e46 AM |
7623 | start = read_cie (start, end, &cie, &version, |
7624 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
7625 | /* PR 17512: file: 027-135133-0.005. */ |
7626 | if (cie == NULL) | |
7627 | break; | |
a1165289 | 7628 | |
49727e46 | 7629 | fc = cie; |
19e6b90e L |
7630 | fc->next = chunks; |
7631 | chunks = fc; | |
7632 | fc->chunk_start = saved_start; | |
a1165289 | 7633 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
7634 | if (mreg < fc->ra) |
7635 | mreg = fc->ra; | |
06614111 NC |
7636 | if (frame_need_space (fc, mreg) < 0) |
7637 | break; | |
49727e46 AM |
7638 | if (fc->fde_encoding) |
7639 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 7640 | |
bf5117e3 NC |
7641 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
7642 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 7643 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 7644 | |
19e6b90e | 7645 | if (do_debug_frames_interp) |
bf5117e3 NC |
7646 | { |
7647 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
7648 | fc->code_factor, fc->data_factor, fc->ra); | |
7649 | } | |
19e6b90e L |
7650 | else |
7651 | { | |
bf5117e3 | 7652 | printf ("CIE\n"); |
19e6b90e L |
7653 | printf (" Version: %d\n", version); |
7654 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
7655 | if (version >= 4) |
7656 | { | |
7657 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
7658 | printf (" Segment Size: %u\n", fc->segment_size); | |
7659 | } | |
19e6b90e L |
7660 | printf (" Code alignment factor: %u\n", fc->code_factor); |
7661 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
7662 | printf (" Return address column: %d\n", fc->ra); | |
7663 | ||
7664 | if (augmentation_data_len) | |
bf59c5d5 | 7665 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 7666 | |
19e6b90e L |
7667 | putchar ('\n'); |
7668 | } | |
19e6b90e L |
7669 | } |
7670 | else | |
7671 | { | |
7672 | unsigned char *look_for; | |
7673 | static Frame_Chunk fde_fc; | |
604282a7 | 7674 | unsigned long segment_selector; |
19e6b90e | 7675 | |
49727e46 AM |
7676 | if (is_eh) |
7677 | { | |
7678 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
7679 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
7680 | } | |
7681 | else | |
7682 | look_for = section_start + cie_id; | |
19e6b90e | 7683 | |
49727e46 AM |
7684 | if (look_for <= saved_start) |
7685 | { | |
7686 | for (cie = chunks; cie ; cie = cie->next) | |
7687 | if (cie->chunk_start == look_for) | |
7688 | break; | |
7689 | } | |
7690 | else | |
7691 | { | |
7692 | for (cie = forward_refs; cie ; cie = cie->next) | |
7693 | if (cie->chunk_start == look_for) | |
7694 | break; | |
7695 | if (!cie) | |
7696 | { | |
7697 | unsigned int off_size; | |
7698 | unsigned char *cie_scan; | |
19e6b90e | 7699 | |
49727e46 AM |
7700 | cie_scan = look_for; |
7701 | off_size = 4; | |
7702 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
7703 | if (length == 0xffffffff) | |
7704 | { | |
7705 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
7706 | off_size = 8; | |
7707 | } | |
7708 | if (length != 0) | |
7709 | { | |
7710 | dwarf_vma c_id; | |
7711 | ||
7712 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
7713 | if (is_eh | |
7714 | ? c_id == 0 | |
7715 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
7716 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
7717 | { | |
7718 | int version; | |
a1165289 | 7719 | unsigned int mreg; |
49727e46 AM |
7720 | |
7721 | read_cie (cie_scan, end, &cie, &version, | |
7722 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
7723 | /* PR 17512: file: 3450-2098-0.004. */ |
7724 | if (cie == NULL) | |
7725 | { | |
7726 | warn (_("Failed to read CIE information\n")); | |
7727 | break; | |
7728 | } | |
49727e46 AM |
7729 | cie->next = forward_refs; |
7730 | forward_refs = cie; | |
7731 | cie->chunk_start = look_for; | |
a1165289 | 7732 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
7733 | if (mreg < cie->ra) |
7734 | mreg = cie->ra; | |
06614111 NC |
7735 | if (frame_need_space (cie, mreg) < 0) |
7736 | { | |
7737 | warn (_("Invalid max register\n")); | |
7738 | break; | |
7739 | } | |
49727e46 AM |
7740 | if (cie->fde_encoding) |
7741 | encoded_ptr_size | |
7742 | = size_of_encoded_value (cie->fde_encoding); | |
7743 | } | |
7744 | } | |
7745 | } | |
7746 | } | |
7747 | ||
7748 | fc = &fde_fc; | |
7749 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
7750 | |
7751 | if (!cie) | |
7752 | { | |
bf5117e3 NC |
7753 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
7754 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
7755 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 7756 | fc->ncols = 0; |
3f5e193b NC |
7757 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
7758 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
7759 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
7760 | { | |
7761 | warn (_("Invalid max register\n")); | |
7762 | break; | |
7763 | } | |
19e6b90e L |
7764 | cie = fc; |
7765 | fc->augmentation = ""; | |
7766 | fc->fde_encoding = 0; | |
604282a7 JJ |
7767 | fc->ptr_size = eh_addr_size; |
7768 | fc->segment_size = 0; | |
19e6b90e L |
7769 | } |
7770 | else | |
7771 | { | |
7772 | fc->ncols = cie->ncols; | |
3f5e193b NC |
7773 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
7774 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
7775 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
7776 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
7777 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
7778 | fc->ptr_size = cie->ptr_size; |
7779 | eh_addr_size = cie->ptr_size; | |
7780 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
7781 | fc->code_factor = cie->code_factor; |
7782 | fc->data_factor = cie->data_factor; | |
7783 | fc->cfa_reg = cie->cfa_reg; | |
7784 | fc->cfa_offset = cie->cfa_offset; | |
7785 | fc->ra = cie->ra; | |
06614111 NC |
7786 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
7787 | { | |
7788 | warn (_("Invalid max register\n")); | |
7789 | break; | |
7790 | } | |
19e6b90e L |
7791 | fc->fde_encoding = cie->fde_encoding; |
7792 | } | |
7793 | ||
7794 | if (fc->fde_encoding) | |
7795 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
7796 | ||
604282a7 JJ |
7797 | segment_selector = 0; |
7798 | if (fc->segment_size) | |
c8071705 NC |
7799 | { |
7800 | if (fc->segment_size > sizeof (segment_selector)) | |
7801 | { | |
7802 | /* PR 17512: file: 9e196b3e. */ | |
7803 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
7804 | fc->segment_size = 4; | |
7805 | } | |
7806 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
7807 | } | |
041830e0 NC |
7808 | |
7809 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 7810 | |
0c588247 NC |
7811 | /* FIXME: It appears that sometimes the final pc_range value is |
7812 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
7813 | run of the "objcopy on compressed debug sections" test for an | |
7814 | example of this. */ | |
7815 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 7816 | |
19e6b90e L |
7817 | if (cie->augmentation[0] == 'z') |
7818 | { | |
7f2c8a1d | 7819 | READ_ULEB (augmentation_data_len); |
19e6b90e L |
7820 | augmentation_data = start; |
7821 | start += augmentation_data_len; | |
bf59c5d5 NC |
7822 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
7823 | if (start >= end | |
7824 | || ((bfd_signed_vma) augmentation_data_len) < 0 | |
7825 | || augmentation_data > start) | |
0a9d414a | 7826 | { |
bf59c5d5 NC |
7827 | warn (_("Corrupt augmentation data length: 0x%s\n"), |
7828 | dwarf_vmatoa ("x", augmentation_data_len)); | |
0a9d414a NC |
7829 | start = end; |
7830 | augmentation_data = NULL; | |
7831 | augmentation_data_len = 0; | |
7832 | } | |
19e6b90e L |
7833 | } |
7834 | ||
bf5117e3 NC |
7835 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
7836 | (unsigned long)(saved_start - section_start), | |
7837 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 7838 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 7839 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 7840 | |
604282a7 JJ |
7841 | if (fc->segment_size) |
7842 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
7843 | |
7844 | printf ("%s..%s\n", | |
7845 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
7846 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
7847 | ||
19e6b90e L |
7848 | if (! do_debug_frames_interp && augmentation_data_len) |
7849 | { | |
bf59c5d5 | 7850 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
7851 | putchar ('\n'); |
7852 | } | |
7853 | } | |
7854 | ||
7855 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
7856 | we're about to interpret instructions for the chunk. */ | |
7857 | /* ??? At present we need to do this always, since this sizes the | |
7858 | fc->col_type and fc->col_offset arrays, which we write into always. | |
7859 | We should probably split the interpreted and non-interpreted bits | |
7860 | into two different routines, since there's so much that doesn't | |
7861 | really overlap between them. */ | |
7862 | if (1 || do_debug_frames_interp) | |
7863 | { | |
7864 | /* Start by making a pass over the chunk, allocating storage | |
7865 | and taking note of what registers are used. */ | |
7866 | unsigned char *tmp = start; | |
7867 | ||
7868 | while (start < block_end) | |
7869 | { | |
041830e0 NC |
7870 | unsigned int reg, op, opa; |
7871 | unsigned long temp; | |
5929c344 | 7872 | unsigned char * new_start; |
19e6b90e L |
7873 | |
7874 | op = *start++; | |
7875 | opa = op & 0x3f; | |
7876 | if (op & 0xc0) | |
7877 | op &= 0xc0; | |
7878 | ||
7879 | /* Warning: if you add any more cases to this switch, be | |
7880 | sure to add them to the corresponding switch below. */ | |
7881 | switch (op) | |
7882 | { | |
7883 | case DW_CFA_advance_loc: | |
7884 | break; | |
7885 | case DW_CFA_offset: | |
7f2c8a1d | 7886 | SKIP_ULEB (); |
665ce1f6 L |
7887 | if (frame_need_space (fc, opa) >= 0) |
7888 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
7889 | break; |
7890 | case DW_CFA_restore: | |
665ce1f6 L |
7891 | if (frame_need_space (fc, opa) >= 0) |
7892 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
7893 | break; |
7894 | case DW_CFA_set_loc: | |
7895 | start += encoded_ptr_size; | |
7896 | break; | |
7897 | case DW_CFA_advance_loc1: | |
7898 | start += 1; | |
7899 | break; | |
7900 | case DW_CFA_advance_loc2: | |
7901 | start += 2; | |
7902 | break; | |
7903 | case DW_CFA_advance_loc4: | |
7904 | start += 4; | |
7905 | break; | |
7906 | case DW_CFA_offset_extended: | |
12eae2d3 | 7907 | case DW_CFA_val_offset: |
7f2c8a1d NC |
7908 | READ_ULEB (reg); |
7909 | SKIP_ULEB (); | |
665ce1f6 L |
7910 | if (frame_need_space (fc, reg) >= 0) |
7911 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7912 | break; |
7913 | case DW_CFA_restore_extended: | |
7f2c8a1d | 7914 | READ_ULEB (reg); |
665ce1f6 L |
7915 | if (frame_need_space (fc, reg) >= 0) |
7916 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7917 | break; |
7918 | case DW_CFA_undefined: | |
7f2c8a1d | 7919 | READ_ULEB (reg); |
665ce1f6 L |
7920 | if (frame_need_space (fc, reg) >= 0) |
7921 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7922 | break; |
7923 | case DW_CFA_same_value: | |
7f2c8a1d | 7924 | READ_ULEB (reg); |
665ce1f6 L |
7925 | if (frame_need_space (fc, reg) >= 0) |
7926 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7927 | break; |
7928 | case DW_CFA_register: | |
7f2c8a1d NC |
7929 | READ_ULEB (reg); |
7930 | SKIP_ULEB (); | |
665ce1f6 L |
7931 | if (frame_need_space (fc, reg) >= 0) |
7932 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7933 | break; |
7934 | case DW_CFA_def_cfa: | |
7f2c8a1d NC |
7935 | SKIP_ULEB (); |
7936 | SKIP_ULEB (); | |
19e6b90e L |
7937 | break; |
7938 | case DW_CFA_def_cfa_register: | |
7f2c8a1d | 7939 | SKIP_ULEB (); |
19e6b90e L |
7940 | break; |
7941 | case DW_CFA_def_cfa_offset: | |
7f2c8a1d | 7942 | SKIP_ULEB (); |
19e6b90e L |
7943 | break; |
7944 | case DW_CFA_def_cfa_expression: | |
7f2c8a1d | 7945 | READ_ULEB (temp); |
5929c344 NC |
7946 | new_start = start + temp; |
7947 | if (new_start < start) | |
041830e0 NC |
7948 | { |
7949 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
7950 | start = block_end; | |
7951 | } | |
7952 | else | |
5929c344 | 7953 | start = new_start; |
19e6b90e L |
7954 | break; |
7955 | case DW_CFA_expression: | |
12eae2d3 | 7956 | case DW_CFA_val_expression: |
7f2c8a1d NC |
7957 | READ_ULEB (reg); |
7958 | READ_ULEB (temp); | |
5929c344 NC |
7959 | new_start = start + temp; |
7960 | if (new_start < start) | |
041830e0 | 7961 | { |
b4eb7656 | 7962 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
7963 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
7964 | start = block_end; | |
7965 | } | |
7966 | else | |
5929c344 | 7967 | start = new_start; |
665ce1f6 L |
7968 | if (frame_need_space (fc, reg) >= 0) |
7969 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7970 | break; |
7971 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 7972 | case DW_CFA_val_offset_sf: |
7f2c8a1d NC |
7973 | READ_ULEB (reg); |
7974 | SKIP_SLEB (); | |
665ce1f6 L |
7975 | if (frame_need_space (fc, reg) >= 0) |
7976 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
7977 | break; |
7978 | case DW_CFA_def_cfa_sf: | |
7f2c8a1d NC |
7979 | SKIP_ULEB (); |
7980 | SKIP_SLEB (); | |
19e6b90e L |
7981 | break; |
7982 | case DW_CFA_def_cfa_offset_sf: | |
7f2c8a1d | 7983 | SKIP_SLEB (); |
19e6b90e L |
7984 | break; |
7985 | case DW_CFA_MIPS_advance_loc8: | |
7986 | start += 8; | |
7987 | break; | |
7988 | case DW_CFA_GNU_args_size: | |
7f2c8a1d | 7989 | SKIP_ULEB (); |
19e6b90e L |
7990 | break; |
7991 | case DW_CFA_GNU_negative_offset_extended: | |
7f2c8a1d NC |
7992 | READ_ULEB (reg); |
7993 | SKIP_ULEB (); | |
665ce1f6 L |
7994 | if (frame_need_space (fc, reg) >= 0) |
7995 | fc->col_type[reg] = DW_CFA_undefined; | |
7996 | break; | |
19e6b90e L |
7997 | default: |
7998 | break; | |
7999 | } | |
8000 | } | |
8001 | start = tmp; | |
8002 | } | |
8003 | ||
5b6312fd NC |
8004 | all_nops = TRUE; |
8005 | ||
19e6b90e L |
8006 | /* Now we know what registers are used, make a second pass over |
8007 | the chunk, this time actually printing out the info. */ | |
8008 | ||
8009 | while (start < block_end) | |
8010 | { | |
362beea4 | 8011 | unsigned char * tmp; |
19e6b90e | 8012 | unsigned op, opa; |
7f2c8a1d NC |
8013 | unsigned long ul, roffs; |
8014 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
8015 | are various functions, notably frame_space_needed() that assume that | |
8016 | reg is an unsigned int. */ | |
8017 | unsigned int reg; | |
8018 | dwarf_signed_vma l; | |
bf5117e3 | 8019 | dwarf_vma ofs; |
19e6b90e | 8020 | dwarf_vma vma; |
665ce1f6 | 8021 | const char *reg_prefix = ""; |
19e6b90e L |
8022 | |
8023 | op = *start++; | |
8024 | opa = op & 0x3f; | |
8025 | if (op & 0xc0) | |
8026 | op &= 0xc0; | |
8027 | ||
5b6312fd NC |
8028 | /* Make a note if something other than DW_CFA_nop happens. */ |
8029 | if (op != DW_CFA_nop) | |
8030 | all_nops = FALSE; | |
8031 | ||
19e6b90e L |
8032 | /* Warning: if you add any more cases to this switch, be |
8033 | sure to add them to the corresponding switch above. */ | |
8034 | switch (op) | |
8035 | { | |
8036 | case DW_CFA_advance_loc: | |
8037 | if (do_debug_frames_interp) | |
8038 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8039 | else | |
bf5117e3 | 8040 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 8041 | opa * fc->code_factor, |
b4eb7656 | 8042 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
8043 | fc->pc_begin + opa * fc->code_factor, |
8044 | fc->ptr_size)); | |
19e6b90e L |
8045 | fc->pc_begin += opa * fc->code_factor; |
8046 | break; | |
8047 | ||
8048 | case DW_CFA_offset: | |
7f2c8a1d | 8049 | READ_ULEB (roffs); |
665ce1f6 L |
8050 | if (opa >= (unsigned int) fc->ncols) |
8051 | reg_prefix = bad_reg; | |
8052 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8053 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
8054 | reg_prefix, regname (opa, 0), | |
8055 | roffs * fc->data_factor); | |
8056 | if (*reg_prefix == '\0') | |
8057 | { | |
8058 | fc->col_type[opa] = DW_CFA_offset; | |
8059 | fc->col_offset[opa] = roffs * fc->data_factor; | |
8060 | } | |
19e6b90e L |
8061 | break; |
8062 | ||
8063 | case DW_CFA_restore: | |
50751e18 | 8064 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
8065 | reg_prefix = bad_reg; |
8066 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8067 | printf (" DW_CFA_restore: %s%s\n", | |
8068 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
8069 | if (*reg_prefix != '\0') |
8070 | break; | |
8071 | ||
8072 | if (opa >= (unsigned int) cie->ncols | |
8073 | || (do_debug_frames_interp | |
8074 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
8075 | { | |
8076 | fc->col_type[opa] = DW_CFA_undefined; | |
8077 | fc->col_offset[opa] = 0; | |
8078 | } | |
8079 | else | |
665ce1f6 L |
8080 | { |
8081 | fc->col_type[opa] = cie->col_type[opa]; | |
8082 | fc->col_offset[opa] = cie->col_offset[opa]; | |
8083 | } | |
19e6b90e L |
8084 | break; |
8085 | ||
8086 | case DW_CFA_set_loc: | |
6937bb54 | 8087 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
8088 | if (do_debug_frames_interp) |
8089 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8090 | else | |
bf5117e3 NC |
8091 | printf (" DW_CFA_set_loc: %s\n", |
8092 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
8093 | fc->pc_begin = vma; |
8094 | break; | |
8095 | ||
8096 | case DW_CFA_advance_loc1: | |
0c588247 | 8097 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
8098 | if (do_debug_frames_interp) |
8099 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8100 | else | |
bf5117e3 NC |
8101 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
8102 | (unsigned long) (ofs * fc->code_factor), | |
8103 | dwarf_vmatoa_1 (NULL, | |
8104 | fc->pc_begin + ofs * fc->code_factor, | |
8105 | fc->ptr_size)); | |
19e6b90e L |
8106 | fc->pc_begin += ofs * fc->code_factor; |
8107 | break; | |
8108 | ||
8109 | case DW_CFA_advance_loc2: | |
6937bb54 | 8110 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
8111 | if (do_debug_frames_interp) |
8112 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8113 | else | |
bf5117e3 NC |
8114 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
8115 | (unsigned long) (ofs * fc->code_factor), | |
8116 | dwarf_vmatoa_1 (NULL, | |
8117 | fc->pc_begin + ofs * fc->code_factor, | |
8118 | fc->ptr_size)); | |
19e6b90e L |
8119 | fc->pc_begin += ofs * fc->code_factor; |
8120 | break; | |
8121 | ||
8122 | case DW_CFA_advance_loc4: | |
6937bb54 | 8123 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
8124 | if (do_debug_frames_interp) |
8125 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8126 | else | |
bf5117e3 NC |
8127 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
8128 | (unsigned long) (ofs * fc->code_factor), | |
8129 | dwarf_vmatoa_1 (NULL, | |
8130 | fc->pc_begin + ofs * fc->code_factor, | |
8131 | fc->ptr_size)); | |
19e6b90e L |
8132 | fc->pc_begin += ofs * fc->code_factor; |
8133 | break; | |
8134 | ||
8135 | case DW_CFA_offset_extended: | |
7f2c8a1d NC |
8136 | READ_ULEB (reg); |
8137 | READ_ULEB (roffs); | |
665ce1f6 L |
8138 | if (reg >= (unsigned int) fc->ncols) |
8139 | reg_prefix = bad_reg; | |
8140 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8141 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
8142 | reg_prefix, regname (reg, 0), | |
8143 | roffs * fc->data_factor); | |
8144 | if (*reg_prefix == '\0') | |
8145 | { | |
8146 | fc->col_type[reg] = DW_CFA_offset; | |
8147 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8148 | } | |
19e6b90e L |
8149 | break; |
8150 | ||
12eae2d3 | 8151 | case DW_CFA_val_offset: |
7f2c8a1d NC |
8152 | READ_ULEB (reg); |
8153 | READ_ULEB (roffs); | |
665ce1f6 L |
8154 | if (reg >= (unsigned int) fc->ncols) |
8155 | reg_prefix = bad_reg; | |
8156 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8157 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
8158 | reg_prefix, regname (reg, 0), |
8159 | roffs * fc->data_factor); | |
8160 | if (*reg_prefix == '\0') | |
8161 | { | |
8162 | fc->col_type[reg] = DW_CFA_val_offset; | |
8163 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8164 | } | |
12eae2d3 JJ |
8165 | break; |
8166 | ||
19e6b90e | 8167 | case DW_CFA_restore_extended: |
7f2c8a1d | 8168 | READ_ULEB (reg); |
50751e18 | 8169 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
8170 | reg_prefix = bad_reg; |
8171 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8172 | printf (" DW_CFA_restore_extended: %s%s\n", | |
8173 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
8174 | if (*reg_prefix != '\0') |
8175 | break; | |
8176 | ||
8177 | if (reg >= (unsigned int) cie->ncols) | |
8178 | { | |
8179 | fc->col_type[reg] = DW_CFA_undefined; | |
8180 | fc->col_offset[reg] = 0; | |
8181 | } | |
8182 | else | |
665ce1f6 L |
8183 | { |
8184 | fc->col_type[reg] = cie->col_type[reg]; | |
8185 | fc->col_offset[reg] = cie->col_offset[reg]; | |
8186 | } | |
19e6b90e L |
8187 | break; |
8188 | ||
8189 | case DW_CFA_undefined: | |
7f2c8a1d | 8190 | READ_ULEB (reg); |
665ce1f6 L |
8191 | if (reg >= (unsigned int) fc->ncols) |
8192 | reg_prefix = bad_reg; | |
8193 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8194 | printf (" DW_CFA_undefined: %s%s\n", | |
8195 | reg_prefix, regname (reg, 0)); | |
8196 | if (*reg_prefix == '\0') | |
8197 | { | |
8198 | fc->col_type[reg] = DW_CFA_undefined; | |
8199 | fc->col_offset[reg] = 0; | |
8200 | } | |
19e6b90e L |
8201 | break; |
8202 | ||
8203 | case DW_CFA_same_value: | |
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_same_value: %s%s\n", | |
8209 | reg_prefix, regname (reg, 0)); | |
8210 | if (*reg_prefix == '\0') | |
8211 | { | |
8212 | fc->col_type[reg] = DW_CFA_same_value; | |
8213 | fc->col_offset[reg] = 0; | |
8214 | } | |
19e6b90e L |
8215 | break; |
8216 | ||
8217 | case DW_CFA_register: | |
7f2c8a1d NC |
8218 | READ_ULEB (reg); |
8219 | READ_ULEB (roffs); | |
665ce1f6 L |
8220 | if (reg >= (unsigned int) fc->ncols) |
8221 | reg_prefix = bad_reg; | |
8222 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 8223 | { |
665ce1f6 L |
8224 | printf (" DW_CFA_register: %s%s in ", |
8225 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
8226 | puts (regname (roffs, 0)); |
8227 | } | |
665ce1f6 L |
8228 | if (*reg_prefix == '\0') |
8229 | { | |
8230 | fc->col_type[reg] = DW_CFA_register; | |
8231 | fc->col_offset[reg] = roffs; | |
8232 | } | |
19e6b90e L |
8233 | break; |
8234 | ||
8235 | case DW_CFA_remember_state: | |
8236 | if (! do_debug_frames_interp) | |
8237 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 8238 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 8239 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
8240 | rs->cfa_reg = fc->cfa_reg; |
8241 | rs->ra = fc->ra; | |
8242 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 8243 | rs->ncols = fc->ncols; |
3f5e193b | 8244 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 8245 | sizeof (* rs->col_type)); |
d71ad7fc RC |
8246 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
8247 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
8248 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
8249 | rs->next = remembered_state; |
8250 | remembered_state = rs; | |
8251 | break; | |
8252 | ||
8253 | case DW_CFA_restore_state: | |
8254 | if (! do_debug_frames_interp) | |
8255 | printf (" DW_CFA_restore_state\n"); | |
8256 | rs = remembered_state; | |
8257 | if (rs) | |
8258 | { | |
8259 | remembered_state = rs->next; | |
d71ad7fc RC |
8260 | fc->cfa_offset = rs->cfa_offset; |
8261 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
8262 | fc->ra = rs->ra; |
8263 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
8264 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
8265 | { | |
1306a742 | 8266 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
8267 | fc->ncols = 0; |
8268 | break; | |
8269 | } | |
d71ad7fc | 8270 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 8271 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 8272 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
8273 | free (rs->col_type); |
8274 | free (rs->col_offset); | |
8275 | free (rs); | |
8276 | } | |
8277 | else if (do_debug_frames_interp) | |
8278 | printf ("Mismatched DW_CFA_restore_state\n"); | |
8279 | break; | |
8280 | ||
8281 | case DW_CFA_def_cfa: | |
32ef3000 | 8282 | READ_ULEB (fc->cfa_reg); |
7f2c8a1d | 8283 | READ_ULEB (fc->cfa_offset); |
19e6b90e L |
8284 | fc->cfa_exp = 0; |
8285 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8286 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 8287 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8288 | break; |
8289 | ||
8290 | case DW_CFA_def_cfa_register: | |
32ef3000 | 8291 | READ_ULEB (fc->cfa_reg); |
19e6b90e L |
8292 | fc->cfa_exp = 0; |
8293 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
8294 | printf (" DW_CFA_def_cfa_register: %s\n", |
8295 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
8296 | break; |
8297 | ||
8298 | case DW_CFA_def_cfa_offset: | |
7f2c8a1d | 8299 | READ_ULEB (fc->cfa_offset); |
19e6b90e | 8300 | if (! do_debug_frames_interp) |
c8071705 | 8301 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8302 | break; |
8303 | ||
8304 | case DW_CFA_nop: | |
8305 | if (! do_debug_frames_interp) | |
8306 | printf (" DW_CFA_nop\n"); | |
8307 | break; | |
8308 | ||
8309 | case DW_CFA_def_cfa_expression: | |
7f2c8a1d | 8310 | READ_ULEB (ul); |
7460c0ab | 8311 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 8312 | { |
a1165289 | 8313 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8314 | break; |
8315 | } | |
19e6b90e L |
8316 | if (! do_debug_frames_interp) |
8317 | { | |
8318 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
8319 | decode_location_expression (start, eh_addr_size, 0, -1, |
8320 | ul, 0, section); | |
19e6b90e L |
8321 | printf (")\n"); |
8322 | } | |
8323 | fc->cfa_exp = 1; | |
8324 | start += ul; | |
8325 | break; | |
8326 | ||
8327 | case DW_CFA_expression: | |
7f2c8a1d NC |
8328 | READ_ULEB (reg); |
8329 | READ_ULEB (ul); | |
665ce1f6 L |
8330 | if (reg >= (unsigned int) fc->ncols) |
8331 | reg_prefix = bad_reg; | |
6937bb54 | 8332 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 8333 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
8334 | tmp = start + ul; |
8335 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8336 | { |
a1165289 | 8337 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8338 | break; |
8339 | } | |
665ce1f6 | 8340 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 8341 | { |
665ce1f6 L |
8342 | printf (" DW_CFA_expression: %s%s (", |
8343 | reg_prefix, regname (reg, 0)); | |
b7807392 | 8344 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 8345 | ul, 0, section); |
19e6b90e L |
8346 | printf (")\n"); |
8347 | } | |
665ce1f6 L |
8348 | if (*reg_prefix == '\0') |
8349 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 8350 | start = tmp; |
19e6b90e L |
8351 | break; |
8352 | ||
12eae2d3 | 8353 | case DW_CFA_val_expression: |
7f2c8a1d NC |
8354 | READ_ULEB (reg); |
8355 | READ_ULEB (ul); | |
665ce1f6 L |
8356 | if (reg >= (unsigned int) fc->ncols) |
8357 | reg_prefix = bad_reg; | |
362beea4 NC |
8358 | tmp = start + ul; |
8359 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8360 | { |
a1165289 | 8361 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
8362 | break; |
8363 | } | |
665ce1f6 | 8364 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 8365 | { |
665ce1f6 L |
8366 | printf (" DW_CFA_val_expression: %s%s (", |
8367 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
8368 | decode_location_expression (start, eh_addr_size, 0, -1, |
8369 | ul, 0, section); | |
12eae2d3 JJ |
8370 | printf (")\n"); |
8371 | } | |
665ce1f6 L |
8372 | if (*reg_prefix == '\0') |
8373 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 8374 | start = tmp; |
12eae2d3 JJ |
8375 | break; |
8376 | ||
19e6b90e | 8377 | case DW_CFA_offset_extended_sf: |
7f2c8a1d NC |
8378 | READ_ULEB (reg); |
8379 | READ_SLEB (l); | |
665ce1f6 L |
8380 | if (frame_need_space (fc, reg) < 0) |
8381 | reg_prefix = bad_reg; | |
8382 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8383 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
8384 | reg_prefix, regname (reg, 0), | |
c8071705 | 8385 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8386 | if (*reg_prefix == '\0') |
8387 | { | |
8388 | fc->col_type[reg] = DW_CFA_offset; | |
8389 | fc->col_offset[reg] = l * fc->data_factor; | |
8390 | } | |
19e6b90e L |
8391 | break; |
8392 | ||
12eae2d3 | 8393 | case DW_CFA_val_offset_sf: |
7f2c8a1d NC |
8394 | READ_ULEB (reg); |
8395 | READ_SLEB (l); | |
665ce1f6 L |
8396 | if (frame_need_space (fc, reg) < 0) |
8397 | reg_prefix = bad_reg; | |
8398 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8399 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 8400 | reg_prefix, regname (reg, 0), |
c8071705 | 8401 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8402 | if (*reg_prefix == '\0') |
8403 | { | |
8404 | fc->col_type[reg] = DW_CFA_val_offset; | |
8405 | fc->col_offset[reg] = l * fc->data_factor; | |
8406 | } | |
12eae2d3 JJ |
8407 | break; |
8408 | ||
19e6b90e | 8409 | case DW_CFA_def_cfa_sf: |
32ef3000 | 8410 | READ_ULEB (fc->cfa_reg); |
7f2c8a1d | 8411 | READ_ULEB (fc->cfa_offset); |
19e6b90e L |
8412 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
8413 | fc->cfa_exp = 0; | |
8414 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8415 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 8416 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8417 | break; |
8418 | ||
8419 | case DW_CFA_def_cfa_offset_sf: | |
7f2c8a1d | 8420 | READ_ULEB (fc->cfa_offset); |
c8071705 | 8421 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 8422 | if (! do_debug_frames_interp) |
c8071705 | 8423 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8424 | break; |
8425 | ||
8426 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 8427 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
8428 | if (do_debug_frames_interp) |
8429 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8430 | else | |
bf5117e3 NC |
8431 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
8432 | (unsigned long) (ofs * fc->code_factor), | |
8433 | dwarf_vmatoa_1 (NULL, | |
8434 | fc->pc_begin + ofs * fc->code_factor, | |
8435 | fc->ptr_size)); | |
19e6b90e L |
8436 | fc->pc_begin += ofs * fc->code_factor; |
8437 | break; | |
8438 | ||
8439 | case DW_CFA_GNU_window_save: | |
8440 | if (! do_debug_frames_interp) | |
8441 | printf (" DW_CFA_GNU_window_save\n"); | |
8442 | break; | |
8443 | ||
8444 | case DW_CFA_GNU_args_size: | |
7f2c8a1d | 8445 | READ_ULEB (ul); |
19e6b90e L |
8446 | if (! do_debug_frames_interp) |
8447 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
8448 | break; | |
8449 | ||
8450 | case DW_CFA_GNU_negative_offset_extended: | |
7f2c8a1d NC |
8451 | READ_ULEB (reg); |
8452 | READ_SLEB (l); | |
8453 | l = - l; | |
665ce1f6 L |
8454 | if (frame_need_space (fc, reg) < 0) |
8455 | reg_prefix = bad_reg; | |
8456 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8457 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
8458 | reg_prefix, regname (reg, 0), | |
c8071705 | 8459 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8460 | if (*reg_prefix == '\0') |
8461 | { | |
8462 | fc->col_type[reg] = DW_CFA_offset; | |
8463 | fc->col_offset[reg] = l * fc->data_factor; | |
8464 | } | |
19e6b90e L |
8465 | break; |
8466 | ||
8467 | default: | |
53b8873b NC |
8468 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
8469 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
8470 | else | |
f41e4712 | 8471 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
8472 | start = block_end; |
8473 | } | |
8474 | } | |
8475 | ||
5b6312fd NC |
8476 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
8477 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
8478 | frame_display_row (fc, &need_col_headers, &max_regs); |
8479 | ||
8480 | start = block_end; | |
604282a7 | 8481 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
8482 | } |
8483 | ||
8484 | printf ("\n"); | |
8485 | ||
3391569f NC |
8486 | while (remembered_state != NULL) |
8487 | { | |
8488 | rs = remembered_state; | |
8489 | remembered_state = rs->next; | |
8490 | free (rs->col_type); | |
8491 | free (rs->col_offset); | |
8492 | rs->next = NULL; /* Paranoia. */ | |
8493 | free (rs); | |
8494 | } | |
8495 | ||
8496 | while (chunks != NULL) | |
8497 | { | |
8498 | rs = chunks; | |
8499 | chunks = rs->next; | |
8500 | free (rs->col_type); | |
8501 | free (rs->col_offset); | |
8502 | rs->next = NULL; /* Paranoia. */ | |
8503 | free (rs); | |
8504 | } | |
8505 | ||
8506 | while (forward_refs != NULL) | |
8507 | { | |
8508 | rs = forward_refs; | |
8509 | forward_refs = rs->next; | |
8510 | free (rs->col_type); | |
8511 | free (rs->col_offset); | |
8512 | rs->next = NULL; /* Paranoia. */ | |
8513 | free (rs); | |
8514 | } | |
8515 | ||
19e6b90e L |
8516 | return 1; |
8517 | } | |
8518 | ||
8519 | #undef GET | |
19e6b90e | 8520 | |
61364358 JK |
8521 | static int |
8522 | display_debug_names (struct dwarf_section *section, void *file) | |
8523 | { | |
8524 | unsigned char *hdrptr = section->start; | |
8525 | dwarf_vma unit_length; | |
8526 | unsigned char *unit_start; | |
8527 | const unsigned char *const section_end = section->start + section->size; | |
8528 | unsigned char *unit_end; | |
8529 | ||
dda8d76d | 8530 | introduce (section, FALSE); |
61364358 | 8531 | |
dda8d76d | 8532 | load_debug_section_with_follow (str, file); |
61364358 JK |
8533 | |
8534 | for (; hdrptr < section_end; hdrptr = unit_end) | |
8535 | { | |
8536 | unsigned int offset_size; | |
8537 | uint16_t dwarf_version, padding; | |
8538 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
8539 | uint32_t bucket_count, name_count, abbrev_table_size; | |
8540 | uint32_t augmentation_string_size; | |
8541 | unsigned int i; | |
e98fdf1a | 8542 | unsigned long sec_off; |
61364358 JK |
8543 | |
8544 | unit_start = hdrptr; | |
8545 | ||
8546 | /* Get and check the length of the block. */ | |
8547 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
8548 | ||
8549 | if (unit_length == 0xffffffff) | |
8550 | { | |
8551 | /* This section is 64-bit DWARF. */ | |
8552 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
8553 | offset_size = 8; | |
8554 | } | |
8555 | else | |
8556 | offset_size = 4; | |
8557 | unit_end = hdrptr + unit_length; | |
8558 | ||
e98fdf1a AM |
8559 | sec_off = hdrptr - section->start; |
8560 | if (sec_off + unit_length < sec_off | |
8561 | || sec_off + unit_length > section->size) | |
61364358 | 8562 | { |
e98fdf1a AM |
8563 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
8564 | section->name, | |
8565 | (unsigned long) (unit_start - section->start), | |
8566 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
8567 | return 0; |
8568 | } | |
8569 | ||
8570 | /* Get and check the version number. */ | |
8571 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
8572 | printf (_("Version %ld\n"), (long) dwarf_version); | |
8573 | ||
8574 | /* Prior versions did not exist, and future versions may not be | |
8575 | backwards compatible. */ | |
8576 | if (dwarf_version != 5) | |
8577 | { | |
8578 | warn (_("Only DWARF version 5 .debug_names " | |
8579 | "is currently supported.\n")); | |
8580 | return 0; | |
8581 | } | |
8582 | ||
8583 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
8584 | if (padding != 0) | |
8585 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
8586 | padding); | |
8587 | ||
8588 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
8589 | if (comp_unit_count == 0) | |
8590 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
8591 | ||
8592 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
8593 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
8594 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
8595 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
8596 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
8597 | ||
8598 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
8599 | if (augmentation_string_size % 4 != 0) | |
8600 | { | |
8601 | warn (_("Augmentation string length %u must be rounded up " | |
8602 | "to a multiple of 4 in .debug_names.\n"), | |
8603 | augmentation_string_size); | |
8604 | augmentation_string_size += (-augmentation_string_size) & 3; | |
8605 | } | |
8606 | printf (_("Augmentation string:")); | |
8607 | for (i = 0; i < augmentation_string_size; i++) | |
8608 | { | |
8609 | unsigned char uc; | |
8610 | ||
8611 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
8612 | printf (" %02x", uc); | |
8613 | } | |
8614 | putchar ('\n'); | |
8615 | putchar ('\n'); | |
8616 | ||
8617 | printf (_("CU table:\n")); | |
8618 | for (i = 0; i < comp_unit_count; i++) | |
8619 | { | |
8620 | uint64_t cu_offset; | |
8621 | ||
8622 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
8623 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
8624 | } | |
8625 | putchar ('\n'); | |
8626 | ||
8627 | printf (_("TU table:\n")); | |
8628 | for (i = 0; i < local_type_unit_count; i++) | |
8629 | { | |
8630 | uint64_t tu_offset; | |
8631 | ||
8632 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
8633 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
8634 | } | |
8635 | putchar ('\n'); | |
8636 | ||
8637 | printf (_("Foreign TU table:\n")); | |
8638 | for (i = 0; i < foreign_type_unit_count; i++) | |
8639 | { | |
8640 | uint64_t signature; | |
8641 | ||
8642 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
8643 | printf (_("[%3u] "), i); | |
8644 | print_dwarf_vma (signature, 8); | |
8645 | putchar ('\n'); | |
8646 | } | |
8647 | putchar ('\n'); | |
8648 | ||
8649 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
8650 | hdrptr += bucket_count * sizeof (uint32_t); | |
8651 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
8652 | hdrptr += name_count * sizeof (uint32_t); | |
8653 | unsigned char *const name_table_string_offsets = hdrptr; | |
8654 | hdrptr += name_count * offset_size; | |
8655 | unsigned char *const name_table_entry_offsets = hdrptr; | |
8656 | hdrptr += name_count * offset_size; | |
8657 | unsigned char *const abbrev_table = hdrptr; | |
8658 | hdrptr += abbrev_table_size; | |
8659 | const unsigned char *const abbrev_table_end = hdrptr; | |
8660 | unsigned char *const entry_pool = hdrptr; | |
8661 | if (hdrptr > unit_end) | |
8662 | { | |
8663 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
8664 | "for unit 0x%lx in the debug_names\n"), | |
8665 | (long) (hdrptr - section->start), | |
8666 | (long) (unit_end - section->start), | |
8667 | (long) (unit_start - section->start)); | |
8668 | return 0; | |
8669 | } | |
8670 | ||
8671 | size_t buckets_filled = 0; | |
8672 | size_t bucketi; | |
8673 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
8674 | { | |
8675 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
8676 | ||
8677 | if (bucket != 0) | |
8678 | ++buckets_filled; | |
8679 | } | |
d3a49aa8 AM |
8680 | printf (ngettext ("Used %zu of %lu bucket.\n", |
8681 | "Used %zu of %lu buckets.\n", | |
8682 | bucket_count), | |
8683 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 8684 | |
0a79bef4 | 8685 | uint32_t hash_prev = 0; |
61364358 JK |
8686 | size_t hash_clash_count = 0; |
8687 | size_t longest_clash = 0; | |
8688 | size_t this_length = 0; | |
8689 | size_t hashi; | |
8690 | for (hashi = 0; hashi < name_count; hashi++) | |
8691 | { | |
8692 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
8693 | ||
8694 | if (hashi > 0) | |
8695 | { | |
8696 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
8697 | { | |
8698 | ++hash_clash_count; | |
8699 | ++this_length; | |
8700 | longest_clash = MAX (longest_clash, this_length); | |
8701 | } | |
8702 | else | |
8703 | this_length = 0; | |
8704 | } | |
8705 | hash_prev = hash_this; | |
8706 | } | |
8707 | printf (_("Out of %lu items there are %zu bucket clashes" | |
8708 | " (longest of %zu entries).\n"), | |
8709 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
8710 | assert (name_count == buckets_filled + hash_clash_count); | |
8711 | ||
8712 | struct abbrev_lookup_entry | |
8713 | { | |
8714 | dwarf_vma abbrev_tag; | |
8715 | unsigned char *abbrev_lookup_ptr; | |
8716 | }; | |
8717 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
8718 | size_t abbrev_lookup_used = 0; | |
8719 | size_t abbrev_lookup_allocated = 0; | |
8720 | ||
8721 | unsigned char *abbrevptr = abbrev_table; | |
8722 | for (;;) | |
8723 | { | |
8724 | unsigned int bytes_read; | |
8725 | const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read, | |
8726 | abbrev_table_end); | |
8727 | abbrevptr += bytes_read; | |
8728 | if (abbrev_tag == 0) | |
8729 | break; | |
8730 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
8731 | { | |
8732 | abbrev_lookup_allocated = MAX (0x100, | |
8733 | abbrev_lookup_allocated * 2); | |
8734 | abbrev_lookup = xrealloc (abbrev_lookup, | |
8735 | (abbrev_lookup_allocated | |
8736 | * sizeof (*abbrev_lookup))); | |
8737 | } | |
8738 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
8739 | struct abbrev_lookup_entry *entry; | |
8740 | for (entry = abbrev_lookup; | |
8741 | entry < abbrev_lookup + abbrev_lookup_used; | |
8742 | entry++) | |
8743 | if (entry->abbrev_tag == abbrev_tag) | |
8744 | { | |
8745 | warn (_("Duplicate abbreviation tag %lu " | |
8746 | "in unit 0x%lx in the debug_names\n"), | |
8747 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
8748 | break; | |
8749 | } | |
8750 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
8751 | entry->abbrev_tag = abbrev_tag; | |
8752 | entry->abbrev_lookup_ptr = abbrevptr; | |
8753 | ||
8754 | /* Skip DWARF tag. */ | |
8755 | read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end); | |
8756 | abbrevptr += bytes_read; | |
8757 | for (;;) | |
8758 | { | |
1d827a72 L |
8759 | const dwarf_vma xindex = read_uleb128 (abbrevptr, |
8760 | &bytes_read, | |
8761 | abbrev_table_end); | |
61364358 JK |
8762 | abbrevptr += bytes_read; |
8763 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, | |
8764 | abbrev_table_end); | |
8765 | abbrevptr += bytes_read; | |
1d827a72 | 8766 | if (xindex == 0 && form == 0) |
61364358 JK |
8767 | break; |
8768 | } | |
8769 | } | |
8770 | ||
8771 | printf (_("\nSymbol table:\n")); | |
8772 | uint32_t namei; | |
8773 | for (namei = 0; namei < name_count; ++namei) | |
8774 | { | |
8775 | uint64_t string_offset, entry_offset; | |
8776 | ||
8777 | SAFE_BYTE_GET (string_offset, | |
8778 | name_table_string_offsets + namei * offset_size, | |
8779 | offset_size, unit_end); | |
8780 | SAFE_BYTE_GET (entry_offset, | |
8781 | name_table_entry_offsets + namei * offset_size, | |
8782 | offset_size, unit_end); | |
8783 | ||
8784 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
8785 | fetch_indirect_string (string_offset)); | |
8786 | ||
8787 | unsigned char *entryptr = entry_pool + entry_offset; | |
8788 | ||
8789 | // We need to scan first whether there is a single or multiple | |
8790 | // entries. TAGNO is -2 for the first entry, it is -1 for the | |
8791 | // initial tag read of the second entry, then it becomes 0 for the | |
8792 | // first entry for real printing etc. | |
8793 | int tagno = -2; | |
8794 | /* Initialize it due to a false compiler warning. */ | |
8795 | dwarf_vma second_abbrev_tag = -1; | |
8796 | for (;;) | |
8797 | { | |
8798 | unsigned int bytes_read; | |
8799 | const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read, | |
8800 | unit_end); | |
8801 | entryptr += bytes_read; | |
8802 | if (tagno == -1) | |
8803 | { | |
8804 | second_abbrev_tag = abbrev_tag; | |
8805 | tagno = 0; | |
8806 | entryptr = entry_pool + entry_offset; | |
8807 | continue; | |
8808 | } | |
8809 | if (abbrev_tag == 0) | |
8810 | break; | |
8811 | if (tagno >= 0) | |
8812 | printf ("%s<%lu>", | |
8813 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
8814 | (unsigned long) abbrev_tag); | |
8815 | ||
8816 | const struct abbrev_lookup_entry *entry; | |
8817 | for (entry = abbrev_lookup; | |
8818 | entry < abbrev_lookup + abbrev_lookup_used; | |
8819 | entry++) | |
8820 | if (entry->abbrev_tag == abbrev_tag) | |
8821 | break; | |
8822 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
8823 | { | |
8824 | warn (_("Undefined abbreviation tag %lu " | |
8825 | "in unit 0x%lx in the debug_names\n"), | |
8826 | (long) abbrev_tag, | |
8827 | (long) (unit_start - section->start)); | |
8828 | break; | |
8829 | } | |
8830 | abbrevptr = entry->abbrev_lookup_ptr; | |
8831 | const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read, | |
8832 | abbrev_table_end); | |
8833 | abbrevptr += bytes_read; | |
8834 | if (tagno >= 0) | |
8835 | printf (" %s", get_TAG_name (dwarf_tag)); | |
8836 | for (;;) | |
8837 | { | |
1d827a72 L |
8838 | const dwarf_vma xindex = read_uleb128 (abbrevptr, |
8839 | &bytes_read, | |
8840 | abbrev_table_end); | |
61364358 JK |
8841 | abbrevptr += bytes_read; |
8842 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, | |
8843 | abbrev_table_end); | |
8844 | abbrevptr += bytes_read; | |
1d827a72 | 8845 | if (xindex == 0 && form == 0) |
61364358 JK |
8846 | break; |
8847 | ||
8848 | if (tagno >= 0) | |
1d827a72 | 8849 | printf (" %s", get_IDX_name (xindex)); |
61364358 JK |
8850 | entryptr = read_and_display_attr_value (0, form, 0, entryptr, |
8851 | unit_end, 0, 0, | |
8852 | offset_size, | |
8853 | dwarf_version, NULL, | |
8854 | (tagno < 0), NULL, | |
8855 | NULL, '='); | |
8856 | } | |
8857 | ++tagno; | |
8858 | } | |
8859 | if (tagno <= 0) | |
8860 | printf (_(" <no entries>")); | |
8861 | putchar ('\n'); | |
8862 | } | |
8863 | ||
8864 | free (abbrev_lookup); | |
8865 | } | |
8866 | ||
8867 | return 1; | |
8868 | } | |
8869 | ||
dda8d76d | 8870 | static int |
d85bf2ba NC |
8871 | display_debug_links (struct dwarf_section * section, |
8872 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
8873 | { |
8874 | const unsigned char * filename; | |
8875 | unsigned int filelen; | |
8876 | ||
8877 | introduce (section, FALSE); | |
8878 | ||
8879 | /* The .gnu_debuglink section is formatted as: | |
8880 | (c-string) Filename. | |
8881 | (padding) If needed to reach a 4 byte boundary. | |
8882 | (uint32_t) CRC32 value. | |
8883 | ||
8884 | The .gun_debugaltlink section is formatted as: | |
8885 | (c-string) Filename. | |
8886 | (binary) Build-ID. */ | |
8887 | ||
8888 | filename = section->start; | |
8889 | filelen = strnlen ((const char *) filename, section->size); | |
8890 | if (filelen == section->size) | |
8891 | { | |
8892 | warn (_("The debuglink filename is corrupt/missing\n")); | |
8893 | return 0; | |
8894 | } | |
8895 | ||
8896 | printf (_(" Separate debug info file: %s\n"), filename); | |
8897 | ||
8898 | if (const_strneq (section->name, ".gnu_debuglink")) | |
8899 | { | |
8900 | unsigned int crc32; | |
8901 | unsigned int crc_offset; | |
8902 | ||
8903 | crc_offset = filelen + 1; | |
8904 | crc_offset = (crc_offset + 3) & ~3; | |
8905 | if (crc_offset + 4 > section->size) | |
8906 | { | |
8907 | warn (_("CRC offset missing/truncated\n")); | |
8908 | return 0; | |
8909 | } | |
8910 | ||
8911 | crc32 = byte_get (filename + crc_offset, 4); | |
8912 | ||
8913 | printf (_(" CRC value: %#x\n"), crc32); | |
8914 | ||
8915 | if (crc_offset + 4 < section->size) | |
8916 | { | |
8917 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
8918 | (long)(section->size - (crc_offset + 4))); | |
8919 | return 0; | |
8920 | } | |
8921 | } | |
8922 | else /* const_strneq (section->name, ".gnu_debugaltlink") */ | |
8923 | { | |
8924 | const unsigned char * build_id = section->start + filelen + 1; | |
8925 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
8926 | bfd_size_type printed; | |
8927 | ||
8928 | /* FIXME: Should we support smaller build-id notes ? */ | |
8929 | if (build_id_len < 0x14) | |
8930 | { | |
8931 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
8932 | return 0; | |
8933 | } | |
8934 | ||
8935 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 8936 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
8937 | putchar ('\n'); |
8938 | } | |
8939 | ||
8940 | putchar ('\n'); | |
8941 | return 1; | |
8942 | } | |
8943 | ||
5bbdf3d5 DE |
8944 | static int |
8945 | display_gdb_index (struct dwarf_section *section, | |
8946 | void *file ATTRIBUTE_UNUSED) | |
8947 | { | |
8948 | unsigned char *start = section->start; | |
8949 | uint32_t version; | |
8950 | uint32_t cu_list_offset, tu_list_offset; | |
8951 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
8952 | unsigned int cu_list_elements, tu_list_elements; | |
8953 | unsigned int address_table_size, symbol_table_slots; | |
8954 | unsigned char *cu_list, *tu_list; | |
8955 | unsigned char *address_table, *symbol_table, *constant_pool; | |
8956 | unsigned int i; | |
8957 | ||
8958 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
8959 | ||
dda8d76d | 8960 | introduce (section, FALSE); |
5bbdf3d5 DE |
8961 | |
8962 | if (section->size < 6 * sizeof (uint32_t)) | |
8963 | { | |
8964 | warn (_("Truncated header in the %s section.\n"), section->name); | |
8965 | return 0; | |
8966 | } | |
8967 | ||
8968 | version = byte_get_little_endian (start, 4); | |
da88a764 | 8969 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
8970 | |
8971 | /* Prior versions are obsolete, and future versions may not be | |
8972 | backwards compatible. */ | |
aa170720 | 8973 | if (version < 3 || version > 8) |
5bbdf3d5 | 8974 | { |
da88a764 | 8975 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
8976 | return 0; |
8977 | } | |
8d6eee87 TT |
8978 | if (version < 4) |
8979 | warn (_("The address table data in version 3 may be wrong.\n")); | |
8980 | if (version < 5) | |
8981 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
8982 | if (version < 6) | |
8983 | warn (_("Version 5 does not include inlined functions.\n")); | |
8984 | if (version < 7) | |
8985 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
8986 | /* Version 7 indices generated by Gold have bad type unit references, |
8987 | PR binutils/15021. But we don't know if the index was generated by | |
8988 | Gold or not, so to avoid worrying users with gdb-generated indices | |
8989 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
8990 | |
8991 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
8992 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
8993 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
8994 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
8995 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
8996 | ||
8997 | if (cu_list_offset > section->size | |
8998 | || tu_list_offset > section->size | |
8999 | || address_table_offset > section->size | |
9000 | || symbol_table_offset > section->size | |
9001 | || constant_pool_offset > section->size) | |
9002 | { | |
9003 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
9004 | return 0; | |
9005 | } | |
9006 | ||
53774b7e NC |
9007 | /* PR 17531: file: 418d0a8a. */ |
9008 | if (tu_list_offset < cu_list_offset) | |
9009 | { | |
9010 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
9011 | tu_list_offset, cu_list_offset); | |
9012 | return 0; | |
9013 | } | |
9014 | ||
5bbdf3d5 | 9015 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
9016 | |
9017 | if (address_table_offset < tu_list_offset) | |
9018 | { | |
9019 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
9020 | address_table_offset, tu_list_offset); | |
9021 | return 0; | |
9022 | } | |
9023 | ||
5bbdf3d5 | 9024 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
9025 | |
9026 | /* PR 17531: file: 18a47d3d. */ | |
9027 | if (symbol_table_offset < address_table_offset) | |
9028 | { | |
13bace4a | 9029 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
9030 | symbol_table_offset, address_table_offset); |
9031 | return 0; | |
9032 | } | |
9033 | ||
5bbdf3d5 | 9034 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
9035 | |
9036 | if (constant_pool_offset < symbol_table_offset) | |
9037 | { | |
9038 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
9039 | constant_pool_offset, symbol_table_offset); | |
9040 | return 0; | |
9041 | } | |
9042 | ||
5bbdf3d5 DE |
9043 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
9044 | ||
9045 | cu_list = start + cu_list_offset; | |
9046 | tu_list = start + tu_list_offset; | |
9047 | address_table = start + address_table_offset; | |
9048 | symbol_table = start + symbol_table_offset; | |
9049 | constant_pool = start + constant_pool_offset; | |
9050 | ||
28d909e5 | 9051 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 9052 | { |
1306a742 | 9053 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
9054 | return 0; |
9055 | } | |
b4eb7656 | 9056 | |
5bbdf3d5 DE |
9057 | printf (_("\nCU table:\n")); |
9058 | for (i = 0; i < cu_list_elements; i += 2) | |
9059 | { | |
9060 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
9061 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
9062 | ||
9063 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
9064 | (unsigned long) cu_offset, | |
9065 | (unsigned long) (cu_offset + cu_length - 1)); | |
9066 | } | |
9067 | ||
9068 | printf (_("\nTU table:\n")); | |
9069 | for (i = 0; i < tu_list_elements; i += 3) | |
9070 | { | |
9071 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
9072 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
9073 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
9074 | ||
9075 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
9076 | (unsigned long) tu_offset, | |
9077 | (unsigned long) type_offset); | |
9078 | print_dwarf_vma (signature, 8); | |
9079 | printf ("\n"); | |
9080 | } | |
9081 | ||
9082 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
9083 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
9084 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
9085 | { |
9086 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
9087 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
9088 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
9089 | ||
9090 | print_dwarf_vma (low, 8); | |
9091 | print_dwarf_vma (high, 8); | |
da88a764 | 9092 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
9093 | } |
9094 | ||
9095 | printf (_("\nSymbol table:\n")); | |
9096 | for (i = 0; i < symbol_table_slots; ++i) | |
9097 | { | |
9098 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
9099 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
9100 | uint32_t num_cus, cu; | |
9101 | ||
9102 | if (name_offset != 0 | |
9103 | || cu_vector_offset != 0) | |
9104 | { | |
9105 | unsigned int j; | |
362beea4 | 9106 | unsigned char * adr; |
5bbdf3d5 | 9107 | |
362beea4 | 9108 | adr = constant_pool + name_offset; |
53774b7e | 9109 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 9110 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
9111 | { |
9112 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
9113 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
9114 | name_offset, i); | |
9115 | } | |
9116 | else | |
acff9664 NC |
9117 | printf ("[%3u] %.*s:", i, |
9118 | (int) (section->size - (constant_pool_offset + name_offset)), | |
9119 | constant_pool + name_offset); | |
53774b7e | 9120 | |
362beea4 NC |
9121 | adr = constant_pool + cu_vector_offset; |
9122 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
9123 | { |
9124 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
9125 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
9126 | cu_vector_offset, i); | |
9127 | continue; | |
9128 | } | |
57028622 | 9129 | |
362beea4 | 9130 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 9131 | |
362beea4 | 9132 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 9133 | if (num_cus * 4 < num_cus |
362beea4 NC |
9134 | || adr >= section->start + section->size |
9135 | || adr < constant_pool) | |
53774b7e NC |
9136 | { |
9137 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 9138 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
9139 | num_cus, i); |
9140 | continue; | |
9141 | } | |
9142 | ||
8d6eee87 TT |
9143 | if (num_cus > 1) |
9144 | printf ("\n"); | |
f3853b34 | 9145 | |
5bbdf3d5 DE |
9146 | for (j = 0; j < num_cus; ++j) |
9147 | { | |
7c1cef97 | 9148 | int is_static; |
8d6eee87 TT |
9149 | gdb_index_symbol_kind kind; |
9150 | ||
5bbdf3d5 | 9151 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 9152 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
9153 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
9154 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 9155 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 9156 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
9157 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
9158 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 9159 | else |
8d6eee87 TT |
9160 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
9161 | ||
459d52c8 DE |
9162 | printf (" [%s, %s]", |
9163 | is_static ? _("static") : _("global"), | |
9164 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
9165 | if (num_cus > 1) |
9166 | printf ("\n"); | |
5bbdf3d5 | 9167 | } |
8d6eee87 TT |
9168 | if (num_cus <= 1) |
9169 | printf ("\n"); | |
5bbdf3d5 DE |
9170 | } |
9171 | } | |
9172 | ||
9173 | return 1; | |
9174 | } | |
9175 | ||
657d0d47 CC |
9176 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
9177 | ||
9178 | static void | |
9179 | prealloc_cu_tu_list (unsigned int nshndx) | |
9180 | { | |
9181 | if (shndx_pool == NULL) | |
9182 | { | |
9183 | shndx_pool_size = nshndx; | |
9184 | shndx_pool_used = 0; | |
9185 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
9186 | sizeof (unsigned int)); | |
9187 | } | |
9188 | else | |
9189 | { | |
9190 | shndx_pool_size = shndx_pool_used + nshndx; | |
9191 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
9192 | sizeof (unsigned int)); | |
9193 | } | |
9194 | } | |
9195 | ||
9196 | static void | |
9197 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
9198 | { | |
9199 | if (shndx_pool_used >= shndx_pool_size) | |
9200 | { | |
9201 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9202 | return; | |
9203 | } | |
9204 | shndx_pool [shndx_pool_used++] = shndx; | |
9205 | } | |
9206 | ||
9207 | static void | |
9208 | end_cu_tu_entry (void) | |
9209 | { | |
9210 | if (shndx_pool_used >= shndx_pool_size) | |
9211 | { | |
9212 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9213 | return; | |
9214 | } | |
9215 | shndx_pool [shndx_pool_used++] = 0; | |
9216 | } | |
9217 | ||
341f9135 CC |
9218 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
9219 | ||
9220 | static const char * | |
9221 | get_DW_SECT_short_name (unsigned int dw_sect) | |
9222 | { | |
9223 | static char buf[16]; | |
9224 | ||
9225 | switch (dw_sect) | |
9226 | { | |
9227 | case DW_SECT_INFO: | |
9228 | return "info"; | |
9229 | case DW_SECT_TYPES: | |
9230 | return "types"; | |
9231 | case DW_SECT_ABBREV: | |
9232 | return "abbrev"; | |
9233 | case DW_SECT_LINE: | |
9234 | return "line"; | |
9235 | case DW_SECT_LOC: | |
9236 | return "loc"; | |
9237 | case DW_SECT_STR_OFFSETS: | |
9238 | return "str_off"; | |
9239 | case DW_SECT_MACINFO: | |
9240 | return "macinfo"; | |
9241 | case DW_SECT_MACRO: | |
9242 | return "macro"; | |
9243 | default: | |
b4eb7656 | 9244 | break; |
341f9135 CC |
9245 | } |
9246 | ||
9247 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
9248 | return buf; | |
9249 | } | |
9250 | ||
9251 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
9252 | These sections are extensions for Fission. | |
9253 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
9254 | |
9255 | static int | |
9256 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
9257 | { | |
9258 | unsigned char *phdr = section->start; | |
9259 | unsigned char *limit = phdr + section->size; | |
9260 | unsigned char *phash; | |
9261 | unsigned char *pindex; | |
9262 | unsigned char *ppool; | |
9263 | unsigned int version; | |
341f9135 | 9264 | unsigned int ncols = 0; |
657d0d47 CC |
9265 | unsigned int nused; |
9266 | unsigned int nslots; | |
9267 | unsigned int i; | |
341f9135 CC |
9268 | unsigned int j; |
9269 | dwarf_vma signature_high; | |
9270 | dwarf_vma signature_low; | |
9271 | char buf[64]; | |
657d0d47 | 9272 | |
6937bb54 NC |
9273 | /* PR 17512: file: 002-168123-0.004. */ |
9274 | if (phdr == NULL) | |
9275 | { | |
9276 | warn (_("Section %s is empty\n"), section->name); | |
9277 | return 0; | |
9278 | } | |
9279 | /* PR 17512: file: 002-376-0.004. */ | |
9280 | if (section->size < 24) | |
9281 | { | |
72c61a0d | 9282 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
9283 | section->name); |
9284 | return 0; | |
9285 | } | |
9286 | ||
9287 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 9288 | if (version >= 2) |
6937bb54 NC |
9289 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
9290 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
9291 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
9292 | ||
657d0d47 CC |
9293 | phash = phdr + 16; |
9294 | pindex = phash + nslots * 8; | |
9295 | ppool = pindex + nslots * 4; | |
9296 | ||
57028622 | 9297 | /* PR 17531: file: 45d69832. */ |
03a91817 | 9298 | if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0)) |
57028622 | 9299 | { |
d3a49aa8 AM |
9300 | warn (ngettext ("Section %s is too small for %d slot\n", |
9301 | "Section %s is too small for %d slots\n", | |
9302 | nslots), | |
57028622 NC |
9303 | section->name, nslots); |
9304 | return 0; | |
9305 | } | |
9306 | ||
657d0d47 CC |
9307 | if (do_display) |
9308 | { | |
dda8d76d NC |
9309 | introduce (section, FALSE); |
9310 | ||
657d0d47 | 9311 | printf (_(" Version: %d\n"), version); |
341f9135 CC |
9312 | if (version >= 2) |
9313 | printf (_(" Number of columns: %d\n"), ncols); | |
657d0d47 CC |
9314 | printf (_(" Number of used entries: %d\n"), nused); |
9315 | printf (_(" Number of slots: %d\n\n"), nslots); | |
9316 | } | |
9317 | ||
03a91817 | 9318 | if (ppool > limit || ppool < phdr) |
657d0d47 CC |
9319 | { |
9320 | warn (_("Section %s too small for %d hash table entries\n"), | |
9321 | section->name, nslots); | |
9322 | return 0; | |
9323 | } | |
9324 | ||
341f9135 | 9325 | if (version == 1) |
657d0d47 | 9326 | { |
341f9135 CC |
9327 | if (!do_display) |
9328 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
9329 | for (i = 0; i < nslots; i++) | |
657d0d47 | 9330 | { |
341f9135 CC |
9331 | unsigned char *shndx_list; |
9332 | unsigned int shndx; | |
9333 | ||
6937bb54 | 9334 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 9335 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 9336 | { |
6937bb54 | 9337 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 9338 | shndx_list = ppool + j * 4; |
f3853b34 NC |
9339 | /* PR 17531: file: 705e010d. */ |
9340 | if (shndx_list < ppool) | |
9341 | { | |
9342 | warn (_("Section index pool located before start of section\n")); | |
9343 | return 0; | |
9344 | } | |
9345 | ||
341f9135 CC |
9346 | if (do_display) |
9347 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
9348 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9349 | buf, sizeof (buf))); | |
9350 | for (;;) | |
657d0d47 | 9351 | { |
341f9135 CC |
9352 | if (shndx_list >= limit) |
9353 | { | |
9354 | warn (_("Section %s too small for shndx pool\n"), | |
9355 | section->name); | |
9356 | return 0; | |
9357 | } | |
6937bb54 | 9358 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
9359 | if (shndx == 0) |
9360 | break; | |
9361 | if (do_display) | |
9362 | printf (" %d", shndx); | |
9363 | else | |
9364 | add_shndx_to_cu_tu_entry (shndx); | |
9365 | shndx_list += 4; | |
657d0d47 | 9366 | } |
657d0d47 | 9367 | if (do_display) |
341f9135 | 9368 | printf ("\n"); |
657d0d47 | 9369 | else |
341f9135 CC |
9370 | end_cu_tu_entry (); |
9371 | } | |
9372 | phash += 8; | |
9373 | pindex += 4; | |
9374 | } | |
9375 | } | |
9376 | else if (version == 2) | |
9377 | { | |
9378 | unsigned int val; | |
9379 | unsigned int dw_sect; | |
9380 | unsigned char *ph = phash; | |
9381 | unsigned char *pi = pindex; | |
9382 | unsigned char *poffsets = ppool + ncols * 4; | |
9383 | unsigned char *psizes = poffsets + nused * ncols * 4; | |
9384 | unsigned char *pend = psizes + nused * ncols * 4; | |
9385 | bfd_boolean is_tu_index; | |
9386 | struct cu_tu_set *this_set = NULL; | |
9387 | unsigned int row; | |
9388 | unsigned char *prow; | |
9389 | ||
9390 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
9391 | ||
362beea4 | 9392 | /* PR 17531: file: 0dd159bf. |
b4eb7656 | 9393 | Check for wraparound with an overlarge ncols value. */ |
c8071705 | 9394 | if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols) |
362beea4 NC |
9395 | { |
9396 | warn (_("Overlarge number of columns: %x\n"), ncols); | |
9397 | return 0; | |
9398 | } | |
9399 | ||
341f9135 CC |
9400 | if (pend > limit) |
9401 | { | |
9402 | warn (_("Section %s too small for offset and size tables\n"), | |
9403 | section->name); | |
9404 | return 0; | |
9405 | } | |
9406 | ||
9407 | if (do_display) | |
9408 | { | |
9409 | printf (_(" Offset table\n")); | |
9410 | printf (" slot %-16s ", | |
9411 | is_tu_index ? _("signature") : _("dwo_id")); | |
9412 | } | |
9413 | else | |
9414 | { | |
9415 | if (is_tu_index) | |
9416 | { | |
9417 | tu_count = nused; | |
72c61a0d | 9418 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 9419 | this_set = tu_sets; |
657d0d47 | 9420 | } |
657d0d47 | 9421 | else |
341f9135 CC |
9422 | { |
9423 | cu_count = nused; | |
72c61a0d | 9424 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
9425 | this_set = cu_sets; |
9426 | } | |
9427 | } | |
6937bb54 | 9428 | |
341f9135 CC |
9429 | if (do_display) |
9430 | { | |
9431 | for (j = 0; j < ncols; j++) | |
9432 | { | |
6937bb54 | 9433 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
9434 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
9435 | } | |
9436 | printf ("\n"); | |
9437 | } | |
6937bb54 | 9438 | |
341f9135 CC |
9439 | for (i = 0; i < nslots; i++) |
9440 | { | |
6937bb54 NC |
9441 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9442 | ||
9443 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9444 | if (row != 0) |
9445 | { | |
591f7597 | 9446 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 9447 | if (row > nused) |
591f7597 NC |
9448 | { |
9449 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
9450 | row, nused); | |
9451 | return 0; | |
9452 | } | |
9453 | ||
341f9135 | 9454 | if (!do_display) |
6aea08d9 NC |
9455 | { |
9456 | size_t num_copy = sizeof (uint64_t); | |
9457 | ||
9458 | /* PR 23064: Beware of buffer overflow. */ | |
9459 | if (ph + num_copy < limit) | |
9460 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
9461 | else | |
9462 | { | |
9463 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); | |
9464 | return 0; | |
9465 | } | |
9466 | } | |
6937bb54 | 9467 | |
341f9135 | 9468 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
9469 | /* PR 17531: file: b8ce60a8. */ |
9470 | if (prow < poffsets || prow > limit) | |
9471 | { | |
9472 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
9473 | row, ncols); | |
9474 | return 0; | |
9475 | } | |
3aade688 | 9476 | |
341f9135 CC |
9477 | if (do_display) |
9478 | printf (_(" [%3d] 0x%s"), | |
9479 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9480 | buf, sizeof (buf))); | |
9481 | for (j = 0; j < ncols; j++) | |
9482 | { | |
6937bb54 | 9483 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9484 | if (do_display) |
9485 | printf (" %8d", val); | |
9486 | else | |
9487 | { | |
6937bb54 | 9488 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9489 | |
9490 | /* PR 17531: file: 10796eb3. */ | |
9491 | if (dw_sect >= DW_SECT_MAX) | |
9492 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9493 | else | |
9494 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
9495 | } |
9496 | } | |
6937bb54 | 9497 | |
341f9135 CC |
9498 | if (do_display) |
9499 | printf ("\n"); | |
9500 | } | |
9501 | ph += 8; | |
9502 | pi += 4; | |
9503 | } | |
9504 | ||
9505 | ph = phash; | |
9506 | pi = pindex; | |
9507 | if (do_display) | |
b4eb7656 | 9508 | { |
341f9135 CC |
9509 | printf ("\n"); |
9510 | printf (_(" Size table\n")); | |
9511 | printf (" slot %-16s ", | |
9512 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 9513 | } |
6937bb54 | 9514 | |
341f9135 CC |
9515 | for (j = 0; j < ncols; j++) |
9516 | { | |
6937bb54 | 9517 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
9518 | if (do_display) |
9519 | printf (" %8s", get_DW_SECT_short_name (val)); | |
9520 | } | |
6937bb54 | 9521 | |
341f9135 CC |
9522 | if (do_display) |
9523 | printf ("\n"); | |
6937bb54 | 9524 | |
341f9135 CC |
9525 | for (i = 0; i < nslots; i++) |
9526 | { | |
6937bb54 NC |
9527 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9528 | ||
9529 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9530 | if (row != 0) |
9531 | { | |
9532 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 9533 | |
341f9135 CC |
9534 | if (do_display) |
9535 | printf (_(" [%3d] 0x%s"), | |
9536 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9537 | buf, sizeof (buf))); | |
6937bb54 | 9538 | |
341f9135 CC |
9539 | for (j = 0; j < ncols; j++) |
9540 | { | |
6937bb54 | 9541 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9542 | if (do_display) |
9543 | printf (" %8d", val); | |
9544 | else | |
9545 | { | |
6937bb54 | 9546 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9547 | if (dw_sect >= DW_SECT_MAX) |
9548 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9549 | else | |
341f9135 CC |
9550 | this_set [row - 1].section_sizes [dw_sect] = val; |
9551 | } | |
9552 | } | |
6937bb54 | 9553 | |
341f9135 CC |
9554 | if (do_display) |
9555 | printf ("\n"); | |
9556 | } | |
6937bb54 | 9557 | |
341f9135 CC |
9558 | ph += 8; |
9559 | pi += 4; | |
657d0d47 | 9560 | } |
657d0d47 | 9561 | } |
341f9135 | 9562 | else if (do_display) |
6937bb54 | 9563 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
9564 | |
9565 | if (do_display) | |
9566 | printf ("\n"); | |
9567 | ||
9568 | return 1; | |
9569 | } | |
9570 | ||
9571 | /* Load the CU and TU indexes if present. This will build a list of | |
9572 | section sets that we can use to associate a .debug_info.dwo section | |
9573 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
9574 | ||
43a444f9 | 9575 | static bfd_boolean |
657d0d47 CC |
9576 | load_cu_tu_indexes (void *file) |
9577 | { | |
43a444f9 NC |
9578 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
9579 | ||
657d0d47 CC |
9580 | /* If we have already loaded (or tried to load) the CU and TU indexes |
9581 | then do not bother to repeat the task. */ | |
43a444f9 NC |
9582 | if (cu_tu_indexes_read == -1) |
9583 | { | |
9584 | cu_tu_indexes_read = TRUE; | |
9585 | ||
dda8d76d | 9586 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 NC |
9587 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
9588 | cu_tu_indexes_read = FALSE; | |
9589 | ||
dda8d76d | 9590 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 NC |
9591 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
9592 | cu_tu_indexes_read = FALSE; | |
9593 | } | |
657d0d47 | 9594 | |
43a444f9 | 9595 | return (bfd_boolean) cu_tu_indexes_read; |
657d0d47 CC |
9596 | } |
9597 | ||
9598 | /* Find the set of sections that includes section SHNDX. */ | |
9599 | ||
9600 | unsigned int * | |
9601 | find_cu_tu_set (void *file, unsigned int shndx) | |
9602 | { | |
9603 | unsigned int i; | |
9604 | ||
43a444f9 NC |
9605 | if (! load_cu_tu_indexes (file)) |
9606 | return NULL; | |
657d0d47 CC |
9607 | |
9608 | /* Find SHNDX in the shndx pool. */ | |
9609 | for (i = 0; i < shndx_pool_used; i++) | |
9610 | if (shndx_pool [i] == shndx) | |
9611 | break; | |
9612 | ||
9613 | if (i >= shndx_pool_used) | |
9614 | return NULL; | |
9615 | ||
9616 | /* Now backup to find the first entry in the set. */ | |
9617 | while (i > 0 && shndx_pool [i - 1] != 0) | |
9618 | i--; | |
9619 | ||
9620 | return shndx_pool + i; | |
9621 | } | |
9622 | ||
9623 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
9624 | ||
9625 | static int | |
9626 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
9627 | { | |
9628 | return process_cu_tu_index (section, 1); | |
9629 | } | |
9630 | ||
19e6b90e L |
9631 | static int |
9632 | display_debug_not_supported (struct dwarf_section *section, | |
9633 | void *file ATTRIBUTE_UNUSED) | |
9634 | { | |
9635 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
9636 | section->name); | |
9637 | ||
9638 | return 1; | |
9639 | } | |
9640 | ||
1306a742 NC |
9641 | /* Like malloc, but takes two parameters like calloc. |
9642 | Verifies that the first parameter is not too large. | |
82b1b41b | 9643 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 9644 | |
19e6b90e L |
9645 | void * |
9646 | cmalloc (size_t nmemb, size_t size) | |
9647 | { | |
9648 | /* Check for overflow. */ | |
9649 | if (nmemb >= ~(size_t) 0 / size) | |
9650 | return NULL; | |
82b1b41b NC |
9651 | |
9652 | return xmalloc (nmemb * size); | |
19e6b90e L |
9653 | } |
9654 | ||
1306a742 NC |
9655 | /* Like xmalloc, but takes two parameters like calloc. |
9656 | Verifies that the first parameter is not too large. | |
9657 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 9658 | |
72c61a0d | 9659 | void * |
1306a742 | 9660 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
9661 | { |
9662 | /* Check for overflow. */ | |
9663 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
9664 | { |
9665 | fprintf (stderr, | |
9666 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
9667 | (long) nmemb); | |
9668 | xexit (1); | |
9669 | } | |
72c61a0d | 9670 | |
1306a742 | 9671 | return xmalloc (nmemb * size); |
72c61a0d NC |
9672 | } |
9673 | ||
1306a742 NC |
9674 | /* Like xrealloc, but takes three parameters. |
9675 | Verifies that the second parameter is not too large. | |
9676 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 9677 | |
19e6b90e | 9678 | void * |
1306a742 | 9679 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
9680 | { |
9681 | /* Check for overflow. */ | |
9682 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 9683 | { |
dda8d76d NC |
9684 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
9685 | (long) nmemb); | |
8490fb40 NC |
9686 | xexit (1); |
9687 | } | |
82b1b41b | 9688 | |
1306a742 | 9689 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
9690 | } |
9691 | ||
1306a742 | 9692 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 9693 | |
19e6b90e | 9694 | void * |
1306a742 | 9695 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
9696 | { |
9697 | /* Check for overflow. */ | |
9698 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 9699 | { |
dda8d76d NC |
9700 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
9701 | (long) nmemb); | |
8490fb40 NC |
9702 | xexit (1); |
9703 | } | |
82b1b41b | 9704 | |
1306a742 | 9705 | return xcalloc (nmemb, size); |
19e6b90e L |
9706 | } |
9707 | ||
dda8d76d NC |
9708 | static unsigned long |
9709 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
9710 | const unsigned char * buf, | |
9711 | bfd_size_type len) | |
9712 | { | |
9713 | static const unsigned long crc32_table[256] = | |
9714 | { | |
9715 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
9716 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
9717 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
9718 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
9719 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
9720 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
9721 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
9722 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
9723 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
9724 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
9725 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
9726 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
9727 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
9728 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
9729 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
9730 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
9731 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
9732 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
9733 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
9734 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
9735 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
9736 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
9737 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
9738 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
9739 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
9740 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
9741 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
9742 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
9743 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
9744 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
9745 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
9746 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
9747 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
9748 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
9749 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
9750 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
9751 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
9752 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
9753 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
9754 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
9755 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
9756 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
9757 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
9758 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
9759 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
9760 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
9761 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
9762 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
9763 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
9764 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
9765 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
9766 | 0x2d02ef8d | |
9767 | }; | |
9768 | const unsigned char *end; | |
9769 | ||
9770 | crc = ~crc & 0xffffffff; | |
9771 | for (end = buf + len; buf < end; ++ buf) | |
9772 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
9773 | return ~crc & 0xffffffff; | |
9774 | } | |
9775 | ||
9776 | typedef bfd_boolean (* check_func_type) (const char *, void *); | |
9777 | typedef const char * (* parse_func_type) (struct dwarf_section *, void *); | |
9778 | ||
9779 | static bfd_boolean | |
9780 | check_gnu_debuglink (const char * pathname, void * crc_pointer) | |
9781 | { | |
9782 | static unsigned char buffer [8 * 1024]; | |
9783 | FILE * f; | |
9784 | bfd_size_type count; | |
9785 | unsigned long crc = 0; | |
9786 | void * sep_data; | |
9787 | ||
9788 | sep_data = open_debug_file (pathname); | |
9789 | if (sep_data == NULL) | |
9790 | return FALSE; | |
9791 | ||
9792 | /* Yes - we are opening the file twice... */ | |
9793 | f = fopen (pathname, "rb"); | |
9794 | if (f == NULL) | |
9795 | { | |
9796 | /* Paranoia: This should never happen. */ | |
9797 | close_debug_file (sep_data); | |
9798 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
9799 | return FALSE; | |
9800 | } | |
9801 | ||
9802 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
9803 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
9804 | ||
9805 | fclose (f); | |
9806 | ||
9807 | if (crc != * (unsigned long *) crc_pointer) | |
9808 | { | |
9809 | close_debug_file (sep_data); | |
9810 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
9811 | pathname); | |
9812 | return FALSE; | |
9813 | } | |
9814 | ||
9815 | return TRUE; | |
9816 | } | |
9817 | ||
9818 | static const char * | |
9819 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
9820 | { | |
9821 | const char * name; | |
9822 | unsigned int crc_offset; | |
9823 | unsigned long * crc32 = (unsigned long *) data; | |
9824 | ||
9825 | /* The name is first. | |
9826 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
9827 | name = (const char *) section->start; | |
9828 | ||
39f0547e | 9829 | |
dda8d76d NC |
9830 | crc_offset = strnlen (name, section->size) + 1; |
9831 | crc_offset = (crc_offset + 3) & ~3; | |
9832 | if (crc_offset + 4 > section->size) | |
9833 | return NULL; | |
9834 | ||
9835 | * crc32 = byte_get (section->start + crc_offset, 4); | |
9836 | return name; | |
9837 | } | |
9838 | ||
9839 | static bfd_boolean | |
9840 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) | |
9841 | { | |
9842 | void * sep_data = open_debug_file (filename); | |
9843 | ||
9844 | if (sep_data == NULL) | |
9845 | return FALSE; | |
9846 | ||
9847 | /* FIXME: We should now extract the build-id in the separate file | |
9848 | and check it... */ | |
9849 | ||
9850 | return TRUE; | |
9851 | } | |
9852 | ||
9853 | typedef struct build_id_data | |
9854 | { | |
9855 | bfd_size_type len; | |
9856 | const unsigned char * data; | |
9857 | } Build_id_data; | |
9858 | ||
9859 | static const char * | |
9860 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
9861 | { | |
9862 | const char * name; | |
9863 | bfd_size_type namelen; | |
9864 | bfd_size_type id_len; | |
9865 | Build_id_data * build_id_data; | |
9866 | ||
9867 | /* The name is first. | |
9868 | The build-id follows immediately, with no padding, up to the section's end. */ | |
9869 | ||
9870 | name = (const char *) section->start; | |
9871 | namelen = strnlen (name, section->size) + 1; | |
9872 | if (namelen >= section->size) | |
9873 | return NULL; | |
9874 | ||
9875 | id_len = section->size - namelen; | |
9876 | if (id_len < 0x14) | |
9877 | return NULL; | |
9878 | ||
9879 | build_id_data = calloc (1, sizeof * build_id_data); | |
9880 | if (build_id_data == NULL) | |
9881 | return NULL; | |
9882 | ||
9883 | build_id_data->len = id_len; | |
9884 | build_id_data->data = section->start + namelen; | |
9885 | ||
9886 | * (Build_id_data **) data = build_id_data; | |
9887 | ||
9888 | return name; | |
9889 | } | |
9890 | ||
24841daa NC |
9891 | static void |
9892 | add_separate_debug_file (const char * filename, void * handle) | |
9893 | { | |
9894 | separate_info * i = xmalloc (sizeof * i); | |
9895 | ||
9896 | i->filename = filename; | |
9897 | i->handle = handle; | |
9898 | i->next = first_separate_info; | |
9899 | first_separate_info = i; | |
9900 | } | |
9901 | ||
dda8d76d NC |
9902 | static void * |
9903 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 9904 | struct dwarf_section * xlink, |
dda8d76d NC |
9905 | parse_func_type parse_func, |
9906 | check_func_type check_func, | |
9907 | void * func_data) | |
9908 | { | |
9909 | const char * separate_filename; | |
24841daa | 9910 | char * debug_filename; |
dda8d76d NC |
9911 | char * canon_dir; |
9912 | size_t canon_dirlen; | |
9913 | size_t dirlen; | |
9914 | ||
2b63c337 | 9915 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
9916 | { |
9917 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 9918 | xlink->name ? xlink->name : xlink->uncompressed_name); |
dda8d76d NC |
9919 | return FALSE; |
9920 | } | |
9921 | ||
9922 | /* Attempt to locate the separate file. | |
9923 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
9924 | ||
9925 | canon_dir = lrealpath (main_filename); | |
9926 | ||
9927 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) | |
9928 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
9929 | break; | |
9930 | canon_dir[canon_dirlen] = '\0'; | |
9931 | ||
9932 | #ifndef DEBUGDIR | |
9933 | #define DEBUGDIR "/lib/debug" | |
9934 | #endif | |
9935 | #ifndef EXTRA_DEBUG_ROOT1 | |
9936 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
9937 | #endif | |
9938 | #ifndef EXTRA_DEBUG_ROOT2 | |
9939 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
9940 | #endif | |
9941 | ||
24841daa NC |
9942 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
9943 | + canon_dirlen | |
9944 | + strlen (".debug/") | |
dda8d76d | 9945 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 9946 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
9947 | #endif |
9948 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 9949 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 9950 | #endif |
24841daa NC |
9951 | + strlen (separate_filename) |
9952 | + 1); | |
9953 | if (debug_filename == NULL) | |
dda8d76d NC |
9954 | { |
9955 | warn (_("Out of memory")); | |
3391569f | 9956 | free (canon_dir); |
dda8d76d NC |
9957 | return NULL; |
9958 | } | |
9959 | ||
9960 | /* First try in the current directory. */ | |
24841daa NC |
9961 | sprintf (debug_filename, "%s", separate_filename); |
9962 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
9963 | goto found; |
9964 | ||
9965 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
9966 | sprintf (debug_filename, ".debug/%s", separate_filename); |
9967 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
9968 | goto found; |
9969 | ||
9970 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
9971 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
9972 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
9973 | goto found; |
9974 | ||
9975 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
9976 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
9977 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
9978 | goto found; |
9979 | ||
9980 | #ifdef EXTRA_DEBUG_ROOT1 | |
9981 | /* Try the first extra debug file root. */ | |
24841daa NC |
9982 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
9983 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 9984 | goto found; |
39f0547e NC |
9985 | |
9986 | /* Try the first extra debug file root. */ | |
9987 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
9988 | if (check_func (debug_filename, func_data)) | |
9989 | goto found; | |
dda8d76d NC |
9990 | #endif |
9991 | ||
9992 | #ifdef EXTRA_DEBUG_ROOT2 | |
9993 | /* Try the second extra debug file root. */ | |
24841daa NC |
9994 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
9995 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
9996 | goto found; |
9997 | #endif | |
9998 | ||
24841daa NC |
9999 | /* Then try in the global debug_filename directory. */ |
10000 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
10001 | dirlen = strlen (DEBUGDIR) - 1; |
10002 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
10003 | strcat (debug_filename, "/"); |
10004 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 10005 | |
24841daa | 10006 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
10007 | goto found; |
10008 | ||
10009 | /* Failed to find the file. */ | |
10010 | warn (_("could not find separate debug file '%s'\n"), separate_filename); | |
24841daa | 10011 | warn (_("tried: %s\n"), debug_filename); |
dda8d76d NC |
10012 | |
10013 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa NC |
10014 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10015 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10016 | #endif |
10017 | ||
10018 | #ifdef EXTRA_DEBUG_ROOT1 | |
39f0547e NC |
10019 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
10020 | warn (_("tried: %s\n"), debug_filename); | |
10021 | ||
24841daa NC |
10022 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10023 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10024 | #endif |
10025 | ||
24841daa NC |
10026 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10027 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10028 | |
24841daa NC |
10029 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10030 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10031 | |
24841daa NC |
10032 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10033 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10034 | |
24841daa NC |
10035 | sprintf (debug_filename, "%s", separate_filename); |
10036 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10037 | |
10038 | free (canon_dir); | |
24841daa | 10039 | free (debug_filename); |
dda8d76d NC |
10040 | return NULL; |
10041 | ||
10042 | found: | |
10043 | free (canon_dir); | |
10044 | ||
24841daa NC |
10045 | void * debug_handle; |
10046 | ||
dda8d76d | 10047 | /* Now open the file.... */ |
24841daa | 10048 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 10049 | { |
24841daa NC |
10050 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
10051 | free (debug_filename); | |
dda8d76d NC |
10052 | return FALSE; |
10053 | } | |
10054 | ||
10055 | /* FIXME: We do not check to see if there are any other separate debug info | |
10056 | files that would also match. */ | |
10057 | ||
24841daa NC |
10058 | printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debug_filename); |
10059 | add_separate_debug_file (debug_filename, debug_handle); | |
dda8d76d | 10060 | |
24841daa | 10061 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 10062 | the structure returned by open_debug_file(). */ |
24841daa | 10063 | return debug_handle; |
dda8d76d NC |
10064 | } |
10065 | ||
d85bf2ba NC |
10066 | /* Attempt to load a separate dwarf object file. */ |
10067 | ||
10068 | static void * | |
24841daa | 10069 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 10070 | { |
24841daa NC |
10071 | char * separate_filename; |
10072 | void * separate_handle; | |
d85bf2ba NC |
10073 | |
10074 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
24841daa NC |
10075 | separate_filename = concat (dir, "/", name, NULL); |
10076 | if (separate_filename == NULL) | |
d85bf2ba NC |
10077 | { |
10078 | warn (_("Out of memory allocating dwo filename\n")); | |
10079 | return NULL; | |
10080 | } | |
10081 | ||
24841daa | 10082 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 10083 | { |
24841daa NC |
10084 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
10085 | free (separate_filename); | |
d85bf2ba NC |
10086 | return NULL; |
10087 | } | |
10088 | ||
10089 | /* FIXME: We should check the dwo_id. */ | |
10090 | ||
24841daa NC |
10091 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
10092 | add_separate_debug_file (separate_filename, separate_handle); | |
10093 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
10094 | return separate_handle; | |
d85bf2ba NC |
10095 | } |
10096 | ||
24841daa NC |
10097 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
10098 | Returns TRUE if any were found, FALSE otherwise. | |
10099 | If TRUE is returned then the linked list starting at first_separate_info | |
10100 | will be populated with open file handles. */ | |
dda8d76d | 10101 | |
24841daa NC |
10102 | bfd_boolean |
10103 | load_separate_debug_files (void * file, const char * filename) | |
dda8d76d | 10104 | { |
8de3a6e2 NC |
10105 | /* Skip this operation if we are not interested in debug links. */ |
10106 | if (! do_follow_links && ! do_debug_links) | |
24841daa | 10107 | return FALSE; |
8de3a6e2 | 10108 | |
24841daa | 10109 | /* See if there are any dwo links. */ |
d85bf2ba NC |
10110 | if (load_debug_section (str, file) |
10111 | && load_debug_section (abbrev, file) | |
10112 | && load_debug_section (info, file)) | |
10113 | { | |
24841daa | 10114 | free_dwo_info (); |
d85bf2ba NC |
10115 | |
10116 | if (process_debug_info (& debug_displays[info].section, file, abbrev, TRUE, FALSE)) | |
10117 | { | |
24841daa NC |
10118 | bfd_boolean introduced = FALSE; |
10119 | dwo_info * dwinfo; | |
10120 | const char * dir = NULL; | |
10121 | const char * id = NULL; | |
10122 | ||
10123 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 10124 | { |
24841daa | 10125 | switch (dwinfo->type) |
d85bf2ba | 10126 | { |
24841daa NC |
10127 | case DWO_NAME: |
10128 | if (do_debug_links) | |
10129 | { | |
10130 | if (! introduced) | |
10131 | { | |
10132 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
10133 | debug_displays [info].section.uncompressed_name); | |
10134 | introduced = TRUE; | |
10135 | } | |
d85bf2ba | 10136 | |
24841daa NC |
10137 | printf (_(" Name: %s\n"), dwinfo->value); |
10138 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); | |
10139 | if (id != NULL) | |
10140 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
10141 | else | |
10142 | printf (_(" ID: <unknown>\n")); | |
10143 | printf ("\n\n"); | |
10144 | } | |
10145 | ||
10146 | if (do_follow_links) | |
10147 | load_dwo_file (filename, dwinfo->value, dir, id); | |
10148 | break; | |
10149 | ||
10150 | case DWO_DIR: | |
10151 | dir = dwinfo->value; | |
10152 | break; | |
10153 | ||
10154 | case DWO_ID: | |
10155 | id = dwinfo->value; | |
10156 | break; | |
10157 | ||
10158 | default: | |
10159 | error (_("Unexpected DWO INFO type")); | |
10160 | break; | |
10161 | } | |
d85bf2ba NC |
10162 | } |
10163 | } | |
10164 | } | |
10165 | ||
dda8d76d | 10166 | if (! do_follow_links) |
8de3a6e2 NC |
10167 | /* The other debug links will be displayed by display_debug_links() |
10168 | so we do not need to do any further processing here. */ | |
24841daa | 10169 | return FALSE; |
dda8d76d NC |
10170 | |
10171 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
10172 | /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */ | |
10173 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ | |
d85bf2ba | 10174 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 10175 | |
dda8d76d NC |
10176 | if (load_debug_section (gnu_debugaltlink, file)) |
10177 | { | |
10178 | Build_id_data * build_id_data; | |
10179 | ||
24841daa NC |
10180 | load_separate_debug_info (filename, |
10181 | & debug_displays[gnu_debugaltlink].section, | |
10182 | parse_gnu_debugaltlink, | |
10183 | check_gnu_debugaltlink, | |
10184 | & build_id_data); | |
dda8d76d NC |
10185 | } |
10186 | ||
10187 | if (load_debug_section (gnu_debuglink, file)) | |
10188 | { | |
10189 | unsigned long crc32; | |
10190 | ||
24841daa NC |
10191 | load_separate_debug_info (filename, |
10192 | & debug_displays[gnu_debuglink].section, | |
10193 | parse_gnu_debuglink, | |
10194 | check_gnu_debuglink, | |
10195 | & crc32); | |
dda8d76d NC |
10196 | } |
10197 | ||
24841daa NC |
10198 | if (first_separate_info != NULL) |
10199 | return TRUE; | |
10200 | ||
dda8d76d | 10201 | do_follow_links = 0; |
24841daa | 10202 | return FALSE; |
dda8d76d NC |
10203 | } |
10204 | ||
19e6b90e L |
10205 | void |
10206 | free_debug_memory (void) | |
10207 | { | |
3f5e193b | 10208 | unsigned int i; |
19e6b90e L |
10209 | |
10210 | free_abbrevs (); | |
10211 | ||
10212 | for (i = 0; i < max; i++) | |
3f5e193b | 10213 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 10214 | |
cc86f28f | 10215 | if (debug_information != NULL) |
19e6b90e | 10216 | { |
cc86f28f | 10217 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
19e6b90e | 10218 | { |
cc86f28f | 10219 | for (i = 0; i < num_debug_info_entries; i++) |
19e6b90e | 10220 | { |
cc86f28f NC |
10221 | if (!debug_information [i].max_loc_offsets) |
10222 | { | |
10223 | free (debug_information [i].loc_offsets); | |
10224 | free (debug_information [i].have_frame_base); | |
10225 | } | |
10226 | if (!debug_information [i].max_range_lists) | |
10227 | free (debug_information [i].range_lists); | |
19e6b90e | 10228 | } |
19e6b90e L |
10229 | } |
10230 | free (debug_information); | |
10231 | debug_information = NULL; | |
82b1b41b | 10232 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 10233 | } |
dda8d76d | 10234 | |
24841daa NC |
10235 | separate_info * d; |
10236 | separate_info * next; | |
dda8d76d | 10237 | |
24841daa NC |
10238 | for (d = first_separate_info; d != NULL; d = next) |
10239 | { | |
10240 | close_debug_file (d->handle); | |
10241 | free ((void *) d->filename); | |
10242 | next = d->next; | |
10243 | free ((void *) d); | |
dda8d76d | 10244 | } |
24841daa NC |
10245 | first_separate_info = NULL; |
10246 | ||
10247 | free_dwo_info (); | |
19e6b90e L |
10248 | } |
10249 | ||
4cb93e3b TG |
10250 | void |
10251 | dwarf_select_sections_by_names (const char *names) | |
10252 | { | |
10253 | typedef struct | |
10254 | { | |
10255 | const char * option; | |
10256 | int * variable; | |
f9f0e732 | 10257 | int val; |
4cb93e3b TG |
10258 | } |
10259 | debug_dump_long_opts; | |
10260 | ||
10261 | static const debug_dump_long_opts opts_table [] = | |
10262 | { | |
10263 | /* Please keep this table alpha- sorted. */ | |
10264 | { "Ranges", & do_debug_ranges, 1 }, | |
10265 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 10266 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 10267 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
10268 | { "cu_index", & do_debug_cu_index, 1 }, |
10269 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 10270 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
10271 | { "frames", & do_debug_frames, 1 }, |
10272 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
10273 | /* The special .gdb_index section. */ |
10274 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
10275 | { "info", & do_debug_info, 1 }, |
10276 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 10277 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
10278 | { "loc", & do_debug_loc, 1 }, |
10279 | { "macro", & do_debug_macinfo, 1 }, | |
10280 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 10281 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 10282 | /* This entry is for compatibility |
4cb93e3b TG |
10283 | with earlier versions of readelf. */ |
10284 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 10285 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 10286 | { "str", & do_debug_str, 1 }, |
6f875884 TG |
10287 | /* These trace_* sections are used by Itanium VMS. */ |
10288 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
10289 | { "trace_aranges", & do_trace_aranges, 1 }, | |
10290 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
10291 | { NULL, NULL, 0 } |
10292 | }; | |
10293 | ||
10294 | const char *p; | |
467c65bc | 10295 | |
4cb93e3b TG |
10296 | p = names; |
10297 | while (*p) | |
10298 | { | |
10299 | const debug_dump_long_opts * entry; | |
467c65bc | 10300 | |
4cb93e3b TG |
10301 | for (entry = opts_table; entry->option; entry++) |
10302 | { | |
10303 | size_t len = strlen (entry->option); | |
467c65bc | 10304 | |
4cb93e3b TG |
10305 | if (strncmp (p, entry->option, len) == 0 |
10306 | && (p[len] == ',' || p[len] == '\0')) | |
10307 | { | |
10308 | * entry->variable |= entry->val; | |
467c65bc | 10309 | |
4cb93e3b TG |
10310 | /* The --debug-dump=frames-interp option also |
10311 | enables the --debug-dump=frames option. */ | |
10312 | if (do_debug_frames_interp) | |
10313 | do_debug_frames = 1; | |
10314 | ||
10315 | p += len; | |
10316 | break; | |
10317 | } | |
10318 | } | |
467c65bc | 10319 | |
4cb93e3b TG |
10320 | if (entry->option == NULL) |
10321 | { | |
10322 | warn (_("Unrecognized debug option '%s'\n"), p); | |
10323 | p = strchr (p, ','); | |
10324 | if (p == NULL) | |
10325 | break; | |
10326 | } | |
467c65bc | 10327 | |
4cb93e3b TG |
10328 | if (*p == ',') |
10329 | p++; | |
10330 | } | |
10331 | } | |
10332 | ||
10333 | void | |
10334 | dwarf_select_sections_by_letters (const char *letters) | |
10335 | { | |
91d6fa6a | 10336 | unsigned int lindex = 0; |
4cb93e3b | 10337 | |
91d6fa6a NC |
10338 | while (letters[lindex]) |
10339 | switch (letters[lindex++]) | |
4cb93e3b | 10340 | { |
dda8d76d NC |
10341 | case 'A': do_debug_addr = 1; break; |
10342 | case 'a': do_debug_abbrevs = 1; break; | |
10343 | case 'c': do_debug_cu_index = 1; break; | |
10344 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
10345 | case 'f': do_debug_frames = 1; break; | |
10346 | case 'g': do_gdb_index = 1; break; | |
10347 | case 'i': do_debug_info = 1; break; | |
10348 | case 'K': do_follow_links = 1; break; | |
10349 | case 'k': do_debug_links = 1; break; | |
10350 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
10351 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
10352 | case 'm': do_debug_macinfo = 1; break; | |
10353 | case 'o': do_debug_loc = 1; break; | |
10354 | case 'p': do_debug_pubnames = 1; break; | |
10355 | case 'R': do_debug_ranges = 1; break; | |
10356 | case 'r': do_debug_aranges = 1; break; | |
10357 | case 's': do_debug_str = 1; break; | |
10358 | case 'T': do_trace_aranges = 1; break; | |
10359 | case 't': do_debug_pubtypes = 1; break; | |
10360 | case 'U': do_trace_info = 1; break; | |
10361 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 10362 | |
4cb93e3b | 10363 | default: |
7cc78d07 | 10364 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
10365 | break; |
10366 | } | |
10367 | } | |
10368 | ||
10369 | void | |
10370 | dwarf_select_sections_all (void) | |
10371 | { | |
10372 | do_debug_info = 1; | |
10373 | do_debug_abbrevs = 1; | |
10374 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
10375 | do_debug_pubnames = 1; | |
f9f0e732 | 10376 | do_debug_pubtypes = 1; |
4cb93e3b TG |
10377 | do_debug_aranges = 1; |
10378 | do_debug_ranges = 1; | |
10379 | do_debug_frames = 1; | |
10380 | do_debug_macinfo = 1; | |
10381 | do_debug_str = 1; | |
10382 | do_debug_loc = 1; | |
5bbdf3d5 | 10383 | do_gdb_index = 1; |
6f875884 TG |
10384 | do_trace_info = 1; |
10385 | do_trace_abbrevs = 1; | |
10386 | do_trace_aranges = 1; | |
657d0d47 CC |
10387 | do_debug_addr = 1; |
10388 | do_debug_cu_index = 1; | |
dda8d76d NC |
10389 | do_follow_links = 1; |
10390 | do_debug_links = 1; | |
4cb93e3b TG |
10391 | } |
10392 | ||
dda8d76d NC |
10393 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL |
10394 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL | |
10395 | ||
10396 | /* N.B. The order here must match the order in section_display_enum. */ | |
10397 | ||
19e6b90e L |
10398 | struct dwarf_section_display debug_displays[] = |
10399 | { | |
dda8d76d NC |
10400 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, |
10401 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE }, | |
10402 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10403 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE }, | |
10404 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10405 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
10406 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
10407 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10408 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10409 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10410 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10411 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10412 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10413 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10414 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
10415 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
10416 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10417 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10418 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10419 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10420 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE }, | |
10421 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10422 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE }, | |
10423 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE }, | |
10424 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE }, | |
10425 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
10426 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE }, | |
10427 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE }, | |
10428 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
10429 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE }, | |
10430 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10431 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10432 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10433 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10434 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE }, | |
10435 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10436 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10437 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE }, | |
10438 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10439 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10440 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10441 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10442 | /* Separate debug info files can containt their own .debug_str section, | |
10443 | and this might be in *addition* to a .debug_str section already present | |
10444 | in the main file. Hence we need to have two entries for .debug_str. */ | |
10445 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
19e6b90e | 10446 | }; |
b451e98a JK |
10447 | |
10448 | /* A static assertion. */ | |
10449 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |