Commit | Line | Data |
---|---|---|
19e6b90e | 1 | /* dwarf.c -- display DWARF contents of a BFD binary file |
b90efa5b | 2 | Copyright (C) 2005-2015 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" |
19e6b90e | 31 | |
18464d4d JK |
32 | static const char *regname (unsigned int regno, int row); |
33 | ||
19e6b90e L |
34 | static int have_frame_base; |
35 | static int need_base_address; | |
36 | ||
37 | static unsigned int last_pointer_size = 0; | |
38 | static int warned_about_missing_comp_units = FALSE; | |
39 | ||
40 | static unsigned int num_debug_info_entries = 0; | |
82b1b41b | 41 | static unsigned int alloc_num_debug_info_entries = 0; |
19e6b90e | 42 | static debug_info *debug_information = NULL; |
cc86f28f NC |
43 | /* Special value for num_debug_info_entries to indicate |
44 | that the .debug_info section could not be loaded/parsed. */ | |
45 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
19e6b90e | 46 | |
77ef8654 | 47 | unsigned int eh_addr_size; |
19e6b90e L |
48 | |
49 | int do_debug_info; | |
50 | int do_debug_abbrevs; | |
51 | int do_debug_lines; | |
52 | int do_debug_pubnames; | |
f9f0e732 | 53 | int do_debug_pubtypes; |
19e6b90e L |
54 | int do_debug_aranges; |
55 | int do_debug_ranges; | |
56 | int do_debug_frames; | |
57 | int do_debug_frames_interp; | |
58 | int do_debug_macinfo; | |
59 | int do_debug_str; | |
60 | int do_debug_loc; | |
5bbdf3d5 | 61 | int do_gdb_index; |
6f875884 TG |
62 | int do_trace_info; |
63 | int do_trace_abbrevs; | |
64 | int do_trace_aranges; | |
657d0d47 CC |
65 | int do_debug_addr; |
66 | int do_debug_cu_index; | |
a262ae96 | 67 | int do_wide; |
19e6b90e | 68 | |
fd2f0033 TT |
69 | int dwarf_cutoff_level = -1; |
70 | unsigned long dwarf_start_die; | |
71 | ||
4723351a CC |
72 | int dwarf_check = 0; |
73 | ||
341f9135 CC |
74 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
75 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
76 | as a zero-terminated list of section indexes comprising one set of debug | |
77 | sections from a .dwo file. */ | |
78 | ||
79 | static int cu_tu_indexes_read = 0; | |
80 | static unsigned int *shndx_pool = NULL; | |
81 | static unsigned int shndx_pool_size = 0; | |
82 | static unsigned int shndx_pool_used = 0; | |
83 | ||
84 | /* For version 2 package files, each set contains an array of section offsets | |
85 | and an array of section sizes, giving the offset and size of the | |
86 | contribution from a CU or TU within one of the debug sections. | |
87 | When displaying debug info from a package file, we need to use these | |
88 | tables to locate the corresponding contributions to each section. */ | |
89 | ||
90 | struct cu_tu_set | |
91 | { | |
92 | uint64_t signature; | |
93 | dwarf_vma section_offsets[DW_SECT_MAX]; | |
94 | size_t section_sizes[DW_SECT_MAX]; | |
95 | }; | |
96 | ||
97 | static int cu_count = 0; | |
98 | static int tu_count = 0; | |
99 | static struct cu_tu_set *cu_sets = NULL; | |
100 | static struct cu_tu_set *tu_sets = NULL; | |
101 | ||
102 | static void load_cu_tu_indexes (void *file); | |
103 | ||
4cb93e3b TG |
104 | /* Values for do_debug_lines. */ |
105 | #define FLAG_DEBUG_LINES_RAW 1 | |
106 | #define FLAG_DEBUG_LINES_DECODED 2 | |
107 | ||
77ef8654 | 108 | static unsigned int |
f1c4cc75 RH |
109 | size_of_encoded_value (int encoding) |
110 | { | |
111 | switch (encoding & 0x7) | |
112 | { | |
113 | default: /* ??? */ | |
114 | case 0: return eh_addr_size; | |
115 | case 2: return 2; | |
116 | case 3: return 4; | |
117 | case 4: return 8; | |
118 | } | |
119 | } | |
120 | ||
121 | static dwarf_vma | |
041830e0 | 122 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 123 | int encoding, |
041830e0 NC |
124 | struct dwarf_section *section, |
125 | unsigned char * end) | |
f1c4cc75 | 126 | { |
041830e0 | 127 | unsigned char * data = * pdata; |
6937bb54 | 128 | unsigned int size = size_of_encoded_value (encoding); |
bad62cf5 | 129 | dwarf_vma val; |
f1c4cc75 | 130 | |
041830e0 NC |
131 | if (data + size >= end) |
132 | { | |
133 | warn (_("Encoded value extends past end of section\n")); | |
134 | * pdata = end; | |
135 | return 0; | |
136 | } | |
137 | ||
6937bb54 NC |
138 | /* PR 17512: file: 002-829853-0.004. */ |
139 | if (size > 8) | |
140 | { | |
141 | warn (_("Encoded size of %d is too large to read\n"), size); | |
142 | * pdata = end; | |
143 | return 0; | |
144 | } | |
145 | ||
0a9d414a NC |
146 | /* PR 17512: file: 1085-5603-0.004. */ |
147 | if (size == 0) | |
148 | { | |
149 | warn (_("Encoded size of 0 is too small to read\n")); | |
150 | * pdata = end; | |
151 | return 0; | |
152 | } | |
153 | ||
f1c4cc75 | 154 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 155 | val = byte_get_signed (data, size); |
f1c4cc75 | 156 | else |
bad62cf5 AM |
157 | val = byte_get (data, size); |
158 | ||
159 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
160 | val += section->address + (data - section->start); | |
041830e0 NC |
161 | |
162 | * pdata = data + size; | |
bad62cf5 | 163 | return val; |
f1c4cc75 RH |
164 | } |
165 | ||
4c219c2e AM |
166 | #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
167 | # ifndef __MINGW32__ | |
168 | # define DWARF_VMA_FMT "ll" | |
169 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
170 | # else | |
171 | # define DWARF_VMA_FMT "I64" | |
172 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
173 | # endif | |
2e14fae2 | 174 | #else |
4c219c2e AM |
175 | # define DWARF_VMA_FMT "l" |
176 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
177 | #endif |
178 | ||
bf5117e3 NC |
179 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
180 | buffer containing the converted VALUE. The value is converted according | |
181 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
182 | it specifies the maximum number of bytes to be displayed in the converted | |
183 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 184 | |
47704ddf | 185 | static const char * |
bf5117e3 | 186 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
187 | { |
188 | /* As dwarf_vmatoa is used more then once in a printf call | |
189 | for output, we are cycling through an fixed array of pointers | |
190 | for return address. */ | |
191 | static int buf_pos = 0; | |
467c65bc NC |
192 | static struct dwarf_vmatoa_buf |
193 | { | |
47704ddf KT |
194 | char place[64]; |
195 | } buf[16]; | |
47704ddf KT |
196 | char *ret; |
197 | ||
47704ddf | 198 | ret = buf[buf_pos++].place; |
467c65bc | 199 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 200 | |
bf5117e3 NC |
201 | if (num_bytes) |
202 | { | |
203 | /* Printf does not have a way of specifiying a maximum field width for an | |
204 | integer value, so we print the full value into a buffer and then select | |
205 | the precision we need. */ | |
206 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
207 | if (num_bytes > 8) | |
208 | num_bytes = 8; | |
209 | return ret + (16 - 2 * num_bytes); | |
210 | } | |
211 | else | |
212 | { | |
213 | char fmt[32]; | |
214 | ||
215 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
216 | snprintf (ret, sizeof (buf[0].place), fmt, value); | |
217 | return ret; | |
218 | } | |
219 | } | |
47704ddf | 220 | |
bf5117e3 NC |
221 | static inline const char * |
222 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
223 | { | |
224 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
225 | } | |
226 | ||
227 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
228 | hexadecimal format, followed by a space. The length of the VALUE (and | |
229 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
230 | ||
231 | static void | |
232 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
233 | { | |
234 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
235 | } |
236 | ||
74bc6052 CC |
237 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
238 | For reentrancy, this uses a buffer provided by the caller. */ | |
239 | ||
240 | static const char * | |
241 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, | |
242 | unsigned int buf_len) | |
243 | { | |
244 | int len = 0; | |
245 | ||
246 | if (hvalue == 0) | |
247 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); | |
248 | else | |
249 | { | |
250 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); | |
251 | snprintf (buf + len, buf_len - len, | |
252 | "%08" DWARF_VMA_FMT "x", lvalue); | |
253 | } | |
254 | ||
255 | return buf; | |
256 | } | |
257 | ||
f6f0e17b NC |
258 | /* Read in a LEB128 encoded value starting at address DATA. |
259 | If SIGN is true, return a signed LEB128 value. | |
260 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
261 | No bytes will be read at address END or beyond. */ | |
262 | ||
467c65bc | 263 | dwarf_vma |
f6f0e17b NC |
264 | read_leb128 (unsigned char *data, |
265 | unsigned int *length_return, | |
266 | bfd_boolean sign, | |
267 | const unsigned char * const end) | |
19e6b90e | 268 | { |
467c65bc | 269 | dwarf_vma result = 0; |
19e6b90e L |
270 | unsigned int num_read = 0; |
271 | unsigned int shift = 0; | |
f6f0e17b | 272 | unsigned char byte = 0; |
19e6b90e | 273 | |
f6f0e17b | 274 | while (data < end) |
19e6b90e L |
275 | { |
276 | byte = *data++; | |
277 | num_read++; | |
278 | ||
467c65bc | 279 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; |
19e6b90e L |
280 | |
281 | shift += 7; | |
f6f0e17b NC |
282 | if ((byte & 0x80) == 0) |
283 | break; | |
77ef8654 NC |
284 | |
285 | /* PR 17512: file: 0ca183b8. | |
286 | FIXME: Should we signal this error somehow ? */ | |
f641dd96 | 287 | if (shift >= sizeof (result) * 8) |
77ef8654 | 288 | break; |
19e6b90e | 289 | } |
19e6b90e L |
290 | |
291 | if (length_return != NULL) | |
292 | *length_return = num_read; | |
293 | ||
294 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
65879393 | 295 | result |= (dwarf_vma) -1 << shift; |
19e6b90e L |
296 | |
297 | return result; | |
298 | } | |
299 | ||
467c65bc | 300 | /* Create a signed version to avoid painful typecasts. */ |
f6f0e17b NC |
301 | static inline dwarf_signed_vma |
302 | read_sleb128 (unsigned char * data, | |
303 | unsigned int * length_return, | |
304 | const unsigned char * const end) | |
305 | { | |
306 | return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end); | |
307 | } | |
308 | ||
309 | static inline dwarf_vma | |
310 | read_uleb128 (unsigned char * data, | |
311 | unsigned int * length_return, | |
312 | const unsigned char * const end) | |
467c65bc | 313 | { |
f6f0e17b | 314 | return read_leb128 (data, length_return, FALSE, end); |
467c65bc NC |
315 | } |
316 | ||
0c588247 NC |
317 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
318 | do \ | |
319 | { \ | |
e39462cb | 320 | int dummy [sizeof (VAL) < (AMOUNT) ? -1 : 1] ATTRIBUTE_UNUSED ; \ |
0c588247 NC |
321 | unsigned int amount = (AMOUNT); \ |
322 | if (((PTR) + amount) >= (END)) \ | |
323 | { \ | |
324 | if ((PTR) < (END)) \ | |
325 | amount = (END) - (PTR); \ | |
326 | else \ | |
327 | amount = 0; \ | |
328 | } \ | |
6937bb54 | 329 | if (amount == 0 || amount > 8) \ |
0c588247 | 330 | VAL = 0; \ |
6937bb54 NC |
331 | else \ |
332 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
333 | } \ |
334 | while (0) | |
335 | ||
336 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ | |
337 | do \ | |
338 | { \ | |
339 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
340 | PTR += AMOUNT; \ | |
341 | } \ | |
342 | while (0) | |
343 | ||
344 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ | |
345 | do \ | |
346 | { \ | |
347 | unsigned int amount = (AMOUNT); \ | |
348 | if (((PTR) + amount) >= (END)) \ | |
349 | { \ | |
350 | if ((PTR) < (END)) \ | |
351 | amount = (END) - (PTR); \ | |
352 | else \ | |
353 | amount = 0; \ | |
354 | } \ | |
355 | if (amount) \ | |
356 | VAL = byte_get_signed ((PTR), amount); \ | |
357 | else \ | |
358 | VAL = 0; \ | |
359 | } \ | |
360 | while (0) | |
361 | ||
362 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ | |
363 | do \ | |
364 | { \ | |
365 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
366 | PTR += AMOUNT; \ | |
367 | } \ | |
368 | while (0) | |
369 | ||
370 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
371 | do \ | |
372 | { \ | |
87bc83b3 | 373 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
374 | { \ |
375 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
376 | } \ | |
377 | else \ | |
378 | { \ | |
0c588247 NC |
379 | * (LOW) = * (HIGH) = 0; \ |
380 | } \ | |
381 | } \ | |
382 | while (0) | |
383 | ||
19e6b90e L |
384 | typedef struct State_Machine_Registers |
385 | { | |
467c65bc | 386 | dwarf_vma address; |
19e6b90e L |
387 | unsigned int file; |
388 | unsigned int line; | |
389 | unsigned int column; | |
390 | int is_stmt; | |
391 | int basic_block; | |
a233b20c JJ |
392 | unsigned char op_index; |
393 | unsigned char end_sequence; | |
19e6b90e L |
394 | /* This variable hold the number of the last entry seen |
395 | in the File Table. */ | |
396 | unsigned int last_file_entry; | |
397 | } SMR; | |
398 | ||
399 | static SMR state_machine_regs; | |
400 | ||
401 | static void | |
402 | reset_state_machine (int is_stmt) | |
403 | { | |
404 | state_machine_regs.address = 0; | |
a233b20c | 405 | state_machine_regs.op_index = 0; |
19e6b90e L |
406 | state_machine_regs.file = 1; |
407 | state_machine_regs.line = 1; | |
408 | state_machine_regs.column = 0; | |
409 | state_machine_regs.is_stmt = is_stmt; | |
410 | state_machine_regs.basic_block = 0; | |
411 | state_machine_regs.end_sequence = 0; | |
412 | state_machine_regs.last_file_entry = 0; | |
413 | } | |
414 | ||
415 | /* Handled an extend line op. | |
416 | Returns the number of bytes read. */ | |
417 | ||
418 | static int | |
f6f0e17b NC |
419 | process_extended_line_op (unsigned char * data, |
420 | int is_stmt, | |
421 | unsigned char * end) | |
19e6b90e L |
422 | { |
423 | unsigned char op_code; | |
424 | unsigned int bytes_read; | |
425 | unsigned int len; | |
426 | unsigned char *name; | |
143a3db0 | 427 | unsigned char *orig_data = data; |
f6f0e17b | 428 | dwarf_vma adr; |
19e6b90e | 429 | |
f6f0e17b | 430 | len = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
431 | data += bytes_read; |
432 | ||
e44c58ce | 433 | if (len == 0 || data == end || len > (uintptr_t) (end - data)) |
19e6b90e | 434 | { |
f41e4712 | 435 | warn (_("Badly formed extended line op encountered!\n")); |
19e6b90e L |
436 | return bytes_read; |
437 | } | |
438 | ||
439 | len += bytes_read; | |
440 | op_code = *data++; | |
441 | ||
442 | printf (_(" Extended opcode %d: "), op_code); | |
443 | ||
444 | switch (op_code) | |
445 | { | |
446 | case DW_LNE_end_sequence: | |
447 | printf (_("End of Sequence\n\n")); | |
448 | reset_state_machine (is_stmt); | |
449 | break; | |
450 | ||
451 | case DW_LNE_set_address: | |
6937bb54 NC |
452 | /* PR 17512: file: 002-100480-0.004. */ |
453 | if (len - bytes_read - 1 > 8) | |
77ef8654 NC |
454 | { |
455 | warn (_("Length (%d) of DW_LNE_set_address op is too long\n"), | |
456 | len - bytes_read - 1); | |
457 | adr = 0; | |
458 | } | |
459 | else | |
460 | SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end); | |
47704ddf | 461 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 462 | state_machine_regs.address = adr; |
a233b20c | 463 | state_machine_regs.op_index = 0; |
19e6b90e L |
464 | break; |
465 | ||
466 | case DW_LNE_define_file: | |
143a3db0 | 467 | printf (_("define new File Table entry\n")); |
19e6b90e | 468 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 469 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 470 | |
19e6b90e | 471 | name = data; |
0c588247 | 472 | data += strnlen ((char *) data, end - data) + 1; |
f6f0e17b | 473 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
19e6b90e | 474 | data += bytes_read; |
f6f0e17b | 475 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
19e6b90e | 476 | data += bytes_read; |
f6f0e17b | 477 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
143a3db0 | 478 | data += bytes_read; |
f6f0e17b NC |
479 | printf ("%s\n\n", name); |
480 | ||
481 | if (((unsigned int) (data - orig_data) != len) || data == end) | |
b4eb7656 | 482 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
483 | break; |
484 | ||
ed4a4bdf | 485 | case DW_LNE_set_discriminator: |
47704ddf | 486 | printf (_("set Discriminator to %s\n"), |
f6f0e17b | 487 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
ed4a4bdf CC |
488 | break; |
489 | ||
e2a0d921 NC |
490 | /* HP extensions. */ |
491 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 492 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
493 | break; |
494 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 495 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
496 | break; |
497 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 498 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
499 | break; |
500 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 501 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
502 | break; |
503 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 504 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
505 | break; |
506 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 507 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
508 | break; |
509 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 510 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
511 | break; |
512 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 513 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
514 | break; |
515 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 516 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
517 | break; |
518 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 519 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 520 | break; |
43294ab7 TG |
521 | case DW_LNE_HP_source_file_correlation: |
522 | { | |
b4eb7656 AM |
523 | unsigned char *edata = data + len - bytes_read - 1; |
524 | ||
525 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
526 | ||
527 | while (data < edata) | |
528 | { | |
529 | unsigned int opc; | |
530 | ||
531 | opc = read_uleb128 (data, & bytes_read, edata); | |
532 | data += bytes_read; | |
533 | ||
534 | switch (opc) | |
535 | { | |
536 | case DW_LNE_HP_SFC_formfeed: | |
537 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
538 | break; | |
539 | case DW_LNE_HP_SFC_set_listing_line: | |
540 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", | |
541 | dwarf_vmatoa ("u", | |
542 | read_uleb128 (data, & bytes_read, edata))); | |
543 | data += bytes_read; | |
544 | break; | |
545 | case DW_LNE_HP_SFC_associate: | |
546 | printf (" DW_LNE_HP_SFC_associate "); | |
547 | printf ("(%s", | |
548 | dwarf_vmatoa ("u", | |
549 | read_uleb128 (data, & bytes_read, edata))); | |
550 | data += bytes_read; | |
551 | printf (",%s", | |
552 | dwarf_vmatoa ("u", | |
553 | read_uleb128 (data, & bytes_read, edata))); | |
554 | data += bytes_read; | |
555 | printf (",%s)\n", | |
556 | dwarf_vmatoa ("u", | |
557 | read_uleb128 (data, & bytes_read, edata))); | |
558 | data += bytes_read; | |
559 | break; | |
560 | default: | |
561 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
562 | data = edata; | |
563 | break; | |
564 | } | |
565 | } | |
43294ab7 TG |
566 | } |
567 | break; | |
cecf136e | 568 | |
19e6b90e | 569 | default: |
7e665af3 | 570 | { |
b4eb7656 AM |
571 | unsigned int rlen = len - bytes_read - 1; |
572 | ||
573 | if (op_code >= DW_LNE_lo_user | |
574 | /* The test against DW_LNW_hi_user is redundant due to | |
575 | the limited range of the unsigned char data type used | |
576 | for op_code. */ | |
577 | /*&& op_code <= DW_LNE_hi_user*/) | |
578 | printf (_("user defined: ")); | |
579 | else | |
580 | printf (_("UNKNOWN: ")); | |
581 | printf (_("length %d ["), rlen); | |
582 | for (; rlen; rlen--) | |
583 | printf (" %02x", *data++); | |
584 | printf ("]\n"); | |
7e665af3 | 585 | } |
19e6b90e L |
586 | break; |
587 | } | |
588 | ||
589 | return len; | |
590 | } | |
591 | ||
0c588247 | 592 | static const unsigned char * |
467c65bc | 593 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
594 | { |
595 | struct dwarf_section *section = &debug_displays [str].section; | |
596 | ||
597 | if (section->start == NULL) | |
0c588247 | 598 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e L |
599 | |
600 | if (offset > section->size) | |
601 | { | |
467c65bc NC |
602 | warn (_("DW_FORM_strp offset too big: %s\n"), |
603 | dwarf_vmatoa ("x", offset)); | |
0c588247 | 604 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
605 | } |
606 | ||
0c588247 | 607 | return (const unsigned char *) section->start + offset; |
19e6b90e L |
608 | } |
609 | ||
4723351a | 610 | static const char * |
341f9135 CC |
611 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
612 | dwarf_vma offset_size, int dwo) | |
4723351a CC |
613 | { |
614 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
615 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
616 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
617 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
618 | dwarf_vma index_offset = idx * offset_size; | |
619 | dwarf_vma str_offset; | |
620 | ||
621 | if (index_section->start == NULL) | |
622 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
623 | : _("<no .debug_str_offsets section>")); | |
624 | ||
341f9135 CC |
625 | if (this_set != NULL) |
626 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
4723351a CC |
627 | if (index_offset > index_section->size) |
628 | { | |
629 | warn (_("DW_FORM_GNU_str_index offset too big: %s\n"), | |
630 | dwarf_vmatoa ("x", index_offset)); | |
631 | return _("<index offset is too big>"); | |
632 | } | |
633 | ||
634 | if (str_section->start == NULL) | |
635 | return (dwo ? _("<no .debug_str.dwo section>") | |
636 | : _("<no .debug_str section>")); | |
637 | ||
638 | str_offset = byte_get (index_section->start + index_offset, offset_size); | |
639 | str_offset -= str_section->address; | |
640 | if (str_offset > str_section->size) | |
641 | { | |
642 | warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), | |
643 | dwarf_vmatoa ("x", str_offset)); | |
644 | return _("<indirect index offset is too big>"); | |
645 | } | |
646 | ||
647 | return (const char *) str_section->start + str_offset; | |
648 | } | |
649 | ||
650 | static const char * | |
651 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
652 | { | |
653 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
654 | ||
655 | if (section->start == NULL) | |
656 | return (_("<no .debug_addr section>")); | |
657 | ||
658 | if (offset + bytes > section->size) | |
659 | { | |
660 | warn (_("Offset into section %s too big: %s\n"), | |
b4eb7656 | 661 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
662 | return "<offset too big>"; |
663 | } | |
664 | ||
665 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
666 | } | |
667 | ||
668 | ||
19e6b90e L |
669 | /* FIXME: There are better and more efficient ways to handle |
670 | these structures. For now though, I just want something that | |
671 | is simple to implement. */ | |
672 | typedef struct abbrev_attr | |
673 | { | |
674 | unsigned long attribute; | |
675 | unsigned long form; | |
676 | struct abbrev_attr *next; | |
677 | } | |
678 | abbrev_attr; | |
679 | ||
680 | typedef struct abbrev_entry | |
681 | { | |
682 | unsigned long entry; | |
683 | unsigned long tag; | |
684 | int children; | |
685 | struct abbrev_attr *first_attr; | |
686 | struct abbrev_attr *last_attr; | |
687 | struct abbrev_entry *next; | |
688 | } | |
689 | abbrev_entry; | |
690 | ||
691 | static abbrev_entry *first_abbrev = NULL; | |
692 | static abbrev_entry *last_abbrev = NULL; | |
693 | ||
694 | static void | |
695 | free_abbrevs (void) | |
696 | { | |
91d6fa6a | 697 | abbrev_entry *abbrv; |
19e6b90e | 698 | |
91d6fa6a | 699 | for (abbrv = first_abbrev; abbrv;) |
19e6b90e | 700 | { |
91d6fa6a | 701 | abbrev_entry *next_abbrev = abbrv->next; |
19e6b90e L |
702 | abbrev_attr *attr; |
703 | ||
91d6fa6a | 704 | for (attr = abbrv->first_attr; attr;) |
19e6b90e | 705 | { |
91d6fa6a | 706 | abbrev_attr *next_attr = attr->next; |
19e6b90e L |
707 | |
708 | free (attr); | |
91d6fa6a | 709 | attr = next_attr; |
19e6b90e L |
710 | } |
711 | ||
91d6fa6a NC |
712 | free (abbrv); |
713 | abbrv = next_abbrev; | |
19e6b90e L |
714 | } |
715 | ||
716 | last_abbrev = first_abbrev = NULL; | |
717 | } | |
718 | ||
719 | static void | |
720 | add_abbrev (unsigned long number, unsigned long tag, int children) | |
721 | { | |
722 | abbrev_entry *entry; | |
723 | ||
3f5e193b | 724 | entry = (abbrev_entry *) malloc (sizeof (*entry)); |
19e6b90e L |
725 | if (entry == NULL) |
726 | /* ugg */ | |
727 | return; | |
728 | ||
729 | entry->entry = number; | |
730 | entry->tag = tag; | |
731 | entry->children = children; | |
732 | entry->first_attr = NULL; | |
733 | entry->last_attr = NULL; | |
734 | entry->next = NULL; | |
735 | ||
736 | if (first_abbrev == NULL) | |
737 | first_abbrev = entry; | |
738 | else | |
739 | last_abbrev->next = entry; | |
740 | ||
741 | last_abbrev = entry; | |
742 | } | |
743 | ||
744 | static void | |
745 | add_abbrev_attr (unsigned long attribute, unsigned long form) | |
746 | { | |
747 | abbrev_attr *attr; | |
748 | ||
3f5e193b | 749 | attr = (abbrev_attr *) malloc (sizeof (*attr)); |
19e6b90e L |
750 | if (attr == NULL) |
751 | /* ugg */ | |
752 | return; | |
753 | ||
754 | attr->attribute = attribute; | |
755 | attr->form = form; | |
756 | attr->next = NULL; | |
757 | ||
758 | if (last_abbrev->first_attr == NULL) | |
759 | last_abbrev->first_attr = attr; | |
760 | else | |
761 | last_abbrev->last_attr->next = attr; | |
762 | ||
763 | last_abbrev->last_attr = attr; | |
764 | } | |
765 | ||
766 | /* Processes the (partial) contents of a .debug_abbrev section. | |
767 | Returns NULL if the end of the section was encountered. | |
768 | Returns the address after the last byte read if the end of | |
769 | an abbreviation set was found. */ | |
770 | ||
771 | static unsigned char * | |
772 | process_abbrev_section (unsigned char *start, unsigned char *end) | |
773 | { | |
774 | if (first_abbrev != NULL) | |
775 | return NULL; | |
776 | ||
777 | while (start < end) | |
778 | { | |
779 | unsigned int bytes_read; | |
780 | unsigned long entry; | |
781 | unsigned long tag; | |
782 | unsigned long attribute; | |
783 | int children; | |
784 | ||
f6f0e17b | 785 | entry = read_uleb128 (start, & bytes_read, end); |
19e6b90e L |
786 | start += bytes_read; |
787 | ||
788 | /* A single zero is supposed to end the section according | |
789 | to the standard. If there's more, then signal that to | |
790 | the caller. */ | |
f6f0e17b NC |
791 | if (start == end) |
792 | return NULL; | |
19e6b90e | 793 | if (entry == 0) |
f6f0e17b | 794 | return start; |
19e6b90e | 795 | |
f6f0e17b | 796 | tag = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 797 | start += bytes_read; |
f6f0e17b NC |
798 | if (start == end) |
799 | return NULL; | |
19e6b90e L |
800 | |
801 | children = *start++; | |
802 | ||
803 | add_abbrev (entry, tag, children); | |
804 | ||
805 | do | |
806 | { | |
807 | unsigned long form; | |
808 | ||
f6f0e17b | 809 | attribute = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 810 | start += bytes_read; |
f6f0e17b NC |
811 | if (start == end) |
812 | break; | |
19e6b90e | 813 | |
f6f0e17b | 814 | form = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 815 | start += bytes_read; |
f6f0e17b NC |
816 | if (start == end) |
817 | break; | |
19e6b90e | 818 | |
399c99f7 | 819 | add_abbrev_attr (attribute, form); |
19e6b90e L |
820 | } |
821 | while (attribute != 0); | |
822 | } | |
823 | ||
399c99f7 L |
824 | /* Report the missing single zero which ends the section. */ |
825 | error (_(".debug_abbrev section not zero terminated\n")); | |
826 | ||
19e6b90e L |
827 | return NULL; |
828 | } | |
829 | ||
a19c41a7 | 830 | static const char * |
19e6b90e L |
831 | get_TAG_name (unsigned long tag) |
832 | { | |
b9c361e0 | 833 | const char *name = get_DW_TAG_name ((unsigned int)tag); |
a19c41a7 TT |
834 | |
835 | if (name == NULL) | |
19e6b90e | 836 | { |
a19c41a7 | 837 | static char buffer[100]; |
19e6b90e | 838 | |
a19c41a7 TT |
839 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag); |
840 | return buffer; | |
19e6b90e | 841 | } |
a19c41a7 TT |
842 | |
843 | return name; | |
19e6b90e L |
844 | } |
845 | ||
a19c41a7 | 846 | static const char * |
19e6b90e L |
847 | get_FORM_name (unsigned long form) |
848 | { | |
399c99f7 | 849 | const char *name; |
bf5117e3 | 850 | |
399c99f7 L |
851 | if (form == 0) |
852 | return "DW_FORM value: 0"; | |
a19c41a7 | 853 | |
399c99f7 | 854 | name = get_DW_FORM_name (form); |
a19c41a7 | 855 | if (name == NULL) |
19e6b90e | 856 | { |
a19c41a7 | 857 | static char buffer[100]; |
19e6b90e | 858 | |
a19c41a7 TT |
859 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
860 | return buffer; | |
19e6b90e | 861 | } |
a19c41a7 TT |
862 | |
863 | return name; | |
19e6b90e L |
864 | } |
865 | ||
866 | static unsigned char * | |
0c588247 NC |
867 | display_block (unsigned char *data, |
868 | dwarf_vma length, | |
869 | const unsigned char * const end) | |
19e6b90e | 870 | { |
0c588247 NC |
871 | dwarf_vma maxlen; |
872 | ||
467c65bc | 873 | printf (_(" %s byte block: "), dwarf_vmatoa ("u", length)); |
a1165289 NC |
874 | if (data > end) |
875 | return (unsigned char *) end; | |
19e6b90e | 876 | |
0c588247 NC |
877 | maxlen = (dwarf_vma) (end - data); |
878 | length = length > maxlen ? maxlen : length; | |
879 | ||
19e6b90e L |
880 | while (length --) |
881 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
882 | ||
883 | return data; | |
884 | } | |
885 | ||
886 | static int | |
887 | decode_location_expression (unsigned char * data, | |
888 | unsigned int pointer_size, | |
b7807392 JJ |
889 | unsigned int offset_size, |
890 | int dwarf_version, | |
467c65bc NC |
891 | dwarf_vma length, |
892 | dwarf_vma cu_offset, | |
f1c4cc75 | 893 | struct dwarf_section * section) |
19e6b90e L |
894 | { |
895 | unsigned op; | |
896 | unsigned int bytes_read; | |
467c65bc | 897 | dwarf_vma uvalue; |
0c588247 | 898 | dwarf_signed_vma svalue; |
19e6b90e L |
899 | unsigned char *end = data + length; |
900 | int need_frame_base = 0; | |
901 | ||
902 | while (data < end) | |
903 | { | |
904 | op = *data++; | |
905 | ||
906 | switch (op) | |
907 | { | |
908 | case DW_OP_addr: | |
0c588247 NC |
909 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
910 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
911 | break; |
912 | case DW_OP_deref: | |
913 | printf ("DW_OP_deref"); | |
914 | break; | |
915 | case DW_OP_const1u: | |
0c588247 NC |
916 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
917 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
918 | break; |
919 | case DW_OP_const1s: | |
0c588247 NC |
920 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
921 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
922 | break; |
923 | case DW_OP_const2u: | |
87bc83b3 | 924 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 925 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
926 | break; |
927 | case DW_OP_const2s: | |
0c588247 NC |
928 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
929 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
930 | break; |
931 | case DW_OP_const4u: | |
0c588247 NC |
932 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
933 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
934 | break; |
935 | case DW_OP_const4s: | |
0c588247 NC |
936 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
937 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
938 | break; |
939 | case DW_OP_const8u: | |
0c588247 NC |
940 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
941 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
942 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
943 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
944 | break; |
945 | case DW_OP_const8s: | |
0c588247 NC |
946 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
947 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
948 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
949 | printf ("%ld", (long) svalue); | |
19e6b90e L |
950 | break; |
951 | case DW_OP_constu: | |
467c65bc | 952 | printf ("DW_OP_constu: %s", |
f6f0e17b | 953 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
954 | data += bytes_read; |
955 | break; | |
956 | case DW_OP_consts: | |
467c65bc | 957 | printf ("DW_OP_consts: %s", |
f6f0e17b | 958 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
959 | data += bytes_read; |
960 | break; | |
961 | case DW_OP_dup: | |
962 | printf ("DW_OP_dup"); | |
963 | break; | |
964 | case DW_OP_drop: | |
965 | printf ("DW_OP_drop"); | |
966 | break; | |
967 | case DW_OP_over: | |
968 | printf ("DW_OP_over"); | |
969 | break; | |
970 | case DW_OP_pick: | |
0c588247 NC |
971 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
972 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
973 | break; |
974 | case DW_OP_swap: | |
975 | printf ("DW_OP_swap"); | |
976 | break; | |
977 | case DW_OP_rot: | |
978 | printf ("DW_OP_rot"); | |
979 | break; | |
980 | case DW_OP_xderef: | |
981 | printf ("DW_OP_xderef"); | |
982 | break; | |
983 | case DW_OP_abs: | |
984 | printf ("DW_OP_abs"); | |
985 | break; | |
986 | case DW_OP_and: | |
987 | printf ("DW_OP_and"); | |
988 | break; | |
989 | case DW_OP_div: | |
990 | printf ("DW_OP_div"); | |
991 | break; | |
992 | case DW_OP_minus: | |
993 | printf ("DW_OP_minus"); | |
994 | break; | |
995 | case DW_OP_mod: | |
996 | printf ("DW_OP_mod"); | |
997 | break; | |
998 | case DW_OP_mul: | |
999 | printf ("DW_OP_mul"); | |
1000 | break; | |
1001 | case DW_OP_neg: | |
1002 | printf ("DW_OP_neg"); | |
1003 | break; | |
1004 | case DW_OP_not: | |
1005 | printf ("DW_OP_not"); | |
1006 | break; | |
1007 | case DW_OP_or: | |
1008 | printf ("DW_OP_or"); | |
1009 | break; | |
1010 | case DW_OP_plus: | |
1011 | printf ("DW_OP_plus"); | |
1012 | break; | |
1013 | case DW_OP_plus_uconst: | |
467c65bc | 1014 | printf ("DW_OP_plus_uconst: %s", |
f6f0e17b | 1015 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1016 | data += bytes_read; |
1017 | break; | |
1018 | case DW_OP_shl: | |
1019 | printf ("DW_OP_shl"); | |
1020 | break; | |
1021 | case DW_OP_shr: | |
1022 | printf ("DW_OP_shr"); | |
1023 | break; | |
1024 | case DW_OP_shra: | |
1025 | printf ("DW_OP_shra"); | |
1026 | break; | |
1027 | case DW_OP_xor: | |
1028 | printf ("DW_OP_xor"); | |
1029 | break; | |
1030 | case DW_OP_bra: | |
0c588247 NC |
1031 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1032 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1033 | break; |
1034 | case DW_OP_eq: | |
1035 | printf ("DW_OP_eq"); | |
1036 | break; | |
1037 | case DW_OP_ge: | |
1038 | printf ("DW_OP_ge"); | |
1039 | break; | |
1040 | case DW_OP_gt: | |
1041 | printf ("DW_OP_gt"); | |
1042 | break; | |
1043 | case DW_OP_le: | |
1044 | printf ("DW_OP_le"); | |
1045 | break; | |
1046 | case DW_OP_lt: | |
1047 | printf ("DW_OP_lt"); | |
1048 | break; | |
1049 | case DW_OP_ne: | |
1050 | printf ("DW_OP_ne"); | |
1051 | break; | |
1052 | case DW_OP_skip: | |
0c588247 NC |
1053 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1054 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1055 | break; |
1056 | ||
1057 | case DW_OP_lit0: | |
1058 | case DW_OP_lit1: | |
1059 | case DW_OP_lit2: | |
1060 | case DW_OP_lit3: | |
1061 | case DW_OP_lit4: | |
1062 | case DW_OP_lit5: | |
1063 | case DW_OP_lit6: | |
1064 | case DW_OP_lit7: | |
1065 | case DW_OP_lit8: | |
1066 | case DW_OP_lit9: | |
1067 | case DW_OP_lit10: | |
1068 | case DW_OP_lit11: | |
1069 | case DW_OP_lit12: | |
1070 | case DW_OP_lit13: | |
1071 | case DW_OP_lit14: | |
1072 | case DW_OP_lit15: | |
1073 | case DW_OP_lit16: | |
1074 | case DW_OP_lit17: | |
1075 | case DW_OP_lit18: | |
1076 | case DW_OP_lit19: | |
1077 | case DW_OP_lit20: | |
1078 | case DW_OP_lit21: | |
1079 | case DW_OP_lit22: | |
1080 | case DW_OP_lit23: | |
1081 | case DW_OP_lit24: | |
1082 | case DW_OP_lit25: | |
1083 | case DW_OP_lit26: | |
1084 | case DW_OP_lit27: | |
1085 | case DW_OP_lit28: | |
1086 | case DW_OP_lit29: | |
1087 | case DW_OP_lit30: | |
1088 | case DW_OP_lit31: | |
1089 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1090 | break; | |
1091 | ||
1092 | case DW_OP_reg0: | |
1093 | case DW_OP_reg1: | |
1094 | case DW_OP_reg2: | |
1095 | case DW_OP_reg3: | |
1096 | case DW_OP_reg4: | |
1097 | case DW_OP_reg5: | |
1098 | case DW_OP_reg6: | |
1099 | case DW_OP_reg7: | |
1100 | case DW_OP_reg8: | |
1101 | case DW_OP_reg9: | |
1102 | case DW_OP_reg10: | |
1103 | case DW_OP_reg11: | |
1104 | case DW_OP_reg12: | |
1105 | case DW_OP_reg13: | |
1106 | case DW_OP_reg14: | |
1107 | case DW_OP_reg15: | |
1108 | case DW_OP_reg16: | |
1109 | case DW_OP_reg17: | |
1110 | case DW_OP_reg18: | |
1111 | case DW_OP_reg19: | |
1112 | case DW_OP_reg20: | |
1113 | case DW_OP_reg21: | |
1114 | case DW_OP_reg22: | |
1115 | case DW_OP_reg23: | |
1116 | case DW_OP_reg24: | |
1117 | case DW_OP_reg25: | |
1118 | case DW_OP_reg26: | |
1119 | case DW_OP_reg27: | |
1120 | case DW_OP_reg28: | |
1121 | case DW_OP_reg29: | |
1122 | case DW_OP_reg30: | |
1123 | case DW_OP_reg31: | |
18464d4d JK |
1124 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1125 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1126 | break; |
1127 | ||
1128 | case DW_OP_breg0: | |
1129 | case DW_OP_breg1: | |
1130 | case DW_OP_breg2: | |
1131 | case DW_OP_breg3: | |
1132 | case DW_OP_breg4: | |
1133 | case DW_OP_breg5: | |
1134 | case DW_OP_breg6: | |
1135 | case DW_OP_breg7: | |
1136 | case DW_OP_breg8: | |
1137 | case DW_OP_breg9: | |
1138 | case DW_OP_breg10: | |
1139 | case DW_OP_breg11: | |
1140 | case DW_OP_breg12: | |
1141 | case DW_OP_breg13: | |
1142 | case DW_OP_breg14: | |
1143 | case DW_OP_breg15: | |
1144 | case DW_OP_breg16: | |
1145 | case DW_OP_breg17: | |
1146 | case DW_OP_breg18: | |
1147 | case DW_OP_breg19: | |
1148 | case DW_OP_breg20: | |
1149 | case DW_OP_breg21: | |
1150 | case DW_OP_breg22: | |
1151 | case DW_OP_breg23: | |
1152 | case DW_OP_breg24: | |
1153 | case DW_OP_breg25: | |
1154 | case DW_OP_breg26: | |
1155 | case DW_OP_breg27: | |
1156 | case DW_OP_breg28: | |
1157 | case DW_OP_breg29: | |
1158 | case DW_OP_breg30: | |
1159 | case DW_OP_breg31: | |
467c65bc | 1160 | printf ("DW_OP_breg%d (%s): %s", |
47704ddf | 1161 | op - DW_OP_breg0, |
18464d4d | 1162 | regname (op - DW_OP_breg0, 1), |
f6f0e17b | 1163 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1164 | data += bytes_read; |
1165 | break; | |
1166 | ||
1167 | case DW_OP_regx: | |
f6f0e17b | 1168 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1169 | data += bytes_read; |
467c65bc NC |
1170 | printf ("DW_OP_regx: %s (%s)", |
1171 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1172 | break; |
1173 | case DW_OP_fbreg: | |
1174 | need_frame_base = 1; | |
467c65bc | 1175 | printf ("DW_OP_fbreg: %s", |
f6f0e17b | 1176 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1177 | data += bytes_read; |
1178 | break; | |
1179 | case DW_OP_bregx: | |
f6f0e17b | 1180 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1181 | data += bytes_read; |
467c65bc NC |
1182 | printf ("DW_OP_bregx: %s (%s) %s", |
1183 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
f6f0e17b | 1184 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1185 | data += bytes_read; |
1186 | break; | |
1187 | case DW_OP_piece: | |
467c65bc | 1188 | printf ("DW_OP_piece: %s", |
f6f0e17b | 1189 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1190 | data += bytes_read; |
1191 | break; | |
1192 | case DW_OP_deref_size: | |
0c588247 NC |
1193 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1194 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1195 | break; |
1196 | case DW_OP_xderef_size: | |
0c588247 NC |
1197 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1198 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1199 | break; |
1200 | case DW_OP_nop: | |
1201 | printf ("DW_OP_nop"); | |
1202 | break; | |
1203 | ||
1204 | /* DWARF 3 extensions. */ | |
1205 | case DW_OP_push_object_address: | |
1206 | printf ("DW_OP_push_object_address"); | |
1207 | break; | |
1208 | case DW_OP_call2: | |
1209 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
1210 | this ought to be an 8-byte wide computation. */ | |
0c588247 | 1211 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1212 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1213 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1214 | break; |
1215 | case DW_OP_call4: | |
1216 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
1217 | this ought to be an 8-byte wide computation. */ | |
0c588247 | 1218 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1219 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1220 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1221 | break; |
1222 | case DW_OP_call_ref: | |
e2a0d921 NC |
1223 | /* XXX: Strictly speaking for 64-bit DWARF3 files |
1224 | this ought to be an 8-byte wide computation. */ | |
b7807392 JJ |
1225 | if (dwarf_version == -1) |
1226 | { | |
1227 | printf (_("(DW_OP_call_ref in frame info)")); | |
1228 | /* No way to tell where the next op is, so just bail. */ | |
1229 | return need_frame_base; | |
1230 | } | |
1231 | if (dwarf_version == 2) | |
1232 | { | |
0c588247 | 1233 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1234 | } |
1235 | else | |
1236 | { | |
0c588247 | 1237 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1238 | } |
0c588247 | 1239 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1240 | break; |
a87b0a59 NS |
1241 | case DW_OP_form_tls_address: |
1242 | printf ("DW_OP_form_tls_address"); | |
1243 | break; | |
e2a0d921 NC |
1244 | case DW_OP_call_frame_cfa: |
1245 | printf ("DW_OP_call_frame_cfa"); | |
1246 | break; | |
1247 | case DW_OP_bit_piece: | |
1248 | printf ("DW_OP_bit_piece: "); | |
9cf03b7e | 1249 | printf (_("size: %s "), |
f6f0e17b | 1250 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 | 1251 | data += bytes_read; |
9cf03b7e | 1252 | printf (_("offset: %s "), |
f6f0e17b | 1253 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 NC |
1254 | data += bytes_read; |
1255 | break; | |
19e6b90e | 1256 | |
3244e8f5 JJ |
1257 | /* DWARF 4 extensions. */ |
1258 | case DW_OP_stack_value: | |
1259 | printf ("DW_OP_stack_value"); | |
1260 | break; | |
1261 | ||
1262 | case DW_OP_implicit_value: | |
1263 | printf ("DW_OP_implicit_value"); | |
f6f0e17b | 1264 | uvalue = read_uleb128 (data, &bytes_read, end); |
3244e8f5 | 1265 | data += bytes_read; |
6937bb54 | 1266 | data = display_block (data, uvalue, end); |
3244e8f5 JJ |
1267 | break; |
1268 | ||
19e6b90e L |
1269 | /* GNU extensions. */ |
1270 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1271 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1272 | break; |
1273 | case DW_OP_GNU_uninit: | |
1274 | printf ("DW_OP_GNU_uninit"); | |
1275 | /* FIXME: Is there data associated with this OP ? */ | |
1276 | break; | |
f1c4cc75 RH |
1277 | case DW_OP_GNU_encoded_addr: |
1278 | { | |
6937bb54 | 1279 | int encoding = 0; |
f1c4cc75 | 1280 | dwarf_vma addr; |
467c65bc | 1281 | |
6937bb54 NC |
1282 | if (data < end) |
1283 | encoding = *data++; | |
041830e0 | 1284 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1285 | |
1286 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1287 | print_dwarf_vma (addr, pointer_size); | |
1288 | } | |
1289 | break; | |
b7807392 JJ |
1290 | case DW_OP_GNU_implicit_pointer: |
1291 | /* XXX: Strictly speaking for 64-bit DWARF3 files | |
1292 | this ought to be an 8-byte wide computation. */ | |
1293 | if (dwarf_version == -1) | |
1294 | { | |
1295 | printf (_("(DW_OP_GNU_implicit_pointer in frame info)")); | |
1296 | /* No way to tell where the next op is, so just bail. */ | |
1297 | return need_frame_base; | |
1298 | } | |
1299 | if (dwarf_version == 2) | |
1300 | { | |
0c588247 | 1301 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1302 | } |
1303 | else | |
1304 | { | |
0c588247 | 1305 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1306 | } |
0c588247 NC |
1307 | printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s", |
1308 | dwarf_vmatoa ("x", uvalue), | |
1309 | dwarf_vmatoa ("d", read_sleb128 (data, | |
1310 | &bytes_read, end))); | |
1311 | data += bytes_read; | |
b7807392 | 1312 | break; |
0892011d | 1313 | case DW_OP_GNU_entry_value: |
f6f0e17b | 1314 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1315 | data += bytes_read; |
058037d3 NC |
1316 | /* PR 17531: file: 0cc9cd00. */ |
1317 | if (uvalue > (dwarf_vma) (end - data)) | |
1318 | uvalue = end - data; | |
0892011d JJ |
1319 | printf ("DW_OP_GNU_entry_value: ("); |
1320 | if (decode_location_expression (data, pointer_size, offset_size, | |
1321 | dwarf_version, uvalue, | |
1322 | cu_offset, section)) | |
1323 | need_frame_base = 1; | |
1324 | putchar (')'); | |
1325 | data += uvalue; | |
6937bb54 NC |
1326 | if (data > end) |
1327 | data = end; | |
0892011d JJ |
1328 | break; |
1329 | case DW_OP_GNU_const_type: | |
f6f0e17b | 1330 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1331 | data += bytes_read; |
1332 | printf ("DW_OP_GNU_const_type: <0x%s> ", | |
1333 | dwarf_vmatoa ("x", cu_offset + uvalue)); | |
0c588247 | 1334 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
6937bb54 | 1335 | data = display_block (data, uvalue, end); |
0892011d JJ |
1336 | break; |
1337 | case DW_OP_GNU_regval_type: | |
f6f0e17b | 1338 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1339 | data += bytes_read; |
1340 | printf ("DW_OP_GNU_regval_type: %s (%s)", | |
1341 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
f6f0e17b | 1342 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1343 | data += bytes_read; |
1344 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1345 | break; | |
1346 | case DW_OP_GNU_deref_type: | |
0c588247 NC |
1347 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1348 | printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue); | |
f6f0e17b | 1349 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1350 | data += bytes_read; |
1351 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1352 | break; | |
1353 | case DW_OP_GNU_convert: | |
f6f0e17b | 1354 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1355 | data += bytes_read; |
1356 | printf ("DW_OP_GNU_convert <0x%s>", | |
f8b999f9 | 1357 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d JJ |
1358 | break; |
1359 | case DW_OP_GNU_reinterpret: | |
f6f0e17b | 1360 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1361 | data += bytes_read; |
1362 | printf ("DW_OP_GNU_reinterpret <0x%s>", | |
f8b999f9 JJ |
1363 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1364 | break; | |
1365 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1366 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1367 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1368 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1369 | break; |
b4eb7656 AM |
1370 | case DW_OP_GNU_addr_index: |
1371 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1372 | data += bytes_read; | |
1373 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1374 | break; | |
1375 | case DW_OP_GNU_const_index: | |
1376 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1377 | data += bytes_read; | |
1378 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1379 | break; | |
e2a0d921 NC |
1380 | |
1381 | /* HP extensions. */ | |
1382 | case DW_OP_HP_is_value: | |
1383 | printf ("DW_OP_HP_is_value"); | |
1384 | /* FIXME: Is there data associated with this OP ? */ | |
1385 | break; | |
1386 | case DW_OP_HP_fltconst4: | |
1387 | printf ("DW_OP_HP_fltconst4"); | |
1388 | /* FIXME: Is there data associated with this OP ? */ | |
1389 | break; | |
1390 | case DW_OP_HP_fltconst8: | |
1391 | printf ("DW_OP_HP_fltconst8"); | |
1392 | /* FIXME: Is there data associated with this OP ? */ | |
1393 | break; | |
1394 | case DW_OP_HP_mod_range: | |
1395 | printf ("DW_OP_HP_mod_range"); | |
1396 | /* FIXME: Is there data associated with this OP ? */ | |
1397 | break; | |
1398 | case DW_OP_HP_unmod_range: | |
1399 | printf ("DW_OP_HP_unmod_range"); | |
1400 | /* FIXME: Is there data associated with this OP ? */ | |
1401 | break; | |
1402 | case DW_OP_HP_tls: | |
1403 | printf ("DW_OP_HP_tls"); | |
1404 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1405 | break; |
1406 | ||
35d60fe4 NC |
1407 | /* PGI (STMicroelectronics) extensions. */ |
1408 | case DW_OP_PGI_omp_thread_num: | |
1409 | /* Pushes the thread number for the current thread as it would be | |
1410 | returned by the standard OpenMP library function: | |
1411 | omp_get_thread_num(). The "current thread" is the thread for | |
1412 | which the expression is being evaluated. */ | |
1413 | printf ("DW_OP_PGI_omp_thread_num"); | |
1414 | break; | |
1415 | ||
19e6b90e L |
1416 | default: |
1417 | if (op >= DW_OP_lo_user | |
1418 | && op <= DW_OP_hi_user) | |
1419 | printf (_("(User defined location op)")); | |
1420 | else | |
1421 | printf (_("(Unknown location op)")); | |
1422 | /* No way to tell where the next op is, so just bail. */ | |
1423 | return need_frame_base; | |
1424 | } | |
1425 | ||
1426 | /* Separate the ops. */ | |
1427 | if (data < end) | |
1428 | printf ("; "); | |
1429 | } | |
1430 | ||
1431 | return need_frame_base; | |
1432 | } | |
1433 | ||
341f9135 CC |
1434 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1435 | This is used for DWARF package files. */ | |
1436 | ||
1437 | static struct cu_tu_set * | |
1438 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1439 | { | |
1440 | struct cu_tu_set *p; | |
1441 | unsigned int nsets; | |
1442 | unsigned int dw_sect; | |
1443 | ||
1444 | if (do_types) | |
1445 | { | |
1446 | p = tu_sets; | |
1447 | nsets = tu_count; | |
1448 | dw_sect = DW_SECT_TYPES; | |
1449 | } | |
1450 | else | |
1451 | { | |
1452 | p = cu_sets; | |
1453 | nsets = cu_count; | |
1454 | dw_sect = DW_SECT_INFO; | |
1455 | } | |
1456 | while (nsets > 0) | |
1457 | { | |
1458 | if (p->section_offsets [dw_sect] == cu_offset) | |
1459 | return p; | |
1460 | p++; | |
1461 | nsets--; | |
1462 | } | |
1463 | return NULL; | |
1464 | } | |
1465 | ||
a69c4772 NC |
1466 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1467 | static void | |
1468 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1469 | { | |
1470 | dwarf_vma tmp = * low_bits; | |
1471 | ||
1472 | tmp += inc; | |
1473 | ||
1474 | /* FIXME: There is probably a better way of handling this: | |
1475 | ||
1476 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1477 | type. Plus regardless of its size LOW_BITS is meant to | |
1478 | only hold 32-bits, so if there is overflow or wrap around | |
1479 | we must propagate into HIGH_BITS. */ | |
1480 | if (tmp < * low_bits) | |
1481 | { | |
1482 | ++ * high_bits; | |
1483 | } | |
1484 | else if (sizeof (tmp) > 8 | |
1485 | && (tmp >> 31) > 1) | |
1486 | { | |
1487 | ++ * high_bits; | |
1488 | tmp &= 0xFFFFFFFF; | |
1489 | } | |
1490 | ||
1491 | * low_bits = tmp; | |
1492 | } | |
1493 | ||
19e6b90e | 1494 | static unsigned char * |
6e3d6dc1 NC |
1495 | read_and_display_attr_value (unsigned long attribute, |
1496 | unsigned long form, | |
ec4d4525 | 1497 | unsigned char * data, |
f6f0e17b | 1498 | unsigned char * end, |
467c65bc NC |
1499 | dwarf_vma cu_offset, |
1500 | dwarf_vma pointer_size, | |
1501 | dwarf_vma offset_size, | |
6e3d6dc1 NC |
1502 | int dwarf_version, |
1503 | debug_info * debug_info_p, | |
1504 | int do_loc, | |
341f9135 CC |
1505 | struct dwarf_section * section, |
1506 | struct cu_tu_set * this_set) | |
19e6b90e | 1507 | { |
467c65bc | 1508 | dwarf_vma uvalue = 0; |
19e6b90e | 1509 | unsigned char *block_start = NULL; |
6e3d6dc1 | 1510 | unsigned char * orig_data = data; |
19e6b90e L |
1511 | unsigned int bytes_read; |
1512 | ||
f41e4712 | 1513 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 1514 | { |
f41e4712 | 1515 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
1516 | return data; |
1517 | } | |
1518 | ||
19e6b90e L |
1519 | switch (form) |
1520 | { | |
1521 | default: | |
1522 | break; | |
1523 | ||
1524 | case DW_FORM_ref_addr: | |
1525 | if (dwarf_version == 2) | |
0c588247 | 1526 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
932fd279 | 1527 | else if (dwarf_version == 3 || dwarf_version == 4) |
0c588247 | 1528 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 1529 | else |
467c65bc NC |
1530 | error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); |
1531 | ||
19e6b90e L |
1532 | break; |
1533 | ||
1534 | case DW_FORM_addr: | |
0c588247 | 1535 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
1536 | break; |
1537 | ||
1538 | case DW_FORM_strp: | |
932fd279 | 1539 | case DW_FORM_sec_offset: |
a081f3cd JJ |
1540 | case DW_FORM_GNU_ref_alt: |
1541 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 1542 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
1543 | break; |
1544 | ||
932fd279 JJ |
1545 | case DW_FORM_flag_present: |
1546 | uvalue = 1; | |
1547 | break; | |
1548 | ||
19e6b90e L |
1549 | case DW_FORM_ref1: |
1550 | case DW_FORM_flag: | |
1551 | case DW_FORM_data1: | |
0c588247 | 1552 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
1553 | break; |
1554 | ||
1555 | case DW_FORM_ref2: | |
1556 | case DW_FORM_data2: | |
0c588247 | 1557 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
1558 | break; |
1559 | ||
1560 | case DW_FORM_ref4: | |
1561 | case DW_FORM_data4: | |
0c588247 | 1562 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
1563 | break; |
1564 | ||
1565 | case DW_FORM_sdata: | |
f6f0e17b | 1566 | uvalue = read_sleb128 (data, & bytes_read, end); |
19e6b90e L |
1567 | data += bytes_read; |
1568 | break; | |
1569 | ||
4723351a | 1570 | case DW_FORM_GNU_str_index: |
f6f0e17b | 1571 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
1572 | data += bytes_read; |
1573 | break; | |
1574 | ||
19e6b90e L |
1575 | case DW_FORM_ref_udata: |
1576 | case DW_FORM_udata: | |
f6f0e17b | 1577 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
1578 | data += bytes_read; |
1579 | break; | |
1580 | ||
1581 | case DW_FORM_indirect: | |
f6f0e17b | 1582 | form = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
1583 | data += bytes_read; |
1584 | if (!do_loc) | |
1585 | printf (" %s", get_FORM_name (form)); | |
f6f0e17b | 1586 | return read_and_display_attr_value (attribute, form, data, end, |
19e6b90e L |
1587 | cu_offset, pointer_size, |
1588 | offset_size, dwarf_version, | |
ec4d4525 | 1589 | debug_info_p, do_loc, |
341f9135 | 1590 | section, this_set); |
4723351a | 1591 | case DW_FORM_GNU_addr_index: |
f6f0e17b | 1592 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
1593 | data += bytes_read; |
1594 | break; | |
19e6b90e L |
1595 | } |
1596 | ||
1597 | switch (form) | |
1598 | { | |
1599 | case DW_FORM_ref_addr: | |
1600 | if (!do_loc) | |
467c65bc | 1601 | printf (" <0x%s>", dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
1602 | break; |
1603 | ||
a081f3cd JJ |
1604 | case DW_FORM_GNU_ref_alt: |
1605 | if (!do_loc) | |
1606 | printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue)); | |
1607 | break; | |
1608 | ||
19e6b90e L |
1609 | case DW_FORM_ref1: |
1610 | case DW_FORM_ref2: | |
1611 | case DW_FORM_ref4: | |
1612 | case DW_FORM_ref_udata: | |
1613 | if (!do_loc) | |
467c65bc | 1614 | printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
1615 | break; |
1616 | ||
1617 | case DW_FORM_data4: | |
1618 | case DW_FORM_addr: | |
932fd279 | 1619 | case DW_FORM_sec_offset: |
19e6b90e | 1620 | if (!do_loc) |
467c65bc | 1621 | printf (" 0x%s", dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
1622 | break; |
1623 | ||
932fd279 | 1624 | case DW_FORM_flag_present: |
19e6b90e L |
1625 | case DW_FORM_flag: |
1626 | case DW_FORM_data1: | |
1627 | case DW_FORM_data2: | |
1628 | case DW_FORM_sdata: | |
1629 | case DW_FORM_udata: | |
1630 | if (!do_loc) | |
467c65bc | 1631 | printf (" %s", dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
1632 | break; |
1633 | ||
1634 | case DW_FORM_ref8: | |
1635 | case DW_FORM_data8: | |
2bc8690c | 1636 | if (!do_loc) |
19e6b90e | 1637 | { |
74bc6052 | 1638 | dwarf_vma high_bits; |
a69c4772 | 1639 | dwarf_vma utmp; |
74bc6052 CC |
1640 | char buf[64]; |
1641 | ||
0c588247 | 1642 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
1643 | utmp = uvalue; |
1644 | if (form == DW_FORM_ref8) | |
1645 | add64 (& high_bits, & utmp, cu_offset); | |
74bc6052 | 1646 | printf (" 0x%s", |
a69c4772 | 1647 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 1648 | } |
0c588247 | 1649 | |
19e6b90e L |
1650 | if ((do_loc || do_debug_loc || do_debug_ranges) |
1651 | && num_debug_info_entries == 0) | |
1652 | { | |
1653 | if (sizeof (uvalue) == 8) | |
0c588247 | 1654 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 1655 | else |
467c65bc | 1656 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 1657 | } |
0c588247 | 1658 | |
19e6b90e L |
1659 | data += 8; |
1660 | break; | |
1661 | ||
1662 | case DW_FORM_string: | |
1663 | if (!do_loc) | |
2bdc3eca | 1664 | printf (" %.*s", (int) (end - data), data); |
0c588247 | 1665 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
1666 | break; |
1667 | ||
1668 | case DW_FORM_block: | |
932fd279 | 1669 | case DW_FORM_exprloc: |
f6f0e17b | 1670 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e | 1671 | block_start = data + bytes_read; |
a1165289 NC |
1672 | if (block_start >= end) |
1673 | { | |
1674 | warn (_("Block ends prematurely\n")); | |
1675 | uvalue = 0; | |
1676 | block_start = end; | |
1677 | } | |
f3853b34 NC |
1678 | /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with |
1679 | gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute | |
1680 | block_start + uvalue here. */ | |
1681 | data = block_start + uvalue; | |
f41e4712 | 1682 | /* PR 17512: file: 008-103549-0.001:0.1. */ |
f3853b34 | 1683 | if (block_start + uvalue > end || data < block_start) |
f41e4712 NC |
1684 | { |
1685 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1686 | uvalue = end - block_start; | |
1687 | } | |
19e6b90e L |
1688 | if (do_loc) |
1689 | data = block_start + uvalue; | |
1690 | else | |
0c588247 | 1691 | data = display_block (block_start, uvalue, end); |
19e6b90e L |
1692 | break; |
1693 | ||
1694 | case DW_FORM_block1: | |
0c588247 | 1695 | SAFE_BYTE_GET (uvalue, data, 1, end); |
19e6b90e | 1696 | block_start = data + 1; |
a1165289 NC |
1697 | if (block_start >= end) |
1698 | { | |
1699 | warn (_("Block ends prematurely\n")); | |
1700 | uvalue = 0; | |
1701 | block_start = end; | |
1702 | } | |
f3853b34 NC |
1703 | data = block_start + uvalue; |
1704 | if (block_start + uvalue > end || data < block_start) | |
f41e4712 NC |
1705 | { |
1706 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1707 | uvalue = end - block_start; | |
1708 | } | |
19e6b90e L |
1709 | if (do_loc) |
1710 | data = block_start + uvalue; | |
1711 | else | |
0c588247 | 1712 | data = display_block (block_start, uvalue, end); |
19e6b90e L |
1713 | break; |
1714 | ||
1715 | case DW_FORM_block2: | |
0c588247 | 1716 | SAFE_BYTE_GET (uvalue, data, 2, end); |
19e6b90e | 1717 | block_start = data + 2; |
a1165289 NC |
1718 | if (block_start >= end) |
1719 | { | |
1720 | warn (_("Block ends prematurely\n")); | |
1721 | uvalue = 0; | |
1722 | block_start = end; | |
1723 | } | |
f3853b34 NC |
1724 | data = block_start + uvalue; |
1725 | if (block_start + uvalue > end || data < block_start) | |
f41e4712 NC |
1726 | { |
1727 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1728 | uvalue = end - block_start; | |
1729 | } | |
19e6b90e L |
1730 | if (do_loc) |
1731 | data = block_start + uvalue; | |
1732 | else | |
0c588247 | 1733 | data = display_block (block_start, uvalue, end); |
19e6b90e L |
1734 | break; |
1735 | ||
1736 | case DW_FORM_block4: | |
0c588247 | 1737 | SAFE_BYTE_GET (uvalue, data, 4, end); |
19e6b90e | 1738 | block_start = data + 4; |
a1165289 NC |
1739 | /* PR 17512: file: 3371-3907-0.004. */ |
1740 | if (block_start >= end) | |
1741 | { | |
1742 | warn (_("Block ends prematurely\n")); | |
1743 | uvalue = 0; | |
1744 | block_start = end; | |
1745 | } | |
f3853b34 NC |
1746 | data = block_start + uvalue; |
1747 | if (block_start + uvalue > end | |
b4eb7656 | 1748 | /* PR 17531: file: 5b5f0592. */ |
f3853b34 | 1749 | || data < block_start) |
f41e4712 NC |
1750 | { |
1751 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1752 | uvalue = end - block_start; | |
1753 | } | |
19e6b90e L |
1754 | if (do_loc) |
1755 | data = block_start + uvalue; | |
1756 | else | |
0c588247 | 1757 | data = display_block (block_start, uvalue, end); |
19e6b90e L |
1758 | break; |
1759 | ||
1760 | case DW_FORM_strp: | |
1761 | if (!do_loc) | |
47704ddf KT |
1762 | printf (_(" (indirect string, offset: 0x%s): %s"), |
1763 | dwarf_vmatoa ("x", uvalue), | |
1764 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
1765 | break; |
1766 | ||
4723351a CC |
1767 | case DW_FORM_GNU_str_index: |
1768 | if (!do_loc) | |
b4eb7656 AM |
1769 | { |
1770 | const char *suffix = strrchr (section->name, '.'); | |
1771 | int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0; | |
1772 | ||
1773 | printf (_(" (indexed string: 0x%s): %s"), | |
1774 | dwarf_vmatoa ("x", uvalue), | |
1775 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
1776 | } | |
4723351a CC |
1777 | break; |
1778 | ||
a081f3cd JJ |
1779 | case DW_FORM_GNU_strp_alt: |
1780 | if (!do_loc) | |
1781 | printf (_(" (alt indirect string, offset: 0x%s)"), | |
1782 | dwarf_vmatoa ("x", uvalue)); | |
1783 | break; | |
1784 | ||
19e6b90e L |
1785 | case DW_FORM_indirect: |
1786 | /* Handled above. */ | |
1787 | break; | |
1788 | ||
2b6f5997 CC |
1789 | case DW_FORM_ref_sig8: |
1790 | if (!do_loc) | |
1791 | { | |
74bc6052 CC |
1792 | dwarf_vma high_bits; |
1793 | char buf[64]; | |
1794 | ||
0c588247 | 1795 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
74bc6052 CC |
1796 | printf (" signature: 0x%s", |
1797 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); | |
2b6f5997 | 1798 | } |
74bc6052 | 1799 | data += 8; |
2b6f5997 CC |
1800 | break; |
1801 | ||
4723351a CC |
1802 | case DW_FORM_GNU_addr_index: |
1803 | if (!do_loc) | |
b4eb7656 AM |
1804 | printf (_(" (addr_index: 0x%s): %s"), |
1805 | dwarf_vmatoa ("x", uvalue), | |
1806 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
4723351a CC |
1807 | break; |
1808 | ||
19e6b90e L |
1809 | default: |
1810 | warn (_("Unrecognized form: %lu\n"), form); | |
1811 | break; | |
1812 | } | |
1813 | ||
19e6b90e | 1814 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
1815 | && num_debug_info_entries == 0 |
1816 | && debug_info_p != NULL) | |
19e6b90e L |
1817 | { |
1818 | switch (attribute) | |
1819 | { | |
1820 | case DW_AT_frame_base: | |
1821 | have_frame_base = 1; | |
1822 | case DW_AT_location: | |
e2a0d921 NC |
1823 | case DW_AT_string_length: |
1824 | case DW_AT_return_addr: | |
19e6b90e L |
1825 | case DW_AT_data_member_location: |
1826 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
1827 | case DW_AT_segment: |
1828 | case DW_AT_static_link: | |
1829 | case DW_AT_use_location: | |
629e7ca8 JJ |
1830 | case DW_AT_GNU_call_site_value: |
1831 | case DW_AT_GNU_call_site_data_value: | |
1832 | case DW_AT_GNU_call_site_target: | |
1833 | case DW_AT_GNU_call_site_target_clobbered: | |
b4eb7656 | 1834 | if ((dwarf_version < 4 |
212b6063 | 1835 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 1836 | || form == DW_FORM_sec_offset) |
19e6b90e L |
1837 | { |
1838 | /* Process location list. */ | |
91d6fa6a | 1839 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
1840 | unsigned int num = debug_info_p->num_loc_offsets; |
1841 | ||
91d6fa6a | 1842 | if (lmax == 0 || num >= lmax) |
19e6b90e | 1843 | { |
91d6fa6a | 1844 | lmax += 1024; |
467c65bc | 1845 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
1846 | xcrealloc (debug_info_p->loc_offsets, |
1847 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
3f5e193b | 1848 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
1849 | xcrealloc (debug_info_p->have_frame_base, |
1850 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 1851 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 1852 | } |
341f9135 | 1853 | if (this_set != NULL) |
b4eb7656 | 1854 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e L |
1855 | debug_info_p->loc_offsets [num] = uvalue; |
1856 | debug_info_p->have_frame_base [num] = have_frame_base; | |
1857 | debug_info_p->num_loc_offsets++; | |
1858 | } | |
1859 | break; | |
e2a0d921 | 1860 | |
19e6b90e L |
1861 | case DW_AT_low_pc: |
1862 | if (need_base_address) | |
1863 | debug_info_p->base_address = uvalue; | |
1864 | break; | |
1865 | ||
4723351a | 1866 | case DW_AT_GNU_addr_base: |
b4eb7656 | 1867 | debug_info_p->addr_base = uvalue; |
4723351a CC |
1868 | break; |
1869 | ||
1870 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 1871 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
1872 | break; |
1873 | ||
19e6b90e | 1874 | case DW_AT_ranges: |
b4eb7656 | 1875 | if ((dwarf_version < 4 |
212b6063 | 1876 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 1877 | || form == DW_FORM_sec_offset) |
19e6b90e L |
1878 | { |
1879 | /* Process range list. */ | |
91d6fa6a | 1880 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
1881 | unsigned int num = debug_info_p->num_range_lists; |
1882 | ||
91d6fa6a | 1883 | if (lmax == 0 || num >= lmax) |
19e6b90e | 1884 | { |
91d6fa6a | 1885 | lmax += 1024; |
467c65bc | 1886 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
1887 | xcrealloc (debug_info_p->range_lists, |
1888 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 1889 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
1890 | } |
1891 | debug_info_p->range_lists [num] = uvalue; | |
1892 | debug_info_p->num_range_lists++; | |
1893 | } | |
1894 | break; | |
1895 | ||
1896 | default: | |
1897 | break; | |
1898 | } | |
1899 | } | |
1900 | ||
4ccf1e31 | 1901 | if (do_loc || attribute == 0) |
19e6b90e L |
1902 | return data; |
1903 | ||
ec4d4525 | 1904 | /* For some attributes we can display further information. */ |
19e6b90e L |
1905 | switch (attribute) |
1906 | { | |
1907 | case DW_AT_inline: | |
2e9e81a8 | 1908 | printf ("\t"); |
19e6b90e L |
1909 | switch (uvalue) |
1910 | { | |
1911 | case DW_INL_not_inlined: | |
1912 | printf (_("(not inlined)")); | |
1913 | break; | |
1914 | case DW_INL_inlined: | |
1915 | printf (_("(inlined)")); | |
1916 | break; | |
1917 | case DW_INL_declared_not_inlined: | |
1918 | printf (_("(declared as inline but ignored)")); | |
1919 | break; | |
1920 | case DW_INL_declared_inlined: | |
1921 | printf (_("(declared as inline and inlined)")); | |
1922 | break; | |
1923 | default: | |
47704ddf KT |
1924 | printf (_(" (Unknown inline attribute value: %s)"), |
1925 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1926 | break; |
1927 | } | |
1928 | break; | |
1929 | ||
1930 | case DW_AT_language: | |
2e9e81a8 | 1931 | printf ("\t"); |
19e6b90e L |
1932 | switch (uvalue) |
1933 | { | |
4b78141a | 1934 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 1935 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
1936 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
1937 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 1938 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
1939 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
1940 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
1941 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
1942 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 1943 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 1944 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 1945 | /* DWARF 2.1 values. */ |
4b78141a | 1946 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
1947 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
1948 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
1949 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
1950 | /* DWARF 3 values. */ |
1951 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
1952 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
1953 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
1954 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
1955 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
1956 | /* DWARF 4 values. */ |
1957 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 ILT |
1958 | /* DWARF 5 values. */ |
1959 | case DW_LANG_Go: printf ("(Go)"); break; | |
8bc10620 | 1960 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
6ddfe5b4 | 1961 | case DW_LANG_C11: printf ("(C11)"); break; |
8bc10620 | 1962 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
1963 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
1964 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
19e6b90e L |
1965 | /* MIPS extension. */ |
1966 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
1967 | /* UPC extension. */ | |
1968 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
1969 | default: | |
4b78141a | 1970 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 1971 | printf (_("(implementation defined: %s)"), |
467c65bc | 1972 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 1973 | else |
9cf03b7e | 1974 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
1975 | break; |
1976 | } | |
1977 | break; | |
1978 | ||
1979 | case DW_AT_encoding: | |
2e9e81a8 | 1980 | printf ("\t"); |
19e6b90e L |
1981 | switch (uvalue) |
1982 | { | |
1983 | case DW_ATE_void: printf ("(void)"); break; | |
1984 | case DW_ATE_address: printf ("(machine address)"); break; | |
1985 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
1986 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
1987 | case DW_ATE_float: printf ("(float)"); break; | |
1988 | case DW_ATE_signed: printf ("(signed)"); break; | |
1989 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
1990 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
1991 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 1992 | /* DWARF 2.1 values: */ |
19e6b90e L |
1993 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
1994 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
1995 | /* DWARF 3 values: */ |
1996 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
1997 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
1998 | case DW_ATE_edited: printf ("(edited)"); break; | |
1999 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
2000 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
2001 | /* HP extensions: */ | |
2002 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
2003 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
2004 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
2005 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
2006 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
2007 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
2008 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
153a2776 NC |
2009 | /* DWARF 4 values: */ |
2010 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
e2a0d921 | 2011 | |
19e6b90e L |
2012 | default: |
2013 | if (uvalue >= DW_ATE_lo_user | |
2014 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 2015 | printf (_("(user defined type)")); |
19e6b90e | 2016 | else |
9cf03b7e | 2017 | printf (_("(unknown type)")); |
19e6b90e L |
2018 | break; |
2019 | } | |
2020 | break; | |
2021 | ||
2022 | case DW_AT_accessibility: | |
2e9e81a8 | 2023 | printf ("\t"); |
19e6b90e L |
2024 | switch (uvalue) |
2025 | { | |
2026 | case DW_ACCESS_public: printf ("(public)"); break; | |
2027 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
2028 | case DW_ACCESS_private: printf ("(private)"); break; | |
2029 | default: | |
9cf03b7e | 2030 | printf (_("(unknown accessibility)")); |
19e6b90e L |
2031 | break; |
2032 | } | |
2033 | break; | |
2034 | ||
2035 | case DW_AT_visibility: | |
2e9e81a8 | 2036 | printf ("\t"); |
19e6b90e L |
2037 | switch (uvalue) |
2038 | { | |
2039 | case DW_VIS_local: printf ("(local)"); break; | |
2040 | case DW_VIS_exported: printf ("(exported)"); break; | |
2041 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 2042 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
2043 | } |
2044 | break; | |
2045 | ||
2046 | case DW_AT_virtuality: | |
2e9e81a8 | 2047 | printf ("\t"); |
19e6b90e L |
2048 | switch (uvalue) |
2049 | { | |
2050 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
2051 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
2052 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 2053 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
2054 | } |
2055 | break; | |
2056 | ||
2057 | case DW_AT_identifier_case: | |
2e9e81a8 | 2058 | printf ("\t"); |
19e6b90e L |
2059 | switch (uvalue) |
2060 | { | |
2061 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
2062 | case DW_ID_up_case: printf ("(up_case)"); break; | |
2063 | case DW_ID_down_case: printf ("(down_case)"); break; | |
2064 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 2065 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
2066 | } |
2067 | break; | |
2068 | ||
2069 | case DW_AT_calling_convention: | |
2e9e81a8 | 2070 | printf ("\t"); |
19e6b90e L |
2071 | switch (uvalue) |
2072 | { | |
2073 | case DW_CC_normal: printf ("(normal)"); break; | |
2074 | case DW_CC_program: printf ("(program)"); break; | |
2075 | case DW_CC_nocall: printf ("(nocall)"); break; | |
2076 | default: | |
2077 | if (uvalue >= DW_CC_lo_user | |
2078 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 2079 | printf (_("(user defined)")); |
19e6b90e | 2080 | else |
9cf03b7e | 2081 | printf (_("(unknown convention)")); |
19e6b90e L |
2082 | } |
2083 | break; | |
2084 | ||
2085 | case DW_AT_ordering: | |
2e9e81a8 | 2086 | printf ("\t"); |
19e6b90e L |
2087 | switch (uvalue) |
2088 | { | |
9cf03b7e | 2089 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
2090 | case 0: printf ("(row major)"); break; |
2091 | case 1: printf ("(column major)"); break; | |
2092 | } | |
2093 | break; | |
2094 | ||
2095 | case DW_AT_frame_base: | |
2096 | have_frame_base = 1; | |
2097 | case DW_AT_location: | |
e2a0d921 NC |
2098 | case DW_AT_string_length: |
2099 | case DW_AT_return_addr: | |
19e6b90e L |
2100 | case DW_AT_data_member_location: |
2101 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2102 | case DW_AT_segment: |
2103 | case DW_AT_static_link: | |
2104 | case DW_AT_use_location: | |
629e7ca8 JJ |
2105 | case DW_AT_GNU_call_site_value: |
2106 | case DW_AT_GNU_call_site_data_value: | |
2107 | case DW_AT_GNU_call_site_target: | |
2108 | case DW_AT_GNU_call_site_target_clobbered: | |
212b6063 | 2109 | if ((dwarf_version < 4 |
b4eb7656 | 2110 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2111 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 2112 | printf (_(" (location list)")); |
e2a0d921 | 2113 | /* Fall through. */ |
19e6b90e L |
2114 | case DW_AT_allocated: |
2115 | case DW_AT_associated: | |
2116 | case DW_AT_data_location: | |
2117 | case DW_AT_stride: | |
2118 | case DW_AT_upper_bound: | |
cecf136e | 2119 | case DW_AT_lower_bound: |
19e6b90e L |
2120 | if (block_start) |
2121 | { | |
2122 | int need_frame_base; | |
2123 | ||
2e9e81a8 | 2124 | printf ("\t("); |
19e6b90e L |
2125 | need_frame_base = decode_location_expression (block_start, |
2126 | pointer_size, | |
b7807392 JJ |
2127 | offset_size, |
2128 | dwarf_version, | |
19e6b90e | 2129 | uvalue, |
f1c4cc75 | 2130 | cu_offset, section); |
19e6b90e L |
2131 | printf (")"); |
2132 | if (need_frame_base && !have_frame_base) | |
2133 | printf (_(" [without DW_AT_frame_base]")); | |
2134 | } | |
19e6b90e L |
2135 | break; |
2136 | ||
ec4d4525 NC |
2137 | case DW_AT_import: |
2138 | { | |
a081f3cd JJ |
2139 | if (form == DW_FORM_ref_sig8 |
2140 | || form == DW_FORM_GNU_ref_alt) | |
b4eb7656 | 2141 | break; |
2b6f5997 | 2142 | |
ec4d4525 NC |
2143 | if (form == DW_FORM_ref1 |
2144 | || form == DW_FORM_ref2 | |
a7a0b6a5 JK |
2145 | || form == DW_FORM_ref4 |
2146 | || form == DW_FORM_ref_udata) | |
ec4d4525 NC |
2147 | uvalue += cu_offset; |
2148 | ||
6e3d6dc1 | 2149 | if (uvalue >= section->size) |
f3853b34 | 2150 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
47704ddf KT |
2151 | dwarf_vmatoa ("x", uvalue), |
2152 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
2153 | else |
2154 | { | |
2155 | unsigned long abbrev_number; | |
2156 | abbrev_entry * entry; | |
2157 | ||
f6f0e17b | 2158 | abbrev_number = read_uleb128 (section->start + uvalue, NULL, end); |
cecf136e | 2159 | |
2e9e81a8 | 2160 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
afd6e1ff JJ |
2161 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
2162 | use different abbrev table, and we don't track .debug_info chunks | |
2163 | yet. */ | |
2164 | if (form != DW_FORM_ref_addr) | |
2165 | { | |
2166 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
2167 | if (entry->entry == abbrev_number) | |
2168 | break; | |
2169 | if (entry != NULL) | |
2170 | printf (" (%s)", get_TAG_name (entry->tag)); | |
2171 | } | |
6e3d6dc1 NC |
2172 | printf ("]"); |
2173 | } | |
ec4d4525 NC |
2174 | } |
2175 | break; | |
2176 | ||
19e6b90e L |
2177 | default: |
2178 | break; | |
2179 | } | |
2180 | ||
2181 | return data; | |
2182 | } | |
2183 | ||
a19c41a7 | 2184 | static const char * |
19e6b90e L |
2185 | get_AT_name (unsigned long attribute) |
2186 | { | |
a19c41a7 | 2187 | const char *name; |
e2a0d921 | 2188 | |
399c99f7 L |
2189 | if (attribute == 0) |
2190 | return "DW_AT value: 0"; | |
2191 | ||
a19c41a7 TT |
2192 | /* One value is shared by the MIPS and HP extensions: */ |
2193 | if (attribute == DW_AT_MIPS_fde) | |
2194 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
19e6b90e | 2195 | |
a19c41a7 TT |
2196 | name = get_DW_AT_name (attribute); |
2197 | ||
2198 | if (name == NULL) | |
2199 | { | |
2200 | static char buffer[100]; | |
2201 | ||
2202 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
2203 | attribute); | |
2204 | return buffer; | |
19e6b90e | 2205 | } |
a19c41a7 TT |
2206 | |
2207 | return name; | |
19e6b90e L |
2208 | } |
2209 | ||
2210 | static unsigned char * | |
6e3d6dc1 NC |
2211 | read_and_display_attr (unsigned long attribute, |
2212 | unsigned long form, | |
ec4d4525 | 2213 | unsigned char * data, |
f6f0e17b | 2214 | unsigned char * end, |
467c65bc NC |
2215 | dwarf_vma cu_offset, |
2216 | dwarf_vma pointer_size, | |
2217 | dwarf_vma offset_size, | |
6e3d6dc1 NC |
2218 | int dwarf_version, |
2219 | debug_info * debug_info_p, | |
2220 | int do_loc, | |
341f9135 CC |
2221 | struct dwarf_section * section, |
2222 | struct cu_tu_set * this_set) | |
19e6b90e L |
2223 | { |
2224 | if (!do_loc) | |
750f03b7 | 2225 | printf (" %-18s:", get_AT_name (attribute)); |
f6f0e17b NC |
2226 | data = read_and_display_attr_value (attribute, form, data, end, |
2227 | cu_offset, pointer_size, offset_size, | |
19e6b90e | 2228 | dwarf_version, debug_info_p, |
341f9135 | 2229 | do_loc, section, this_set); |
19e6b90e L |
2230 | if (!do_loc) |
2231 | printf ("\n"); | |
2232 | return data; | |
2233 | } | |
2234 | ||
19e6b90e L |
2235 | /* Process the contents of a .debug_info section. If do_loc is non-zero |
2236 | then we are scanning for location lists and we do not want to display | |
2b6f5997 CC |
2237 | anything to the user. If do_types is non-zero, we are processing |
2238 | a .debug_types section instead of a .debug_info section. */ | |
19e6b90e L |
2239 | |
2240 | static int | |
6e3d6dc1 NC |
2241 | process_debug_info (struct dwarf_section *section, |
2242 | void *file, | |
b4eb7656 | 2243 | enum dwarf_section_display_enum abbrev_sec, |
2b6f5997 CC |
2244 | int do_loc, |
2245 | int do_types) | |
19e6b90e L |
2246 | { |
2247 | unsigned char *start = section->start; | |
2248 | unsigned char *end = start + section->size; | |
2249 | unsigned char *section_begin; | |
2250 | unsigned int unit; | |
2251 | unsigned int num_units = 0; | |
2252 | ||
2253 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
2254 | && num_debug_info_entries == 0 |
2255 | && ! do_types) | |
19e6b90e | 2256 | { |
767221a9 | 2257 | dwarf_vma length; |
19e6b90e L |
2258 | |
2259 | /* First scan the section to get the number of comp units. */ | |
2260 | for (section_begin = start, num_units = 0; section_begin < end; | |
2261 | num_units ++) | |
2262 | { | |
2263 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
2264 | will be the length. For a 64-bit DWARF section, it'll be | |
2265 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 2266 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
2267 | |
2268 | if (length == 0xffffffff) | |
2269 | { | |
0c588247 | 2270 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
2271 | section_begin += length + 12; |
2272 | } | |
ec4d4525 NC |
2273 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
2274 | { | |
767221a9 NC |
2275 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
2276 | dwarf_vmatoa ("x", length), section->name); | |
ec4d4525 NC |
2277 | return 0; |
2278 | } | |
19e6b90e L |
2279 | else |
2280 | section_begin += length + 4; | |
aca88567 NC |
2281 | |
2282 | /* Negative values are illegal, they may even cause infinite | |
2283 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
2284 | relocations to an object file, or if the file is corrupt. */ |
2285 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 2286 | { |
767221a9 NC |
2287 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
2288 | dwarf_vmatoa ("x", length), section->name); | |
aca88567 NC |
2289 | return 0; |
2290 | } | |
19e6b90e L |
2291 | } |
2292 | ||
2293 | if (num_units == 0) | |
2294 | { | |
f41e4712 | 2295 | error (_("No comp units in %s section ?\n"), section->name); |
19e6b90e L |
2296 | return 0; |
2297 | } | |
2298 | ||
2299 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 2300 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 2301 | sizeof (* debug_information)); |
19e6b90e L |
2302 | if (debug_information == NULL) |
2303 | { | |
f41e4712 | 2304 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 2305 | num_units); |
82b1b41b | 2306 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e L |
2307 | return 0; |
2308 | } | |
03a91817 NC |
2309 | /* PR 17531: file: 92ca3797. |
2310 | We cannot rely upon the debug_information array being initialised | |
2311 | before it is used. A corrupt file could easily contain references | |
2312 | to a unit for which information has not been made available. So | |
2313 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
2314 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
2315 | ||
82b1b41b | 2316 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
2317 | } |
2318 | ||
2319 | if (!do_loc) | |
2320 | { | |
fd2f0033 TT |
2321 | if (dwarf_start_die == 0) |
2322 | printf (_("Contents of the %s section:\n\n"), section->name); | |
19e6b90e L |
2323 | |
2324 | load_debug_section (str, file); | |
4723351a CC |
2325 | load_debug_section (str_dwo, file); |
2326 | load_debug_section (str_index, file); | |
2327 | load_debug_section (str_index_dwo, file); | |
2328 | load_debug_section (debug_addr, file); | |
19e6b90e L |
2329 | } |
2330 | ||
6f875884 TG |
2331 | load_debug_section (abbrev_sec, file); |
2332 | if (debug_displays [abbrev_sec].section.start == NULL) | |
19e6b90e L |
2333 | { |
2334 | warn (_("Unable to locate %s section!\n"), | |
6f875884 | 2335 | debug_displays [abbrev_sec].section.name); |
19e6b90e L |
2336 | return 0; |
2337 | } | |
2338 | ||
2339 | for (section_begin = start, unit = 0; start < end; unit++) | |
2340 | { | |
2341 | DWARF2_Internal_CompUnit compunit; | |
2342 | unsigned char *hdrptr; | |
19e6b90e | 2343 | unsigned char *tags; |
fd2f0033 | 2344 | int level, last_level, saved_level; |
467c65bc | 2345 | dwarf_vma cu_offset; |
bf5117e3 | 2346 | unsigned int offset_size; |
19e6b90e | 2347 | int initial_length_size; |
74bc6052 CC |
2348 | dwarf_vma signature_high = 0; |
2349 | dwarf_vma signature_low = 0; | |
767221a9 | 2350 | dwarf_vma type_offset = 0; |
341f9135 CC |
2351 | struct cu_tu_set *this_set; |
2352 | dwarf_vma abbrev_base; | |
2353 | size_t abbrev_size; | |
19e6b90e L |
2354 | |
2355 | hdrptr = start; | |
2356 | ||
0c588247 | 2357 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
2358 | |
2359 | if (compunit.cu_length == 0xffffffff) | |
2360 | { | |
0c588247 | 2361 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
2362 | offset_size = 8; |
2363 | initial_length_size = 12; | |
2364 | } | |
2365 | else | |
2366 | { | |
2367 | offset_size = 4; | |
2368 | initial_length_size = 4; | |
2369 | } | |
2370 | ||
0c588247 | 2371 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
2372 | |
2373 | cu_offset = start - section_begin; | |
19e6b90e | 2374 | |
341f9135 CC |
2375 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
2376 | ||
0c588247 | 2377 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 2378 | |
341f9135 CC |
2379 | if (this_set == NULL) |
2380 | { | |
2381 | abbrev_base = 0; | |
2382 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
2383 | } | |
2384 | else | |
2385 | { | |
2386 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
2387 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
2388 | } | |
2389 | ||
0c588247 | 2390 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); |
f41e4712 NC |
2391 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
2392 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
2393 | { | |
2394 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
2395 | compunit.cu_pointer_size, offset_size); | |
2396 | compunit.cu_pointer_size = offset_size; | |
2397 | } | |
2b6f5997 CC |
2398 | |
2399 | if (do_types) | |
b4eb7656 | 2400 | { |
0c588247 | 2401 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 2402 | hdrptr += 8; |
0c588247 | 2403 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 2404 | } |
2b6f5997 | 2405 | |
19e6b90e | 2406 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 CC |
2407 | && num_debug_info_entries == 0 |
2408 | && ! do_types) | |
19e6b90e L |
2409 | { |
2410 | debug_information [unit].cu_offset = cu_offset; | |
2411 | debug_information [unit].pointer_size | |
2412 | = compunit.cu_pointer_size; | |
b7807392 JJ |
2413 | debug_information [unit].offset_size = offset_size; |
2414 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 2415 | debug_information [unit].base_address = 0; |
4723351a CC |
2416 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
2417 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
2418 | debug_information [unit].loc_offsets = NULL; |
2419 | debug_information [unit].have_frame_base = NULL; | |
2420 | debug_information [unit].max_loc_offsets = 0; | |
2421 | debug_information [unit].num_loc_offsets = 0; | |
2422 | debug_information [unit].range_lists = NULL; | |
2423 | debug_information [unit].max_range_lists= 0; | |
2424 | debug_information [unit].num_range_lists = 0; | |
2425 | } | |
2426 | ||
fd2f0033 | 2427 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 2428 | { |
47704ddf KT |
2429 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
2430 | dwarf_vmatoa ("x", cu_offset)); | |
2431 | printf (_(" Length: 0x%s (%s)\n"), | |
2432 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 2433 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 2434 | printf (_(" Version: %d\n"), compunit.cu_version); |
7282333f AM |
2435 | printf (_(" Abbrev Offset: 0x%s\n"), |
2436 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 2437 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
2438 | if (do_types) |
2439 | { | |
74bc6052 CC |
2440 | char buf[64]; |
2441 | ||
2442 | printf (_(" Signature: 0x%s\n"), | |
2443 | dwarf_vmatoa64 (signature_high, signature_low, | |
2444 | buf, sizeof (buf))); | |
2445 | printf (_(" Type Offset: 0x%s\n"), | |
2446 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 2447 | } |
341f9135 CC |
2448 | if (this_set != NULL) |
2449 | { | |
2450 | dwarf_vma *offsets = this_set->section_offsets; | |
2451 | size_t *sizes = this_set->section_sizes; | |
2452 | ||
2453 | printf (_(" Section contributions:\n")); | |
2454 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
2455 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
2456 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
2457 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
2458 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
2459 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
2460 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
2461 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
2462 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
2463 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
2464 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
2465 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
2466 | } | |
19e6b90e L |
2467 | } |
2468 | ||
460c89ff NS |
2469 | if (cu_offset + compunit.cu_length + initial_length_size |
2470 | > section->size) | |
2471 | { | |
47704ddf | 2472 | warn (_("Debug info is corrupted, length of CU at %s" |
b4eb7656 | 2473 | " extends beyond end of section (length = %s)\n"), |
47704ddf KT |
2474 | dwarf_vmatoa ("x", cu_offset), |
2475 | dwarf_vmatoa ("x", compunit.cu_length)); | |
57028622 | 2476 | num_units = unit; |
460c89ff NS |
2477 | break; |
2478 | } | |
2479 | tags = hdrptr; | |
2480 | start += compunit.cu_length + initial_length_size; | |
2481 | ||
57028622 NC |
2482 | if (start > end) |
2483 | { | |
2484 | warn (_("Debug info is corrupt. CU at %s extends beyond end of section"), | |
2485 | dwarf_vmatoa ("x", cu_offset)); | |
2486 | start = end; | |
2487 | } | |
2488 | ||
932fd279 JJ |
2489 | if (compunit.cu_version != 2 |
2490 | && compunit.cu_version != 3 | |
2491 | && compunit.cu_version != 4) | |
19e6b90e | 2492 | { |
47704ddf KT |
2493 | warn (_("CU at offset %s contains corrupt or " |
2494 | "unsupported version number: %d.\n"), | |
2495 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
2496 | continue; |
2497 | } | |
2498 | ||
2499 | free_abbrevs (); | |
2500 | ||
d493b283 | 2501 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 2502 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
2503 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
2504 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 2505 | (unsigned long) abbrev_size); |
b4eb7656 | 2506 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
2507 | else if ((abbrev_base + abbrev_size) |
2508 | > debug_displays [abbrev_sec].section.size) | |
2509 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
2510 | (unsigned long) abbrev_base + abbrev_size, | |
2511 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff NS |
2512 | else |
2513 | process_abbrev_section | |
341f9135 CC |
2514 | (((unsigned char *) debug_displays [abbrev_sec].section.start |
2515 | + abbrev_base + compunit.cu_abbrev_offset), | |
2516 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
2517 | + abbrev_base + abbrev_size)); | |
19e6b90e L |
2518 | |
2519 | level = 0; | |
fd2f0033 TT |
2520 | last_level = level; |
2521 | saved_level = -1; | |
19e6b90e L |
2522 | while (tags < start) |
2523 | { | |
2524 | unsigned int bytes_read; | |
2525 | unsigned long abbrev_number; | |
ec4d4525 | 2526 | unsigned long die_offset; |
19e6b90e L |
2527 | abbrev_entry *entry; |
2528 | abbrev_attr *attr; | |
fd2f0033 | 2529 | int do_printing = 1; |
19e6b90e | 2530 | |
ec4d4525 NC |
2531 | die_offset = tags - section_begin; |
2532 | ||
f6f0e17b | 2533 | abbrev_number = read_uleb128 (tags, & bytes_read, start); |
19e6b90e L |
2534 | tags += bytes_read; |
2535 | ||
eb7cc021 JK |
2536 | /* A null DIE marks the end of a list of siblings or it may also be |
2537 | a section padding. */ | |
19e6b90e L |
2538 | if (abbrev_number == 0) |
2539 | { | |
eb7cc021 JK |
2540 | /* Check if it can be a section padding for the last CU. */ |
2541 | if (level == 0 && start == end) | |
2542 | { | |
2543 | unsigned char *chk; | |
2544 | ||
2545 | for (chk = tags; chk < start; chk++) | |
2546 | if (*chk != 0) | |
2547 | break; | |
2548 | if (chk == start) | |
2549 | break; | |
2550 | } | |
2551 | ||
4337774f TT |
2552 | if (!do_loc && die_offset >= dwarf_start_die |
2553 | && (dwarf_cutoff_level == -1 | |
2554 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
2555 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
2556 | level, die_offset); | |
2557 | ||
19e6b90e | 2558 | --level; |
ec4d4525 NC |
2559 | if (level < 0) |
2560 | { | |
2561 | static unsigned num_bogus_warns = 0; | |
2562 | ||
2563 | if (num_bogus_warns < 3) | |
2564 | { | |
4723351a CC |
2565 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
2566 | die_offset, section->name); | |
ec4d4525 NC |
2567 | num_bogus_warns ++; |
2568 | if (num_bogus_warns == 3) | |
2569 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
2570 | } | |
2571 | } | |
fd2f0033 TT |
2572 | if (dwarf_start_die != 0 && level < saved_level) |
2573 | return 1; | |
19e6b90e L |
2574 | continue; |
2575 | } | |
2576 | ||
4b78141a | 2577 | if (!do_loc) |
fd2f0033 TT |
2578 | { |
2579 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
2580 | do_printing = 0; | |
2581 | else | |
2582 | { | |
2583 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
2584 | saved_level = level; | |
2585 | do_printing = (dwarf_cutoff_level == -1 | |
2586 | || level < dwarf_cutoff_level); | |
2587 | if (do_printing) | |
2588 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
2589 | level, die_offset, abbrev_number); | |
2590 | else if (dwarf_cutoff_level == -1 | |
2591 | || last_level < dwarf_cutoff_level) | |
2592 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
2593 | last_level = level; | |
2594 | } | |
2595 | } | |
cecf136e | 2596 | |
19e6b90e L |
2597 | /* Scan through the abbreviation list until we reach the |
2598 | correct entry. */ | |
2599 | for (entry = first_abbrev; | |
2600 | entry && entry->entry != abbrev_number; | |
2601 | entry = entry->next) | |
2602 | continue; | |
2603 | ||
2604 | if (entry == NULL) | |
2605 | { | |
fd2f0033 | 2606 | if (!do_loc && do_printing) |
4b78141a NC |
2607 | { |
2608 | printf ("\n"); | |
2609 | fflush (stdout); | |
2610 | } | |
f3853b34 | 2611 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 2612 | die_offset, abbrev_number); |
19e6b90e L |
2613 | return 0; |
2614 | } | |
2615 | ||
fd2f0033 | 2616 | if (!do_loc && do_printing) |
cc5914eb | 2617 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 2618 | |
19e6b90e L |
2619 | switch (entry->tag) |
2620 | { | |
2621 | default: | |
2622 | need_base_address = 0; | |
2623 | break; | |
2624 | case DW_TAG_compile_unit: | |
2625 | need_base_address = 1; | |
2626 | break; | |
2627 | case DW_TAG_entry_point: | |
19e6b90e L |
2628 | case DW_TAG_subprogram: |
2629 | need_base_address = 0; | |
2630 | /* Assuming that there is no DW_AT_frame_base. */ | |
2631 | have_frame_base = 0; | |
2632 | break; | |
2633 | } | |
2634 | ||
399c99f7 L |
2635 | for (attr = entry->first_attr; |
2636 | attr && attr->attribute; | |
2637 | attr = attr->next) | |
4b78141a | 2638 | { |
fd2f0033 TT |
2639 | debug_info *arg; |
2640 | ||
2641 | if (! do_loc && do_printing) | |
4b78141a | 2642 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 TT |
2643 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
2644 | ||
82b1b41b NC |
2645 | if (debug_information && unit < alloc_num_debug_info_entries) |
2646 | arg = debug_information + unit; | |
2647 | else | |
2648 | arg = NULL; | |
f3853b34 | 2649 | |
4b78141a NC |
2650 | tags = read_and_display_attr (attr->attribute, |
2651 | attr->form, | |
341f9135 | 2652 | tags, |
f6f0e17b | 2653 | end, |
341f9135 | 2654 | cu_offset, |
4b78141a NC |
2655 | compunit.cu_pointer_size, |
2656 | offset_size, | |
2657 | compunit.cu_version, | |
fd2f0033 | 2658 | arg, |
341f9135 CC |
2659 | do_loc || ! do_printing, |
2660 | section, | |
2661 | this_set); | |
4b78141a | 2662 | } |
cecf136e | 2663 | |
b4eb7656 AM |
2664 | if (entry->children) |
2665 | ++level; | |
2666 | } | |
19e6b90e | 2667 | } |
cecf136e | 2668 | |
19e6b90e L |
2669 | /* Set num_debug_info_entries here so that it can be used to check if |
2670 | we need to process .debug_loc and .debug_ranges sections. */ | |
2671 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
2672 | && num_debug_info_entries == 0 |
2673 | && ! do_types) | |
82b1b41b | 2674 | { |
b4eb7656 | 2675 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
2676 | num_debug_info_entries = alloc_num_debug_info_entries; |
2677 | else | |
2678 | num_debug_info_entries = num_units; | |
2679 | } | |
cecf136e | 2680 | |
19e6b90e | 2681 | if (!do_loc) |
467c65bc | 2682 | printf ("\n"); |
cecf136e | 2683 | |
19e6b90e L |
2684 | return 1; |
2685 | } | |
2686 | ||
2687 | /* Locate and scan the .debug_info section in the file and record the pointer | |
2688 | sizes and offsets for the compilation units in it. Usually an executable | |
2689 | will have just one pointer size, but this is not guaranteed, and so we try | |
2690 | not to make any assumptions. Returns zero upon failure, or the number of | |
2691 | compilation units upon success. */ | |
2692 | ||
2693 | static unsigned int | |
2694 | load_debug_info (void * file) | |
2695 | { | |
2696 | /* Reset the last pointer size so that we can issue correct error | |
2697 | messages if we are displaying the contents of more than one section. */ | |
2698 | last_pointer_size = 0; | |
2699 | warned_about_missing_comp_units = FALSE; | |
2700 | ||
1febe64d | 2701 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 2702 | section then do not bother to repeat the task. */ |
cc86f28f | 2703 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
2704 | return 0; |
2705 | ||
19e6b90e L |
2706 | /* If we already have the information there is nothing else to do. */ |
2707 | if (num_debug_info_entries > 0) | |
2708 | return num_debug_info_entries; | |
2709 | ||
341f9135 CC |
2710 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
2711 | load_cu_tu_indexes (file); | |
2712 | ||
19e6b90e | 2713 | if (load_debug_section (info, file) |
6f875884 | 2714 | && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0)) |
19e6b90e | 2715 | return num_debug_info_entries; |
82b1b41b NC |
2716 | |
2717 | if (load_debug_section (info_dwo, file) | |
2718 | && process_debug_info (&debug_displays [info_dwo].section, file, | |
2719 | abbrev_dwo, 1, 0)) | |
4723351a | 2720 | return num_debug_info_entries; |
1febe64d | 2721 | |
cc86f28f | 2722 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 2723 | return 0; |
19e6b90e L |
2724 | } |
2725 | ||
b40bf0a2 NC |
2726 | /* Read a DWARF .debug_line section header starting at DATA. |
2727 | Upon success returns an updated DATA pointer and the LINFO | |
2728 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
2729 | Otherwise returns NULL. */ | |
19e6b90e | 2730 | |
b40bf0a2 NC |
2731 | static unsigned char * |
2732 | read_debug_line_header (struct dwarf_section * section, | |
2733 | unsigned char * data, | |
2734 | unsigned char * end, | |
2735 | DWARF2_Internal_LineInfo * linfo, | |
2736 | unsigned char ** end_of_sequence) | |
2737 | { | |
2738 | unsigned char *hdrptr; | |
2739 | unsigned int offset_size; | |
2740 | unsigned int initial_length_size; | |
19e6b90e | 2741 | |
b40bf0a2 NC |
2742 | /* Extract information from the Line Number Program Header. |
2743 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 2744 | hdrptr = data; |
19e6b90e | 2745 | |
b40bf0a2 NC |
2746 | /* Get and check the length of the block. */ |
2747 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 2748 | |
b40bf0a2 | 2749 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
2750 | { |
2751 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 2752 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
f41e4712 NC |
2753 | offset_size = 8; |
2754 | initial_length_size = 12; | |
2755 | } | |
2756 | else | |
2757 | { | |
2758 | offset_size = 4; | |
2759 | initial_length_size = 4; | |
2760 | } | |
19e6b90e | 2761 | |
b40bf0a2 | 2762 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 2763 | { |
b40bf0a2 NC |
2764 | /* If the length is just a bias against the initial_length_size then |
2765 | this means that the field has a relocation against it which has not | |
2766 | been applied. (Ie we are dealing with an object file, not a linked | |
2767 | binary). Do not complain but instead assume that the rest of the | |
2768 | section applies to this particular header. */ | |
2769 | if (linfo->li_length == - initial_length_size) | |
2770 | { | |
2771 | linfo->li_length = section->size - initial_length_size; | |
2772 | } | |
2773 | else | |
2774 | { | |
f41e4712 | 2775 | warn (_("The line info appears to be corrupt - the section is too small\n")); |
b40bf0a2 NC |
2776 | return NULL; |
2777 | } | |
f41e4712 | 2778 | } |
19e6b90e | 2779 | |
b40bf0a2 NC |
2780 | /* Get and check the version number. */ |
2781 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
2782 | ||
2783 | if (linfo->li_version != 2 | |
2784 | && linfo->li_version != 3 | |
2785 | && linfo->li_version != 4) | |
f41e4712 NC |
2786 | { |
2787 | warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n")); | |
b40bf0a2 | 2788 | return NULL; |
f41e4712 | 2789 | } |
19e6b90e | 2790 | |
b40bf0a2 NC |
2791 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, offset_size, end); |
2792 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); | |
0c588247 | 2793 | |
b40bf0a2 | 2794 | if (linfo->li_version >= 4) |
f41e4712 | 2795 | { |
b40bf0a2 | 2796 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 2797 | |
b40bf0a2 | 2798 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
2799 | { |
2800 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 2801 | return NULL; |
a233b20c | 2802 | } |
f41e4712 NC |
2803 | } |
2804 | else | |
b40bf0a2 | 2805 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 2806 | |
b40bf0a2 | 2807 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 2808 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
2809 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
2810 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 2811 | |
b40bf0a2 | 2812 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 2813 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
2814 | if (* end_of_sequence > end) |
2815 | { | |
4c219c2e AM |
2816 | warn (_("Line length %s extends beyond end of section\n"), |
2817 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
2818 | * end_of_sequence = end; |
2819 | return NULL; | |
2820 | } | |
2821 | ||
b40bf0a2 NC |
2822 | return hdrptr; |
2823 | } | |
19e6b90e | 2824 | |
b40bf0a2 NC |
2825 | static int |
2826 | display_debug_lines_raw (struct dwarf_section *section, | |
2827 | unsigned char *data, | |
b4eb7656 | 2828 | unsigned char *end) |
b40bf0a2 NC |
2829 | { |
2830 | unsigned char *start = section->start; | |
19e6b90e | 2831 | |
b40bf0a2 | 2832 | printf (_("Raw dump of debug contents of section %s:\n\n"), |
b4eb7656 | 2833 | section->name); |
19e6b90e | 2834 | |
b40bf0a2 NC |
2835 | while (data < end) |
2836 | { | |
2837 | static DWARF2_Internal_LineInfo saved_linfo; | |
2838 | DWARF2_Internal_LineInfo linfo; | |
2839 | unsigned char *standard_opcodes; | |
2840 | unsigned char *end_of_sequence; | |
fe59e83d CC |
2841 | unsigned int last_dir_entry = 0; |
2842 | int i; | |
19e6b90e | 2843 | |
4925cdd7 NC |
2844 | if (const_strneq (section->name, ".debug_line.") |
2845 | /* Note: the following does not apply to .debug_line.dwo sections. | |
2846 | These are full debug_line sections. */ | |
2847 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 2848 | { |
b40bf0a2 NC |
2849 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
2850 | section containing just the Line Number Statements. They are | |
2851 | created by the assembler and intended to be used alongside gcc's | |
2852 | -ffunction-sections command line option. When the linker's | |
2853 | garbage collection decides to discard a .text.<foo> section it | |
2854 | can then also discard the line number information in .debug_line.<foo>. | |
2855 | ||
4925cdd7 | 2856 | Since the section is a fragment it does not have the details |
b40bf0a2 | 2857 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 2858 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
2859 | end_of_sequence = end; |
2860 | standard_opcodes = NULL; | |
2861 | linfo = saved_linfo; | |
058037d3 NC |
2862 | /* PR 17531: file: 0522b371. */ |
2863 | if (linfo.li_line_range == 0) | |
2864 | { | |
1306a742 | 2865 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
2866 | return 0; |
2867 | } | |
b40bf0a2 | 2868 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 2869 | } |
19e6b90e L |
2870 | else |
2871 | { | |
b40bf0a2 | 2872 | unsigned char * hdrptr; |
19e6b90e | 2873 | |
b40bf0a2 NC |
2874 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
2875 | & end_of_sequence)) == NULL) | |
2876 | return 0; | |
19e6b90e | 2877 | |
b40bf0a2 NC |
2878 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
2879 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
2880 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
77ef8654 | 2881 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
2882 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
2883 | if (linfo.li_version >= 4) | |
2884 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
2885 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
2886 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
2887 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
2888 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 2889 | |
0a9d414a NC |
2890 | /* PR 17512: file: 1665-6428-0.004. */ |
2891 | if (linfo.li_line_range == 0) | |
2892 | { | |
2893 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
2894 | linfo.li_line_range = 1; | |
2895 | } | |
77ef8654 | 2896 | |
b40bf0a2 | 2897 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 2898 | |
b40bf0a2 NC |
2899 | /* Display the contents of the Opcodes table. */ |
2900 | standard_opcodes = hdrptr; | |
19e6b90e | 2901 | |
6937bb54 NC |
2902 | /* PR 17512: file: 002-417945-0.004. */ |
2903 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
2904 | { | |
2905 | warn (_("Line Base extends beyond end of section\n")); | |
2906 | return 0; | |
2907 | } | |
2908 | ||
b40bf0a2 | 2909 | printf (_("\n Opcodes:\n")); |
19e6b90e | 2910 | |
b40bf0a2 NC |
2911 | for (i = 1; i < linfo.li_opcode_base; i++) |
2912 | printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]); | |
19e6b90e | 2913 | |
b40bf0a2 NC |
2914 | /* Display the contents of the Directory table. */ |
2915 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 2916 | |
b40bf0a2 NC |
2917 | if (*data == 0) |
2918 | printf (_("\n The Directory Table is empty.\n")); | |
2919 | else | |
2920 | { | |
fe59e83d CC |
2921 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
2922 | (long)(data - start)); | |
19e6b90e | 2923 | |
6937bb54 | 2924 | while (data < end && *data != 0) |
a233b20c | 2925 | { |
6937bb54 | 2926 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); |
b40bf0a2 NC |
2927 | |
2928 | data += strnlen ((char *) data, end - data) + 1; | |
a233b20c | 2929 | } |
6937bb54 NC |
2930 | |
2931 | /* PR 17512: file: 002-132094-0.004. */ | |
2932 | if (data >= end - 1) | |
2933 | break; | |
b40bf0a2 | 2934 | } |
19e6b90e | 2935 | |
b40bf0a2 NC |
2936 | /* Skip the NUL at the end of the table. */ |
2937 | data++; | |
19e6b90e | 2938 | |
b40bf0a2 NC |
2939 | /* Display the contents of the File Name table. */ |
2940 | if (*data == 0) | |
2941 | printf (_("\n The File Name Table is empty.\n")); | |
2942 | else | |
2943 | { | |
fe59e83d CC |
2944 | printf (_("\n The File Name Table (offset 0x%lx):\n"), |
2945 | (long)(data - start)); | |
b40bf0a2 | 2946 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
19e6b90e | 2947 | |
6937bb54 | 2948 | while (data < end && *data != 0) |
b40bf0a2 NC |
2949 | { |
2950 | unsigned char *name; | |
2951 | unsigned int bytes_read; | |
19e6b90e | 2952 | |
b40bf0a2 NC |
2953 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
2954 | name = data; | |
2955 | data += strnlen ((char *) data, end - data) + 1; | |
19e6b90e | 2956 | |
b40bf0a2 NC |
2957 | printf ("%s\t", |
2958 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
2959 | data += bytes_read; | |
2960 | printf ("%s\t", | |
2961 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
2962 | data += bytes_read; | |
2963 | printf ("%s\t", | |
2964 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
2965 | data += bytes_read; | |
6937bb54 | 2966 | printf ("%.*s\n", (int)(end - name), name); |
19e6b90e | 2967 | |
b40bf0a2 NC |
2968 | if (data == end) |
2969 | { | |
2970 | warn (_("Corrupt file name table entry\n")); | |
2971 | break; | |
2972 | } | |
a233b20c | 2973 | } |
b40bf0a2 | 2974 | } |
19e6b90e | 2975 | |
b40bf0a2 NC |
2976 | /* Skip the NUL at the end of the table. */ |
2977 | data++; | |
2978 | putchar ('\n'); | |
2979 | saved_linfo = linfo; | |
2980 | } | |
19e6b90e | 2981 | |
b40bf0a2 NC |
2982 | /* Now display the statements. */ |
2983 | if (data >= end_of_sequence) | |
2984 | printf (_(" No Line Number Statements.\n")); | |
2985 | else | |
2986 | { | |
2987 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 2988 | |
b40bf0a2 NC |
2989 | while (data < end_of_sequence) |
2990 | { | |
2991 | unsigned char op_code; | |
2992 | dwarf_signed_vma adv; | |
2993 | dwarf_vma uladv; | |
2994 | unsigned int bytes_read; | |
19e6b90e | 2995 | |
fe59e83d CC |
2996 | printf (" [0x%08lx]", (long)(data - start)); |
2997 | ||
b40bf0a2 | 2998 | op_code = *data++; |
19e6b90e | 2999 | |
b40bf0a2 | 3000 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 3001 | { |
b40bf0a2 NC |
3002 | op_code -= linfo.li_opcode_base; |
3003 | uladv = (op_code / linfo.li_line_range); | |
3004 | if (linfo.li_max_ops_per_insn == 1) | |
3005 | { | |
3006 | uladv *= linfo.li_min_insn_length; | |
3007 | state_machine_regs.address += uladv; | |
3008 | printf (_(" Special opcode %d: " | |
3009 | "advance Address by %s to 0x%s"), | |
3010 | op_code, dwarf_vmatoa ("u", uladv), | |
3011 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
3012 | } | |
3013 | else | |
3014 | { | |
3015 | state_machine_regs.address | |
3016 | += ((state_machine_regs.op_index + uladv) | |
3017 | / linfo.li_max_ops_per_insn) | |
3018 | * linfo.li_min_insn_length; | |
3019 | state_machine_regs.op_index | |
3020 | = (state_machine_regs.op_index + uladv) | |
3021 | % linfo.li_max_ops_per_insn; | |
3022 | printf (_(" Special opcode %d: " | |
3023 | "advance Address by %s to 0x%s[%d]"), | |
3024 | op_code, dwarf_vmatoa ("u", uladv), | |
3025 | dwarf_vmatoa ("x", state_machine_regs.address), | |
3026 | state_machine_regs.op_index); | |
3027 | } | |
3028 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
3029 | state_machine_regs.line += adv; | |
3030 | printf (_(" and Line by %s to %d\n"), | |
3031 | dwarf_vmatoa ("d", adv), state_machine_regs.line); | |
19e6b90e | 3032 | } |
b40bf0a2 NC |
3033 | else switch (op_code) |
3034 | { | |
3035 | case DW_LNS_extended_op: | |
3036 | data += process_extended_line_op (data, linfo.li_default_is_stmt, end); | |
3037 | break; | |
3038 | ||
3039 | case DW_LNS_copy: | |
3040 | printf (_(" Copy\n")); | |
3041 | break; | |
3042 | ||
3043 | case DW_LNS_advance_pc: | |
3044 | uladv = read_uleb128 (data, & bytes_read, end); | |
3045 | data += bytes_read; | |
3046 | if (linfo.li_max_ops_per_insn == 1) | |
3047 | { | |
3048 | uladv *= linfo.li_min_insn_length; | |
3049 | state_machine_regs.address += uladv; | |
3050 | printf (_(" Advance PC by %s to 0x%s\n"), | |
3051 | dwarf_vmatoa ("u", uladv), | |
3052 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
3053 | } | |
3054 | else | |
3055 | { | |
3056 | state_machine_regs.address | |
3057 | += ((state_machine_regs.op_index + uladv) | |
3058 | / linfo.li_max_ops_per_insn) | |
3059 | * linfo.li_min_insn_length; | |
3060 | state_machine_regs.op_index | |
3061 | = (state_machine_regs.op_index + uladv) | |
3062 | % linfo.li_max_ops_per_insn; | |
3063 | printf (_(" Advance PC by %s to 0x%s[%d]\n"), | |
3064 | dwarf_vmatoa ("u", uladv), | |
3065 | dwarf_vmatoa ("x", state_machine_regs.address), | |
3066 | state_machine_regs.op_index); | |
3067 | } | |
3068 | break; | |
3069 | ||
3070 | case DW_LNS_advance_line: | |
3071 | adv = read_sleb128 (data, & bytes_read, end); | |
3072 | data += bytes_read; | |
3073 | state_machine_regs.line += adv; | |
3074 | printf (_(" Advance Line by %s to %d\n"), | |
3075 | dwarf_vmatoa ("d", adv), | |
3076 | state_machine_regs.line); | |
3077 | break; | |
3078 | ||
3079 | case DW_LNS_set_file: | |
3080 | adv = read_uleb128 (data, & bytes_read, end); | |
3081 | data += bytes_read; | |
3082 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
3083 | dwarf_vmatoa ("d", adv)); | |
3084 | state_machine_regs.file = adv; | |
3085 | break; | |
3086 | ||
3087 | case DW_LNS_set_column: | |
3088 | uladv = read_uleb128 (data, & bytes_read, end); | |
3089 | data += bytes_read; | |
3090 | printf (_(" Set column to %s\n"), | |
3091 | dwarf_vmatoa ("u", uladv)); | |
3092 | state_machine_regs.column = uladv; | |
3093 | break; | |
3094 | ||
3095 | case DW_LNS_negate_stmt: | |
3096 | adv = state_machine_regs.is_stmt; | |
3097 | adv = ! adv; | |
3098 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
3099 | state_machine_regs.is_stmt = adv; | |
3100 | break; | |
3101 | ||
3102 | case DW_LNS_set_basic_block: | |
3103 | printf (_(" Set basic block\n")); | |
3104 | state_machine_regs.basic_block = 1; | |
3105 | break; | |
3106 | ||
3107 | case DW_LNS_const_add_pc: | |
3108 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
3109 | if (linfo.li_max_ops_per_insn) | |
3110 | { | |
3111 | uladv *= linfo.li_min_insn_length; | |
3112 | state_machine_regs.address += uladv; | |
3113 | printf (_(" Advance PC by constant %s to 0x%s\n"), | |
3114 | dwarf_vmatoa ("u", uladv), | |
3115 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
3116 | } | |
3117 | else | |
3118 | { | |
3119 | state_machine_regs.address | |
3120 | += ((state_machine_regs.op_index + uladv) | |
3121 | / linfo.li_max_ops_per_insn) | |
3122 | * linfo.li_min_insn_length; | |
3123 | state_machine_regs.op_index | |
3124 | = (state_machine_regs.op_index + uladv) | |
3125 | % linfo.li_max_ops_per_insn; | |
3126 | printf (_(" Advance PC by constant %s to 0x%s[%d]\n"), | |
3127 | dwarf_vmatoa ("u", uladv), | |
3128 | dwarf_vmatoa ("x", state_machine_regs.address), | |
3129 | state_machine_regs.op_index); | |
3130 | } | |
3131 | break; | |
3132 | ||
3133 | case DW_LNS_fixed_advance_pc: | |
3134 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
3135 | state_machine_regs.address += uladv; | |
3136 | state_machine_regs.op_index = 0; | |
3137 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
3138 | dwarf_vmatoa ("u", uladv), | |
3139 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
3140 | break; | |
3141 | ||
3142 | case DW_LNS_set_prologue_end: | |
3143 | printf (_(" Set prologue_end to true\n")); | |
3144 | break; | |
3145 | ||
3146 | case DW_LNS_set_epilogue_begin: | |
3147 | printf (_(" Set epilogue_begin to true\n")); | |
3148 | break; | |
3149 | ||
3150 | case DW_LNS_set_isa: | |
3151 | uladv = read_uleb128 (data, & bytes_read, end); | |
3152 | data += bytes_read; | |
3153 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
3154 | break; | |
3155 | ||
3156 | default: | |
3157 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
3158 | ||
3159 | if (standard_opcodes != NULL) | |
3160 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
3161 | { | |
3162 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
3163 | &bytes_read, end)), | |
3164 | i == 1 ? "" : ", "); | |
3165 | data += bytes_read; | |
3166 | } | |
3167 | putchar ('\n'); | |
3168 | break; | |
3169 | } | |
19e6b90e | 3170 | } |
b40bf0a2 | 3171 | putchar ('\n'); |
19e6b90e | 3172 | } |
19e6b90e L |
3173 | } |
3174 | ||
3175 | return 1; | |
3176 | } | |
3177 | ||
a262ae96 NC |
3178 | typedef struct |
3179 | { | |
467c65bc NC |
3180 | unsigned char *name; |
3181 | unsigned int directory_index; | |
3182 | unsigned int modification_date; | |
3183 | unsigned int length; | |
a262ae96 NC |
3184 | } File_Entry; |
3185 | ||
3186 | /* Output a decoded representation of the .debug_line section. */ | |
3187 | ||
3188 | static int | |
3189 | display_debug_lines_decoded (struct dwarf_section *section, | |
3190 | unsigned char *data, | |
3191 | unsigned char *end) | |
3192 | { | |
b40bf0a2 NC |
3193 | static DWARF2_Internal_LineInfo saved_linfo; |
3194 | ||
a262ae96 | 3195 | printf (_("Decoded dump of debug contents of section %s:\n\n"), |
b4eb7656 | 3196 | section->name); |
a262ae96 NC |
3197 | |
3198 | while (data < end) | |
3199 | { | |
3200 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 3201 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
3202 | unsigned char *standard_opcodes; |
3203 | unsigned char *end_of_sequence; | |
a262ae96 NC |
3204 | int i; |
3205 | File_Entry *file_table = NULL; | |
143a3db0 | 3206 | unsigned int n_files = 0; |
a262ae96 | 3207 | unsigned char **directory_table = NULL; |
143a3db0 | 3208 | unsigned int n_directories = 0; |
a262ae96 | 3209 | |
4925cdd7 NC |
3210 | if (const_strneq (section->name, ".debug_line.") |
3211 | /* Note: the following does not apply to .debug_line.dwo sections. | |
3212 | These are full debug_line sections. */ | |
3213 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 3214 | { |
4925cdd7 | 3215 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
3216 | end_of_sequence = end; |
3217 | standard_opcodes = NULL; | |
3218 | linfo = saved_linfo; | |
058037d3 NC |
3219 | /* PR 17531: file: 0522b371. */ |
3220 | if (linfo.li_line_range == 0) | |
3221 | { | |
1306a742 | 3222 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
3223 | return 0; |
3224 | } | |
b40bf0a2 | 3225 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 3226 | } |
a262ae96 | 3227 | else |
b4eb7656 | 3228 | { |
b40bf0a2 | 3229 | unsigned char *hdrptr; |
a262ae96 | 3230 | |
b40bf0a2 NC |
3231 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
3232 | & end_of_sequence)) == NULL) | |
a233b20c | 3233 | return 0; |
0c588247 | 3234 | |
058037d3 NC |
3235 | /* PR 17531: file: 0522b371. */ |
3236 | if (linfo.li_line_range == 0) | |
3237 | { | |
3238 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
3239 | linfo.li_line_range = 1; | |
3240 | } | |
b40bf0a2 | 3241 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 3242 | |
b40bf0a2 NC |
3243 | /* Save a pointer to the contents of the Opcodes table. */ |
3244 | standard_opcodes = hdrptr; | |
a262ae96 | 3245 | |
b40bf0a2 NC |
3246 | /* Traverse the Directory table just to count entries. */ |
3247 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
3248 | if (*data != 0) | |
3249 | { | |
3250 | unsigned char *ptr_directory_table = data; | |
a262ae96 | 3251 | |
b40bf0a2 NC |
3252 | while (*data != 0) |
3253 | { | |
3254 | data += strnlen ((char *) data, end - data) + 1; | |
3255 | n_directories++; | |
3256 | } | |
a262ae96 | 3257 | |
b40bf0a2 NC |
3258 | /* Go through the directory table again to save the directories. */ |
3259 | directory_table = (unsigned char **) | |
3260 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 3261 | |
b40bf0a2 NC |
3262 | i = 0; |
3263 | while (*ptr_directory_table != 0) | |
3264 | { | |
3265 | directory_table[i] = ptr_directory_table; | |
3266 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
3267 | ptr_directory_table - end) + 1; | |
3268 | i++; | |
3269 | } | |
a262ae96 | 3270 | } |
b40bf0a2 NC |
3271 | /* Skip the NUL at the end of the table. */ |
3272 | data++; | |
a262ae96 | 3273 | |
b40bf0a2 NC |
3274 | /* Traverse the File Name table just to count the entries. */ |
3275 | if (*data != 0) | |
3276 | { | |
3277 | unsigned char *ptr_file_name_table = data; | |
a262ae96 | 3278 | |
b40bf0a2 NC |
3279 | while (*data != 0) |
3280 | { | |
3281 | unsigned int bytes_read; | |
a262ae96 | 3282 | |
b40bf0a2 NC |
3283 | /* Skip Name, directory index, last modification time and length |
3284 | of file. */ | |
3285 | data += strnlen ((char *) data, end - data) + 1; | |
3286 | read_uleb128 (data, & bytes_read, end); | |
3287 | data += bytes_read; | |
3288 | read_uleb128 (data, & bytes_read, end); | |
3289 | data += bytes_read; | |
3290 | read_uleb128 (data, & bytes_read, end); | |
3291 | data += bytes_read; | |
a262ae96 | 3292 | |
b40bf0a2 NC |
3293 | n_files++; |
3294 | } | |
a262ae96 | 3295 | |
b40bf0a2 NC |
3296 | /* Go through the file table again to save the strings. */ |
3297 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
a262ae96 | 3298 | |
b40bf0a2 NC |
3299 | i = 0; |
3300 | while (*ptr_file_name_table != 0) | |
3301 | { | |
3302 | unsigned int bytes_read; | |
3303 | ||
3304 | file_table[i].name = ptr_file_name_table; | |
3305 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
3306 | end - ptr_file_name_table) + 1; | |
3307 | ||
3308 | /* We are not interested in directory, time or size. */ | |
3309 | file_table[i].directory_index = read_uleb128 (ptr_file_name_table, | |
3310 | & bytes_read, end); | |
3311 | ptr_file_name_table += bytes_read; | |
3312 | file_table[i].modification_date = read_uleb128 (ptr_file_name_table, | |
3313 | & bytes_read, end); | |
3314 | ptr_file_name_table += bytes_read; | |
3315 | file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end); | |
3316 | ptr_file_name_table += bytes_read; | |
3317 | i++; | |
3318 | } | |
3319 | i = 0; | |
a262ae96 | 3320 | |
b40bf0a2 NC |
3321 | /* Print the Compilation Unit's name and a header. */ |
3322 | if (directory_table == NULL) | |
3323 | { | |
3324 | printf (_("CU: %s:\n"), file_table[0].name); | |
3325 | printf (_("File name Line number Starting address\n")); | |
3326 | } | |
3327 | else | |
3328 | { | |
3329 | unsigned int ix = file_table[0].directory_index; | |
3330 | const char *directory = ix ? (char *)directory_table[ix - 1] : "."; | |
a262ae96 | 3331 | |
b40bf0a2 NC |
3332 | if (do_wide || strlen (directory) < 76) |
3333 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
3334 | else | |
3335 | printf ("%s:\n", file_table[0].name); | |
0c588247 | 3336 | |
b40bf0a2 NC |
3337 | printf (_("File name Line number Starting address\n")); |
3338 | } | |
3339 | } | |
cc5914eb | 3340 | |
b40bf0a2 NC |
3341 | /* Skip the NUL at the end of the table. */ |
3342 | data++; | |
a262ae96 | 3343 | |
b40bf0a2 NC |
3344 | saved_linfo = linfo; |
3345 | } | |
a262ae96 NC |
3346 | |
3347 | /* This loop iterates through the Dwarf Line Number Program. */ | |
3348 | while (data < end_of_sequence) | |
b4eb7656 | 3349 | { |
a262ae96 | 3350 | unsigned char op_code; |
b4eb7656 AM |
3351 | int adv; |
3352 | unsigned long int uladv; | |
3353 | unsigned int bytes_read; | |
3354 | int is_special_opcode = 0; | |
a262ae96 | 3355 | |
b4eb7656 | 3356 | op_code = *data++; |
a262ae96 | 3357 | |
b4eb7656 | 3358 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 3359 | { |
91d6fa6a | 3360 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
3361 | uladv = (op_code / linfo.li_line_range); |
3362 | if (linfo.li_max_ops_per_insn == 1) | |
3363 | { | |
3364 | uladv *= linfo.li_min_insn_length; | |
3365 | state_machine_regs.address += uladv; | |
3366 | } | |
3367 | else | |
3368 | { | |
3369 | state_machine_regs.address | |
3370 | += ((state_machine_regs.op_index + uladv) | |
3371 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 3372 | * linfo.li_min_insn_length; |
a233b20c JJ |
3373 | state_machine_regs.op_index |
3374 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 3375 | % linfo.li_max_ops_per_insn; |
a233b20c | 3376 | } |
a262ae96 | 3377 | |
b4eb7656 AM |
3378 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
3379 | state_machine_regs.line += adv; | |
3380 | is_special_opcode = 1; | |
3381 | } | |
3382 | else switch (op_code) | |
b40bf0a2 NC |
3383 | { |
3384 | case DW_LNS_extended_op: | |
3385 | { | |
3386 | unsigned int ext_op_code_len; | |
3387 | unsigned char ext_op_code; | |
3388 | unsigned char *op_code_data = data; | |
3389 | ||
3390 | ext_op_code_len = read_uleb128 (op_code_data, &bytes_read, | |
3391 | end_of_sequence); | |
3392 | op_code_data += bytes_read; | |
3393 | ||
3394 | if (ext_op_code_len == 0) | |
3395 | { | |
f41e4712 | 3396 | warn (_("Badly formed extended line op encountered!\n")); |
b40bf0a2 NC |
3397 | break; |
3398 | } | |
3399 | ext_op_code_len += bytes_read; | |
3400 | ext_op_code = *op_code_data++; | |
3401 | ||
3402 | switch (ext_op_code) | |
3403 | { | |
3404 | case DW_LNE_end_sequence: | |
3405 | reset_state_machine (linfo.li_default_is_stmt); | |
3406 | break; | |
3407 | case DW_LNE_set_address: | |
3408 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
87bc83b3 CC |
3409 | op_code_data, |
3410 | ext_op_code_len - bytes_read - 1, | |
b40bf0a2 NC |
3411 | end); |
3412 | state_machine_regs.op_index = 0; | |
3413 | break; | |
3414 | case DW_LNE_define_file: | |
3415 | { | |
3416 | file_table = (File_Entry *) xrealloc | |
3417 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
3418 | ||
3419 | ++state_machine_regs.last_file_entry; | |
3420 | /* Source file name. */ | |
3421 | file_table[n_files].name = op_code_data; | |
3422 | op_code_data += strlen ((char *) op_code_data) + 1; | |
3423 | /* Directory index. */ | |
3424 | file_table[n_files].directory_index = | |
3425 | read_uleb128 (op_code_data, & bytes_read, | |
3426 | end_of_sequence); | |
3427 | op_code_data += bytes_read; | |
3428 | /* Last modification time. */ | |
3429 | file_table[n_files].modification_date = | |
3430 | read_uleb128 (op_code_data, & bytes_read, | |
3431 | end_of_sequence); | |
3432 | op_code_data += bytes_read; | |
3433 | /* File length. */ | |
3434 | file_table[n_files].length = | |
3435 | read_uleb128 (op_code_data, & bytes_read, | |
3436 | end_of_sequence); | |
3437 | ||
3438 | n_files++; | |
3439 | break; | |
3440 | } | |
3441 | case DW_LNE_set_discriminator: | |
3442 | case DW_LNE_HP_set_sequence: | |
3443 | /* Simply ignored. */ | |
3444 | break; | |
3445 | ||
3446 | default: | |
3447 | printf (_("UNKNOWN (%u): length %d\n"), | |
3448 | ext_op_code, ext_op_code_len - bytes_read); | |
3449 | break; | |
3450 | } | |
3451 | data += ext_op_code_len; | |
3452 | break; | |
3453 | } | |
3454 | case DW_LNS_copy: | |
3455 | break; | |
3456 | ||
3457 | case DW_LNS_advance_pc: | |
3458 | uladv = read_uleb128 (data, & bytes_read, end); | |
3459 | data += bytes_read; | |
3460 | if (linfo.li_max_ops_per_insn == 1) | |
3461 | { | |
3462 | uladv *= linfo.li_min_insn_length; | |
3463 | state_machine_regs.address += uladv; | |
3464 | } | |
3465 | else | |
3466 | { | |
3467 | state_machine_regs.address | |
3468 | += ((state_machine_regs.op_index + uladv) | |
3469 | / linfo.li_max_ops_per_insn) | |
3470 | * linfo.li_min_insn_length; | |
3471 | state_machine_regs.op_index | |
3472 | = (state_machine_regs.op_index + uladv) | |
3473 | % linfo.li_max_ops_per_insn; | |
3474 | } | |
3475 | break; | |
3476 | ||
3477 | case DW_LNS_advance_line: | |
3478 | adv = read_sleb128 (data, & bytes_read, end); | |
3479 | data += bytes_read; | |
3480 | state_machine_regs.line += adv; | |
3481 | break; | |
3482 | ||
3483 | case DW_LNS_set_file: | |
3484 | adv = read_uleb128 (data, & bytes_read, end); | |
3485 | data += bytes_read; | |
3486 | state_machine_regs.file = adv; | |
3487 | ||
3488 | if (file_table == NULL) | |
3489 | printf (_("\n [Use file table entry %d]\n"), state_machine_regs.file - 1); | |
3490 | else if (file_table[state_machine_regs.file - 1].directory_index == 0) | |
3491 | /* If directory index is 0, that means current directory. */ | |
3492 | printf ("\n./%s:[++]\n", | |
3493 | file_table[state_machine_regs.file - 1].name); | |
3494 | else if (directory_table == NULL) | |
3495 | printf (_("\n [Use directory table entry %d]\n"), | |
3496 | file_table[state_machine_regs.file - 1].directory_index - 1); | |
3497 | else | |
3498 | /* The directory index starts counting at 1. */ | |
3499 | printf ("\n%s/%s:\n", | |
3500 | directory_table[file_table[state_machine_regs.file - 1].directory_index - 1], | |
3501 | file_table[state_machine_regs.file - 1].name); | |
3502 | break; | |
3503 | ||
3504 | case DW_LNS_set_column: | |
3505 | uladv = read_uleb128 (data, & bytes_read, end); | |
3506 | data += bytes_read; | |
3507 | state_machine_regs.column = uladv; | |
3508 | break; | |
3509 | ||
3510 | case DW_LNS_negate_stmt: | |
3511 | adv = state_machine_regs.is_stmt; | |
3512 | adv = ! adv; | |
3513 | state_machine_regs.is_stmt = adv; | |
3514 | break; | |
3515 | ||
3516 | case DW_LNS_set_basic_block: | |
3517 | state_machine_regs.basic_block = 1; | |
3518 | break; | |
3519 | ||
3520 | case DW_LNS_const_add_pc: | |
3521 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
3522 | if (linfo.li_max_ops_per_insn == 1) | |
3523 | { | |
3524 | uladv *= linfo.li_min_insn_length; | |
3525 | state_machine_regs.address += uladv; | |
3526 | } | |
3527 | else | |
3528 | { | |
3529 | state_machine_regs.address | |
3530 | += ((state_machine_regs.op_index + uladv) | |
3531 | / linfo.li_max_ops_per_insn) | |
3532 | * linfo.li_min_insn_length; | |
3533 | state_machine_regs.op_index | |
3534 | = (state_machine_regs.op_index + uladv) | |
3535 | % linfo.li_max_ops_per_insn; | |
3536 | } | |
3537 | break; | |
3538 | ||
3539 | case DW_LNS_fixed_advance_pc: | |
3540 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
3541 | state_machine_regs.address += uladv; | |
3542 | state_machine_regs.op_index = 0; | |
3543 | break; | |
3544 | ||
3545 | case DW_LNS_set_prologue_end: | |
3546 | break; | |
3547 | ||
3548 | case DW_LNS_set_epilogue_begin: | |
3549 | break; | |
3550 | ||
3551 | case DW_LNS_set_isa: | |
3552 | uladv = read_uleb128 (data, & bytes_read, end); | |
3553 | data += bytes_read; | |
3554 | printf (_(" Set ISA to %lu\n"), uladv); | |
3555 | break; | |
3556 | ||
3557 | default: | |
3558 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
3559 | ||
3560 | if (standard_opcodes != NULL) | |
3561 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
3562 | { | |
3563 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
3564 | &bytes_read, end)), | |
3565 | i == 1 ? "" : ", "); | |
3566 | data += bytes_read; | |
3567 | } | |
3568 | putchar ('\n'); | |
3569 | break; | |
3570 | } | |
a262ae96 | 3571 | |
b4eb7656 AM |
3572 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
3573 | to the DWARF address/line matrix. */ | |
3574 | if ((is_special_opcode) || (op_code == DW_LNE_end_sequence) | |
a262ae96 | 3575 | || (op_code == DW_LNS_copy)) |
b4eb7656 AM |
3576 | { |
3577 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
3578 | char *fileName; | |
3579 | char *newFileName = NULL; | |
3580 | size_t fileNameLength; | |
b40bf0a2 NC |
3581 | |
3582 | if (file_table) | |
3583 | fileName = (char *) file_table[state_machine_regs.file - 1].name; | |
3584 | else | |
3585 | fileName = "<unknown>"; | |
3586 | ||
3587 | fileNameLength = strlen (fileName); | |
a262ae96 | 3588 | |
b4eb7656 AM |
3589 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
3590 | { | |
3591 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
3592 | /* Truncate file name */ | |
3593 | strncpy (newFileName, | |
3594 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
3595 | MAX_FILENAME_LENGTH + 1); | |
3596 | } | |
3597 | else | |
3598 | { | |
3599 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
3600 | strncpy (newFileName, fileName, fileNameLength + 1); | |
3601 | } | |
3602 | ||
3603 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) | |
3604 | { | |
a233b20c | 3605 | if (linfo.li_max_ops_per_insn == 1) |
467c65bc NC |
3606 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n", |
3607 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3608 | state_machine_regs.address); |
3609 | else | |
467c65bc NC |
3610 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n", |
3611 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3612 | state_machine_regs.address, |
3613 | state_machine_regs.op_index); | |
b4eb7656 AM |
3614 | } |
3615 | else | |
3616 | { | |
a233b20c | 3617 | if (linfo.li_max_ops_per_insn == 1) |
467c65bc NC |
3618 | printf ("%s %11d %#18" DWARF_VMA_FMT "x\n", |
3619 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3620 | state_machine_regs.address); |
3621 | else | |
467c65bc NC |
3622 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n", |
3623 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3624 | state_machine_regs.address, |
3625 | state_machine_regs.op_index); | |
b4eb7656 | 3626 | } |
a262ae96 | 3627 | |
b4eb7656 | 3628 | if (op_code == DW_LNE_end_sequence) |
a262ae96 NC |
3629 | printf ("\n"); |
3630 | ||
b4eb7656 AM |
3631 | free (newFileName); |
3632 | } | |
3633 | } | |
b40bf0a2 NC |
3634 | |
3635 | if (file_table) | |
3636 | { | |
3637 | free (file_table); | |
3638 | file_table = NULL; | |
3639 | n_files = 0; | |
3640 | } | |
3641 | ||
3642 | if (directory_table) | |
3643 | { | |
3644 | free (directory_table); | |
3645 | directory_table = NULL; | |
3646 | n_directories = 0; | |
3647 | } | |
3648 | ||
a262ae96 NC |
3649 | putchar ('\n'); |
3650 | } | |
3651 | ||
3652 | return 1; | |
3653 | } | |
3654 | ||
3655 | static int | |
1c4cc746 | 3656 | display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) |
a262ae96 NC |
3657 | { |
3658 | unsigned char *data = section->start; | |
3659 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
3660 | int retValRaw = 1; |
3661 | int retValDecoded = 1; | |
a262ae96 | 3662 | |
008f4c78 NC |
3663 | if (do_debug_lines == 0) |
3664 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
3665 | ||
4cb93e3b | 3666 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
a262ae96 NC |
3667 | retValRaw = display_debug_lines_raw (section, data, end); |
3668 | ||
4cb93e3b | 3669 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
a262ae96 NC |
3670 | retValDecoded = display_debug_lines_decoded (section, data, end); |
3671 | ||
4cb93e3b | 3672 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
3673 | return 0; |
3674 | ||
3675 | return 1; | |
3676 | } | |
3677 | ||
6e3d6dc1 NC |
3678 | static debug_info * |
3679 | find_debug_info_for_offset (unsigned long offset) | |
3680 | { | |
3681 | unsigned int i; | |
3682 | ||
3683 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
3684 | return NULL; | |
3685 | ||
3686 | for (i = 0; i < num_debug_info_entries; i++) | |
3687 | if (debug_information[i].cu_offset == offset) | |
3688 | return debug_information + i; | |
3689 | ||
3690 | return NULL; | |
3691 | } | |
3692 | ||
459d52c8 DE |
3693 | static const char * |
3694 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
3695 | { | |
3696 | /* See gdb/gdb-index.h. */ | |
3697 | static const char * const kinds[] = | |
3698 | { | |
3699 | N_ ("no info"), | |
3700 | N_ ("type"), | |
3701 | N_ ("variable"), | |
3702 | N_ ("function"), | |
3703 | N_ ("other"), | |
3704 | N_ ("unused5"), | |
3705 | N_ ("unused6"), | |
3706 | N_ ("unused7") | |
3707 | }; | |
3708 | ||
3709 | return _ (kinds[kind]); | |
3710 | } | |
3711 | ||
19e6b90e | 3712 | static int |
459d52c8 DE |
3713 | display_debug_pubnames_worker (struct dwarf_section *section, |
3714 | void *file ATTRIBUTE_UNUSED, | |
3715 | int is_gnu) | |
19e6b90e | 3716 | { |
91d6fa6a | 3717 | DWARF2_Internal_PubNames names; |
19e6b90e L |
3718 | unsigned char *start = section->start; |
3719 | unsigned char *end = start + section->size; | |
3720 | ||
6e3d6dc1 NC |
3721 | /* It does not matter if this load fails, |
3722 | we test for that later on. */ | |
3723 | load_debug_info (file); | |
3724 | ||
19e6b90e L |
3725 | printf (_("Contents of the %s section:\n\n"), section->name); |
3726 | ||
3727 | while (start < end) | |
3728 | { | |
3729 | unsigned char *data; | |
362beea4 | 3730 | unsigned char *adr; |
834f871c | 3731 | dwarf_vma offset; |
bf5117e3 | 3732 | unsigned int offset_size, initial_length_size; |
19e6b90e L |
3733 | |
3734 | data = start; | |
3735 | ||
0c588247 | 3736 | SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end); |
91d6fa6a | 3737 | if (names.pn_length == 0xffffffff) |
19e6b90e | 3738 | { |
0c588247 | 3739 | SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end); |
19e6b90e L |
3740 | offset_size = 8; |
3741 | initial_length_size = 12; | |
3742 | } | |
3743 | else | |
3744 | { | |
3745 | offset_size = 4; | |
3746 | initial_length_size = 4; | |
3747 | } | |
3748 | ||
0c588247 NC |
3749 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
3750 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
3751 | |
3752 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
3753 | && num_debug_info_entries > 0 | |
91d6fa6a | 3754 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 3755 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 3756 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 3757 | |
0c588247 | 3758 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 3759 | |
362beea4 | 3760 | adr = start + names.pn_length + initial_length_size; |
058037d3 | 3761 | /* PR 17531: file: 7615b6b2. */ |
57028622 NC |
3762 | if ((dwarf_signed_vma) names.pn_length < 0 |
3763 | /* PR 17531: file: a5dbeaa7. */ | |
362beea4 | 3764 | || adr < start) |
058037d3 NC |
3765 | { |
3766 | warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length); | |
3767 | start = end; | |
3768 | } | |
3769 | else | |
362beea4 | 3770 | start = adr; |
b4eb7656 | 3771 | |
058037d3 NC |
3772 | printf (_(" Length: %ld\n"), |
3773 | (long) names.pn_length); | |
3774 | printf (_(" Version: %d\n"), | |
3775 | names.pn_version); | |
3776 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
3777 | (unsigned long) names.pn_offset); | |
3778 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
3779 | (long) names.pn_size); | |
19e6b90e | 3780 | |
91d6fa6a | 3781 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
3782 | { |
3783 | static int warned = 0; | |
3784 | ||
3785 | if (! warned) | |
3786 | { | |
3787 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
3788 | warned = 1; | |
3789 | } | |
3790 | ||
3791 | continue; | |
3792 | } | |
3793 | ||
459d52c8 DE |
3794 | if (is_gnu) |
3795 | printf (_("\n Offset Kind Name\n")); | |
3796 | else | |
3797 | printf (_("\n Offset\tName\n")); | |
19e6b90e L |
3798 | |
3799 | do | |
3800 | { | |
f41e4712 NC |
3801 | bfd_size_type maxprint; |
3802 | ||
0c588247 | 3803 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e L |
3804 | |
3805 | if (offset != 0) | |
3806 | { | |
3807 | data += offset_size; | |
f41e4712 NC |
3808 | if (data >= end) |
3809 | break; | |
3810 | maxprint = (end - data) - 1; | |
b4eb7656 | 3811 | |
459d52c8 DE |
3812 | if (is_gnu) |
3813 | { | |
3814 | unsigned int kind_data; | |
3815 | gdb_index_symbol_kind kind; | |
3816 | const char *kind_name; | |
3817 | int is_static; | |
3818 | ||
3819 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
3820 | data++; | |
f41e4712 | 3821 | maxprint --; |
459d52c8 DE |
3822 | /* GCC computes the kind as the upper byte in the CU index |
3823 | word, and then right shifts it by the CU index size. | |
3824 | Left shift KIND to where the gdb-index.h accessor macros | |
3825 | can use it. */ | |
3826 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
3827 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
3828 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
3829 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
f41e4712 | 3830 | printf (" %-6lx %s,%-10s %.*s\n", |
834f871c | 3831 | (unsigned long) offset, is_static ? _("s") : _("g"), |
f41e4712 | 3832 | kind_name, (int) maxprint, data); |
459d52c8 DE |
3833 | } |
3834 | else | |
b4eb7656 AM |
3835 | printf (" %-6lx\t%.*s\n", |
3836 | (unsigned long) offset, (int) maxprint, data); | |
f41e4712 NC |
3837 | |
3838 | data += strnlen ((char *) data, maxprint) + 1; | |
3839 | if (data >= end) | |
3840 | break; | |
19e6b90e L |
3841 | } |
3842 | } | |
3843 | while (offset != 0); | |
3844 | } | |
3845 | ||
3846 | printf ("\n"); | |
3847 | return 1; | |
3848 | } | |
3849 | ||
459d52c8 DE |
3850 | static int |
3851 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
3852 | { | |
3853 | return display_debug_pubnames_worker (section, file, 0); | |
3854 | } | |
3855 | ||
3856 | static int | |
3857 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
3858 | { | |
3859 | return display_debug_pubnames_worker (section, file, 1); | |
3860 | } | |
3861 | ||
19e6b90e L |
3862 | static int |
3863 | display_debug_macinfo (struct dwarf_section *section, | |
3864 | void *file ATTRIBUTE_UNUSED) | |
3865 | { | |
3866 | unsigned char *start = section->start; | |
3867 | unsigned char *end = start + section->size; | |
3868 | unsigned char *curr = start; | |
3869 | unsigned int bytes_read; | |
3870 | enum dwarf_macinfo_record_type op; | |
3871 | ||
3872 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3873 | ||
3874 | while (curr < end) | |
3875 | { | |
3876 | unsigned int lineno; | |
0c588247 | 3877 | const unsigned char *string; |
19e6b90e | 3878 | |
3f5e193b | 3879 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
3880 | curr++; |
3881 | ||
3882 | switch (op) | |
3883 | { | |
3884 | case DW_MACINFO_start_file: | |
3885 | { | |
3886 | unsigned int filenum; | |
3887 | ||
f6f0e17b | 3888 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 3889 | curr += bytes_read; |
f6f0e17b | 3890 | filenum = read_uleb128 (curr, & bytes_read, end); |
19e6b90e L |
3891 | curr += bytes_read; |
3892 | ||
3893 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), | |
3894 | lineno, filenum); | |
3895 | } | |
3896 | break; | |
3897 | ||
3898 | case DW_MACINFO_end_file: | |
3899 | printf (_(" DW_MACINFO_end_file\n")); | |
3900 | break; | |
3901 | ||
3902 | case DW_MACINFO_define: | |
f6f0e17b | 3903 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 3904 | curr += bytes_read; |
0c588247 NC |
3905 | string = curr; |
3906 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
3907 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
3908 | lineno, string); | |
3909 | break; | |
3910 | ||
3911 | case DW_MACINFO_undef: | |
f6f0e17b | 3912 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 3913 | curr += bytes_read; |
0c588247 NC |
3914 | string = curr; |
3915 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
3916 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
3917 | lineno, string); | |
3918 | break; | |
3919 | ||
3920 | case DW_MACINFO_vendor_ext: | |
3921 | { | |
3922 | unsigned int constant; | |
3923 | ||
f6f0e17b | 3924 | constant = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 3925 | curr += bytes_read; |
0c588247 NC |
3926 | string = curr; |
3927 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
3928 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
3929 | constant, string); | |
3930 | } | |
3931 | break; | |
3932 | } | |
3933 | } | |
3934 | ||
3935 | return 1; | |
3936 | } | |
3937 | ||
4ccf1e31 JJ |
3938 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
3939 | filename and dirname corresponding to file name table entry with index | |
3940 | FILEIDX. Return NULL on failure. */ | |
3941 | ||
3942 | static unsigned char * | |
f6f0e17b NC |
3943 | get_line_filename_and_dirname (dwarf_vma line_offset, |
3944 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
3945 | unsigned char **dir_name) |
3946 | { | |
3947 | struct dwarf_section *section = &debug_displays [line].section; | |
3948 | unsigned char *hdrptr, *dirtable, *file_name; | |
3949 | unsigned int offset_size, initial_length_size; | |
3950 | unsigned int version, opcode_base, bytes_read; | |
3951 | dwarf_vma length, diridx; | |
f6f0e17b | 3952 | const unsigned char * end; |
4ccf1e31 JJ |
3953 | |
3954 | *dir_name = NULL; | |
3955 | if (section->start == NULL | |
3956 | || line_offset >= section->size | |
3957 | || fileidx == 0) | |
3958 | return NULL; | |
3959 | ||
3960 | hdrptr = section->start + line_offset; | |
f6f0e17b | 3961 | end = section->start + section->size; |
0c588247 NC |
3962 | |
3963 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
3964 | if (length == 0xffffffff) |
3965 | { | |
3966 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 3967 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
3968 | offset_size = 8; |
3969 | initial_length_size = 12; | |
3970 | } | |
3971 | else | |
3972 | { | |
3973 | offset_size = 4; | |
3974 | initial_length_size = 4; | |
3975 | } | |
3976 | if (length + initial_length_size > section->size) | |
3977 | return NULL; | |
0c588247 NC |
3978 | |
3979 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
3980 | if (version != 2 && version != 3 && version != 4) |
3981 | return NULL; | |
3982 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
3983 | if (version >= 4) | |
3984 | hdrptr++; /* Skip max_ops_per_insn. */ | |
3985 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
3986 | |
3987 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
3988 | if (opcode_base == 0) |
3989 | return NULL; | |
0c588247 | 3990 | |
4ccf1e31 JJ |
3991 | hdrptr += opcode_base - 1; |
3992 | dirtable = hdrptr; | |
3993 | /* Skip over dirname table. */ | |
3994 | while (*hdrptr != '\0') | |
0c588247 | 3995 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
4ccf1e31 JJ |
3996 | hdrptr++; /* Skip the NUL at the end of the table. */ |
3997 | /* Now skip over preceding filename table entries. */ | |
3998 | for (; *hdrptr != '\0' && fileidx > 1; fileidx--) | |
3999 | { | |
0c588247 | 4000 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
f6f0e17b | 4001 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 4002 | hdrptr += bytes_read; |
f6f0e17b | 4003 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 4004 | hdrptr += bytes_read; |
f6f0e17b | 4005 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
4006 | hdrptr += bytes_read; |
4007 | } | |
f6f0e17b | 4008 | if (hdrptr == end || *hdrptr == '\0') |
4ccf1e31 JJ |
4009 | return NULL; |
4010 | file_name = hdrptr; | |
0c588247 | 4011 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
f6f0e17b | 4012 | diridx = read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
4013 | if (diridx == 0) |
4014 | return file_name; | |
4015 | for (; *dirtable != '\0' && diridx > 1; diridx--) | |
0c588247 | 4016 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
4ccf1e31 JJ |
4017 | if (*dirtable == '\0') |
4018 | return NULL; | |
4019 | *dir_name = dirtable; | |
4020 | return file_name; | |
4021 | } | |
4022 | ||
4023 | static int | |
4024 | display_debug_macro (struct dwarf_section *section, | |
4025 | void *file) | |
4026 | { | |
4027 | unsigned char *start = section->start; | |
4028 | unsigned char *end = start + section->size; | |
4029 | unsigned char *curr = start; | |
4030 | unsigned char *extended_op_buf[256]; | |
4031 | unsigned int bytes_read; | |
4032 | ||
4033 | load_debug_section (str, file); | |
4034 | load_debug_section (line, file); | |
4035 | ||
4036 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4037 | ||
4038 | while (curr < end) | |
4039 | { | |
4040 | unsigned int lineno, version, flags; | |
4041 | unsigned int offset_size = 4; | |
0c588247 | 4042 | const unsigned char *string; |
4ccf1e31 JJ |
4043 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
4044 | unsigned char **extended_ops = NULL; | |
4045 | ||
0c588247 | 4046 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
4ccf1e31 JJ |
4047 | if (version != 4) |
4048 | { | |
4049 | error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"), | |
4050 | section->name); | |
4051 | return 0; | |
4052 | } | |
4053 | ||
0c588247 | 4054 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
4055 | if (flags & 1) |
4056 | offset_size = 8; | |
4057 | printf (_(" Offset: 0x%lx\n"), | |
4058 | (unsigned long) sec_offset); | |
4059 | printf (_(" Version: %d\n"), version); | |
4060 | printf (_(" Offset size: %d\n"), offset_size); | |
4061 | if (flags & 2) | |
4062 | { | |
0c588247 | 4063 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
4064 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
4065 | (unsigned long) line_offset); | |
4066 | } | |
4067 | if (flags & 4) | |
4068 | { | |
0c588247 | 4069 | unsigned int i, count, op; |
4ccf1e31 | 4070 | dwarf_vma nargs, n; |
0c588247 NC |
4071 | |
4072 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 4073 | |
4ccf1e31 JJ |
4074 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
4075 | extended_ops = extended_op_buf; | |
4076 | if (count) | |
4077 | { | |
4078 | printf (_(" Extension opcode arguments:\n")); | |
4079 | for (i = 0; i < count; i++) | |
4080 | { | |
0c588247 | 4081 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 4082 | extended_ops[op] = curr; |
f6f0e17b | 4083 | nargs = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
4084 | curr += bytes_read; |
4085 | if (nargs == 0) | |
4086 | printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op); | |
4087 | else | |
4088 | { | |
4089 | printf (_(" DW_MACRO_GNU_%02x arguments: "), op); | |
4090 | for (n = 0; n < nargs; n++) | |
4091 | { | |
0c588247 NC |
4092 | unsigned int form; |
4093 | ||
4094 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
4095 | printf ("%s%s", get_FORM_name (form), |
4096 | n == nargs - 1 ? "\n" : ", "); | |
4097 | switch (form) | |
4098 | { | |
4099 | case DW_FORM_data1: | |
4100 | case DW_FORM_data2: | |
4101 | case DW_FORM_data4: | |
4102 | case DW_FORM_data8: | |
4103 | case DW_FORM_sdata: | |
4104 | case DW_FORM_udata: | |
4105 | case DW_FORM_block: | |
4106 | case DW_FORM_block1: | |
4107 | case DW_FORM_block2: | |
4108 | case DW_FORM_block4: | |
4109 | case DW_FORM_flag: | |
4110 | case DW_FORM_string: | |
4111 | case DW_FORM_strp: | |
4112 | case DW_FORM_sec_offset: | |
4113 | break; | |
4114 | default: | |
4115 | error (_("Invalid extension opcode form %s\n"), | |
4116 | get_FORM_name (form)); | |
4117 | return 0; | |
4118 | } | |
4119 | } | |
4120 | } | |
4121 | } | |
4122 | } | |
4123 | } | |
4124 | printf ("\n"); | |
4125 | ||
4126 | while (1) | |
4127 | { | |
4128 | unsigned int op; | |
4129 | ||
4130 | if (curr >= end) | |
4131 | { | |
4132 | error (_(".debug_macro section not zero terminated\n")); | |
4133 | return 0; | |
4134 | } | |
4135 | ||
0c588247 | 4136 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
4137 | if (op == 0) |
4138 | break; | |
4139 | ||
4140 | switch (op) | |
4141 | { | |
4142 | case DW_MACRO_GNU_start_file: | |
4143 | { | |
4144 | unsigned int filenum; | |
4145 | unsigned char *file_name = NULL, *dir_name = NULL; | |
4146 | ||
f6f0e17b | 4147 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4148 | curr += bytes_read; |
f6f0e17b | 4149 | filenum = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
4150 | curr += bytes_read; |
4151 | ||
4152 | if ((flags & 2) == 0) | |
4153 | error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n")); | |
4154 | else | |
4155 | file_name | |
4156 | = get_line_filename_and_dirname (line_offset, filenum, | |
4157 | &dir_name); | |
4158 | if (file_name == NULL) | |
4159 | printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"), | |
4160 | lineno, filenum); | |
4161 | else | |
4162 | printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), | |
4163 | lineno, filenum, | |
4164 | dir_name != NULL ? (const char *) dir_name : "", | |
4165 | dir_name != NULL ? "/" : "", file_name); | |
4166 | } | |
4167 | break; | |
4168 | ||
4169 | case DW_MACRO_GNU_end_file: | |
4170 | printf (_(" DW_MACRO_GNU_end_file\n")); | |
4171 | break; | |
4172 | ||
4173 | case DW_MACRO_GNU_define: | |
f6f0e17b | 4174 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4175 | curr += bytes_read; |
0c588247 NC |
4176 | string = curr; |
4177 | curr += strnlen ((char *) string, end - string) + 1; | |
4ccf1e31 JJ |
4178 | printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"), |
4179 | lineno, string); | |
4180 | break; | |
4181 | ||
4182 | case DW_MACRO_GNU_undef: | |
f6f0e17b | 4183 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4184 | curr += bytes_read; |
0c588247 NC |
4185 | string = curr; |
4186 | curr += strnlen ((char *) string, end - string) + 1; | |
4ccf1e31 JJ |
4187 | printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"), |
4188 | lineno, string); | |
4189 | break; | |
4190 | ||
4191 | case DW_MACRO_GNU_define_indirect: | |
f6f0e17b | 4192 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4193 | curr += bytes_read; |
0c588247 | 4194 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 JJ |
4195 | string = fetch_indirect_string (offset); |
4196 | printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"), | |
4197 | lineno, string); | |
4198 | break; | |
4199 | ||
4200 | case DW_MACRO_GNU_undef_indirect: | |
f6f0e17b | 4201 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 4202 | curr += bytes_read; |
0c588247 | 4203 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 JJ |
4204 | string = fetch_indirect_string (offset); |
4205 | printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"), | |
4206 | lineno, string); | |
4207 | break; | |
4208 | ||
4209 | case DW_MACRO_GNU_transparent_include: | |
0c588247 | 4210 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 JJ |
4211 | printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"), |
4212 | (unsigned long) offset); | |
4213 | break; | |
4214 | ||
a081f3cd | 4215 | case DW_MACRO_GNU_define_indirect_alt: |
f6f0e17b | 4216 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 4217 | curr += bytes_read; |
0c588247 | 4218 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
a081f3cd JJ |
4219 | printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"), |
4220 | lineno, (unsigned long) offset); | |
4221 | break; | |
4222 | ||
4223 | case DW_MACRO_GNU_undef_indirect_alt: | |
f6f0e17b | 4224 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 4225 | curr += bytes_read; |
0c588247 | 4226 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
a081f3cd JJ |
4227 | printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"), |
4228 | lineno, (unsigned long) offset); | |
4229 | break; | |
4230 | ||
4231 | case DW_MACRO_GNU_transparent_include_alt: | |
0c588247 | 4232 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
a081f3cd JJ |
4233 | printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"), |
4234 | (unsigned long) offset); | |
4235 | break; | |
4236 | ||
4ccf1e31 JJ |
4237 | default: |
4238 | if (extended_ops == NULL || extended_ops[op] == NULL) | |
4239 | { | |
4240 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
4241 | return 0; | |
4242 | } | |
4243 | else | |
4244 | { | |
4245 | /* Skip over unhandled opcodes. */ | |
4246 | dwarf_vma nargs, n; | |
4247 | unsigned char *desc = extended_ops[op]; | |
f6f0e17b | 4248 | nargs = read_uleb128 (desc, &bytes_read, end); |
4ccf1e31 JJ |
4249 | desc += bytes_read; |
4250 | if (nargs == 0) | |
4251 | { | |
4252 | printf (_(" DW_MACRO_GNU_%02x\n"), op); | |
4253 | break; | |
4254 | } | |
4255 | printf (_(" DW_MACRO_GNU_%02x -"), op); | |
4256 | for (n = 0; n < nargs; n++) | |
4257 | { | |
0c588247 NC |
4258 | int val; |
4259 | ||
4260 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); | |
4ccf1e31 | 4261 | curr |
0c588247 | 4262 | = read_and_display_attr_value (0, val, |
f6f0e17b | 4263 | curr, end, 0, 0, offset_size, |
341f9135 CC |
4264 | version, NULL, 0, NULL, |
4265 | NULL); | |
4ccf1e31 JJ |
4266 | if (n != nargs - 1) |
4267 | printf (","); | |
4268 | } | |
4269 | printf ("\n"); | |
4270 | } | |
4271 | break; | |
4272 | } | |
4273 | } | |
4274 | ||
4275 | printf ("\n"); | |
b4eb7656 | 4276 | } |
4ccf1e31 JJ |
4277 | |
4278 | return 1; | |
4279 | } | |
4280 | ||
19e6b90e L |
4281 | static int |
4282 | display_debug_abbrev (struct dwarf_section *section, | |
4283 | void *file ATTRIBUTE_UNUSED) | |
4284 | { | |
4285 | abbrev_entry *entry; | |
4286 | unsigned char *start = section->start; | |
4287 | unsigned char *end = start + section->size; | |
4288 | ||
4289 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4290 | ||
4291 | do | |
4292 | { | |
7282333f AM |
4293 | unsigned char *last; |
4294 | ||
19e6b90e L |
4295 | free_abbrevs (); |
4296 | ||
7282333f | 4297 | last = start; |
19e6b90e L |
4298 | start = process_abbrev_section (start, end); |
4299 | ||
4300 | if (first_abbrev == NULL) | |
4301 | continue; | |
4302 | ||
7282333f | 4303 | printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); |
19e6b90e L |
4304 | |
4305 | for (entry = first_abbrev; entry; entry = entry->next) | |
4306 | { | |
4307 | abbrev_attr *attr; | |
4308 | ||
cc5914eb | 4309 | printf (" %ld %s [%s]\n", |
19e6b90e L |
4310 | entry->entry, |
4311 | get_TAG_name (entry->tag), | |
4312 | entry->children ? _("has children") : _("no children")); | |
4313 | ||
4314 | for (attr = entry->first_attr; attr; attr = attr->next) | |
cc5914eb | 4315 | printf (" %-18s %s\n", |
19e6b90e L |
4316 | get_AT_name (attr->attribute), |
4317 | get_FORM_name (attr->form)); | |
4318 | } | |
4319 | } | |
4320 | while (start); | |
4321 | ||
4322 | printf ("\n"); | |
4323 | ||
4324 | return 1; | |
4325 | } | |
4326 | ||
4723351a CC |
4327 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
4328 | ||
4329 | static void | |
4330 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
4331 | unsigned char **start_ptr, |
4332 | unsigned int debug_info_entry, | |
4333 | unsigned long offset, | |
4334 | unsigned long base_address, | |
4335 | int has_frame_base) | |
4723351a CC |
4336 | { |
4337 | unsigned char *start = *start_ptr; | |
4338 | unsigned char *section_end = section->start + section->size; | |
82b1b41b NC |
4339 | unsigned long cu_offset; |
4340 | unsigned int pointer_size; | |
4341 | unsigned int offset_size; | |
4342 | int dwarf_version; | |
4723351a CC |
4343 | |
4344 | dwarf_vma begin; | |
4345 | dwarf_vma end; | |
4346 | unsigned short length; | |
4347 | int need_frame_base; | |
4348 | ||
82b1b41b NC |
4349 | if (debug_info_entry >= num_debug_info_entries) |
4350 | { | |
4351 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
4352 | debug_info_entry); | |
4353 | return; | |
4354 | } | |
b4eb7656 | 4355 | |
82b1b41b NC |
4356 | cu_offset = debug_information [debug_info_entry].cu_offset; |
4357 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
4358 | offset_size = debug_information [debug_info_entry].offset_size; | |
4359 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 4360 | |
f41e4712 NC |
4361 | if (pointer_size < 2 || pointer_size > 8) |
4362 | { | |
4363 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
4364 | pointer_size, debug_info_entry); | |
4365 | return; | |
4366 | } | |
4367 | ||
4723351a CC |
4368 | while (1) |
4369 | { | |
4370 | if (start + 2 * pointer_size > section_end) | |
b4eb7656 AM |
4371 | { |
4372 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
4373 | offset); | |
4374 | break; | |
4375 | } | |
4723351a | 4376 | |
fab128ef CC |
4377 | printf (" %8.8lx ", offset + (start - *start_ptr)); |
4378 | ||
4723351a | 4379 | /* Note: we use sign extension here in order to be sure that we can detect |
b4eb7656 AM |
4380 | the -1 escape value. Sign extension into the top 32 bits of a 32-bit |
4381 | address will not affect the values that we display since we always show | |
4382 | hex values, and always the bottom 32-bits. */ | |
0c588247 NC |
4383 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
4384 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 4385 | |
4723351a | 4386 | if (begin == 0 && end == 0) |
b4eb7656 AM |
4387 | { |
4388 | printf (_("<End of list>\n")); | |
4389 | break; | |
4390 | } | |
4723351a CC |
4391 | |
4392 | /* Check base address specifiers. */ | |
4393 | if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1) | |
b4eb7656 AM |
4394 | { |
4395 | base_address = end; | |
4396 | print_dwarf_vma (begin, pointer_size); | |
4397 | print_dwarf_vma (end, pointer_size); | |
4398 | printf (_("(base address)\n")); | |
4399 | continue; | |
4400 | } | |
4723351a CC |
4401 | |
4402 | if (start + 2 > section_end) | |
b4eb7656 AM |
4403 | { |
4404 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
4405 | offset); | |
4406 | break; | |
4407 | } | |
4723351a | 4408 | |
0c588247 | 4409 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
4410 | |
4411 | if (start + length > section_end) | |
b4eb7656 AM |
4412 | { |
4413 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
4414 | offset); | |
4415 | break; | |
4416 | } | |
4723351a CC |
4417 | |
4418 | print_dwarf_vma (begin + base_address, pointer_size); | |
4419 | print_dwarf_vma (end + base_address, pointer_size); | |
4420 | ||
4421 | putchar ('('); | |
4422 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
4423 | pointer_size, |
4424 | offset_size, | |
4425 | dwarf_version, | |
4426 | length, | |
4427 | cu_offset, section); | |
4723351a CC |
4428 | putchar (')'); |
4429 | ||
4430 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 4431 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
4432 | |
4433 | if (begin == end) | |
b4eb7656 | 4434 | fputs (_(" (start == end)"), stdout); |
4723351a | 4435 | else if (begin > end) |
b4eb7656 | 4436 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
4437 | |
4438 | putchar ('\n'); | |
4439 | ||
4440 | start += length; | |
4441 | } | |
4442 | ||
4443 | *start_ptr = start; | |
4444 | } | |
4445 | ||
fab128ef CC |
4446 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
4447 | right-adjusted in a field of length LEN, and followed by a space. */ | |
4448 | ||
4449 | static void | |
4450 | print_addr_index (unsigned int idx, unsigned int len) | |
4451 | { | |
4452 | static char buf[15]; | |
4453 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 4454 | printf ("%*s ", len, buf); |
fab128ef CC |
4455 | } |
4456 | ||
4723351a CC |
4457 | /* Display a location list from a .dwo section. It uses address indexes rather |
4458 | than embedded addresses. This code closely follows display_loc_list, but the | |
4459 | two are sufficiently different that combining things is very ugly. */ | |
4460 | ||
4461 | static void | |
4462 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
4463 | unsigned char **start_ptr, |
4464 | unsigned int debug_info_entry, | |
4465 | unsigned long offset, | |
4466 | int has_frame_base) | |
4723351a CC |
4467 | { |
4468 | unsigned char *start = *start_ptr; | |
4469 | unsigned char *section_end = section->start + section->size; | |
82b1b41b NC |
4470 | unsigned long cu_offset; |
4471 | unsigned int pointer_size; | |
4472 | unsigned int offset_size; | |
4473 | int dwarf_version; | |
4723351a CC |
4474 | int entry_type; |
4475 | unsigned short length; | |
4476 | int need_frame_base; | |
fab128ef | 4477 | unsigned int idx; |
4723351a CC |
4478 | unsigned int bytes_read; |
4479 | ||
82b1b41b NC |
4480 | if (debug_info_entry >= num_debug_info_entries) |
4481 | { | |
4482 | warn (_("No debug information for loc lists of entry: %u\n"), | |
4483 | debug_info_entry); | |
4484 | return; | |
4485 | } | |
4486 | ||
4487 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
4488 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
4489 | offset_size = debug_information [debug_info_entry].offset_size; | |
4490 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
4491 | ||
f41e4712 NC |
4492 | if (pointer_size < 2 || pointer_size > 8) |
4493 | { | |
4494 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
4495 | pointer_size, debug_info_entry); | |
4496 | return; | |
4497 | } | |
4498 | ||
4723351a CC |
4499 | while (1) |
4500 | { | |
fab128ef | 4501 | printf (" %8.8lx ", offset + (start - *start_ptr)); |
4723351a | 4502 | |
fab128ef | 4503 | if (start >= section_end) |
b4eb7656 AM |
4504 | { |
4505 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
4506 | offset); | |
4507 | break; | |
4508 | } | |
4723351a | 4509 | |
0c588247 | 4510 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
4723351a | 4511 | switch (entry_type) |
b4eb7656 AM |
4512 | { |
4513 | case 0: /* A terminating entry. */ | |
4514 | *start_ptr = start; | |
4515 | printf (_("<End of list>\n")); | |
4516 | return; | |
4517 | case 1: /* A base-address entry. */ | |
4518 | idx = read_uleb128 (start, &bytes_read, section_end); | |
4519 | start += bytes_read; | |
4520 | print_addr_index (idx, 8); | |
4521 | printf (" "); | |
4522 | printf (_("(base address selection entry)\n")); | |
4523 | continue; | |
4524 | case 2: /* A start/end entry. */ | |
4525 | idx = read_uleb128 (start, &bytes_read, section_end); | |
4526 | start += bytes_read; | |
4527 | print_addr_index (idx, 8); | |
4528 | idx = read_uleb128 (start, &bytes_read, section_end); | |
4529 | start += bytes_read; | |
4530 | print_addr_index (idx, 8); | |
4531 | break; | |
4532 | case 3: /* A start/length entry. */ | |
4533 | idx = read_uleb128 (start, &bytes_read, section_end); | |
4534 | start += bytes_read; | |
4535 | print_addr_index (idx, 8); | |
4536 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
4537 | printf ("%08x ", idx); | |
4538 | break; | |
4539 | case 4: /* An offset pair entry. */ | |
4540 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
4541 | printf ("%08x ", idx); | |
4542 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
4543 | printf ("%08x ", idx); | |
4544 | break; | |
4545 | default: | |
4546 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
4547 | *start_ptr = start; | |
4548 | return; | |
4549 | } | |
4723351a CC |
4550 | |
4551 | if (start + 2 > section_end) | |
b4eb7656 AM |
4552 | { |
4553 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
4554 | offset); | |
4555 | break; | |
4556 | } | |
4723351a | 4557 | |
0c588247 | 4558 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 4559 | if (start + length > section_end) |
b4eb7656 AM |
4560 | { |
4561 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
4562 | offset); | |
4563 | break; | |
4564 | } | |
4723351a CC |
4565 | |
4566 | putchar ('('); | |
4567 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
4568 | pointer_size, |
4569 | offset_size, | |
4570 | dwarf_version, | |
4571 | length, | |
4572 | cu_offset, section); | |
4723351a CC |
4573 | putchar (')'); |
4574 | ||
4575 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 4576 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
4577 | |
4578 | putchar ('\n'); | |
4579 | ||
4580 | start += length; | |
4581 | } | |
4582 | ||
4583 | *start_ptr = start; | |
4584 | } | |
4585 | ||
51d0d03f JJ |
4586 | /* Sort array of indexes in ascending order of loc_offsets[idx]. */ |
4587 | ||
4588 | static dwarf_vma *loc_offsets; | |
4589 | ||
4590 | static int | |
4591 | loc_offsets_compar (const void *ap, const void *bp) | |
4592 | { | |
4593 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
4594 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
4595 | ||
4596 | return (a > b) - (b > a); | |
4597 | } | |
4598 | ||
19e6b90e L |
4599 | static int |
4600 | display_debug_loc (struct dwarf_section *section, void *file) | |
4601 | { | |
4602 | unsigned char *start = section->start; | |
19e6b90e L |
4603 | unsigned long bytes; |
4604 | unsigned char *section_begin = start; | |
4605 | unsigned int num_loc_list = 0; | |
4606 | unsigned long last_offset = 0; | |
4607 | unsigned int first = 0; | |
4608 | unsigned int i; | |
4609 | unsigned int j; | |
51d0d03f | 4610 | unsigned int k; |
19e6b90e | 4611 | int seen_first_offset = 0; |
51d0d03f | 4612 | int locs_sorted = 1; |
19e6b90e | 4613 | unsigned char *next; |
51d0d03f | 4614 | unsigned int *array = NULL; |
4723351a CC |
4615 | const char *suffix = strrchr (section->name, '.'); |
4616 | int is_dwo = 0; | |
4617 | ||
4618 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
4619 | is_dwo = 1; | |
19e6b90e L |
4620 | |
4621 | bytes = section->size; | |
19e6b90e L |
4622 | |
4623 | if (bytes == 0) | |
4624 | { | |
4625 | printf (_("\nThe %s section is empty.\n"), section->name); | |
4626 | return 0; | |
4627 | } | |
4628 | ||
1febe64d NC |
4629 | if (load_debug_info (file) == 0) |
4630 | { | |
4631 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
4632 | section->name); | |
4633 | return 0; | |
4634 | } | |
19e6b90e L |
4635 | |
4636 | /* Check the order of location list in .debug_info section. If | |
4637 | offsets of location lists are in the ascending order, we can | |
4638 | use `debug_information' directly. */ | |
4639 | for (i = 0; i < num_debug_info_entries; i++) | |
4640 | { | |
4641 | unsigned int num; | |
4642 | ||
4643 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
4644 | if (num > num_loc_list) |
4645 | num_loc_list = num; | |
19e6b90e L |
4646 | |
4647 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 4648 | if (locs_sorted && num != 0) |
19e6b90e L |
4649 | { |
4650 | if (!seen_first_offset) | |
4651 | { | |
4652 | /* This is the first location list. */ | |
4653 | last_offset = debug_information [i].loc_offsets [0]; | |
4654 | first = i; | |
4655 | seen_first_offset = 1; | |
4656 | j = 1; | |
4657 | } | |
4658 | else | |
4659 | j = 0; | |
4660 | ||
4661 | for (; j < num; j++) | |
4662 | { | |
4663 | if (last_offset > | |
4664 | debug_information [i].loc_offsets [j]) | |
4665 | { | |
51d0d03f | 4666 | locs_sorted = 0; |
19e6b90e L |
4667 | break; |
4668 | } | |
4669 | last_offset = debug_information [i].loc_offsets [j]; | |
4670 | } | |
4671 | } | |
4672 | } | |
4673 | ||
19e6b90e L |
4674 | if (!seen_first_offset) |
4675 | error (_("No location lists in .debug_info section!\n")); | |
4676 | ||
d4bfc77b | 4677 | if (debug_information [first].num_loc_offsets > 0 |
d493b283 | 4678 | && debug_information [first].loc_offsets [0] != 0) |
47704ddf KT |
4679 | warn (_("Location lists in %s section start at 0x%s\n"), |
4680 | section->name, | |
4681 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 4682 | |
51d0d03f JJ |
4683 | if (!locs_sorted) |
4684 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
19e6b90e | 4685 | printf (_("Contents of the %s section:\n\n"), section->name); |
fab128ef | 4686 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
4687 | |
4688 | seen_first_offset = 0; | |
4689 | for (i = first; i < num_debug_info_entries; i++) | |
4690 | { | |
19e6b90e | 4691 | unsigned long offset; |
19e6b90e | 4692 | unsigned long base_address; |
19e6b90e L |
4693 | int has_frame_base; |
4694 | ||
51d0d03f JJ |
4695 | if (!locs_sorted) |
4696 | { | |
4697 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
4698 | array[k] = k; | |
4699 | loc_offsets = debug_information [i].loc_offsets; | |
4700 | qsort (array, debug_information [i].num_loc_offsets, | |
4701 | sizeof (*array), loc_offsets_compar); | |
4702 | } | |
19e6b90e | 4703 | |
51d0d03f | 4704 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 4705 | { |
51d0d03f JJ |
4706 | j = locs_sorted ? k : array[k]; |
4707 | if (k | |
4708 | && debug_information [i].loc_offsets [locs_sorted | |
4709 | ? k - 1 : array [k - 1]] | |
4710 | == debug_information [i].loc_offsets [j]) | |
4711 | continue; | |
19e6b90e | 4712 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 4713 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e L |
4714 | next = section_begin + offset; |
4715 | base_address = debug_information [i].base_address; | |
4716 | ||
4717 | if (!seen_first_offset) | |
4718 | seen_first_offset = 1; | |
4719 | else | |
4720 | { | |
4721 | if (start < next) | |
4722 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 4723 | (unsigned long) (start - section_begin), |
c8071705 | 4724 | (unsigned long) offset); |
19e6b90e L |
4725 | else if (start > next) |
4726 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 4727 | (unsigned long) (start - section_begin), |
c8071705 | 4728 | (unsigned long) offset); |
19e6b90e L |
4729 | } |
4730 | start = next; | |
4731 | ||
4732 | if (offset >= bytes) | |
4733 | { | |
4734 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
4735 | offset); | |
4736 | continue; | |
4737 | } | |
4738 | ||
b4eb7656 AM |
4739 | if (is_dwo) |
4740 | display_loc_list_dwo (section, &start, i, offset, has_frame_base); | |
4741 | else | |
4742 | display_loc_list (section, &start, i, offset, base_address, | |
4743 | has_frame_base); | |
19e6b90e L |
4744 | } |
4745 | } | |
031cd65f | 4746 | |
4723351a | 4747 | if (start < section->start + section->size) |
031cd65f | 4748 | warn (_("There are %ld unused bytes at the end of section %s\n"), |
4723351a | 4749 | (long) (section->start + section->size - start), section->name); |
98fb390a | 4750 | putchar ('\n'); |
51d0d03f | 4751 | free (array); |
19e6b90e L |
4752 | return 1; |
4753 | } | |
4754 | ||
4755 | static int | |
4756 | display_debug_str (struct dwarf_section *section, | |
4757 | void *file ATTRIBUTE_UNUSED) | |
4758 | { | |
4759 | unsigned char *start = section->start; | |
4760 | unsigned long bytes = section->size; | |
4761 | dwarf_vma addr = section->address; | |
4762 | ||
4763 | if (bytes == 0) | |
4764 | { | |
4765 | printf (_("\nThe %s section is empty.\n"), section->name); | |
4766 | return 0; | |
4767 | } | |
4768 | ||
4769 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4770 | ||
4771 | while (bytes) | |
4772 | { | |
4773 | int j; | |
4774 | int k; | |
4775 | int lbytes; | |
4776 | ||
4777 | lbytes = (bytes > 16 ? 16 : bytes); | |
4778 | ||
4779 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
4780 | ||
4781 | for (j = 0; j < 16; j++) | |
4782 | { | |
4783 | if (j < lbytes) | |
4784 | printf ("%2.2x", start[j]); | |
4785 | else | |
4786 | printf (" "); | |
4787 | ||
4788 | if ((j & 3) == 3) | |
4789 | printf (" "); | |
4790 | } | |
4791 | ||
4792 | for (j = 0; j < lbytes; j++) | |
4793 | { | |
4794 | k = start[j]; | |
4795 | if (k >= ' ' && k < 0x80) | |
4796 | printf ("%c", k); | |
4797 | else | |
4798 | printf ("."); | |
4799 | } | |
4800 | ||
4801 | putchar ('\n'); | |
4802 | ||
4803 | start += lbytes; | |
4804 | addr += lbytes; | |
4805 | bytes -= lbytes; | |
4806 | } | |
4807 | ||
4808 | putchar ('\n'); | |
4809 | ||
4810 | return 1; | |
4811 | } | |
4812 | ||
19e6b90e L |
4813 | static int |
4814 | display_debug_info (struct dwarf_section *section, void *file) | |
4815 | { | |
4723351a | 4816 | return process_debug_info (section, file, section->abbrev_sec, 0, 0); |
19e6b90e L |
4817 | } |
4818 | ||
2b6f5997 CC |
4819 | static int |
4820 | display_debug_types (struct dwarf_section *section, void *file) | |
4821 | { | |
4723351a | 4822 | return process_debug_info (section, file, section->abbrev_sec, 0, 1); |
6f875884 TG |
4823 | } |
4824 | ||
4825 | static int | |
4826 | display_trace_info (struct dwarf_section *section, void *file) | |
4827 | { | |
4723351a | 4828 | return process_debug_info (section, file, section->abbrev_sec, 0, 0); |
2b6f5997 | 4829 | } |
19e6b90e L |
4830 | |
4831 | static int | |
4832 | display_debug_aranges (struct dwarf_section *section, | |
4833 | void *file ATTRIBUTE_UNUSED) | |
4834 | { | |
4835 | unsigned char *start = section->start; | |
4836 | unsigned char *end = start + section->size; | |
4837 | ||
80c35038 | 4838 | printf (_("Contents of the %s section:\n\n"), section->name); |
19e6b90e | 4839 | |
6e3d6dc1 NC |
4840 | /* It does not matter if this load fails, |
4841 | we test for that later on. */ | |
4842 | load_debug_info (file); | |
4843 | ||
19e6b90e L |
4844 | while (start < end) |
4845 | { | |
4846 | unsigned char *hdrptr; | |
4847 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 4848 | unsigned char *addr_ranges; |
2d9472a2 NC |
4849 | dwarf_vma length; |
4850 | dwarf_vma address; | |
53b8873b | 4851 | unsigned char address_size; |
19e6b90e | 4852 | int excess; |
bf5117e3 NC |
4853 | unsigned int offset_size; |
4854 | unsigned int initial_length_size; | |
19e6b90e L |
4855 | |
4856 | hdrptr = start; | |
4857 | ||
0c588247 | 4858 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
4859 | if (arange.ar_length == 0xffffffff) |
4860 | { | |
0c588247 | 4861 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
4862 | offset_size = 8; |
4863 | initial_length_size = 12; | |
4864 | } | |
4865 | else | |
4866 | { | |
4867 | offset_size = 4; | |
4868 | initial_length_size = 4; | |
4869 | } | |
4870 | ||
0c588247 NC |
4871 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
4872 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 4873 | |
6e3d6dc1 NC |
4874 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
4875 | && num_debug_info_entries > 0 | |
4876 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
4877 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 4878 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 4879 | |
0c588247 NC |
4880 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
4881 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
4882 | |
4883 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
4884 | { | |
4885 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
4886 | break; | |
4887 | } | |
4888 | ||
47704ddf KT |
4889 | printf (_(" Length: %ld\n"), |
4890 | (long) arange.ar_length); | |
19e6b90e | 4891 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
4892 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
4893 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
4894 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
4895 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
4896 | ||
53b8873b NC |
4897 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
4898 | ||
f41e4712 NC |
4899 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
4900 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
4901 | { |
4902 | error (_("Invalid address size in %s section!\n"), | |
4903 | section->name); | |
4904 | break; | |
4905 | } | |
4906 | ||
53b8873b NC |
4907 | /* The DWARF spec does not require that the address size be a power |
4908 | of two, but we do. This will have to change if we ever encounter | |
4909 | an uneven architecture. */ | |
4910 | if ((address_size & (address_size - 1)) != 0) | |
4911 | { | |
4912 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
4913 | break; | |
4914 | } | |
cecf136e | 4915 | |
209c9a13 NC |
4916 | if (address_size > 4) |
4917 | printf (_("\n Address Length\n")); | |
4918 | else | |
4919 | printf (_("\n Address Length\n")); | |
19e6b90e | 4920 | |
91d6fa6a | 4921 | addr_ranges = hdrptr; |
19e6b90e | 4922 | |
53b8873b NC |
4923 | /* Must pad to an alignment boundary that is twice the address size. */ |
4924 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 4925 | if (excess) |
91d6fa6a | 4926 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 4927 | |
ffc0f143 NC |
4928 | hdrptr = start + arange.ar_length + initial_length_size; |
4929 | if (hdrptr < start || hdrptr > end) | |
4930 | { | |
4931 | error (_("Excessive header length: %lx\n"), (long) arange.ar_length); | |
4932 | break; | |
4933 | } | |
4934 | start = hdrptr; | |
1617e571 | 4935 | |
91d6fa6a | 4936 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 4937 | { |
0c588247 NC |
4938 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
4939 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 4940 | |
80c35038 | 4941 | printf (" "); |
2d9472a2 NC |
4942 | print_dwarf_vma (address, address_size); |
4943 | print_dwarf_vma (length, address_size); | |
4944 | putchar ('\n'); | |
19e6b90e | 4945 | } |
19e6b90e L |
4946 | } |
4947 | ||
4948 | printf ("\n"); | |
4949 | ||
4950 | return 1; | |
4951 | } | |
4952 | ||
4723351a CC |
4953 | /* Comparison function for qsort. */ |
4954 | static int | |
4955 | comp_addr_base (const void * v0, const void * v1) | |
4956 | { | |
4957 | debug_info * info0 = (debug_info *) v0; | |
4958 | debug_info * info1 = (debug_info *) v1; | |
4959 | return info0->addr_base - info1->addr_base; | |
4960 | } | |
4961 | ||
4962 | /* Display the debug_addr section. */ | |
4963 | static int | |
4964 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 4965 | void *file) |
4723351a CC |
4966 | { |
4967 | debug_info **debug_addr_info; | |
4968 | unsigned char *entry; | |
4969 | unsigned char *end; | |
4970 | unsigned int i; | |
4971 | unsigned int count; | |
4972 | ||
4973 | if (section->size == 0) | |
4974 | { | |
4975 | printf (_("\nThe %s section is empty.\n"), section->name); | |
4976 | return 0; | |
4977 | } | |
4978 | ||
4979 | if (load_debug_info (file) == 0) | |
4980 | { | |
4981 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
4982 | section->name); | |
4983 | return 0; | |
4984 | } | |
4985 | ||
4986 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4987 | ||
1306a742 NC |
4988 | /* PR 17531: file: cf38d01b. |
4989 | We use xcalloc because a corrupt file may not have initialised all of the | |
4990 | fields in the debug_info structure, which means that the sort below might | |
4991 | try to move uninitialised data. */ | |
4992 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 4993 | sizeof (debug_info *)); |
4723351a CC |
4994 | |
4995 | count = 0; | |
4996 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 4997 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
4998 | { |
4999 | /* PR 17531: file: cf38d01b. */ | |
5000 | if (debug_information[i].addr_base >= section->size) | |
5001 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
5002 | (unsigned long) debug_information[i].addr_base, i); | |
5003 | else | |
5004 | debug_addr_info [count++] = debug_information + i; | |
5005 | } | |
4723351a CC |
5006 | |
5007 | /* Add a sentinel to make iteration convenient. */ | |
5008 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
5009 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 5010 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 5011 | |
4723351a CC |
5012 | for (i = 0; i < count; i++) |
5013 | { | |
5014 | unsigned int idx; | |
fab128ef | 5015 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
5016 | |
5017 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 5018 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 5019 | |
fab128ef | 5020 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
5021 | entry = section->start + debug_addr_info [i]->addr_base; |
5022 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
5023 | idx = 0; | |
5024 | while (entry < end) | |
b4eb7656 AM |
5025 | { |
5026 | dwarf_vma base = byte_get (entry, address_size); | |
5027 | printf (_("\t%d:\t"), idx); | |
5028 | print_dwarf_vma (base, address_size); | |
5029 | printf ("\n"); | |
5030 | entry += address_size; | |
5031 | idx++; | |
5032 | } | |
4723351a CC |
5033 | } |
5034 | printf ("\n"); | |
5035 | ||
5036 | free (debug_addr_info); | |
5037 | return 1; | |
5038 | } | |
5039 | ||
5040 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
5041 | static int | |
5042 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 5043 | void *file ATTRIBUTE_UNUSED) |
4723351a CC |
5044 | { |
5045 | if (section->size == 0) | |
5046 | { | |
5047 | printf (_("\nThe %s section is empty.\n"), section->name); | |
5048 | return 0; | |
5049 | } | |
5050 | /* TODO: Dump the contents. This is made somewhat difficult by not knowing | |
5051 | what the offset size is for this section. */ | |
5052 | return 1; | |
5053 | } | |
5054 | ||
01a8f077 JK |
5055 | /* Each debug_information[x].range_lists[y] gets this representation for |
5056 | sorting purposes. */ | |
5057 | ||
5058 | struct range_entry | |
467c65bc NC |
5059 | { |
5060 | /* The debug_information[x].range_lists[y] value. */ | |
5061 | unsigned long ranges_offset; | |
01a8f077 | 5062 | |
467c65bc NC |
5063 | /* Original debug_information to find parameters of the data. */ |
5064 | debug_info *debug_info_p; | |
5065 | }; | |
01a8f077 JK |
5066 | |
5067 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
5068 | ||
5069 | static int | |
5070 | range_entry_compar (const void *ap, const void *bp) | |
5071 | { | |
3f5e193b NC |
5072 | const struct range_entry *a_re = (const struct range_entry *) ap; |
5073 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
01a8f077 JK |
5074 | const unsigned long a = a_re->ranges_offset; |
5075 | const unsigned long b = b_re->ranges_offset; | |
5076 | ||
5077 | return (a > b) - (b > a); | |
5078 | } | |
5079 | ||
19e6b90e L |
5080 | static int |
5081 | display_debug_ranges (struct dwarf_section *section, | |
5082 | void *file ATTRIBUTE_UNUSED) | |
5083 | { | |
5084 | unsigned char *start = section->start; | |
a2ff7a4b | 5085 | unsigned char *last_start = start; |
f6f0e17b | 5086 | unsigned long bytes = section->size; |
19e6b90e | 5087 | unsigned char *section_begin = start; |
f6f0e17b | 5088 | unsigned char *finish = start + bytes; |
01a8f077 JK |
5089 | unsigned int num_range_list, i; |
5090 | struct range_entry *range_entries, *range_entry_fill; | |
19e6b90e | 5091 | |
19e6b90e L |
5092 | if (bytes == 0) |
5093 | { | |
5094 | printf (_("\nThe %s section is empty.\n"), section->name); | |
5095 | return 0; | |
5096 | } | |
5097 | ||
1febe64d NC |
5098 | if (load_debug_info (file) == 0) |
5099 | { | |
5100 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
5101 | section->name); | |
5102 | return 0; | |
5103 | } | |
19e6b90e | 5104 | |
01a8f077 | 5105 | num_range_list = 0; |
19e6b90e | 5106 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 5107 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 5108 | |
01a8f077 | 5109 | if (num_range_list == 0) |
4723351a CC |
5110 | { |
5111 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 5112 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
5113 | printf (_("No range lists in .debug_info section.\n")); |
5114 | return 1; | |
5115 | } | |
19e6b90e | 5116 | |
3f5e193b NC |
5117 | range_entries = (struct range_entry *) |
5118 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 5119 | range_entry_fill = range_entries; |
19e6b90e | 5120 | |
01a8f077 JK |
5121 | for (i = 0; i < num_debug_info_entries; i++) |
5122 | { | |
5123 | debug_info *debug_info_p = &debug_information[i]; | |
5124 | unsigned int j; | |
5125 | ||
5126 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
5127 | { | |
5128 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
5129 | range_entry_fill->debug_info_p = debug_info_p; | |
5130 | range_entry_fill++; | |
19e6b90e L |
5131 | } |
5132 | } | |
5133 | ||
01a8f077 JK |
5134 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
5135 | range_entry_compar); | |
19e6b90e | 5136 | |
d493b283 | 5137 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 5138 | warn (_("Range lists in %s section start at 0x%lx\n"), |
01a8f077 | 5139 | section->name, range_entries[0].ranges_offset); |
19e6b90e L |
5140 | |
5141 | printf (_("Contents of the %s section:\n\n"), section->name); | |
5142 | printf (_(" Offset Begin End\n")); | |
5143 | ||
01a8f077 | 5144 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 5145 | { |
01a8f077 JK |
5146 | struct range_entry *range_entry = &range_entries[i]; |
5147 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 5148 | unsigned int pointer_size; |
01a8f077 JK |
5149 | unsigned long offset; |
5150 | unsigned char *next; | |
19e6b90e L |
5151 | unsigned long base_address; |
5152 | ||
01a8f077 | 5153 | pointer_size = debug_info_p->pointer_size; |
d493b283 | 5154 | offset = range_entry->ranges_offset; |
01a8f077 JK |
5155 | next = section_begin + offset; |
5156 | base_address = debug_info_p->base_address; | |
cecf136e | 5157 | |
f41e4712 NC |
5158 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
5159 | if (pointer_size < 2 || pointer_size > 8) | |
5160 | { | |
5161 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
5162 | pointer_size, offset); | |
5163 | continue; | |
5164 | } | |
b4eb7656 | 5165 | |
4723351a | 5166 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 5167 | { |
01a8f077 JK |
5168 | if (start < next) |
5169 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
5170 | (unsigned long) (start - section_begin), | |
5171 | (unsigned long) (next - section_begin), section->name); | |
5172 | else if (start > next) | |
a2ff7a4b AM |
5173 | { |
5174 | if (next == last_start) | |
5175 | continue; | |
5176 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
5177 | (unsigned long) (start - section_begin), | |
5178 | (unsigned long) (next - section_begin), section->name); | |
5179 | } | |
01a8f077 JK |
5180 | } |
5181 | start = next; | |
a2ff7a4b | 5182 | last_start = next; |
19e6b90e | 5183 | |
f6f0e17b | 5184 | while (start < finish) |
01a8f077 JK |
5185 | { |
5186 | dwarf_vma begin; | |
5187 | dwarf_vma end; | |
5188 | ||
5189 | /* Note: we use sign extension here in order to be sure that | |
5190 | we can detect the -1 escape value. Sign extension into the | |
5191 | top 32 bits of a 32-bit address will not affect the values | |
5192 | that we display since we always show hex values, and always | |
5193 | the bottom 32-bits. */ | |
0c588247 | 5194 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); |
f6f0e17b NC |
5195 | if (start >= finish) |
5196 | break; | |
0c588247 | 5197 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); |
01a8f077 JK |
5198 | |
5199 | printf (" %8.8lx ", offset); | |
5200 | ||
5201 | if (begin == 0 && end == 0) | |
19e6b90e | 5202 | { |
01a8f077 JK |
5203 | printf (_("<End of list>\n")); |
5204 | break; | |
19e6b90e | 5205 | } |
19e6b90e | 5206 | |
01a8f077 JK |
5207 | /* Check base address specifiers. */ |
5208 | if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1) | |
19e6b90e | 5209 | { |
01a8f077 JK |
5210 | base_address = end; |
5211 | print_dwarf_vma (begin, pointer_size); | |
5212 | print_dwarf_vma (end, pointer_size); | |
5213 | printf ("(base address)\n"); | |
5214 | continue; | |
5215 | } | |
19e6b90e | 5216 | |
01a8f077 JK |
5217 | print_dwarf_vma (begin + base_address, pointer_size); |
5218 | print_dwarf_vma (end + base_address, pointer_size); | |
4a149252 | 5219 | |
01a8f077 JK |
5220 | if (begin == end) |
5221 | fputs (_("(start == end)"), stdout); | |
5222 | else if (begin > end) | |
5223 | fputs (_("(start > end)"), stdout); | |
19e6b90e | 5224 | |
01a8f077 | 5225 | putchar ('\n'); |
19e6b90e L |
5226 | } |
5227 | } | |
5228 | putchar ('\n'); | |
01a8f077 JK |
5229 | |
5230 | free (range_entries); | |
5231 | ||
19e6b90e L |
5232 | return 1; |
5233 | } | |
5234 | ||
5235 | typedef struct Frame_Chunk | |
5236 | { | |
5237 | struct Frame_Chunk *next; | |
5238 | unsigned char *chunk_start; | |
a1165289 | 5239 | unsigned int ncols; |
19e6b90e L |
5240 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
5241 | short int *col_type; | |
5242 | int *col_offset; | |
5243 | char *augmentation; | |
5244 | unsigned int code_factor; | |
5245 | int data_factor; | |
bf5117e3 NC |
5246 | dwarf_vma pc_begin; |
5247 | dwarf_vma pc_range; | |
19e6b90e | 5248 | int cfa_reg; |
c8071705 | 5249 | dwarf_vma cfa_offset; |
a1165289 | 5250 | unsigned int ra; |
19e6b90e L |
5251 | unsigned char fde_encoding; |
5252 | unsigned char cfa_exp; | |
604282a7 JJ |
5253 | unsigned char ptr_size; |
5254 | unsigned char segment_size; | |
19e6b90e L |
5255 | } |
5256 | Frame_Chunk; | |
5257 | ||
665ce1f6 L |
5258 | static const char *const *dwarf_regnames; |
5259 | static unsigned int dwarf_regnames_count; | |
5260 | ||
19e6b90e L |
5261 | /* A marker for a col_type that means this column was never referenced |
5262 | in the frame info. */ | |
5263 | #define DW_CFA_unreferenced (-1) | |
5264 | ||
a1165289 | 5265 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
5266 | -1 for invalid reg. */ |
5267 | ||
5268 | static int | |
5269 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 5270 | { |
a1165289 | 5271 | unsigned int prev = fc->ncols; |
19e6b90e | 5272 | |
665ce1f6 L |
5273 | if (reg < (unsigned int) fc->ncols) |
5274 | return 0; | |
5275 | ||
5276 | if (dwarf_regnames_count | |
5277 | && reg > dwarf_regnames_count) | |
5278 | return -1; | |
19e6b90e L |
5279 | |
5280 | fc->ncols = reg + 1; | |
a1165289 NC |
5281 | /* PR 17512: file: 10450-2643-0.004. |
5282 | If reg == -1 then this can happen... */ | |
5283 | if (fc->ncols == 0) | |
5284 | return -1; | |
5285 | ||
06614111 NC |
5286 | /* PR 17512: file: 2844a11d. */ |
5287 | if (fc->ncols > 1024) | |
5288 | { | |
5289 | error (_("Unfeasibly large register number: %u\n"), reg); | |
5290 | fc->ncols = 0; | |
5291 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
5292 | we ever encounter a valid binary that exceeds it. */ | |
5293 | return -1; | |
5294 | } | |
5295 | ||
3f5e193b | 5296 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 5297 | sizeof (short int)); |
3f5e193b | 5298 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 5299 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
5300 | if (fc->col_type == NULL || fc->col_offset == NULL) |
5301 | { | |
5302 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
5303 | fc->ncols); | |
5304 | fc->ncols = 0; | |
5305 | return -1; | |
5306 | } | |
19e6b90e L |
5307 | |
5308 | while (prev < fc->ncols) | |
5309 | { | |
5310 | fc->col_type[prev] = DW_CFA_unreferenced; | |
5311 | fc->col_offset[prev] = 0; | |
5312 | prev++; | |
5313 | } | |
665ce1f6 | 5314 | return 1; |
19e6b90e L |
5315 | } |
5316 | ||
2dc4cec1 L |
5317 | static const char *const dwarf_regnames_i386[] = |
5318 | { | |
43234a1e L |
5319 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
5320 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
5321 | "eip", "eflags", NULL, /* 8 - 10 */ | |
5322 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
5323 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
5324 | NULL, NULL, /* 19 - 20 */ | |
5325 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
5326 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
5327 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
5328 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
5329 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
5330 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
5331 | "tr", "ldtr", /* 48 - 49 */ | |
5332 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
5333 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
5334 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
5335 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
5336 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
5337 | NULL, NULL, NULL, /* 90 - 92 */ | |
5338 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
5339 | }; |
5340 | ||
3d875af5 L |
5341 | static const char *const dwarf_regnames_iamcu[] = |
5342 | { | |
5343 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
5344 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
5345 | "eip", "eflags", NULL, /* 8 - 10 */ | |
5346 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
5347 | NULL, NULL, /* 19 - 20 */ | |
5348 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
5349 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
5350 | NULL, NULL, NULL, /* 37 - 39 */ | |
5351 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
5352 | "tr", "ldtr", /* 48 - 49 */ | |
5353 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
5354 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
5355 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
5356 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
5357 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
5358 | NULL, NULL, NULL, /* 90 - 92 */ | |
5359 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
5360 | }; | |
5361 | ||
b129eb0e RH |
5362 | void |
5363 | init_dwarf_regnames_i386 (void) | |
5364 | { | |
5365 | dwarf_regnames = dwarf_regnames_i386; | |
5366 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
5367 | } | |
5368 | ||
3d875af5 L |
5369 | void |
5370 | init_dwarf_regnames_iamcu (void) | |
5371 | { | |
5372 | dwarf_regnames = dwarf_regnames_iamcu; | |
5373 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
5374 | } | |
5375 | ||
2dc4cec1 L |
5376 | static const char *const dwarf_regnames_x86_64[] = |
5377 | { | |
5378 | "rax", "rdx", "rcx", "rbx", | |
5379 | "rsi", "rdi", "rbp", "rsp", | |
5380 | "r8", "r9", "r10", "r11", | |
5381 | "r12", "r13", "r14", "r15", | |
5382 | "rip", | |
5383 | "xmm0", "xmm1", "xmm2", "xmm3", | |
5384 | "xmm4", "xmm5", "xmm6", "xmm7", | |
5385 | "xmm8", "xmm9", "xmm10", "xmm11", | |
5386 | "xmm12", "xmm13", "xmm14", "xmm15", | |
5387 | "st0", "st1", "st2", "st3", | |
5388 | "st4", "st5", "st6", "st7", | |
5389 | "mm0", "mm1", "mm2", "mm3", | |
5390 | "mm4", "mm5", "mm6", "mm7", | |
5391 | "rflags", | |
5392 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
5393 | "fs.base", "gs.base", NULL, NULL, | |
5394 | "tr", "ldtr", | |
43234a1e L |
5395 | "mxcsr", "fcw", "fsw", |
5396 | "xmm16", "xmm17", "xmm18", "xmm19", | |
5397 | "xmm20", "xmm21", "xmm22", "xmm23", | |
5398 | "xmm24", "xmm25", "xmm26", "xmm27", | |
5399 | "xmm28", "xmm29", "xmm30", "xmm31", | |
5400 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
5401 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
5402 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
5403 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
5404 | NULL, NULL, NULL, /* 115 - 117 */ | |
5405 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
5406 | }; |
5407 | ||
b129eb0e RH |
5408 | void |
5409 | init_dwarf_regnames_x86_64 (void) | |
5410 | { | |
5411 | dwarf_regnames = dwarf_regnames_x86_64; | |
5412 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
5413 | } | |
5414 | ||
4ee22035 RH |
5415 | static const char *const dwarf_regnames_aarch64[] = |
5416 | { | |
b4eb7656 AM |
5417 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
5418 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
5419 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
5420 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
5421 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
5422 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
5423 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
5424 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
b4eb7656 AM |
5425 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
5426 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
5427 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
5428 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
5429 | }; | |
5430 | ||
5431 | void | |
5432 | init_dwarf_regnames_aarch64 (void) | |
5433 | { | |
5434 | dwarf_regnames = dwarf_regnames_aarch64; | |
5435 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
5436 | } | |
5437 | ||
2dc4cec1 L |
5438 | void |
5439 | init_dwarf_regnames (unsigned int e_machine) | |
5440 | { | |
5441 | switch (e_machine) | |
5442 | { | |
5443 | case EM_386: | |
b129eb0e | 5444 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
5445 | break; |
5446 | ||
3d875af5 L |
5447 | case EM_IAMCU: |
5448 | init_dwarf_regnames_iamcu (); | |
5449 | break; | |
5450 | ||
2dc4cec1 | 5451 | case EM_X86_64: |
7f502d6c | 5452 | case EM_L1OM: |
7a9068fe | 5453 | case EM_K1OM: |
b129eb0e | 5454 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
5455 | break; |
5456 | ||
4ee22035 RH |
5457 | case EM_AARCH64: |
5458 | init_dwarf_regnames_aarch64 (); | |
5459 | break; | |
5460 | ||
2dc4cec1 L |
5461 | default: |
5462 | break; | |
5463 | } | |
5464 | } | |
5465 | ||
5466 | static const char * | |
5467 | regname (unsigned int regno, int row) | |
5468 | { | |
5469 | static char reg[64]; | |
5470 | if (dwarf_regnames | |
5471 | && regno < dwarf_regnames_count | |
5472 | && dwarf_regnames [regno] != NULL) | |
5473 | { | |
5474 | if (row) | |
5475 | return dwarf_regnames [regno]; | |
5476 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, | |
5477 | dwarf_regnames [regno]); | |
5478 | } | |
5479 | else | |
5480 | snprintf (reg, sizeof (reg), "r%d", regno); | |
5481 | return reg; | |
5482 | } | |
5483 | ||
19e6b90e | 5484 | static void |
a1165289 | 5485 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 5486 | { |
a1165289 | 5487 | unsigned int r; |
19e6b90e L |
5488 | char tmp[100]; |
5489 | ||
5490 | if (*max_regs < fc->ncols) | |
5491 | *max_regs = fc->ncols; | |
5492 | ||
5493 | if (*need_col_headers) | |
5494 | { | |
91d6fa6a | 5495 | static const char *sloc = " LOC"; |
2dc4cec1 | 5496 | |
19e6b90e L |
5497 | *need_col_headers = 0; |
5498 | ||
91d6fa6a | 5499 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
5500 | |
5501 | for (r = 0; r < *max_regs; r++) | |
5502 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
5503 | { | |
5504 | if (r == fc->ra) | |
2dc4cec1 | 5505 | printf ("ra "); |
19e6b90e | 5506 | else |
2dc4cec1 | 5507 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
5508 | } |
5509 | ||
5510 | printf ("\n"); | |
5511 | } | |
5512 | ||
bf5117e3 | 5513 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
5514 | if (fc->cfa_exp) |
5515 | strcpy (tmp, "exp"); | |
5516 | else | |
c8071705 | 5517 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
5518 | printf ("%-8s ", tmp); |
5519 | ||
5520 | for (r = 0; r < fc->ncols; r++) | |
5521 | { | |
5522 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
5523 | { | |
5524 | switch (fc->col_type[r]) | |
5525 | { | |
5526 | case DW_CFA_undefined: | |
5527 | strcpy (tmp, "u"); | |
5528 | break; | |
5529 | case DW_CFA_same_value: | |
5530 | strcpy (tmp, "s"); | |
5531 | break; | |
5532 | case DW_CFA_offset: | |
5533 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
5534 | break; | |
12eae2d3 JJ |
5535 | case DW_CFA_val_offset: |
5536 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
5537 | break; | |
19e6b90e | 5538 | case DW_CFA_register: |
2dc4cec1 | 5539 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
5540 | break; |
5541 | case DW_CFA_expression: | |
5542 | strcpy (tmp, "exp"); | |
5543 | break; | |
12eae2d3 JJ |
5544 | case DW_CFA_val_expression: |
5545 | strcpy (tmp, "vexp"); | |
5546 | break; | |
19e6b90e L |
5547 | default: |
5548 | strcpy (tmp, "n/a"); | |
5549 | break; | |
5550 | } | |
2dc4cec1 | 5551 | printf ("%-5s ", tmp); |
19e6b90e L |
5552 | } |
5553 | } | |
5554 | printf ("\n"); | |
5555 | } | |
5556 | ||
49727e46 | 5557 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
f6f0e17b NC |
5558 | #define LEB() read_uleb128 (start, & length_return, end); start += length_return |
5559 | #define SLEB() read_sleb128 (start, & length_return, end); start += length_return | |
19e6b90e | 5560 | |
49727e46 AM |
5561 | static unsigned char * |
5562 | read_cie (unsigned char *start, unsigned char *end, | |
5563 | Frame_Chunk **p_cie, int *p_version, | |
5564 | unsigned long *p_aug_len, unsigned char **p_aug) | |
5565 | { | |
5566 | int version; | |
5567 | Frame_Chunk *fc; | |
5568 | unsigned int length_return; | |
5569 | unsigned char *augmentation_data = NULL; | |
5570 | unsigned long augmentation_data_len = 0; | |
5571 | ||
041830e0 | 5572 | * p_cie = NULL; |
f41e4712 NC |
5573 | /* PR 17512: file: 001-228113-0.004. */ |
5574 | if (start >= end) | |
5575 | return end; | |
5576 | ||
49727e46 AM |
5577 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
5578 | memset (fc, 0, sizeof (Frame_Chunk)); | |
5579 | ||
5580 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
5581 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
5582 | ||
5583 | version = *start++; | |
5584 | ||
5585 | fc->augmentation = (char *) start; | |
f41e4712 NC |
5586 | /* PR 17512: file: 001-228113-0.004. |
5587 | Skip past augmentation name, but avoid running off the end of the data. */ | |
5588 | while (start < end) | |
5589 | if (* start ++ == '\0') | |
5590 | break; | |
5591 | if (start == end) | |
5592 | { | |
5593 | warn (_("No terminator for augmentation name\n")); | |
5594 | return start; | |
5595 | } | |
49727e46 AM |
5596 | |
5597 | if (strcmp (fc->augmentation, "eh") == 0) | |
5598 | start += eh_addr_size; | |
5599 | ||
5600 | if (version >= 4) | |
5601 | { | |
5602 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
5603 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
5604 | { | |
5605 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
5606 | return end; | |
5607 | } | |
5608 | ||
49727e46 | 5609 | GET (fc->segment_size, 1); |
77ef8654 NC |
5610 | /* PR 17512: file: e99d2804. */ |
5611 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
5612 | { | |
5613 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
5614 | return end; | |
5615 | } | |
5616 | ||
49727e46 AM |
5617 | eh_addr_size = fc->ptr_size; |
5618 | } | |
5619 | else | |
5620 | { | |
5621 | fc->ptr_size = eh_addr_size; | |
5622 | fc->segment_size = 0; | |
5623 | } | |
5624 | fc->code_factor = LEB (); | |
5625 | fc->data_factor = SLEB (); | |
5626 | if (version == 1) | |
5627 | { | |
5628 | GET (fc->ra, 1); | |
5629 | } | |
5630 | else | |
5631 | { | |
5632 | fc->ra = LEB (); | |
5633 | } | |
5634 | ||
5635 | if (fc->augmentation[0] == 'z') | |
5636 | { | |
5637 | augmentation_data_len = LEB (); | |
5638 | augmentation_data = start; | |
5639 | start += augmentation_data_len; | |
a1165289 NC |
5640 | /* PR 17512: file: 11042-2589-0.004. */ |
5641 | if (start > end) | |
5642 | { | |
1306a742 | 5643 | warn (_("Augmentation data too long: 0x%lx\n"), augmentation_data_len); |
a1165289 NC |
5644 | return end; |
5645 | } | |
49727e46 AM |
5646 | } |
5647 | ||
5648 | if (augmentation_data_len) | |
5649 | { | |
058037d3 NC |
5650 | unsigned char *p; |
5651 | unsigned char *q; | |
5652 | unsigned char *qend; | |
b4eb7656 | 5653 | |
49727e46 AM |
5654 | p = (unsigned char *) fc->augmentation + 1; |
5655 | q = augmentation_data; | |
058037d3 NC |
5656 | qend = q + augmentation_data_len; |
5657 | ||
5658 | /* PR 17531: file: 015adfaa. */ | |
5659 | if (qend < q) | |
5660 | { | |
5661 | warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len); | |
5662 | augmentation_data_len = 0; | |
5663 | } | |
49727e46 | 5664 | |
a1165289 | 5665 | while (p < end && q < augmentation_data + augmentation_data_len) |
49727e46 AM |
5666 | { |
5667 | if (*p == 'L') | |
5668 | q++; | |
5669 | else if (*p == 'P') | |
5670 | q += 1 + size_of_encoded_value (*q); | |
5671 | else if (*p == 'R') | |
5672 | fc->fde_encoding = *q++; | |
5673 | else if (*p == 'S') | |
5674 | ; | |
5675 | else | |
5676 | break; | |
5677 | p++; | |
5678 | } | |
c361b9ac NC |
5679 | /* Note - it is OK if this loop terminates with q < qend. |
5680 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
5681 | } |
5682 | ||
5683 | *p_cie = fc; | |
5684 | if (p_version) | |
5685 | *p_version = version; | |
5686 | if (p_aug_len) | |
5687 | { | |
5688 | *p_aug_len = augmentation_data_len; | |
5689 | *p_aug = augmentation_data; | |
5690 | } | |
5691 | return start; | |
5692 | } | |
5693 | ||
19e6b90e L |
5694 | static int |
5695 | display_debug_frames (struct dwarf_section *section, | |
5696 | void *file ATTRIBUTE_UNUSED) | |
5697 | { | |
5698 | unsigned char *start = section->start; | |
5699 | unsigned char *end = start + section->size; | |
5700 | unsigned char *section_start = start; | |
49727e46 | 5701 | Frame_Chunk *chunks = 0, *forward_refs = 0; |
19e6b90e L |
5702 | Frame_Chunk *remembered_state = 0; |
5703 | Frame_Chunk *rs; | |
5704 | int is_eh = strcmp (section->name, ".eh_frame") == 0; | |
5705 | unsigned int length_return; | |
a1165289 | 5706 | unsigned int max_regs = 0; |
665ce1f6 | 5707 | const char *bad_reg = _("bad register: "); |
77ef8654 | 5708 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 5709 | |
80c35038 | 5710 | printf (_("Contents of the %s section:\n"), section->name); |
19e6b90e L |
5711 | |
5712 | while (start < end) | |
5713 | { | |
5714 | unsigned char *saved_start; | |
5715 | unsigned char *block_end; | |
bf5117e3 NC |
5716 | dwarf_vma length; |
5717 | dwarf_vma cie_id; | |
19e6b90e L |
5718 | Frame_Chunk *fc; |
5719 | Frame_Chunk *cie; | |
5720 | int need_col_headers = 1; | |
5721 | unsigned char *augmentation_data = NULL; | |
5722 | unsigned long augmentation_data_len = 0; | |
bf5117e3 NC |
5723 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
5724 | unsigned int offset_size; | |
5725 | unsigned int initial_length_size; | |
19e6b90e L |
5726 | |
5727 | saved_start = start; | |
19e6b90e | 5728 | |
0c588247 | 5729 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 5730 | |
19e6b90e L |
5731 | if (length == 0) |
5732 | { | |
5733 | printf ("\n%08lx ZERO terminator\n\n", | |
5734 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
5735 | /* Skip any zero terminators that directly follow. |
5736 | A corrupt section size could have loaded a whole | |
5737 | slew of zero filled memory bytes. eg | |
5738 | PR 17512: file: 070-19381-0.004. */ | |
5739 | while (start < end && * start == 0) | |
5740 | ++ start; | |
b758e50f | 5741 | continue; |
19e6b90e L |
5742 | } |
5743 | ||
5744 | if (length == 0xffffffff) | |
5745 | { | |
0c588247 | 5746 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
5747 | offset_size = 8; |
5748 | initial_length_size = 12; | |
5749 | } | |
5750 | else | |
5751 | { | |
5752 | offset_size = 4; | |
5753 | initial_length_size = 4; | |
5754 | } | |
5755 | ||
5756 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 5757 | if (block_end > end || block_end < start) |
53b8873b | 5758 | { |
bf5117e3 NC |
5759 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
5760 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
5761 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
5762 | block_end = end; |
5763 | } | |
0c588247 NC |
5764 | |
5765 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 5766 | |
846a11e4 NC |
5767 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
5768 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
5769 | { |
5770 | int version; | |
a1165289 | 5771 | unsigned int mreg; |
19e6b90e | 5772 | |
49727e46 AM |
5773 | start = read_cie (start, end, &cie, &version, |
5774 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
5775 | /* PR 17512: file: 027-135133-0.005. */ |
5776 | if (cie == NULL) | |
5777 | break; | |
a1165289 | 5778 | |
49727e46 | 5779 | fc = cie; |
19e6b90e L |
5780 | fc->next = chunks; |
5781 | chunks = fc; | |
5782 | fc->chunk_start = saved_start; | |
a1165289 | 5783 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
5784 | if (mreg < fc->ra) |
5785 | mreg = fc->ra; | |
06614111 NC |
5786 | if (frame_need_space (fc, mreg) < 0) |
5787 | break; | |
49727e46 AM |
5788 | if (fc->fde_encoding) |
5789 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 5790 | |
bf5117e3 NC |
5791 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
5792 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 5793 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 5794 | |
19e6b90e | 5795 | if (do_debug_frames_interp) |
bf5117e3 NC |
5796 | { |
5797 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
5798 | fc->code_factor, fc->data_factor, fc->ra); | |
5799 | } | |
19e6b90e L |
5800 | else |
5801 | { | |
bf5117e3 | 5802 | printf ("CIE\n"); |
19e6b90e L |
5803 | printf (" Version: %d\n", version); |
5804 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
5805 | if (version >= 4) |
5806 | { | |
5807 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
5808 | printf (" Segment Size: %u\n", fc->segment_size); | |
5809 | } | |
19e6b90e L |
5810 | printf (" Code alignment factor: %u\n", fc->code_factor); |
5811 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
5812 | printf (" Return address column: %d\n", fc->ra); | |
5813 | ||
5814 | if (augmentation_data_len) | |
5815 | { | |
5816 | unsigned long i; | |
a1165289 | 5817 | |
19e6b90e L |
5818 | printf (" Augmentation data: "); |
5819 | for (i = 0; i < augmentation_data_len; ++i) | |
a1165289 NC |
5820 | /* FIXME: If do_wide is FALSE, then we should |
5821 | add carriage returns at 80 columns... */ | |
19e6b90e L |
5822 | printf (" %02x", augmentation_data[i]); |
5823 | putchar ('\n'); | |
5824 | } | |
5825 | putchar ('\n'); | |
5826 | } | |
19e6b90e L |
5827 | } |
5828 | else | |
5829 | { | |
5830 | unsigned char *look_for; | |
5831 | static Frame_Chunk fde_fc; | |
604282a7 | 5832 | unsigned long segment_selector; |
19e6b90e | 5833 | |
49727e46 AM |
5834 | if (is_eh) |
5835 | { | |
5836 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
5837 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
5838 | } | |
5839 | else | |
5840 | look_for = section_start + cie_id; | |
19e6b90e | 5841 | |
49727e46 AM |
5842 | if (look_for <= saved_start) |
5843 | { | |
5844 | for (cie = chunks; cie ; cie = cie->next) | |
5845 | if (cie->chunk_start == look_for) | |
5846 | break; | |
5847 | } | |
5848 | else | |
5849 | { | |
5850 | for (cie = forward_refs; cie ; cie = cie->next) | |
5851 | if (cie->chunk_start == look_for) | |
5852 | break; | |
5853 | if (!cie) | |
5854 | { | |
5855 | unsigned int off_size; | |
5856 | unsigned char *cie_scan; | |
19e6b90e | 5857 | |
49727e46 AM |
5858 | cie_scan = look_for; |
5859 | off_size = 4; | |
5860 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
5861 | if (length == 0xffffffff) | |
5862 | { | |
5863 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
5864 | off_size = 8; | |
5865 | } | |
5866 | if (length != 0) | |
5867 | { | |
5868 | dwarf_vma c_id; | |
5869 | ||
5870 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
5871 | if (is_eh | |
5872 | ? c_id == 0 | |
5873 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
5874 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
5875 | { | |
5876 | int version; | |
a1165289 | 5877 | unsigned int mreg; |
49727e46 AM |
5878 | |
5879 | read_cie (cie_scan, end, &cie, &version, | |
5880 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
5881 | /* PR 17512: file: 3450-2098-0.004. */ |
5882 | if (cie == NULL) | |
5883 | { | |
5884 | warn (_("Failed to read CIE information\n")); | |
5885 | break; | |
5886 | } | |
49727e46 AM |
5887 | cie->next = forward_refs; |
5888 | forward_refs = cie; | |
5889 | cie->chunk_start = look_for; | |
a1165289 | 5890 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
5891 | if (mreg < cie->ra) |
5892 | mreg = cie->ra; | |
06614111 NC |
5893 | if (frame_need_space (cie, mreg) < 0) |
5894 | { | |
5895 | warn (_("Invalid max register\n")); | |
5896 | break; | |
5897 | } | |
49727e46 AM |
5898 | if (cie->fde_encoding) |
5899 | encoded_ptr_size | |
5900 | = size_of_encoded_value (cie->fde_encoding); | |
5901 | } | |
5902 | } | |
5903 | } | |
5904 | } | |
5905 | ||
5906 | fc = &fde_fc; | |
5907 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
5908 | |
5909 | if (!cie) | |
5910 | { | |
bf5117e3 NC |
5911 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
5912 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
5913 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 5914 | fc->ncols = 0; |
3f5e193b NC |
5915 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
5916 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
5917 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
5918 | { | |
5919 | warn (_("Invalid max register\n")); | |
5920 | break; | |
5921 | } | |
19e6b90e L |
5922 | cie = fc; |
5923 | fc->augmentation = ""; | |
5924 | fc->fde_encoding = 0; | |
604282a7 JJ |
5925 | fc->ptr_size = eh_addr_size; |
5926 | fc->segment_size = 0; | |
19e6b90e L |
5927 | } |
5928 | else | |
5929 | { | |
5930 | fc->ncols = cie->ncols; | |
3f5e193b NC |
5931 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
5932 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
5933 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
5934 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
5935 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
5936 | fc->ptr_size = cie->ptr_size; |
5937 | eh_addr_size = cie->ptr_size; | |
5938 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
5939 | fc->code_factor = cie->code_factor; |
5940 | fc->data_factor = cie->data_factor; | |
5941 | fc->cfa_reg = cie->cfa_reg; | |
5942 | fc->cfa_offset = cie->cfa_offset; | |
5943 | fc->ra = cie->ra; | |
06614111 NC |
5944 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
5945 | { | |
5946 | warn (_("Invalid max register\n")); | |
5947 | break; | |
5948 | } | |
19e6b90e L |
5949 | fc->fde_encoding = cie->fde_encoding; |
5950 | } | |
5951 | ||
5952 | if (fc->fde_encoding) | |
5953 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
5954 | ||
604282a7 JJ |
5955 | segment_selector = 0; |
5956 | if (fc->segment_size) | |
c8071705 NC |
5957 | { |
5958 | if (fc->segment_size > sizeof (segment_selector)) | |
5959 | { | |
5960 | /* PR 17512: file: 9e196b3e. */ | |
5961 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
5962 | fc->segment_size = 4; | |
5963 | } | |
5964 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
5965 | } | |
041830e0 NC |
5966 | |
5967 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 5968 | |
0c588247 NC |
5969 | /* FIXME: It appears that sometimes the final pc_range value is |
5970 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
5971 | run of the "objcopy on compressed debug sections" test for an | |
5972 | example of this. */ | |
5973 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 5974 | |
19e6b90e L |
5975 | if (cie->augmentation[0] == 'z') |
5976 | { | |
5977 | augmentation_data_len = LEB (); | |
5978 | augmentation_data = start; | |
5979 | start += augmentation_data_len; | |
0a9d414a | 5980 | /* PR 17512: file: 722-8446-0.004. */ |
53774b7e | 5981 | if (start >= end || ((signed long) augmentation_data_len) < 0) |
0a9d414a NC |
5982 | { |
5983 | warn (_("Corrupt augmentation data length: %lx\n"), | |
5984 | augmentation_data_len); | |
5985 | start = end; | |
5986 | augmentation_data = NULL; | |
5987 | augmentation_data_len = 0; | |
5988 | } | |
19e6b90e L |
5989 | } |
5990 | ||
bf5117e3 NC |
5991 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
5992 | (unsigned long)(saved_start - section_start), | |
5993 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 5994 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 5995 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 5996 | |
604282a7 JJ |
5997 | if (fc->segment_size) |
5998 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
5999 | |
6000 | printf ("%s..%s\n", | |
6001 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
6002 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
6003 | ||
19e6b90e L |
6004 | if (! do_debug_frames_interp && augmentation_data_len) |
6005 | { | |
6006 | unsigned long i; | |
6007 | ||
6008 | printf (" Augmentation data: "); | |
6009 | for (i = 0; i < augmentation_data_len; ++i) | |
6010 | printf (" %02x", augmentation_data[i]); | |
6011 | putchar ('\n'); | |
6012 | putchar ('\n'); | |
6013 | } | |
6014 | } | |
6015 | ||
6016 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
6017 | we're about to interpret instructions for the chunk. */ | |
6018 | /* ??? At present we need to do this always, since this sizes the | |
6019 | fc->col_type and fc->col_offset arrays, which we write into always. | |
6020 | We should probably split the interpreted and non-interpreted bits | |
6021 | into two different routines, since there's so much that doesn't | |
6022 | really overlap between them. */ | |
6023 | if (1 || do_debug_frames_interp) | |
6024 | { | |
6025 | /* Start by making a pass over the chunk, allocating storage | |
6026 | and taking note of what registers are used. */ | |
6027 | unsigned char *tmp = start; | |
6028 | ||
6029 | while (start < block_end) | |
6030 | { | |
041830e0 NC |
6031 | unsigned int reg, op, opa; |
6032 | unsigned long temp; | |
5929c344 | 6033 | unsigned char * new_start; |
19e6b90e L |
6034 | |
6035 | op = *start++; | |
6036 | opa = op & 0x3f; | |
6037 | if (op & 0xc0) | |
6038 | op &= 0xc0; | |
6039 | ||
6040 | /* Warning: if you add any more cases to this switch, be | |
6041 | sure to add them to the corresponding switch below. */ | |
6042 | switch (op) | |
6043 | { | |
6044 | case DW_CFA_advance_loc: | |
6045 | break; | |
6046 | case DW_CFA_offset: | |
6047 | LEB (); | |
665ce1f6 L |
6048 | if (frame_need_space (fc, opa) >= 0) |
6049 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
6050 | break; |
6051 | case DW_CFA_restore: | |
665ce1f6 L |
6052 | if (frame_need_space (fc, opa) >= 0) |
6053 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
6054 | break; |
6055 | case DW_CFA_set_loc: | |
6056 | start += encoded_ptr_size; | |
6057 | break; | |
6058 | case DW_CFA_advance_loc1: | |
6059 | start += 1; | |
6060 | break; | |
6061 | case DW_CFA_advance_loc2: | |
6062 | start += 2; | |
6063 | break; | |
6064 | case DW_CFA_advance_loc4: | |
6065 | start += 4; | |
6066 | break; | |
6067 | case DW_CFA_offset_extended: | |
12eae2d3 | 6068 | case DW_CFA_val_offset: |
19e6b90e | 6069 | reg = LEB (); LEB (); |
665ce1f6 L |
6070 | if (frame_need_space (fc, reg) >= 0) |
6071 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
6072 | break; |
6073 | case DW_CFA_restore_extended: | |
6074 | reg = LEB (); | |
665ce1f6 L |
6075 | if (frame_need_space (fc, reg) >= 0) |
6076 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
6077 | break; |
6078 | case DW_CFA_undefined: | |
6079 | reg = LEB (); | |
665ce1f6 L |
6080 | if (frame_need_space (fc, reg) >= 0) |
6081 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
6082 | break; |
6083 | case DW_CFA_same_value: | |
6084 | reg = LEB (); | |
665ce1f6 L |
6085 | if (frame_need_space (fc, reg) >= 0) |
6086 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
6087 | break; |
6088 | case DW_CFA_register: | |
6089 | reg = LEB (); LEB (); | |
665ce1f6 L |
6090 | if (frame_need_space (fc, reg) >= 0) |
6091 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
6092 | break; |
6093 | case DW_CFA_def_cfa: | |
6094 | LEB (); LEB (); | |
6095 | break; | |
6096 | case DW_CFA_def_cfa_register: | |
6097 | LEB (); | |
6098 | break; | |
6099 | case DW_CFA_def_cfa_offset: | |
6100 | LEB (); | |
6101 | break; | |
6102 | case DW_CFA_def_cfa_expression: | |
91d6fa6a | 6103 | temp = LEB (); |
5929c344 NC |
6104 | new_start = start + temp; |
6105 | if (new_start < start) | |
041830e0 NC |
6106 | { |
6107 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
6108 | start = block_end; | |
6109 | } | |
6110 | else | |
5929c344 | 6111 | start = new_start; |
19e6b90e L |
6112 | break; |
6113 | case DW_CFA_expression: | |
12eae2d3 | 6114 | case DW_CFA_val_expression: |
19e6b90e | 6115 | reg = LEB (); |
91d6fa6a | 6116 | temp = LEB (); |
5929c344 NC |
6117 | new_start = start + temp; |
6118 | if (new_start < start) | |
041830e0 | 6119 | { |
b4eb7656 | 6120 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
6121 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
6122 | start = block_end; | |
6123 | } | |
6124 | else | |
5929c344 | 6125 | start = new_start; |
665ce1f6 L |
6126 | if (frame_need_space (fc, reg) >= 0) |
6127 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
6128 | break; |
6129 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 6130 | case DW_CFA_val_offset_sf: |
19e6b90e | 6131 | reg = LEB (); SLEB (); |
665ce1f6 L |
6132 | if (frame_need_space (fc, reg) >= 0) |
6133 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
6134 | break; |
6135 | case DW_CFA_def_cfa_sf: | |
6136 | LEB (); SLEB (); | |
6137 | break; | |
6138 | case DW_CFA_def_cfa_offset_sf: | |
6139 | SLEB (); | |
6140 | break; | |
6141 | case DW_CFA_MIPS_advance_loc8: | |
6142 | start += 8; | |
6143 | break; | |
6144 | case DW_CFA_GNU_args_size: | |
6145 | LEB (); | |
6146 | break; | |
6147 | case DW_CFA_GNU_negative_offset_extended: | |
6148 | reg = LEB (); LEB (); | |
665ce1f6 L |
6149 | if (frame_need_space (fc, reg) >= 0) |
6150 | fc->col_type[reg] = DW_CFA_undefined; | |
6151 | break; | |
19e6b90e L |
6152 | default: |
6153 | break; | |
6154 | } | |
6155 | } | |
6156 | start = tmp; | |
6157 | } | |
6158 | ||
6159 | /* Now we know what registers are used, make a second pass over | |
6160 | the chunk, this time actually printing out the info. */ | |
6161 | ||
6162 | while (start < block_end) | |
6163 | { | |
362beea4 | 6164 | unsigned char * tmp; |
19e6b90e L |
6165 | unsigned op, opa; |
6166 | unsigned long ul, reg, roffs; | |
c8071705 | 6167 | dwarf_vma l; |
bf5117e3 | 6168 | dwarf_vma ofs; |
19e6b90e | 6169 | dwarf_vma vma; |
665ce1f6 | 6170 | const char *reg_prefix = ""; |
19e6b90e L |
6171 | |
6172 | op = *start++; | |
6173 | opa = op & 0x3f; | |
6174 | if (op & 0xc0) | |
6175 | op &= 0xc0; | |
6176 | ||
6177 | /* Warning: if you add any more cases to this switch, be | |
6178 | sure to add them to the corresponding switch above. */ | |
6179 | switch (op) | |
6180 | { | |
6181 | case DW_CFA_advance_loc: | |
6182 | if (do_debug_frames_interp) | |
6183 | frame_display_row (fc, &need_col_headers, &max_regs); | |
6184 | else | |
bf5117e3 | 6185 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 6186 | opa * fc->code_factor, |
b4eb7656 | 6187 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
6188 | fc->pc_begin + opa * fc->code_factor, |
6189 | fc->ptr_size)); | |
19e6b90e L |
6190 | fc->pc_begin += opa * fc->code_factor; |
6191 | break; | |
6192 | ||
6193 | case DW_CFA_offset: | |
6194 | roffs = LEB (); | |
665ce1f6 L |
6195 | if (opa >= (unsigned int) fc->ncols) |
6196 | reg_prefix = bad_reg; | |
6197 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6198 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
6199 | reg_prefix, regname (opa, 0), | |
6200 | roffs * fc->data_factor); | |
6201 | if (*reg_prefix == '\0') | |
6202 | { | |
6203 | fc->col_type[opa] = DW_CFA_offset; | |
6204 | fc->col_offset[opa] = roffs * fc->data_factor; | |
6205 | } | |
19e6b90e L |
6206 | break; |
6207 | ||
6208 | case DW_CFA_restore: | |
665ce1f6 L |
6209 | if (opa >= (unsigned int) cie->ncols |
6210 | || opa >= (unsigned int) fc->ncols) | |
6211 | reg_prefix = bad_reg; | |
6212 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6213 | printf (" DW_CFA_restore: %s%s\n", | |
6214 | reg_prefix, regname (opa, 0)); | |
6215 | if (*reg_prefix == '\0') | |
6216 | { | |
6217 | fc->col_type[opa] = cie->col_type[opa]; | |
6218 | fc->col_offset[opa] = cie->col_offset[opa]; | |
b3f5b73b ILT |
6219 | if (do_debug_frames_interp |
6220 | && fc->col_type[opa] == DW_CFA_unreferenced) | |
6221 | fc->col_type[opa] = DW_CFA_undefined; | |
665ce1f6 | 6222 | } |
19e6b90e L |
6223 | break; |
6224 | ||
6225 | case DW_CFA_set_loc: | |
6937bb54 | 6226 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
6227 | if (do_debug_frames_interp) |
6228 | frame_display_row (fc, &need_col_headers, &max_regs); | |
6229 | else | |
bf5117e3 NC |
6230 | printf (" DW_CFA_set_loc: %s\n", |
6231 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
6232 | fc->pc_begin = vma; |
6233 | break; | |
6234 | ||
6235 | case DW_CFA_advance_loc1: | |
0c588247 | 6236 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
6237 | if (do_debug_frames_interp) |
6238 | frame_display_row (fc, &need_col_headers, &max_regs); | |
6239 | else | |
bf5117e3 NC |
6240 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
6241 | (unsigned long) (ofs * fc->code_factor), | |
6242 | dwarf_vmatoa_1 (NULL, | |
6243 | fc->pc_begin + ofs * fc->code_factor, | |
6244 | fc->ptr_size)); | |
19e6b90e L |
6245 | fc->pc_begin += ofs * fc->code_factor; |
6246 | break; | |
6247 | ||
6248 | case DW_CFA_advance_loc2: | |
6937bb54 | 6249 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
6250 | if (do_debug_frames_interp) |
6251 | frame_display_row (fc, &need_col_headers, &max_regs); | |
6252 | else | |
bf5117e3 NC |
6253 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
6254 | (unsigned long) (ofs * fc->code_factor), | |
6255 | dwarf_vmatoa_1 (NULL, | |
6256 | fc->pc_begin + ofs * fc->code_factor, | |
6257 | fc->ptr_size)); | |
19e6b90e L |
6258 | fc->pc_begin += ofs * fc->code_factor; |
6259 | break; | |
6260 | ||
6261 | case DW_CFA_advance_loc4: | |
6937bb54 | 6262 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
6263 | if (do_debug_frames_interp) |
6264 | frame_display_row (fc, &need_col_headers, &max_regs); | |
6265 | else | |
bf5117e3 NC |
6266 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
6267 | (unsigned long) (ofs * fc->code_factor), | |
6268 | dwarf_vmatoa_1 (NULL, | |
6269 | fc->pc_begin + ofs * fc->code_factor, | |
6270 | fc->ptr_size)); | |
19e6b90e L |
6271 | fc->pc_begin += ofs * fc->code_factor; |
6272 | break; | |
6273 | ||
6274 | case DW_CFA_offset_extended: | |
6275 | reg = LEB (); | |
6276 | roffs = LEB (); | |
665ce1f6 L |
6277 | if (reg >= (unsigned int) fc->ncols) |
6278 | reg_prefix = bad_reg; | |
6279 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6280 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
6281 | reg_prefix, regname (reg, 0), | |
6282 | roffs * fc->data_factor); | |
6283 | if (*reg_prefix == '\0') | |
6284 | { | |
6285 | fc->col_type[reg] = DW_CFA_offset; | |
6286 | fc->col_offset[reg] = roffs * fc->data_factor; | |
6287 | } | |
19e6b90e L |
6288 | break; |
6289 | ||
12eae2d3 JJ |
6290 | case DW_CFA_val_offset: |
6291 | reg = LEB (); | |
6292 | roffs = LEB (); | |
665ce1f6 L |
6293 | if (reg >= (unsigned int) fc->ncols) |
6294 | reg_prefix = bad_reg; | |
6295 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6296 | printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n", | |
6297 | reg_prefix, regname (reg, 0), | |
6298 | roffs * fc->data_factor); | |
6299 | if (*reg_prefix == '\0') | |
6300 | { | |
6301 | fc->col_type[reg] = DW_CFA_val_offset; | |
6302 | fc->col_offset[reg] = roffs * fc->data_factor; | |
6303 | } | |
12eae2d3 JJ |
6304 | break; |
6305 | ||
19e6b90e L |
6306 | case DW_CFA_restore_extended: |
6307 | reg = LEB (); | |
665ce1f6 L |
6308 | if (reg >= (unsigned int) cie->ncols |
6309 | || reg >= (unsigned int) fc->ncols) | |
6310 | reg_prefix = bad_reg; | |
6311 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6312 | printf (" DW_CFA_restore_extended: %s%s\n", | |
6313 | reg_prefix, regname (reg, 0)); | |
6314 | if (*reg_prefix == '\0') | |
6315 | { | |
6316 | fc->col_type[reg] = cie->col_type[reg]; | |
6317 | fc->col_offset[reg] = cie->col_offset[reg]; | |
6318 | } | |
19e6b90e L |
6319 | break; |
6320 | ||
6321 | case DW_CFA_undefined: | |
6322 | reg = LEB (); | |
665ce1f6 L |
6323 | if (reg >= (unsigned int) fc->ncols) |
6324 | reg_prefix = bad_reg; | |
6325 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6326 | printf (" DW_CFA_undefined: %s%s\n", | |
6327 | reg_prefix, regname (reg, 0)); | |
6328 | if (*reg_prefix == '\0') | |
6329 | { | |
6330 | fc->col_type[reg] = DW_CFA_undefined; | |
6331 | fc->col_offset[reg] = 0; | |
6332 | } | |
19e6b90e L |
6333 | break; |
6334 | ||
6335 | case DW_CFA_same_value: | |
6336 | reg = LEB (); | |
665ce1f6 L |
6337 | if (reg >= (unsigned int) fc->ncols) |
6338 | reg_prefix = bad_reg; | |
6339 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6340 | printf (" DW_CFA_same_value: %s%s\n", | |
6341 | reg_prefix, regname (reg, 0)); | |
6342 | if (*reg_prefix == '\0') | |
6343 | { | |
6344 | fc->col_type[reg] = DW_CFA_same_value; | |
6345 | fc->col_offset[reg] = 0; | |
6346 | } | |
19e6b90e L |
6347 | break; |
6348 | ||
6349 | case DW_CFA_register: | |
6350 | reg = LEB (); | |
6351 | roffs = LEB (); | |
665ce1f6 L |
6352 | if (reg >= (unsigned int) fc->ncols) |
6353 | reg_prefix = bad_reg; | |
6354 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 6355 | { |
665ce1f6 L |
6356 | printf (" DW_CFA_register: %s%s in ", |
6357 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
6358 | puts (regname (roffs, 0)); |
6359 | } | |
665ce1f6 L |
6360 | if (*reg_prefix == '\0') |
6361 | { | |
6362 | fc->col_type[reg] = DW_CFA_register; | |
6363 | fc->col_offset[reg] = roffs; | |
6364 | } | |
19e6b90e L |
6365 | break; |
6366 | ||
6367 | case DW_CFA_remember_state: | |
6368 | if (! do_debug_frames_interp) | |
6369 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 6370 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 6371 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
6372 | rs->cfa_reg = fc->cfa_reg; |
6373 | rs->ra = fc->ra; | |
6374 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 6375 | rs->ncols = fc->ncols; |
3f5e193b | 6376 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 6377 | sizeof (* rs->col_type)); |
d71ad7fc RC |
6378 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
6379 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
6380 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
6381 | rs->next = remembered_state; |
6382 | remembered_state = rs; | |
6383 | break; | |
6384 | ||
6385 | case DW_CFA_restore_state: | |
6386 | if (! do_debug_frames_interp) | |
6387 | printf (" DW_CFA_restore_state\n"); | |
6388 | rs = remembered_state; | |
6389 | if (rs) | |
6390 | { | |
6391 | remembered_state = rs->next; | |
d71ad7fc RC |
6392 | fc->cfa_offset = rs->cfa_offset; |
6393 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
6394 | fc->ra = rs->ra; |
6395 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
6396 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
6397 | { | |
1306a742 | 6398 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
6399 | fc->ncols = 0; |
6400 | break; | |
6401 | } | |
d71ad7fc | 6402 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 6403 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 6404 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
6405 | free (rs->col_type); |
6406 | free (rs->col_offset); | |
6407 | free (rs); | |
6408 | } | |
6409 | else if (do_debug_frames_interp) | |
6410 | printf ("Mismatched DW_CFA_restore_state\n"); | |
6411 | break; | |
6412 | ||
6413 | case DW_CFA_def_cfa: | |
6414 | fc->cfa_reg = LEB (); | |
6415 | fc->cfa_offset = LEB (); | |
6416 | fc->cfa_exp = 0; | |
6417 | if (! do_debug_frames_interp) | |
2dc4cec1 | 6418 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 6419 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
6420 | break; |
6421 | ||
6422 | case DW_CFA_def_cfa_register: | |
6423 | fc->cfa_reg = LEB (); | |
6424 | fc->cfa_exp = 0; | |
6425 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
6426 | printf (" DW_CFA_def_cfa_register: %s\n", |
6427 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
6428 | break; |
6429 | ||
6430 | case DW_CFA_def_cfa_offset: | |
6431 | fc->cfa_offset = LEB (); | |
6432 | if (! do_debug_frames_interp) | |
c8071705 | 6433 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
6434 | break; |
6435 | ||
6436 | case DW_CFA_nop: | |
6437 | if (! do_debug_frames_interp) | |
6438 | printf (" DW_CFA_nop\n"); | |
6439 | break; | |
6440 | ||
6441 | case DW_CFA_def_cfa_expression: | |
6442 | ul = LEB (); | |
06614111 | 6443 | if (start >= block_end || start + ul > block_end || start + ul < start) |
6937bb54 | 6444 | { |
a1165289 | 6445 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
6446 | break; |
6447 | } | |
19e6b90e L |
6448 | if (! do_debug_frames_interp) |
6449 | { | |
6450 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
6451 | decode_location_expression (start, eh_addr_size, 0, -1, |
6452 | ul, 0, section); | |
19e6b90e L |
6453 | printf (")\n"); |
6454 | } | |
6455 | fc->cfa_exp = 1; | |
6456 | start += ul; | |
6457 | break; | |
6458 | ||
6459 | case DW_CFA_expression: | |
6460 | reg = LEB (); | |
6461 | ul = LEB (); | |
665ce1f6 L |
6462 | if (reg >= (unsigned int) fc->ncols) |
6463 | reg_prefix = bad_reg; | |
6937bb54 | 6464 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 6465 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
6466 | tmp = start + ul; |
6467 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 6468 | { |
a1165289 | 6469 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
6470 | break; |
6471 | } | |
665ce1f6 | 6472 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 6473 | { |
665ce1f6 L |
6474 | printf (" DW_CFA_expression: %s%s (", |
6475 | reg_prefix, regname (reg, 0)); | |
b7807392 | 6476 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 6477 | ul, 0, section); |
19e6b90e L |
6478 | printf (")\n"); |
6479 | } | |
665ce1f6 L |
6480 | if (*reg_prefix == '\0') |
6481 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 6482 | start = tmp; |
19e6b90e L |
6483 | break; |
6484 | ||
12eae2d3 JJ |
6485 | case DW_CFA_val_expression: |
6486 | reg = LEB (); | |
6487 | ul = LEB (); | |
665ce1f6 L |
6488 | if (reg >= (unsigned int) fc->ncols) |
6489 | reg_prefix = bad_reg; | |
362beea4 NC |
6490 | tmp = start + ul; |
6491 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 6492 | { |
a1165289 | 6493 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
6494 | break; |
6495 | } | |
665ce1f6 | 6496 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 6497 | { |
665ce1f6 L |
6498 | printf (" DW_CFA_val_expression: %s%s (", |
6499 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
6500 | decode_location_expression (start, eh_addr_size, 0, -1, |
6501 | ul, 0, section); | |
12eae2d3 JJ |
6502 | printf (")\n"); |
6503 | } | |
665ce1f6 L |
6504 | if (*reg_prefix == '\0') |
6505 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 6506 | start = tmp; |
12eae2d3 JJ |
6507 | break; |
6508 | ||
19e6b90e L |
6509 | case DW_CFA_offset_extended_sf: |
6510 | reg = LEB (); | |
6511 | l = SLEB (); | |
665ce1f6 L |
6512 | if (frame_need_space (fc, reg) < 0) |
6513 | reg_prefix = bad_reg; | |
6514 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6515 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
6516 | reg_prefix, regname (reg, 0), | |
c8071705 | 6517 | (long)(l * fc->data_factor)); |
665ce1f6 L |
6518 | if (*reg_prefix == '\0') |
6519 | { | |
6520 | fc->col_type[reg] = DW_CFA_offset; | |
6521 | fc->col_offset[reg] = l * fc->data_factor; | |
6522 | } | |
19e6b90e L |
6523 | break; |
6524 | ||
12eae2d3 JJ |
6525 | case DW_CFA_val_offset_sf: |
6526 | reg = LEB (); | |
6527 | l = SLEB (); | |
665ce1f6 L |
6528 | if (frame_need_space (fc, reg) < 0) |
6529 | reg_prefix = bad_reg; | |
6530 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6531 | printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n", | |
6532 | reg_prefix, regname (reg, 0), | |
c8071705 | 6533 | (long)(l * fc->data_factor)); |
665ce1f6 L |
6534 | if (*reg_prefix == '\0') |
6535 | { | |
6536 | fc->col_type[reg] = DW_CFA_val_offset; | |
6537 | fc->col_offset[reg] = l * fc->data_factor; | |
6538 | } | |
12eae2d3 JJ |
6539 | break; |
6540 | ||
19e6b90e L |
6541 | case DW_CFA_def_cfa_sf: |
6542 | fc->cfa_reg = LEB (); | |
6543 | fc->cfa_offset = SLEB (); | |
6544 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; | |
6545 | fc->cfa_exp = 0; | |
6546 | if (! do_debug_frames_interp) | |
2dc4cec1 | 6547 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 6548 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
6549 | break; |
6550 | ||
6551 | case DW_CFA_def_cfa_offset_sf: | |
6552 | fc->cfa_offset = SLEB (); | |
c8071705 | 6553 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 6554 | if (! do_debug_frames_interp) |
c8071705 | 6555 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
6556 | break; |
6557 | ||
6558 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 6559 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
6560 | if (do_debug_frames_interp) |
6561 | frame_display_row (fc, &need_col_headers, &max_regs); | |
6562 | else | |
bf5117e3 NC |
6563 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
6564 | (unsigned long) (ofs * fc->code_factor), | |
6565 | dwarf_vmatoa_1 (NULL, | |
6566 | fc->pc_begin + ofs * fc->code_factor, | |
6567 | fc->ptr_size)); | |
19e6b90e L |
6568 | fc->pc_begin += ofs * fc->code_factor; |
6569 | break; | |
6570 | ||
6571 | case DW_CFA_GNU_window_save: | |
6572 | if (! do_debug_frames_interp) | |
6573 | printf (" DW_CFA_GNU_window_save\n"); | |
6574 | break; | |
6575 | ||
6576 | case DW_CFA_GNU_args_size: | |
6577 | ul = LEB (); | |
6578 | if (! do_debug_frames_interp) | |
6579 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
6580 | break; | |
6581 | ||
6582 | case DW_CFA_GNU_negative_offset_extended: | |
6583 | reg = LEB (); | |
6584 | l = - LEB (); | |
665ce1f6 L |
6585 | if (frame_need_space (fc, reg) < 0) |
6586 | reg_prefix = bad_reg; | |
6587 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
6588 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
6589 | reg_prefix, regname (reg, 0), | |
c8071705 | 6590 | (long)(l * fc->data_factor)); |
665ce1f6 L |
6591 | if (*reg_prefix == '\0') |
6592 | { | |
6593 | fc->col_type[reg] = DW_CFA_offset; | |
6594 | fc->col_offset[reg] = l * fc->data_factor; | |
6595 | } | |
19e6b90e L |
6596 | break; |
6597 | ||
6598 | default: | |
53b8873b NC |
6599 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
6600 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
6601 | else | |
f41e4712 | 6602 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
6603 | start = block_end; |
6604 | } | |
6605 | } | |
6606 | ||
6607 | if (do_debug_frames_interp) | |
6608 | frame_display_row (fc, &need_col_headers, &max_regs); | |
6609 | ||
6610 | start = block_end; | |
604282a7 | 6611 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
6612 | } |
6613 | ||
6614 | printf ("\n"); | |
6615 | ||
6616 | return 1; | |
6617 | } | |
6618 | ||
6619 | #undef GET | |
6620 | #undef LEB | |
6621 | #undef SLEB | |
6622 | ||
5bbdf3d5 DE |
6623 | static int |
6624 | display_gdb_index (struct dwarf_section *section, | |
6625 | void *file ATTRIBUTE_UNUSED) | |
6626 | { | |
6627 | unsigned char *start = section->start; | |
6628 | uint32_t version; | |
6629 | uint32_t cu_list_offset, tu_list_offset; | |
6630 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
6631 | unsigned int cu_list_elements, tu_list_elements; | |
6632 | unsigned int address_table_size, symbol_table_slots; | |
6633 | unsigned char *cu_list, *tu_list; | |
6634 | unsigned char *address_table, *symbol_table, *constant_pool; | |
6635 | unsigned int i; | |
6636 | ||
6637 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
6638 | ||
6639 | printf (_("Contents of the %s section:\n"), section->name); | |
6640 | ||
6641 | if (section->size < 6 * sizeof (uint32_t)) | |
6642 | { | |
6643 | warn (_("Truncated header in the %s section.\n"), section->name); | |
6644 | return 0; | |
6645 | } | |
6646 | ||
6647 | version = byte_get_little_endian (start, 4); | |
da88a764 | 6648 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
6649 | |
6650 | /* Prior versions are obsolete, and future versions may not be | |
6651 | backwards compatible. */ | |
aa170720 | 6652 | if (version < 3 || version > 8) |
5bbdf3d5 | 6653 | { |
da88a764 | 6654 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
6655 | return 0; |
6656 | } | |
8d6eee87 TT |
6657 | if (version < 4) |
6658 | warn (_("The address table data in version 3 may be wrong.\n")); | |
6659 | if (version < 5) | |
6660 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
6661 | if (version < 6) | |
6662 | warn (_("Version 5 does not include inlined functions.\n")); | |
6663 | if (version < 7) | |
6664 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
6665 | /* Version 7 indices generated by Gold have bad type unit references, |
6666 | PR binutils/15021. But we don't know if the index was generated by | |
6667 | Gold or not, so to avoid worrying users with gdb-generated indices | |
6668 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
6669 | |
6670 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
6671 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
6672 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
6673 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
6674 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
6675 | ||
6676 | if (cu_list_offset > section->size | |
6677 | || tu_list_offset > section->size | |
6678 | || address_table_offset > section->size | |
6679 | || symbol_table_offset > section->size | |
6680 | || constant_pool_offset > section->size) | |
6681 | { | |
6682 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
6683 | return 0; | |
6684 | } | |
6685 | ||
53774b7e NC |
6686 | /* PR 17531: file: 418d0a8a. */ |
6687 | if (tu_list_offset < cu_list_offset) | |
6688 | { | |
6689 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
6690 | tu_list_offset, cu_list_offset); | |
6691 | return 0; | |
6692 | } | |
6693 | ||
5bbdf3d5 | 6694 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
6695 | |
6696 | if (address_table_offset < tu_list_offset) | |
6697 | { | |
6698 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
6699 | address_table_offset, tu_list_offset); | |
6700 | return 0; | |
6701 | } | |
6702 | ||
5bbdf3d5 | 6703 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
6704 | |
6705 | /* PR 17531: file: 18a47d3d. */ | |
6706 | if (symbol_table_offset < address_table_offset) | |
6707 | { | |
acff9664 | 6708 | warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"), |
53774b7e NC |
6709 | symbol_table_offset, address_table_offset); |
6710 | return 0; | |
6711 | } | |
6712 | ||
5bbdf3d5 | 6713 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
6714 | |
6715 | if (constant_pool_offset < symbol_table_offset) | |
6716 | { | |
6717 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
6718 | constant_pool_offset, symbol_table_offset); | |
6719 | return 0; | |
6720 | } | |
6721 | ||
5bbdf3d5 DE |
6722 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
6723 | ||
6724 | cu_list = start + cu_list_offset; | |
6725 | tu_list = start + tu_list_offset; | |
6726 | address_table = start + address_table_offset; | |
6727 | symbol_table = start + symbol_table_offset; | |
6728 | constant_pool = start + constant_pool_offset; | |
6729 | ||
acff9664 NC |
6730 | if (address_table + address_table_size * (2 + 8 + 4) > section->start + section->size) |
6731 | { | |
1306a742 | 6732 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
6733 | return 0; |
6734 | } | |
b4eb7656 | 6735 | |
5bbdf3d5 DE |
6736 | printf (_("\nCU table:\n")); |
6737 | for (i = 0; i < cu_list_elements; i += 2) | |
6738 | { | |
6739 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
6740 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
6741 | ||
6742 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
6743 | (unsigned long) cu_offset, | |
6744 | (unsigned long) (cu_offset + cu_length - 1)); | |
6745 | } | |
6746 | ||
6747 | printf (_("\nTU table:\n")); | |
6748 | for (i = 0; i < tu_list_elements; i += 3) | |
6749 | { | |
6750 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
6751 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
6752 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
6753 | ||
6754 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
6755 | (unsigned long) tu_offset, | |
6756 | (unsigned long) type_offset); | |
6757 | print_dwarf_vma (signature, 8); | |
6758 | printf ("\n"); | |
6759 | } | |
6760 | ||
6761 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
6762 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
6763 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
6764 | { |
6765 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
6766 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
6767 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
6768 | ||
6769 | print_dwarf_vma (low, 8); | |
6770 | print_dwarf_vma (high, 8); | |
da88a764 | 6771 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
6772 | } |
6773 | ||
6774 | printf (_("\nSymbol table:\n")); | |
6775 | for (i = 0; i < symbol_table_slots; ++i) | |
6776 | { | |
6777 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
6778 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
6779 | uint32_t num_cus, cu; | |
6780 | ||
6781 | if (name_offset != 0 | |
6782 | || cu_vector_offset != 0) | |
6783 | { | |
6784 | unsigned int j; | |
362beea4 | 6785 | unsigned char * adr; |
5bbdf3d5 | 6786 | |
362beea4 | 6787 | adr = constant_pool + name_offset; |
53774b7e | 6788 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 6789 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
6790 | { |
6791 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
6792 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
6793 | name_offset, i); | |
6794 | } | |
6795 | else | |
acff9664 NC |
6796 | printf ("[%3u] %.*s:", i, |
6797 | (int) (section->size - (constant_pool_offset + name_offset)), | |
6798 | constant_pool + name_offset); | |
53774b7e | 6799 | |
362beea4 NC |
6800 | adr = constant_pool + cu_vector_offset; |
6801 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
6802 | { |
6803 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
6804 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
6805 | cu_vector_offset, i); | |
6806 | continue; | |
6807 | } | |
57028622 | 6808 | |
362beea4 | 6809 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 6810 | |
362beea4 | 6811 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 6812 | if (num_cus * 4 < num_cus |
362beea4 NC |
6813 | || adr >= section->start + section->size |
6814 | || adr < constant_pool) | |
53774b7e NC |
6815 | { |
6816 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 6817 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
6818 | num_cus, i); |
6819 | continue; | |
6820 | } | |
6821 | ||
8d6eee87 TT |
6822 | if (num_cus > 1) |
6823 | printf ("\n"); | |
f3853b34 | 6824 | |
5bbdf3d5 DE |
6825 | for (j = 0; j < num_cus; ++j) |
6826 | { | |
7c1cef97 | 6827 | int is_static; |
8d6eee87 TT |
6828 | gdb_index_symbol_kind kind; |
6829 | ||
5bbdf3d5 | 6830 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 6831 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
6832 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
6833 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 6834 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 6835 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
6836 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
6837 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 6838 | else |
8d6eee87 TT |
6839 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
6840 | ||
459d52c8 DE |
6841 | printf (" [%s, %s]", |
6842 | is_static ? _("static") : _("global"), | |
6843 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
6844 | if (num_cus > 1) |
6845 | printf ("\n"); | |
5bbdf3d5 | 6846 | } |
8d6eee87 TT |
6847 | if (num_cus <= 1) |
6848 | printf ("\n"); | |
5bbdf3d5 DE |
6849 | } |
6850 | } | |
6851 | ||
6852 | return 1; | |
6853 | } | |
6854 | ||
657d0d47 CC |
6855 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
6856 | ||
6857 | static void | |
6858 | prealloc_cu_tu_list (unsigned int nshndx) | |
6859 | { | |
6860 | if (shndx_pool == NULL) | |
6861 | { | |
6862 | shndx_pool_size = nshndx; | |
6863 | shndx_pool_used = 0; | |
6864 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
6865 | sizeof (unsigned int)); | |
6866 | } | |
6867 | else | |
6868 | { | |
6869 | shndx_pool_size = shndx_pool_used + nshndx; | |
6870 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
6871 | sizeof (unsigned int)); | |
6872 | } | |
6873 | } | |
6874 | ||
6875 | static void | |
6876 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
6877 | { | |
6878 | if (shndx_pool_used >= shndx_pool_size) | |
6879 | { | |
6880 | error (_("Internal error: out of space in the shndx pool.\n")); | |
6881 | return; | |
6882 | } | |
6883 | shndx_pool [shndx_pool_used++] = shndx; | |
6884 | } | |
6885 | ||
6886 | static void | |
6887 | end_cu_tu_entry (void) | |
6888 | { | |
6889 | if (shndx_pool_used >= shndx_pool_size) | |
6890 | { | |
6891 | error (_("Internal error: out of space in the shndx pool.\n")); | |
6892 | return; | |
6893 | } | |
6894 | shndx_pool [shndx_pool_used++] = 0; | |
6895 | } | |
6896 | ||
341f9135 CC |
6897 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
6898 | ||
6899 | static const char * | |
6900 | get_DW_SECT_short_name (unsigned int dw_sect) | |
6901 | { | |
6902 | static char buf[16]; | |
6903 | ||
6904 | switch (dw_sect) | |
6905 | { | |
6906 | case DW_SECT_INFO: | |
6907 | return "info"; | |
6908 | case DW_SECT_TYPES: | |
6909 | return "types"; | |
6910 | case DW_SECT_ABBREV: | |
6911 | return "abbrev"; | |
6912 | case DW_SECT_LINE: | |
6913 | return "line"; | |
6914 | case DW_SECT_LOC: | |
6915 | return "loc"; | |
6916 | case DW_SECT_STR_OFFSETS: | |
6917 | return "str_off"; | |
6918 | case DW_SECT_MACINFO: | |
6919 | return "macinfo"; | |
6920 | case DW_SECT_MACRO: | |
6921 | return "macro"; | |
6922 | default: | |
b4eb7656 | 6923 | break; |
341f9135 CC |
6924 | } |
6925 | ||
6926 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
6927 | return buf; | |
6928 | } | |
6929 | ||
6930 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
6931 | These sections are extensions for Fission. | |
6932 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
6933 | |
6934 | static int | |
6935 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
6936 | { | |
6937 | unsigned char *phdr = section->start; | |
6938 | unsigned char *limit = phdr + section->size; | |
6939 | unsigned char *phash; | |
6940 | unsigned char *pindex; | |
6941 | unsigned char *ppool; | |
6942 | unsigned int version; | |
341f9135 | 6943 | unsigned int ncols = 0; |
657d0d47 CC |
6944 | unsigned int nused; |
6945 | unsigned int nslots; | |
6946 | unsigned int i; | |
341f9135 CC |
6947 | unsigned int j; |
6948 | dwarf_vma signature_high; | |
6949 | dwarf_vma signature_low; | |
6950 | char buf[64]; | |
657d0d47 | 6951 | |
6937bb54 NC |
6952 | /* PR 17512: file: 002-168123-0.004. */ |
6953 | if (phdr == NULL) | |
6954 | { | |
6955 | warn (_("Section %s is empty\n"), section->name); | |
6956 | return 0; | |
6957 | } | |
6958 | /* PR 17512: file: 002-376-0.004. */ | |
6959 | if (section->size < 24) | |
6960 | { | |
72c61a0d | 6961 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
6962 | section->name); |
6963 | return 0; | |
6964 | } | |
6965 | ||
6966 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 6967 | if (version >= 2) |
6937bb54 NC |
6968 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
6969 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
6970 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
6971 | ||
657d0d47 CC |
6972 | phash = phdr + 16; |
6973 | pindex = phash + nslots * 8; | |
6974 | ppool = pindex + nslots * 4; | |
6975 | ||
57028622 | 6976 | /* PR 17531: file: 45d69832. */ |
03a91817 | 6977 | if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0)) |
57028622 NC |
6978 | { |
6979 | warn (_("Section %s is too small for %d slots\n"), | |
6980 | section->name, nslots); | |
6981 | return 0; | |
6982 | } | |
6983 | ||
657d0d47 CC |
6984 | if (do_display) |
6985 | { | |
6986 | printf (_("Contents of the %s section:\n\n"), section->name); | |
6987 | printf (_(" Version: %d\n"), version); | |
341f9135 CC |
6988 | if (version >= 2) |
6989 | printf (_(" Number of columns: %d\n"), ncols); | |
657d0d47 CC |
6990 | printf (_(" Number of used entries: %d\n"), nused); |
6991 | printf (_(" Number of slots: %d\n\n"), nslots); | |
6992 | } | |
6993 | ||
03a91817 | 6994 | if (ppool > limit || ppool < phdr) |
657d0d47 CC |
6995 | { |
6996 | warn (_("Section %s too small for %d hash table entries\n"), | |
6997 | section->name, nslots); | |
6998 | return 0; | |
6999 | } | |
7000 | ||
341f9135 | 7001 | if (version == 1) |
657d0d47 | 7002 | { |
341f9135 CC |
7003 | if (!do_display) |
7004 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
7005 | for (i = 0; i < nslots; i++) | |
657d0d47 | 7006 | { |
341f9135 CC |
7007 | unsigned char *shndx_list; |
7008 | unsigned int shndx; | |
7009 | ||
6937bb54 | 7010 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 7011 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 7012 | { |
6937bb54 | 7013 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 7014 | shndx_list = ppool + j * 4; |
f3853b34 NC |
7015 | /* PR 17531: file: 705e010d. */ |
7016 | if (shndx_list < ppool) | |
7017 | { | |
7018 | warn (_("Section index pool located before start of section\n")); | |
7019 | return 0; | |
7020 | } | |
7021 | ||
341f9135 CC |
7022 | if (do_display) |
7023 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
7024 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
7025 | buf, sizeof (buf))); | |
7026 | for (;;) | |
657d0d47 | 7027 | { |
341f9135 CC |
7028 | if (shndx_list >= limit) |
7029 | { | |
7030 | warn (_("Section %s too small for shndx pool\n"), | |
7031 | section->name); | |
7032 | return 0; | |
7033 | } | |
6937bb54 | 7034 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
7035 | if (shndx == 0) |
7036 | break; | |
7037 | if (do_display) | |
7038 | printf (" %d", shndx); | |
7039 | else | |
7040 | add_shndx_to_cu_tu_entry (shndx); | |
7041 | shndx_list += 4; | |
657d0d47 | 7042 | } |
657d0d47 | 7043 | if (do_display) |
341f9135 | 7044 | printf ("\n"); |
657d0d47 | 7045 | else |
341f9135 CC |
7046 | end_cu_tu_entry (); |
7047 | } | |
7048 | phash += 8; | |
7049 | pindex += 4; | |
7050 | } | |
7051 | } | |
7052 | else if (version == 2) | |
7053 | { | |
7054 | unsigned int val; | |
7055 | unsigned int dw_sect; | |
7056 | unsigned char *ph = phash; | |
7057 | unsigned char *pi = pindex; | |
7058 | unsigned char *poffsets = ppool + ncols * 4; | |
7059 | unsigned char *psizes = poffsets + nused * ncols * 4; | |
7060 | unsigned char *pend = psizes + nused * ncols * 4; | |
7061 | bfd_boolean is_tu_index; | |
7062 | struct cu_tu_set *this_set = NULL; | |
7063 | unsigned int row; | |
7064 | unsigned char *prow; | |
7065 | ||
7066 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
7067 | ||
362beea4 | 7068 | /* PR 17531: file: 0dd159bf. |
b4eb7656 | 7069 | Check for wraparound with an overlarge ncols value. */ |
c8071705 | 7070 | if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols) |
362beea4 NC |
7071 | { |
7072 | warn (_("Overlarge number of columns: %x\n"), ncols); | |
7073 | return 0; | |
7074 | } | |
7075 | ||
341f9135 CC |
7076 | if (pend > limit) |
7077 | { | |
7078 | warn (_("Section %s too small for offset and size tables\n"), | |
7079 | section->name); | |
7080 | return 0; | |
7081 | } | |
7082 | ||
7083 | if (do_display) | |
7084 | { | |
7085 | printf (_(" Offset table\n")); | |
7086 | printf (" slot %-16s ", | |
7087 | is_tu_index ? _("signature") : _("dwo_id")); | |
7088 | } | |
7089 | else | |
7090 | { | |
7091 | if (is_tu_index) | |
7092 | { | |
7093 | tu_count = nused; | |
72c61a0d | 7094 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 7095 | this_set = tu_sets; |
657d0d47 | 7096 | } |
657d0d47 | 7097 | else |
341f9135 CC |
7098 | { |
7099 | cu_count = nused; | |
72c61a0d | 7100 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
7101 | this_set = cu_sets; |
7102 | } | |
7103 | } | |
6937bb54 | 7104 | |
341f9135 CC |
7105 | if (do_display) |
7106 | { | |
7107 | for (j = 0; j < ncols; j++) | |
7108 | { | |
6937bb54 | 7109 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
7110 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
7111 | } | |
7112 | printf ("\n"); | |
7113 | } | |
6937bb54 | 7114 | |
341f9135 CC |
7115 | for (i = 0; i < nslots; i++) |
7116 | { | |
6937bb54 NC |
7117 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
7118 | ||
7119 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
7120 | if (row != 0) |
7121 | { | |
591f7597 | 7122 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 7123 | if (row > nused) |
591f7597 NC |
7124 | { |
7125 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
7126 | row, nused); | |
7127 | return 0; | |
7128 | } | |
7129 | ||
341f9135 CC |
7130 | if (!do_display) |
7131 | memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t)); | |
6937bb54 | 7132 | |
341f9135 | 7133 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
7134 | /* PR 17531: file: b8ce60a8. */ |
7135 | if (prow < poffsets || prow > limit) | |
7136 | { | |
7137 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
7138 | row, ncols); | |
7139 | return 0; | |
7140 | } | |
7141 | ||
341f9135 CC |
7142 | if (do_display) |
7143 | printf (_(" [%3d] 0x%s"), | |
7144 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
7145 | buf, sizeof (buf))); | |
7146 | for (j = 0; j < ncols; j++) | |
7147 | { | |
6937bb54 | 7148 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
7149 | if (do_display) |
7150 | printf (" %8d", val); | |
7151 | else | |
7152 | { | |
6937bb54 | 7153 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
7154 | |
7155 | /* PR 17531: file: 10796eb3. */ | |
7156 | if (dw_sect >= DW_SECT_MAX) | |
7157 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
7158 | else | |
7159 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
7160 | } |
7161 | } | |
6937bb54 | 7162 | |
341f9135 CC |
7163 | if (do_display) |
7164 | printf ("\n"); | |
7165 | } | |
7166 | ph += 8; | |
7167 | pi += 4; | |
7168 | } | |
7169 | ||
7170 | ph = phash; | |
7171 | pi = pindex; | |
7172 | if (do_display) | |
b4eb7656 | 7173 | { |
341f9135 CC |
7174 | printf ("\n"); |
7175 | printf (_(" Size table\n")); | |
7176 | printf (" slot %-16s ", | |
7177 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 7178 | } |
6937bb54 | 7179 | |
341f9135 CC |
7180 | for (j = 0; j < ncols; j++) |
7181 | { | |
6937bb54 | 7182 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
7183 | if (do_display) |
7184 | printf (" %8s", get_DW_SECT_short_name (val)); | |
7185 | } | |
6937bb54 | 7186 | |
341f9135 CC |
7187 | if (do_display) |
7188 | printf ("\n"); | |
6937bb54 | 7189 | |
341f9135 CC |
7190 | for (i = 0; i < nslots; i++) |
7191 | { | |
6937bb54 NC |
7192 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
7193 | ||
7194 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
7195 | if (row != 0) |
7196 | { | |
7197 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 7198 | |
341f9135 CC |
7199 | if (do_display) |
7200 | printf (_(" [%3d] 0x%s"), | |
7201 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
7202 | buf, sizeof (buf))); | |
6937bb54 | 7203 | |
341f9135 CC |
7204 | for (j = 0; j < ncols; j++) |
7205 | { | |
6937bb54 | 7206 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
7207 | if (do_display) |
7208 | printf (" %8d", val); | |
7209 | else | |
7210 | { | |
6937bb54 | 7211 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
7212 | if (dw_sect >= DW_SECT_MAX) |
7213 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
7214 | else | |
341f9135 CC |
7215 | this_set [row - 1].section_sizes [dw_sect] = val; |
7216 | } | |
7217 | } | |
6937bb54 | 7218 | |
341f9135 CC |
7219 | if (do_display) |
7220 | printf ("\n"); | |
7221 | } | |
6937bb54 | 7222 | |
341f9135 CC |
7223 | ph += 8; |
7224 | pi += 4; | |
657d0d47 | 7225 | } |
657d0d47 | 7226 | } |
341f9135 | 7227 | else if (do_display) |
6937bb54 | 7228 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
7229 | |
7230 | if (do_display) | |
7231 | printf ("\n"); | |
7232 | ||
7233 | return 1; | |
7234 | } | |
7235 | ||
7236 | /* Load the CU and TU indexes if present. This will build a list of | |
7237 | section sets that we can use to associate a .debug_info.dwo section | |
7238 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
7239 | ||
7240 | static void | |
7241 | load_cu_tu_indexes (void *file) | |
7242 | { | |
7243 | /* If we have already loaded (or tried to load) the CU and TU indexes | |
7244 | then do not bother to repeat the task. */ | |
7245 | if (cu_tu_indexes_read) | |
7246 | return; | |
7247 | ||
7248 | if (load_debug_section (dwp_cu_index, file)) | |
7249 | process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0); | |
7250 | ||
7251 | if (load_debug_section (dwp_tu_index, file)) | |
7252 | process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0); | |
7253 | ||
7254 | cu_tu_indexes_read = 1; | |
7255 | } | |
7256 | ||
7257 | /* Find the set of sections that includes section SHNDX. */ | |
7258 | ||
7259 | unsigned int * | |
7260 | find_cu_tu_set (void *file, unsigned int shndx) | |
7261 | { | |
7262 | unsigned int i; | |
7263 | ||
7264 | load_cu_tu_indexes (file); | |
7265 | ||
7266 | /* Find SHNDX in the shndx pool. */ | |
7267 | for (i = 0; i < shndx_pool_used; i++) | |
7268 | if (shndx_pool [i] == shndx) | |
7269 | break; | |
7270 | ||
7271 | if (i >= shndx_pool_used) | |
7272 | return NULL; | |
7273 | ||
7274 | /* Now backup to find the first entry in the set. */ | |
7275 | while (i > 0 && shndx_pool [i - 1] != 0) | |
7276 | i--; | |
7277 | ||
7278 | return shndx_pool + i; | |
7279 | } | |
7280 | ||
7281 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
7282 | ||
7283 | static int | |
7284 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
7285 | { | |
7286 | return process_cu_tu_index (section, 1); | |
7287 | } | |
7288 | ||
19e6b90e L |
7289 | static int |
7290 | display_debug_not_supported (struct dwarf_section *section, | |
7291 | void *file ATTRIBUTE_UNUSED) | |
7292 | { | |
7293 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
7294 | section->name); | |
7295 | ||
7296 | return 1; | |
7297 | } | |
7298 | ||
1306a742 NC |
7299 | /* Like malloc, but takes two parameters like calloc. |
7300 | Verifies that the first parameter is not too large. | |
82b1b41b | 7301 | Note: does *not* initialise the allocated memory to zero. */ |
19e6b90e L |
7302 | void * |
7303 | cmalloc (size_t nmemb, size_t size) | |
7304 | { | |
7305 | /* Check for overflow. */ | |
7306 | if (nmemb >= ~(size_t) 0 / size) | |
7307 | return NULL; | |
82b1b41b NC |
7308 | |
7309 | return xmalloc (nmemb * size); | |
19e6b90e L |
7310 | } |
7311 | ||
1306a742 NC |
7312 | /* Like xmalloc, but takes two parameters like calloc. |
7313 | Verifies that the first parameter is not too large. | |
7314 | Note: does *not* initialise the allocated memory to zero. */ | |
72c61a0d | 7315 | void * |
1306a742 | 7316 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
7317 | { |
7318 | /* Check for overflow. */ | |
7319 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
7320 | { |
7321 | fprintf (stderr, | |
7322 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
7323 | (long) nmemb); | |
7324 | xexit (1); | |
7325 | } | |
72c61a0d | 7326 | |
1306a742 | 7327 | return xmalloc (nmemb * size); |
72c61a0d NC |
7328 | } |
7329 | ||
1306a742 NC |
7330 | /* Like xrealloc, but takes three parameters. |
7331 | Verifies that the second parameter is not too large. | |
7332 | Note: does *not* initialise any new memory to zero. */ | |
19e6b90e | 7333 | void * |
1306a742 | 7334 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
7335 | { |
7336 | /* Check for overflow. */ | |
7337 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
7338 | { |
7339 | fprintf (stderr, | |
7340 | _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), | |
7341 | (long) nmemb); | |
7342 | xexit (1); | |
7343 | } | |
82b1b41b | 7344 | |
1306a742 | 7345 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
7346 | } |
7347 | ||
1306a742 | 7348 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
19e6b90e | 7349 | void * |
1306a742 | 7350 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
7351 | { |
7352 | /* Check for overflow. */ | |
7353 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
7354 | { |
7355 | fprintf (stderr, | |
7356 | _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), | |
7357 | (long) nmemb); | |
7358 | xexit (1); | |
7359 | } | |
82b1b41b | 7360 | |
1306a742 | 7361 | return xcalloc (nmemb, size); |
19e6b90e L |
7362 | } |
7363 | ||
19e6b90e L |
7364 | void |
7365 | free_debug_memory (void) | |
7366 | { | |
3f5e193b | 7367 | unsigned int i; |
19e6b90e L |
7368 | |
7369 | free_abbrevs (); | |
7370 | ||
7371 | for (i = 0; i < max; i++) | |
3f5e193b | 7372 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 7373 | |
cc86f28f | 7374 | if (debug_information != NULL) |
19e6b90e | 7375 | { |
cc86f28f | 7376 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
19e6b90e | 7377 | { |
cc86f28f | 7378 | for (i = 0; i < num_debug_info_entries; i++) |
19e6b90e | 7379 | { |
cc86f28f NC |
7380 | if (!debug_information [i].max_loc_offsets) |
7381 | { | |
7382 | free (debug_information [i].loc_offsets); | |
7383 | free (debug_information [i].have_frame_base); | |
7384 | } | |
7385 | if (!debug_information [i].max_range_lists) | |
7386 | free (debug_information [i].range_lists); | |
19e6b90e | 7387 | } |
19e6b90e L |
7388 | } |
7389 | free (debug_information); | |
7390 | debug_information = NULL; | |
82b1b41b | 7391 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 7392 | } |
19e6b90e L |
7393 | } |
7394 | ||
4cb93e3b TG |
7395 | void |
7396 | dwarf_select_sections_by_names (const char *names) | |
7397 | { | |
7398 | typedef struct | |
7399 | { | |
7400 | const char * option; | |
7401 | int * variable; | |
f9f0e732 | 7402 | int val; |
4cb93e3b TG |
7403 | } |
7404 | debug_dump_long_opts; | |
7405 | ||
7406 | static const debug_dump_long_opts opts_table [] = | |
7407 | { | |
7408 | /* Please keep this table alpha- sorted. */ | |
7409 | { "Ranges", & do_debug_ranges, 1 }, | |
7410 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 7411 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 7412 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
7413 | { "cu_index", & do_debug_cu_index, 1 }, |
7414 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
4cb93e3b TG |
7415 | { "frames", & do_debug_frames, 1 }, |
7416 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
7417 | /* The special .gdb_index section. */ |
7418 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
7419 | { "info", & do_debug_info, 1 }, |
7420 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
4cb93e3b TG |
7421 | { "loc", & do_debug_loc, 1 }, |
7422 | { "macro", & do_debug_macinfo, 1 }, | |
7423 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 7424 | { "pubtypes", & do_debug_pubtypes, 1 }, |
4cb93e3b TG |
7425 | /* This entry is for compatability |
7426 | with earlier versions of readelf. */ | |
7427 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 7428 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 7429 | { "str", & do_debug_str, 1 }, |
6f875884 TG |
7430 | /* These trace_* sections are used by Itanium VMS. */ |
7431 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
7432 | { "trace_aranges", & do_trace_aranges, 1 }, | |
7433 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
7434 | { NULL, NULL, 0 } |
7435 | }; | |
7436 | ||
7437 | const char *p; | |
467c65bc | 7438 | |
4cb93e3b TG |
7439 | p = names; |
7440 | while (*p) | |
7441 | { | |
7442 | const debug_dump_long_opts * entry; | |
467c65bc | 7443 | |
4cb93e3b TG |
7444 | for (entry = opts_table; entry->option; entry++) |
7445 | { | |
7446 | size_t len = strlen (entry->option); | |
467c65bc | 7447 | |
4cb93e3b TG |
7448 | if (strncmp (p, entry->option, len) == 0 |
7449 | && (p[len] == ',' || p[len] == '\0')) | |
7450 | { | |
7451 | * entry->variable |= entry->val; | |
467c65bc | 7452 | |
4cb93e3b TG |
7453 | /* The --debug-dump=frames-interp option also |
7454 | enables the --debug-dump=frames option. */ | |
7455 | if (do_debug_frames_interp) | |
7456 | do_debug_frames = 1; | |
7457 | ||
7458 | p += len; | |
7459 | break; | |
7460 | } | |
7461 | } | |
467c65bc | 7462 | |
4cb93e3b TG |
7463 | if (entry->option == NULL) |
7464 | { | |
7465 | warn (_("Unrecognized debug option '%s'\n"), p); | |
7466 | p = strchr (p, ','); | |
7467 | if (p == NULL) | |
7468 | break; | |
7469 | } | |
467c65bc | 7470 | |
4cb93e3b TG |
7471 | if (*p == ',') |
7472 | p++; | |
7473 | } | |
7474 | } | |
7475 | ||
7476 | void | |
7477 | dwarf_select_sections_by_letters (const char *letters) | |
7478 | { | |
91d6fa6a | 7479 | unsigned int lindex = 0; |
4cb93e3b | 7480 | |
91d6fa6a NC |
7481 | while (letters[lindex]) |
7482 | switch (letters[lindex++]) | |
4cb93e3b TG |
7483 | { |
7484 | case 'i': | |
7485 | do_debug_info = 1; | |
7486 | break; | |
467c65bc | 7487 | |
4cb93e3b TG |
7488 | case 'a': |
7489 | do_debug_abbrevs = 1; | |
7490 | break; | |
467c65bc | 7491 | |
4cb93e3b TG |
7492 | case 'l': |
7493 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
7494 | break; | |
467c65bc | 7495 | |
4cb93e3b TG |
7496 | case 'L': |
7497 | do_debug_lines |= FLAG_DEBUG_LINES_DECODED; | |
7498 | break; | |
467c65bc | 7499 | |
4cb93e3b TG |
7500 | case 'p': |
7501 | do_debug_pubnames = 1; | |
7502 | break; | |
467c65bc | 7503 | |
f9f0e732 NC |
7504 | case 't': |
7505 | do_debug_pubtypes = 1; | |
7506 | break; | |
467c65bc | 7507 | |
4cb93e3b TG |
7508 | case 'r': |
7509 | do_debug_aranges = 1; | |
7510 | break; | |
467c65bc | 7511 | |
4cb93e3b TG |
7512 | case 'R': |
7513 | do_debug_ranges = 1; | |
7514 | break; | |
467c65bc | 7515 | |
4cb93e3b TG |
7516 | case 'F': |
7517 | do_debug_frames_interp = 1; | |
7518 | case 'f': | |
7519 | do_debug_frames = 1; | |
7520 | break; | |
467c65bc | 7521 | |
4cb93e3b TG |
7522 | case 'm': |
7523 | do_debug_macinfo = 1; | |
7524 | break; | |
467c65bc | 7525 | |
4cb93e3b TG |
7526 | case 's': |
7527 | do_debug_str = 1; | |
7528 | break; | |
467c65bc | 7529 | |
4cb93e3b TG |
7530 | case 'o': |
7531 | do_debug_loc = 1; | |
7532 | break; | |
467c65bc | 7533 | |
4cb93e3b | 7534 | default: |
7cc78d07 | 7535 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
7536 | break; |
7537 | } | |
7538 | } | |
7539 | ||
7540 | void | |
7541 | dwarf_select_sections_all (void) | |
7542 | { | |
7543 | do_debug_info = 1; | |
7544 | do_debug_abbrevs = 1; | |
7545 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
7546 | do_debug_pubnames = 1; | |
f9f0e732 | 7547 | do_debug_pubtypes = 1; |
4cb93e3b TG |
7548 | do_debug_aranges = 1; |
7549 | do_debug_ranges = 1; | |
7550 | do_debug_frames = 1; | |
7551 | do_debug_macinfo = 1; | |
7552 | do_debug_str = 1; | |
7553 | do_debug_loc = 1; | |
5bbdf3d5 | 7554 | do_gdb_index = 1; |
6f875884 TG |
7555 | do_trace_info = 1; |
7556 | do_trace_abbrevs = 1; | |
7557 | do_trace_aranges = 1; | |
657d0d47 CC |
7558 | do_debug_addr = 1; |
7559 | do_debug_cu_index = 1; | |
4cb93e3b TG |
7560 | } |
7561 | ||
19e6b90e L |
7562 | struct dwarf_section_display debug_displays[] = |
7563 | { | |
06614111 | 7564 | { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7565 | display_debug_abbrev, &do_debug_abbrevs, 0 }, |
06614111 | 7566 | { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7567 | display_debug_aranges, &do_debug_aranges, 1 }, |
06614111 | 7568 | { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7569 | display_debug_frames, &do_debug_frames, 1 }, |
06614111 | 7570 | { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL }, |
4723351a | 7571 | display_debug_info, &do_debug_info, 1 }, |
06614111 | 7572 | { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7573 | display_debug_lines, &do_debug_lines, 1 }, |
06614111 | 7574 | { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7575 | display_debug_pubnames, &do_debug_pubnames, 0 }, |
06614111 | 7576 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL }, |
459d52c8 | 7577 | display_debug_gnu_pubnames, &do_debug_pubnames, 0 }, |
06614111 | 7578 | { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7579 | display_debug_frames, &do_debug_frames, 1 }, |
06614111 | 7580 | { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7581 | display_debug_macinfo, &do_debug_macinfo, 0 }, |
06614111 | 7582 | { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7583 | display_debug_macro, &do_debug_macinfo, 1 }, |
06614111 | 7584 | { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7585 | display_debug_str, &do_debug_str, 0 }, |
06614111 | 7586 | { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7587 | display_debug_loc, &do_debug_loc, 1 }, |
06614111 | 7588 | { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7589 | display_debug_pubnames, &do_debug_pubtypes, 0 }, |
06614111 | 7590 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL }, |
459d52c8 | 7591 | display_debug_gnu_pubnames, &do_debug_pubtypes, 0 }, |
06614111 | 7592 | { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7593 | display_debug_ranges, &do_debug_ranges, 1 }, |
06614111 | 7594 | { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7595 | display_debug_not_supported, NULL, 0 }, |
06614111 | 7596 | { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7597 | display_debug_not_supported, NULL, 0 }, |
06614111 | 7598 | { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL }, |
4723351a | 7599 | display_debug_types, &do_debug_info, 1 }, |
06614111 | 7600 | { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7601 | display_debug_not_supported, NULL, 0 }, |
b4eb7656 | 7602 | { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7603 | display_gdb_index, &do_gdb_index, 0 }, |
06614111 | 7604 | { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL }, |
657d0d47 | 7605 | display_trace_info, &do_trace_info, 1 }, |
06614111 | 7606 | { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7607 | display_debug_abbrev, &do_trace_abbrevs, 0 }, |
06614111 | 7608 | { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7609 | display_debug_aranges, &do_trace_aranges, 0 }, |
06614111 | 7610 | { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL }, |
657d0d47 | 7611 | display_debug_info, &do_debug_info, 1 }, |
06614111 | 7612 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7613 | display_debug_abbrev, &do_debug_abbrevs, 0 }, |
06614111 | 7614 | { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL }, |
657d0d47 | 7615 | display_debug_types, &do_debug_info, 1 }, |
06614111 | 7616 | { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7617 | display_debug_lines, &do_debug_lines, 1 }, |
06614111 | 7618 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7619 | display_debug_loc, &do_debug_loc, 1 }, |
06614111 | 7620 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7621 | display_debug_macro, &do_debug_macinfo, 1 }, |
06614111 | 7622 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7623 | display_debug_macinfo, &do_debug_macinfo, 0 }, |
06614111 | 7624 | { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7625 | display_debug_str, &do_debug_str, 1 }, |
06614111 | 7626 | { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7627 | display_debug_str_offsets, NULL, 0 }, |
06614111 | 7628 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL }, |
4723351a | 7629 | display_debug_str_offsets, NULL, 0 }, |
06614111 | 7630 | { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7631 | display_debug_addr, &do_debug_addr, 1 }, |
06614111 | 7632 | { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7633 | display_cu_index, &do_debug_cu_index, 0 }, |
06614111 | 7634 | { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL }, |
657d0d47 | 7635 | display_cu_index, &do_debug_cu_index, 0 }, |
19e6b90e | 7636 | }; |