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