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