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