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