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