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