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: |
19e6b90e L |
1287 | uvalue = byte_get (data, offset_size); |
1288 | data += offset_size; | |
1289 | break; | |
1290 | ||
932fd279 JJ |
1291 | case DW_FORM_flag_present: |
1292 | uvalue = 1; | |
1293 | break; | |
1294 | ||
19e6b90e L |
1295 | case DW_FORM_ref1: |
1296 | case DW_FORM_flag: | |
1297 | case DW_FORM_data1: | |
1298 | uvalue = byte_get (data++, 1); | |
1299 | break; | |
1300 | ||
1301 | case DW_FORM_ref2: | |
1302 | case DW_FORM_data2: | |
1303 | uvalue = byte_get (data, 2); | |
1304 | data += 2; | |
1305 | break; | |
1306 | ||
1307 | case DW_FORM_ref4: | |
1308 | case DW_FORM_data4: | |
1309 | uvalue = byte_get (data, 4); | |
1310 | data += 4; | |
1311 | break; | |
1312 | ||
1313 | case DW_FORM_sdata: | |
1314 | uvalue = read_leb128 (data, & bytes_read, 1); | |
1315 | data += bytes_read; | |
1316 | break; | |
1317 | ||
4723351a CC |
1318 | case DW_FORM_GNU_str_index: |
1319 | uvalue = read_leb128 (data, & bytes_read, 0); | |
1320 | data += bytes_read; | |
1321 | break; | |
1322 | ||
19e6b90e L |
1323 | case DW_FORM_ref_udata: |
1324 | case DW_FORM_udata: | |
1325 | uvalue = read_leb128 (data, & bytes_read, 0); | |
1326 | data += bytes_read; | |
1327 | break; | |
1328 | ||
1329 | case DW_FORM_indirect: | |
1330 | form = read_leb128 (data, & bytes_read, 0); | |
1331 | data += bytes_read; | |
1332 | if (!do_loc) | |
1333 | printf (" %s", get_FORM_name (form)); | |
1334 | return read_and_display_attr_value (attribute, form, data, | |
1335 | cu_offset, pointer_size, | |
1336 | offset_size, dwarf_version, | |
ec4d4525 | 1337 | debug_info_p, do_loc, |
6e3d6dc1 | 1338 | section); |
4723351a CC |
1339 | case DW_FORM_GNU_addr_index: |
1340 | uvalue = read_leb128 (data, & bytes_read, 0); | |
1341 | data += bytes_read; | |
1342 | break; | |
19e6b90e L |
1343 | } |
1344 | ||
1345 | switch (form) | |
1346 | { | |
1347 | case DW_FORM_ref_addr: | |
1348 | if (!do_loc) | |
467c65bc | 1349 | printf (" <0x%s>", dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
1350 | break; |
1351 | ||
1352 | case DW_FORM_ref1: | |
1353 | case DW_FORM_ref2: | |
1354 | case DW_FORM_ref4: | |
1355 | case DW_FORM_ref_udata: | |
1356 | if (!do_loc) | |
467c65bc | 1357 | printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
1358 | break; |
1359 | ||
1360 | case DW_FORM_data4: | |
1361 | case DW_FORM_addr: | |
932fd279 | 1362 | case DW_FORM_sec_offset: |
19e6b90e | 1363 | if (!do_loc) |
467c65bc | 1364 | printf (" 0x%s", dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
1365 | break; |
1366 | ||
932fd279 | 1367 | case DW_FORM_flag_present: |
19e6b90e L |
1368 | case DW_FORM_flag: |
1369 | case DW_FORM_data1: | |
1370 | case DW_FORM_data2: | |
1371 | case DW_FORM_sdata: | |
1372 | case DW_FORM_udata: | |
1373 | if (!do_loc) | |
467c65bc | 1374 | printf (" %s", dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
1375 | break; |
1376 | ||
1377 | case DW_FORM_ref8: | |
1378 | case DW_FORM_data8: | |
1379 | if (!do_loc) | |
1380 | { | |
74bc6052 CC |
1381 | dwarf_vma high_bits; |
1382 | char buf[64]; | |
1383 | ||
1384 | byte_get_64 (data, &high_bits, &uvalue); | |
1385 | printf (" 0x%s", | |
1386 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); | |
19e6b90e L |
1387 | } |
1388 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
1389 | && num_debug_info_entries == 0) | |
1390 | { | |
1391 | if (sizeof (uvalue) == 8) | |
1392 | uvalue = byte_get (data, 8); | |
1393 | else | |
467c65bc | 1394 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e L |
1395 | } |
1396 | data += 8; | |
1397 | break; | |
1398 | ||
1399 | case DW_FORM_string: | |
1400 | if (!do_loc) | |
1401 | printf (" %s", data); | |
1402 | data += strlen ((char *) data) + 1; | |
1403 | break; | |
1404 | ||
1405 | case DW_FORM_block: | |
932fd279 | 1406 | case DW_FORM_exprloc: |
19e6b90e L |
1407 | uvalue = read_leb128 (data, & bytes_read, 0); |
1408 | block_start = data + bytes_read; | |
1409 | if (do_loc) | |
1410 | data = block_start + uvalue; | |
1411 | else | |
1412 | data = display_block (block_start, uvalue); | |
1413 | break; | |
1414 | ||
1415 | case DW_FORM_block1: | |
1416 | uvalue = byte_get (data, 1); | |
1417 | block_start = data + 1; | |
1418 | if (do_loc) | |
1419 | data = block_start + uvalue; | |
1420 | else | |
1421 | data = display_block (block_start, uvalue); | |
1422 | break; | |
1423 | ||
1424 | case DW_FORM_block2: | |
1425 | uvalue = byte_get (data, 2); | |
1426 | block_start = data + 2; | |
1427 | if (do_loc) | |
1428 | data = block_start + uvalue; | |
1429 | else | |
1430 | data = display_block (block_start, uvalue); | |
1431 | break; | |
1432 | ||
1433 | case DW_FORM_block4: | |
1434 | uvalue = byte_get (data, 4); | |
1435 | block_start = data + 4; | |
1436 | if (do_loc) | |
1437 | data = block_start + uvalue; | |
1438 | else | |
1439 | data = display_block (block_start, uvalue); | |
1440 | break; | |
1441 | ||
1442 | case DW_FORM_strp: | |
1443 | if (!do_loc) | |
47704ddf KT |
1444 | printf (_(" (indirect string, offset: 0x%s): %s"), |
1445 | dwarf_vmatoa ("x", uvalue), | |
1446 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
1447 | break; |
1448 | ||
4723351a CC |
1449 | case DW_FORM_GNU_str_index: |
1450 | if (!do_loc) | |
1451 | { | |
1452 | const char *suffix = strrchr (section->name, '.'); | |
1453 | int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0; | |
1454 | ||
1455 | printf (_(" (indexed string: 0x%s): %s"), | |
1456 | dwarf_vmatoa ("x", uvalue), | |
1457 | fetch_indexed_string (uvalue, offset_size, dwo)); | |
1458 | } | |
1459 | break; | |
1460 | ||
19e6b90e L |
1461 | case DW_FORM_indirect: |
1462 | /* Handled above. */ | |
1463 | break; | |
1464 | ||
2b6f5997 CC |
1465 | case DW_FORM_ref_sig8: |
1466 | if (!do_loc) | |
1467 | { | |
74bc6052 CC |
1468 | dwarf_vma high_bits; |
1469 | char buf[64]; | |
1470 | ||
1471 | byte_get_64 (data, &high_bits, &uvalue); | |
1472 | printf (" signature: 0x%s", | |
1473 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); | |
2b6f5997 | 1474 | } |
74bc6052 | 1475 | data += 8; |
2b6f5997 CC |
1476 | break; |
1477 | ||
4723351a CC |
1478 | case DW_FORM_GNU_addr_index: |
1479 | if (!do_loc) | |
1480 | printf (_(" (addr_index: 0x%s): %s"), | |
1481 | dwarf_vmatoa ("x", uvalue), | |
1482 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
1483 | break; | |
1484 | ||
19e6b90e L |
1485 | default: |
1486 | warn (_("Unrecognized form: %lu\n"), form); | |
1487 | break; | |
1488 | } | |
1489 | ||
19e6b90e | 1490 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
1491 | && num_debug_info_entries == 0 |
1492 | && debug_info_p != NULL) | |
19e6b90e L |
1493 | { |
1494 | switch (attribute) | |
1495 | { | |
1496 | case DW_AT_frame_base: | |
1497 | have_frame_base = 1; | |
1498 | case DW_AT_location: | |
e2a0d921 NC |
1499 | case DW_AT_string_length: |
1500 | case DW_AT_return_addr: | |
19e6b90e L |
1501 | case DW_AT_data_member_location: |
1502 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
1503 | case DW_AT_segment: |
1504 | case DW_AT_static_link: | |
1505 | case DW_AT_use_location: | |
629e7ca8 JJ |
1506 | case DW_AT_GNU_call_site_value: |
1507 | case DW_AT_GNU_call_site_data_value: | |
1508 | case DW_AT_GNU_call_site_target: | |
1509 | case DW_AT_GNU_call_site_target_clobbered: | |
212b6063 JK |
1510 | if ((dwarf_version < 4 |
1511 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) | |
932fd279 | 1512 | || form == DW_FORM_sec_offset) |
19e6b90e L |
1513 | { |
1514 | /* Process location list. */ | |
91d6fa6a | 1515 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
1516 | unsigned int num = debug_info_p->num_loc_offsets; |
1517 | ||
91d6fa6a | 1518 | if (lmax == 0 || num >= lmax) |
19e6b90e | 1519 | { |
91d6fa6a | 1520 | lmax += 1024; |
467c65bc | 1521 | debug_info_p->loc_offsets = (dwarf_vma *) |
3f5e193b | 1522 | xcrealloc (debug_info_p->loc_offsets, |
91d6fa6a | 1523 | lmax, sizeof (*debug_info_p->loc_offsets)); |
3f5e193b NC |
1524 | debug_info_p->have_frame_base = (int *) |
1525 | xcrealloc (debug_info_p->have_frame_base, | |
91d6fa6a NC |
1526 | lmax, sizeof (*debug_info_p->have_frame_base)); |
1527 | debug_info_p->max_loc_offsets = lmax; | |
19e6b90e L |
1528 | } |
1529 | debug_info_p->loc_offsets [num] = uvalue; | |
1530 | debug_info_p->have_frame_base [num] = have_frame_base; | |
1531 | debug_info_p->num_loc_offsets++; | |
1532 | } | |
1533 | break; | |
e2a0d921 | 1534 | |
19e6b90e L |
1535 | case DW_AT_low_pc: |
1536 | if (need_base_address) | |
1537 | debug_info_p->base_address = uvalue; | |
1538 | break; | |
1539 | ||
4723351a CC |
1540 | case DW_AT_GNU_addr_base: |
1541 | debug_info_p->addr_base = uvalue; | |
1542 | break; | |
1543 | ||
1544 | case DW_AT_GNU_ranges_base: | |
1545 | debug_info_p->ranges_base = uvalue; | |
1546 | break; | |
1547 | ||
19e6b90e | 1548 | case DW_AT_ranges: |
212b6063 JK |
1549 | if ((dwarf_version < 4 |
1550 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) | |
932fd279 | 1551 | || form == DW_FORM_sec_offset) |
19e6b90e L |
1552 | { |
1553 | /* Process range list. */ | |
91d6fa6a | 1554 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
1555 | unsigned int num = debug_info_p->num_range_lists; |
1556 | ||
91d6fa6a | 1557 | if (lmax == 0 || num >= lmax) |
19e6b90e | 1558 | { |
91d6fa6a | 1559 | lmax += 1024; |
467c65bc | 1560 | debug_info_p->range_lists = (dwarf_vma *) |
3f5e193b | 1561 | xcrealloc (debug_info_p->range_lists, |
91d6fa6a NC |
1562 | lmax, sizeof (*debug_info_p->range_lists)); |
1563 | debug_info_p->max_range_lists = lmax; | |
19e6b90e L |
1564 | } |
1565 | debug_info_p->range_lists [num] = uvalue; | |
1566 | debug_info_p->num_range_lists++; | |
1567 | } | |
1568 | break; | |
1569 | ||
1570 | default: | |
1571 | break; | |
1572 | } | |
1573 | } | |
1574 | ||
4ccf1e31 | 1575 | if (do_loc || attribute == 0) |
19e6b90e L |
1576 | return data; |
1577 | ||
ec4d4525 | 1578 | /* For some attributes we can display further information. */ |
19e6b90e L |
1579 | printf ("\t"); |
1580 | ||
1581 | switch (attribute) | |
1582 | { | |
1583 | case DW_AT_inline: | |
1584 | switch (uvalue) | |
1585 | { | |
1586 | case DW_INL_not_inlined: | |
1587 | printf (_("(not inlined)")); | |
1588 | break; | |
1589 | case DW_INL_inlined: | |
1590 | printf (_("(inlined)")); | |
1591 | break; | |
1592 | case DW_INL_declared_not_inlined: | |
1593 | printf (_("(declared as inline but ignored)")); | |
1594 | break; | |
1595 | case DW_INL_declared_inlined: | |
1596 | printf (_("(declared as inline and inlined)")); | |
1597 | break; | |
1598 | default: | |
47704ddf KT |
1599 | printf (_(" (Unknown inline attribute value: %s)"), |
1600 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1601 | break; |
1602 | } | |
1603 | break; | |
1604 | ||
1605 | case DW_AT_language: | |
1606 | switch (uvalue) | |
1607 | { | |
4b78141a | 1608 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 1609 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
1610 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
1611 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 1612 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
1613 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
1614 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
1615 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
1616 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 1617 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 1618 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 1619 | /* DWARF 2.1 values. */ |
4b78141a | 1620 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
1621 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
1622 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
1623 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
1624 | /* DWARF 3 values. */ |
1625 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
1626 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
1627 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
1628 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
1629 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
1630 | /* DWARF 4 values. */ |
1631 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 ILT |
1632 | /* DWARF 5 values. */ |
1633 | case DW_LANG_Go: printf ("(Go)"); break; | |
19e6b90e L |
1634 | /* MIPS extension. */ |
1635 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
1636 | /* UPC extension. */ | |
1637 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
1638 | default: | |
4b78141a | 1639 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 1640 | printf (_("(implementation defined: %s)"), |
467c65bc | 1641 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 1642 | else |
9cf03b7e | 1643 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
1644 | break; |
1645 | } | |
1646 | break; | |
1647 | ||
1648 | case DW_AT_encoding: | |
1649 | switch (uvalue) | |
1650 | { | |
1651 | case DW_ATE_void: printf ("(void)"); break; | |
1652 | case DW_ATE_address: printf ("(machine address)"); break; | |
1653 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
1654 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
1655 | case DW_ATE_float: printf ("(float)"); break; | |
1656 | case DW_ATE_signed: printf ("(signed)"); break; | |
1657 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
1658 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
1659 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 1660 | /* DWARF 2.1 values: */ |
19e6b90e L |
1661 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
1662 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
1663 | /* DWARF 3 values: */ |
1664 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
1665 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
1666 | case DW_ATE_edited: printf ("(edited)"); break; | |
1667 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
1668 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
1669 | /* HP extensions: */ | |
1670 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
1671 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
1672 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
1673 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
1674 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
1675 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
1676 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
1677 | ||
19e6b90e L |
1678 | default: |
1679 | if (uvalue >= DW_ATE_lo_user | |
1680 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 1681 | printf (_("(user defined type)")); |
19e6b90e | 1682 | else |
9cf03b7e | 1683 | printf (_("(unknown type)")); |
19e6b90e L |
1684 | break; |
1685 | } | |
1686 | break; | |
1687 | ||
1688 | case DW_AT_accessibility: | |
1689 | switch (uvalue) | |
1690 | { | |
1691 | case DW_ACCESS_public: printf ("(public)"); break; | |
1692 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
1693 | case DW_ACCESS_private: printf ("(private)"); break; | |
1694 | default: | |
9cf03b7e | 1695 | printf (_("(unknown accessibility)")); |
19e6b90e L |
1696 | break; |
1697 | } | |
1698 | break; | |
1699 | ||
1700 | case DW_AT_visibility: | |
1701 | switch (uvalue) | |
1702 | { | |
1703 | case DW_VIS_local: printf ("(local)"); break; | |
1704 | case DW_VIS_exported: printf ("(exported)"); break; | |
1705 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 1706 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
1707 | } |
1708 | break; | |
1709 | ||
1710 | case DW_AT_virtuality: | |
1711 | switch (uvalue) | |
1712 | { | |
1713 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
1714 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
1715 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 1716 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
1717 | } |
1718 | break; | |
1719 | ||
1720 | case DW_AT_identifier_case: | |
1721 | switch (uvalue) | |
1722 | { | |
1723 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
1724 | case DW_ID_up_case: printf ("(up_case)"); break; | |
1725 | case DW_ID_down_case: printf ("(down_case)"); break; | |
1726 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 1727 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
1728 | } |
1729 | break; | |
1730 | ||
1731 | case DW_AT_calling_convention: | |
1732 | switch (uvalue) | |
1733 | { | |
1734 | case DW_CC_normal: printf ("(normal)"); break; | |
1735 | case DW_CC_program: printf ("(program)"); break; | |
1736 | case DW_CC_nocall: printf ("(nocall)"); break; | |
1737 | default: | |
1738 | if (uvalue >= DW_CC_lo_user | |
1739 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 1740 | printf (_("(user defined)")); |
19e6b90e | 1741 | else |
9cf03b7e | 1742 | printf (_("(unknown convention)")); |
19e6b90e L |
1743 | } |
1744 | break; | |
1745 | ||
1746 | case DW_AT_ordering: | |
1747 | switch (uvalue) | |
1748 | { | |
9cf03b7e | 1749 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
1750 | case 0: printf ("(row major)"); break; |
1751 | case 1: printf ("(column major)"); break; | |
1752 | } | |
1753 | break; | |
1754 | ||
1755 | case DW_AT_frame_base: | |
1756 | have_frame_base = 1; | |
1757 | case DW_AT_location: | |
e2a0d921 NC |
1758 | case DW_AT_string_length: |
1759 | case DW_AT_return_addr: | |
19e6b90e L |
1760 | case DW_AT_data_member_location: |
1761 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
1762 | case DW_AT_segment: |
1763 | case DW_AT_static_link: | |
1764 | case DW_AT_use_location: | |
629e7ca8 JJ |
1765 | case DW_AT_GNU_call_site_value: |
1766 | case DW_AT_GNU_call_site_data_value: | |
1767 | case DW_AT_GNU_call_site_target: | |
1768 | case DW_AT_GNU_call_site_target_clobbered: | |
212b6063 JK |
1769 | if ((dwarf_version < 4 |
1770 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) | |
932fd279 | 1771 | || form == DW_FORM_sec_offset) |
e2a0d921 NC |
1772 | printf (_("(location list)")); |
1773 | /* Fall through. */ | |
19e6b90e L |
1774 | case DW_AT_allocated: |
1775 | case DW_AT_associated: | |
1776 | case DW_AT_data_location: | |
1777 | case DW_AT_stride: | |
1778 | case DW_AT_upper_bound: | |
cecf136e | 1779 | case DW_AT_lower_bound: |
19e6b90e L |
1780 | if (block_start) |
1781 | { | |
1782 | int need_frame_base; | |
1783 | ||
1784 | printf ("("); | |
1785 | need_frame_base = decode_location_expression (block_start, | |
1786 | pointer_size, | |
b7807392 JJ |
1787 | offset_size, |
1788 | dwarf_version, | |
19e6b90e | 1789 | uvalue, |
f1c4cc75 | 1790 | cu_offset, section); |
19e6b90e L |
1791 | printf (")"); |
1792 | if (need_frame_base && !have_frame_base) | |
1793 | printf (_(" [without DW_AT_frame_base]")); | |
1794 | } | |
19e6b90e L |
1795 | break; |
1796 | ||
ec4d4525 NC |
1797 | case DW_AT_import: |
1798 | { | |
2b6f5997 CC |
1799 | if (form == DW_FORM_ref_sig8) |
1800 | break; | |
1801 | ||
ec4d4525 NC |
1802 | if (form == DW_FORM_ref1 |
1803 | || form == DW_FORM_ref2 | |
a7a0b6a5 JK |
1804 | || form == DW_FORM_ref4 |
1805 | || form == DW_FORM_ref_udata) | |
ec4d4525 NC |
1806 | uvalue += cu_offset; |
1807 | ||
6e3d6dc1 | 1808 | if (uvalue >= section->size) |
47704ddf KT |
1809 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"), |
1810 | dwarf_vmatoa ("x", uvalue), | |
1811 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
1812 | else |
1813 | { | |
1814 | unsigned long abbrev_number; | |
1815 | abbrev_entry * entry; | |
1816 | ||
1817 | abbrev_number = read_leb128 (section->start + uvalue, NULL, 0); | |
cecf136e | 1818 | |
9cf03b7e | 1819 | printf (_("[Abbrev Number: %ld"), abbrev_number); |
afd6e1ff JJ |
1820 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
1821 | use different abbrev table, and we don't track .debug_info chunks | |
1822 | yet. */ | |
1823 | if (form != DW_FORM_ref_addr) | |
1824 | { | |
1825 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
1826 | if (entry->entry == abbrev_number) | |
1827 | break; | |
1828 | if (entry != NULL) | |
1829 | printf (" (%s)", get_TAG_name (entry->tag)); | |
1830 | } | |
6e3d6dc1 NC |
1831 | printf ("]"); |
1832 | } | |
ec4d4525 NC |
1833 | } |
1834 | break; | |
1835 | ||
19e6b90e L |
1836 | default: |
1837 | break; | |
1838 | } | |
1839 | ||
1840 | return data; | |
1841 | } | |
1842 | ||
a19c41a7 | 1843 | static const char * |
19e6b90e L |
1844 | get_AT_name (unsigned long attribute) |
1845 | { | |
a19c41a7 | 1846 | const char *name; |
e2a0d921 | 1847 | |
a19c41a7 TT |
1848 | /* One value is shared by the MIPS and HP extensions: */ |
1849 | if (attribute == DW_AT_MIPS_fde) | |
1850 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
19e6b90e | 1851 | |
a19c41a7 TT |
1852 | name = get_DW_AT_name (attribute); |
1853 | ||
1854 | if (name == NULL) | |
1855 | { | |
1856 | static char buffer[100]; | |
1857 | ||
1858 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1859 | attribute); | |
1860 | return buffer; | |
19e6b90e | 1861 | } |
a19c41a7 TT |
1862 | |
1863 | return name; | |
19e6b90e L |
1864 | } |
1865 | ||
1866 | static unsigned char * | |
6e3d6dc1 NC |
1867 | read_and_display_attr (unsigned long attribute, |
1868 | unsigned long form, | |
ec4d4525 | 1869 | unsigned char * data, |
467c65bc NC |
1870 | dwarf_vma cu_offset, |
1871 | dwarf_vma pointer_size, | |
1872 | dwarf_vma offset_size, | |
6e3d6dc1 NC |
1873 | int dwarf_version, |
1874 | debug_info * debug_info_p, | |
1875 | int do_loc, | |
1876 | struct dwarf_section * section) | |
19e6b90e L |
1877 | { |
1878 | if (!do_loc) | |
750f03b7 | 1879 | printf (" %-18s:", get_AT_name (attribute)); |
19e6b90e L |
1880 | data = read_and_display_attr_value (attribute, form, data, cu_offset, |
1881 | pointer_size, offset_size, | |
1882 | dwarf_version, debug_info_p, | |
6e3d6dc1 | 1883 | do_loc, section); |
19e6b90e L |
1884 | if (!do_loc) |
1885 | printf ("\n"); | |
1886 | return data; | |
1887 | } | |
1888 | ||
1889 | ||
1890 | /* Process the contents of a .debug_info section. If do_loc is non-zero | |
1891 | then we are scanning for location lists and we do not want to display | |
2b6f5997 CC |
1892 | anything to the user. If do_types is non-zero, we are processing |
1893 | a .debug_types section instead of a .debug_info section. */ | |
19e6b90e L |
1894 | |
1895 | static int | |
6e3d6dc1 NC |
1896 | process_debug_info (struct dwarf_section *section, |
1897 | void *file, | |
6f875884 | 1898 | enum dwarf_section_display_enum abbrev_sec, |
2b6f5997 CC |
1899 | int do_loc, |
1900 | int do_types) | |
19e6b90e L |
1901 | { |
1902 | unsigned char *start = section->start; | |
1903 | unsigned char *end = start + section->size; | |
1904 | unsigned char *section_begin; | |
1905 | unsigned int unit; | |
1906 | unsigned int num_units = 0; | |
1907 | ||
1908 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
1909 | && num_debug_info_entries == 0 |
1910 | && ! do_types) | |
19e6b90e | 1911 | { |
767221a9 | 1912 | dwarf_vma length; |
19e6b90e L |
1913 | |
1914 | /* First scan the section to get the number of comp units. */ | |
1915 | for (section_begin = start, num_units = 0; section_begin < end; | |
1916 | num_units ++) | |
1917 | { | |
1918 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
1919 | will be the length. For a 64-bit DWARF section, it'll be | |
1920 | the escape code 0xffffffff followed by an 8 byte length. */ | |
1921 | length = byte_get (section_begin, 4); | |
1922 | ||
1923 | if (length == 0xffffffff) | |
1924 | { | |
1925 | length = byte_get (section_begin + 4, 8); | |
1926 | section_begin += length + 12; | |
1927 | } | |
ec4d4525 NC |
1928 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
1929 | { | |
767221a9 NC |
1930 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
1931 | dwarf_vmatoa ("x", length), section->name); | |
ec4d4525 NC |
1932 | return 0; |
1933 | } | |
19e6b90e L |
1934 | else |
1935 | section_begin += length + 4; | |
aca88567 NC |
1936 | |
1937 | /* Negative values are illegal, they may even cause infinite | |
1938 | looping. This can happen if we can't accurately apply | |
1939 | relocations to an object file. */ | |
1940 | if ((signed long) length <= 0) | |
1941 | { | |
767221a9 NC |
1942 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
1943 | dwarf_vmatoa ("x", length), section->name); | |
aca88567 NC |
1944 | return 0; |
1945 | } | |
19e6b90e L |
1946 | } |
1947 | ||
1948 | if (num_units == 0) | |
1949 | { | |
1950 | error (_("No comp units in %s section ?"), section->name); | |
1951 | return 0; | |
1952 | } | |
1953 | ||
1954 | /* Then allocate an array to hold the information. */ | |
3f5e193b NC |
1955 | debug_information = (debug_info *) cmalloc (num_units, |
1956 | sizeof (* debug_information)); | |
19e6b90e L |
1957 | if (debug_information == NULL) |
1958 | { | |
1959 | error (_("Not enough memory for a debug info array of %u entries"), | |
1960 | num_units); | |
1961 | return 0; | |
1962 | } | |
1963 | } | |
1964 | ||
1965 | if (!do_loc) | |
1966 | { | |
fd2f0033 TT |
1967 | if (dwarf_start_die == 0) |
1968 | printf (_("Contents of the %s section:\n\n"), section->name); | |
19e6b90e L |
1969 | |
1970 | load_debug_section (str, file); | |
4723351a CC |
1971 | load_debug_section (str_dwo, file); |
1972 | load_debug_section (str_index, file); | |
1973 | load_debug_section (str_index_dwo, file); | |
1974 | load_debug_section (debug_addr, file); | |
19e6b90e L |
1975 | } |
1976 | ||
6f875884 TG |
1977 | load_debug_section (abbrev_sec, file); |
1978 | if (debug_displays [abbrev_sec].section.start == NULL) | |
19e6b90e L |
1979 | { |
1980 | warn (_("Unable to locate %s section!\n"), | |
6f875884 | 1981 | debug_displays [abbrev_sec].section.name); |
19e6b90e L |
1982 | return 0; |
1983 | } | |
1984 | ||
1985 | for (section_begin = start, unit = 0; start < end; unit++) | |
1986 | { | |
1987 | DWARF2_Internal_CompUnit compunit; | |
1988 | unsigned char *hdrptr; | |
19e6b90e | 1989 | unsigned char *tags; |
fd2f0033 | 1990 | int level, last_level, saved_level; |
467c65bc | 1991 | dwarf_vma cu_offset; |
19e6b90e L |
1992 | int offset_size; |
1993 | int initial_length_size; | |
74bc6052 CC |
1994 | dwarf_vma signature_high = 0; |
1995 | dwarf_vma signature_low = 0; | |
767221a9 | 1996 | dwarf_vma type_offset = 0; |
19e6b90e L |
1997 | |
1998 | hdrptr = start; | |
1999 | ||
2000 | compunit.cu_length = byte_get (hdrptr, 4); | |
2001 | hdrptr += 4; | |
2002 | ||
2003 | if (compunit.cu_length == 0xffffffff) | |
2004 | { | |
2005 | compunit.cu_length = byte_get (hdrptr, 8); | |
2006 | hdrptr += 8; | |
2007 | offset_size = 8; | |
2008 | initial_length_size = 12; | |
2009 | } | |
2010 | else | |
2011 | { | |
2012 | offset_size = 4; | |
2013 | initial_length_size = 4; | |
2014 | } | |
2015 | ||
2016 | compunit.cu_version = byte_get (hdrptr, 2); | |
2017 | hdrptr += 2; | |
2018 | ||
2019 | cu_offset = start - section_begin; | |
19e6b90e | 2020 | |
19e6b90e L |
2021 | compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size); |
2022 | hdrptr += offset_size; | |
2023 | ||
2024 | compunit.cu_pointer_size = byte_get (hdrptr, 1); | |
2025 | hdrptr += 1; | |
2b6f5997 CC |
2026 | |
2027 | if (do_types) | |
2028 | { | |
74bc6052 CC |
2029 | byte_get_64 (hdrptr, &signature_high, &signature_low); |
2030 | hdrptr += 8; | |
2b6f5997 CC |
2031 | type_offset = byte_get (hdrptr, offset_size); |
2032 | hdrptr += offset_size; | |
2033 | } | |
2034 | ||
19e6b90e | 2035 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 CC |
2036 | && num_debug_info_entries == 0 |
2037 | && ! do_types) | |
19e6b90e L |
2038 | { |
2039 | debug_information [unit].cu_offset = cu_offset; | |
2040 | debug_information [unit].pointer_size | |
2041 | = compunit.cu_pointer_size; | |
b7807392 JJ |
2042 | debug_information [unit].offset_size = offset_size; |
2043 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 2044 | debug_information [unit].base_address = 0; |
4723351a CC |
2045 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
2046 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
2047 | debug_information [unit].loc_offsets = NULL; |
2048 | debug_information [unit].have_frame_base = NULL; | |
2049 | debug_information [unit].max_loc_offsets = 0; | |
2050 | debug_information [unit].num_loc_offsets = 0; | |
2051 | debug_information [unit].range_lists = NULL; | |
2052 | debug_information [unit].max_range_lists= 0; | |
2053 | debug_information [unit].num_range_lists = 0; | |
2054 | } | |
2055 | ||
fd2f0033 | 2056 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 2057 | { |
47704ddf KT |
2058 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
2059 | dwarf_vmatoa ("x", cu_offset)); | |
2060 | printf (_(" Length: 0x%s (%s)\n"), | |
2061 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 2062 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 2063 | printf (_(" Version: %d\n"), compunit.cu_version); |
47704ddf KT |
2064 | printf (_(" Abbrev Offset: %s\n"), |
2065 | dwarf_vmatoa ("d", compunit.cu_abbrev_offset)); | |
19e6b90e | 2066 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
2067 | if (do_types) |
2068 | { | |
74bc6052 CC |
2069 | char buf[64]; |
2070 | ||
2071 | printf (_(" Signature: 0x%s\n"), | |
2072 | dwarf_vmatoa64 (signature_high, signature_low, | |
2073 | buf, sizeof (buf))); | |
2074 | printf (_(" Type Offset: 0x%s\n"), | |
2075 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 2076 | } |
19e6b90e L |
2077 | } |
2078 | ||
460c89ff NS |
2079 | if (cu_offset + compunit.cu_length + initial_length_size |
2080 | > section->size) | |
2081 | { | |
47704ddf KT |
2082 | warn (_("Debug info is corrupted, length of CU at %s" |
2083 | " extends beyond end of section (length = %s)\n"), | |
2084 | dwarf_vmatoa ("x", cu_offset), | |
2085 | dwarf_vmatoa ("x", compunit.cu_length)); | |
460c89ff NS |
2086 | break; |
2087 | } | |
2088 | tags = hdrptr; | |
2089 | start += compunit.cu_length + initial_length_size; | |
2090 | ||
932fd279 JJ |
2091 | if (compunit.cu_version != 2 |
2092 | && compunit.cu_version != 3 | |
2093 | && compunit.cu_version != 4) | |
19e6b90e | 2094 | { |
47704ddf KT |
2095 | warn (_("CU at offset %s contains corrupt or " |
2096 | "unsupported version number: %d.\n"), | |
2097 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
2098 | continue; |
2099 | } | |
2100 | ||
2101 | free_abbrevs (); | |
2102 | ||
bfe2612a L |
2103 | /* Process the abbrevs used by this compilation unit. DWARF |
2104 | sections under Mach-O have non-zero addresses. */ | |
6f875884 | 2105 | if (compunit.cu_abbrev_offset >= debug_displays [abbrev_sec].section.size) |
ec4d4525 NC |
2106 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
2107 | (unsigned long) compunit.cu_abbrev_offset, | |
6f875884 | 2108 | (unsigned long) debug_displays [abbrev_sec].section.size); |
460c89ff NS |
2109 | else |
2110 | process_abbrev_section | |
6f875884 | 2111 | ((unsigned char *) debug_displays [abbrev_sec].section.start |
0ac6fba0 | 2112 | + compunit.cu_abbrev_offset, |
6f875884 TG |
2113 | (unsigned char *) debug_displays [abbrev_sec].section.start |
2114 | + debug_displays [abbrev_sec].section.size); | |
19e6b90e L |
2115 | |
2116 | level = 0; | |
fd2f0033 TT |
2117 | last_level = level; |
2118 | saved_level = -1; | |
19e6b90e L |
2119 | while (tags < start) |
2120 | { | |
2121 | unsigned int bytes_read; | |
2122 | unsigned long abbrev_number; | |
ec4d4525 | 2123 | unsigned long die_offset; |
19e6b90e L |
2124 | abbrev_entry *entry; |
2125 | abbrev_attr *attr; | |
fd2f0033 | 2126 | int do_printing = 1; |
19e6b90e | 2127 | |
ec4d4525 NC |
2128 | die_offset = tags - section_begin; |
2129 | ||
19e6b90e L |
2130 | abbrev_number = read_leb128 (tags, & bytes_read, 0); |
2131 | tags += bytes_read; | |
2132 | ||
eb7cc021 JK |
2133 | /* A null DIE marks the end of a list of siblings or it may also be |
2134 | a section padding. */ | |
19e6b90e L |
2135 | if (abbrev_number == 0) |
2136 | { | |
eb7cc021 JK |
2137 | /* Check if it can be a section padding for the last CU. */ |
2138 | if (level == 0 && start == end) | |
2139 | { | |
2140 | unsigned char *chk; | |
2141 | ||
2142 | for (chk = tags; chk < start; chk++) | |
2143 | if (*chk != 0) | |
2144 | break; | |
2145 | if (chk == start) | |
2146 | break; | |
2147 | } | |
2148 | ||
19e6b90e | 2149 | --level; |
ec4d4525 NC |
2150 | if (level < 0) |
2151 | { | |
2152 | static unsigned num_bogus_warns = 0; | |
2153 | ||
2154 | if (num_bogus_warns < 3) | |
2155 | { | |
4723351a CC |
2156 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
2157 | die_offset, section->name); | |
ec4d4525 NC |
2158 | num_bogus_warns ++; |
2159 | if (num_bogus_warns == 3) | |
2160 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
2161 | } | |
2162 | } | |
fd2f0033 TT |
2163 | if (dwarf_start_die != 0 && level < saved_level) |
2164 | return 1; | |
19e6b90e L |
2165 | continue; |
2166 | } | |
2167 | ||
4b78141a | 2168 | if (!do_loc) |
fd2f0033 TT |
2169 | { |
2170 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
2171 | do_printing = 0; | |
2172 | else | |
2173 | { | |
2174 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
2175 | saved_level = level; | |
2176 | do_printing = (dwarf_cutoff_level == -1 | |
2177 | || level < dwarf_cutoff_level); | |
2178 | if (do_printing) | |
2179 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
2180 | level, die_offset, abbrev_number); | |
2181 | else if (dwarf_cutoff_level == -1 | |
2182 | || last_level < dwarf_cutoff_level) | |
2183 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
2184 | last_level = level; | |
2185 | } | |
2186 | } | |
cecf136e | 2187 | |
19e6b90e L |
2188 | /* Scan through the abbreviation list until we reach the |
2189 | correct entry. */ | |
2190 | for (entry = first_abbrev; | |
2191 | entry && entry->entry != abbrev_number; | |
2192 | entry = entry->next) | |
2193 | continue; | |
2194 | ||
2195 | if (entry == NULL) | |
2196 | { | |
fd2f0033 | 2197 | if (!do_loc && do_printing) |
4b78141a NC |
2198 | { |
2199 | printf ("\n"); | |
2200 | fflush (stdout); | |
2201 | } | |
cc86f28f NC |
2202 | warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"), |
2203 | die_offset, abbrev_number); | |
19e6b90e L |
2204 | return 0; |
2205 | } | |
2206 | ||
fd2f0033 | 2207 | if (!do_loc && do_printing) |
cc5914eb | 2208 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 2209 | |
19e6b90e L |
2210 | switch (entry->tag) |
2211 | { | |
2212 | default: | |
2213 | need_base_address = 0; | |
2214 | break; | |
2215 | case DW_TAG_compile_unit: | |
2216 | need_base_address = 1; | |
2217 | break; | |
2218 | case DW_TAG_entry_point: | |
19e6b90e L |
2219 | case DW_TAG_subprogram: |
2220 | need_base_address = 0; | |
2221 | /* Assuming that there is no DW_AT_frame_base. */ | |
2222 | have_frame_base = 0; | |
2223 | break; | |
2224 | } | |
2225 | ||
2226 | for (attr = entry->first_attr; attr; attr = attr->next) | |
4b78141a | 2227 | { |
fd2f0033 TT |
2228 | debug_info *arg; |
2229 | ||
2230 | if (! do_loc && do_printing) | |
4b78141a | 2231 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 TT |
2232 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
2233 | ||
2234 | arg = debug_information; | |
2235 | if (debug_information) | |
2236 | arg += unit; | |
4b78141a NC |
2237 | |
2238 | tags = read_and_display_attr (attr->attribute, | |
2239 | attr->form, | |
2240 | tags, cu_offset, | |
2241 | compunit.cu_pointer_size, | |
2242 | offset_size, | |
2243 | compunit.cu_version, | |
fd2f0033 TT |
2244 | arg, |
2245 | do_loc || ! do_printing, section); | |
4b78141a | 2246 | } |
cecf136e | 2247 | |
19e6b90e L |
2248 | if (entry->children) |
2249 | ++level; | |
2250 | } | |
2251 | } | |
cecf136e | 2252 | |
19e6b90e L |
2253 | /* Set num_debug_info_entries here so that it can be used to check if |
2254 | we need to process .debug_loc and .debug_ranges sections. */ | |
2255 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
2256 | && num_debug_info_entries == 0 |
2257 | && ! do_types) | |
19e6b90e | 2258 | num_debug_info_entries = num_units; |
cecf136e | 2259 | |
19e6b90e | 2260 | if (!do_loc) |
467c65bc | 2261 | printf ("\n"); |
cecf136e | 2262 | |
19e6b90e L |
2263 | return 1; |
2264 | } | |
2265 | ||
2266 | /* Locate and scan the .debug_info section in the file and record the pointer | |
2267 | sizes and offsets for the compilation units in it. Usually an executable | |
2268 | will have just one pointer size, but this is not guaranteed, and so we try | |
2269 | not to make any assumptions. Returns zero upon failure, or the number of | |
2270 | compilation units upon success. */ | |
2271 | ||
2272 | static unsigned int | |
2273 | load_debug_info (void * file) | |
2274 | { | |
2275 | /* Reset the last pointer size so that we can issue correct error | |
2276 | messages if we are displaying the contents of more than one section. */ | |
2277 | last_pointer_size = 0; | |
2278 | warned_about_missing_comp_units = FALSE; | |
2279 | ||
1febe64d NC |
2280 | /* If we have already tried and failed to load the .debug_info |
2281 | section then do not bother to repear the task. */ | |
cc86f28f | 2282 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
2283 | return 0; |
2284 | ||
19e6b90e L |
2285 | /* If we already have the information there is nothing else to do. */ |
2286 | if (num_debug_info_entries > 0) | |
2287 | return num_debug_info_entries; | |
2288 | ||
2289 | if (load_debug_section (info, file) | |
6f875884 | 2290 | && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0)) |
19e6b90e | 2291 | return num_debug_info_entries; |
4723351a CC |
2292 | else if (load_debug_section (info_dwo, file) |
2293 | && process_debug_info (&debug_displays [info_dwo].section, file, | |
2294 | abbrev_dwo, 1, 0)) | |
2295 | return num_debug_info_entries; | |
1febe64d | 2296 | |
cc86f28f | 2297 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 2298 | return 0; |
19e6b90e L |
2299 | } |
2300 | ||
19e6b90e | 2301 | static int |
a262ae96 NC |
2302 | display_debug_lines_raw (struct dwarf_section *section, |
2303 | unsigned char *data, | |
2304 | unsigned char *end) | |
19e6b90e L |
2305 | { |
2306 | unsigned char *start = section->start; | |
19e6b90e | 2307 | |
a262ae96 NC |
2308 | printf (_("Raw dump of debug contents of section %s:\n\n"), |
2309 | section->name); | |
19e6b90e L |
2310 | |
2311 | while (data < end) | |
2312 | { | |
91d6fa6a | 2313 | DWARF2_Internal_LineInfo linfo; |
19e6b90e L |
2314 | unsigned char *standard_opcodes; |
2315 | unsigned char *end_of_sequence; | |
2316 | unsigned char *hdrptr; | |
6523721c | 2317 | unsigned long hdroff; |
19e6b90e L |
2318 | int initial_length_size; |
2319 | int offset_size; | |
2320 | int i; | |
2321 | ||
2322 | hdrptr = data; | |
6523721c | 2323 | hdroff = hdrptr - start; |
19e6b90e L |
2324 | |
2325 | /* Check the length of the block. */ | |
91d6fa6a | 2326 | linfo.li_length = byte_get (hdrptr, 4); |
19e6b90e L |
2327 | hdrptr += 4; |
2328 | ||
91d6fa6a | 2329 | if (linfo.li_length == 0xffffffff) |
19e6b90e L |
2330 | { |
2331 | /* This section is 64-bit DWARF 3. */ | |
91d6fa6a | 2332 | linfo.li_length = byte_get (hdrptr, 8); |
19e6b90e L |
2333 | hdrptr += 8; |
2334 | offset_size = 8; | |
2335 | initial_length_size = 12; | |
2336 | } | |
2337 | else | |
2338 | { | |
2339 | offset_size = 4; | |
2340 | initial_length_size = 4; | |
2341 | } | |
2342 | ||
91d6fa6a | 2343 | if (linfo.li_length + initial_length_size > section->size) |
19e6b90e L |
2344 | { |
2345 | warn | |
cf13d699 NC |
2346 | (_("The information in section %s appears to be corrupt - the section is too small\n"), |
2347 | section->name); | |
19e6b90e L |
2348 | return 0; |
2349 | } | |
2350 | ||
2351 | /* Check its version number. */ | |
91d6fa6a | 2352 | linfo.li_version = byte_get (hdrptr, 2); |
19e6b90e | 2353 | hdrptr += 2; |
932fd279 JJ |
2354 | if (linfo.li_version != 2 |
2355 | && linfo.li_version != 3 | |
2356 | && linfo.li_version != 4) | |
19e6b90e | 2357 | { |
932fd279 | 2358 | warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n")); |
19e6b90e L |
2359 | return 0; |
2360 | } | |
2361 | ||
91d6fa6a | 2362 | linfo.li_prologue_length = byte_get (hdrptr, offset_size); |
19e6b90e | 2363 | hdrptr += offset_size; |
91d6fa6a | 2364 | linfo.li_min_insn_length = byte_get (hdrptr, 1); |
19e6b90e | 2365 | hdrptr++; |
a233b20c JJ |
2366 | if (linfo.li_version >= 4) |
2367 | { | |
2368 | linfo.li_max_ops_per_insn = byte_get (hdrptr, 1); | |
2369 | hdrptr++; | |
2370 | if (linfo.li_max_ops_per_insn == 0) | |
2371 | { | |
2372 | warn (_("Invalid maximum operations per insn.\n")); | |
2373 | return 0; | |
2374 | } | |
2375 | } | |
2376 | else | |
2377 | linfo.li_max_ops_per_insn = 1; | |
91d6fa6a | 2378 | linfo.li_default_is_stmt = byte_get (hdrptr, 1); |
19e6b90e | 2379 | hdrptr++; |
91d6fa6a | 2380 | linfo.li_line_base = byte_get (hdrptr, 1); |
19e6b90e | 2381 | hdrptr++; |
91d6fa6a | 2382 | linfo.li_line_range = byte_get (hdrptr, 1); |
19e6b90e | 2383 | hdrptr++; |
91d6fa6a | 2384 | linfo.li_opcode_base = byte_get (hdrptr, 1); |
19e6b90e L |
2385 | hdrptr++; |
2386 | ||
2387 | /* Sign extend the line base field. */ | |
91d6fa6a NC |
2388 | linfo.li_line_base <<= 24; |
2389 | linfo.li_line_base >>= 24; | |
19e6b90e | 2390 | |
6523721c | 2391 | printf (_(" Offset: 0x%lx\n"), hdroff); |
47704ddf | 2392 | printf (_(" Length: %ld\n"), (long) linfo.li_length); |
91d6fa6a NC |
2393 | printf (_(" DWARF Version: %d\n"), linfo.li_version); |
2394 | printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length); | |
2395 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); | |
a233b20c JJ |
2396 | if (linfo.li_version >= 4) |
2397 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
91d6fa6a NC |
2398 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); |
2399 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
2400 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
2401 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 2402 | |
91d6fa6a | 2403 | end_of_sequence = data + linfo.li_length + initial_length_size; |
19e6b90e | 2404 | |
91d6fa6a | 2405 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e L |
2406 | |
2407 | /* Display the contents of the Opcodes table. */ | |
2408 | standard_opcodes = hdrptr; | |
2409 | ||
2410 | printf (_("\n Opcodes:\n")); | |
2411 | ||
91d6fa6a | 2412 | for (i = 1; i < linfo.li_opcode_base; i++) |
19e6b90e L |
2413 | printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]); |
2414 | ||
2415 | /* Display the contents of the Directory table. */ | |
91d6fa6a | 2416 | data = standard_opcodes + linfo.li_opcode_base - 1; |
19e6b90e L |
2417 | |
2418 | if (*data == 0) | |
2419 | printf (_("\n The Directory Table is empty.\n")); | |
2420 | else | |
2421 | { | |
2422 | printf (_("\n The Directory Table:\n")); | |
2423 | ||
2424 | while (*data != 0) | |
2425 | { | |
cc5914eb | 2426 | printf (" %s\n", data); |
19e6b90e L |
2427 | |
2428 | data += strlen ((char *) data) + 1; | |
2429 | } | |
2430 | } | |
2431 | ||
2432 | /* Skip the NUL at the end of the table. */ | |
2433 | data++; | |
2434 | ||
2435 | /* Display the contents of the File Name table. */ | |
2436 | if (*data == 0) | |
2437 | printf (_("\n The File Name Table is empty.\n")); | |
2438 | else | |
2439 | { | |
2440 | printf (_("\n The File Name Table:\n")); | |
2441 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
2442 | ||
2443 | while (*data != 0) | |
2444 | { | |
2445 | unsigned char *name; | |
2446 | unsigned int bytes_read; | |
2447 | ||
cc5914eb | 2448 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
19e6b90e L |
2449 | name = data; |
2450 | ||
2451 | data += strlen ((char *) data) + 1; | |
2452 | ||
467c65bc NC |
2453 | printf ("%s\t", |
2454 | dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); | |
19e6b90e | 2455 | data += bytes_read; |
467c65bc NC |
2456 | printf ("%s\t", |
2457 | dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); | |
19e6b90e | 2458 | data += bytes_read; |
467c65bc NC |
2459 | printf ("%s\t", |
2460 | dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); | |
19e6b90e | 2461 | data += bytes_read; |
cc5914eb | 2462 | printf ("%s\n", name); |
19e6b90e L |
2463 | } |
2464 | } | |
2465 | ||
2466 | /* Skip the NUL at the end of the table. */ | |
2467 | data++; | |
2468 | ||
2469 | /* Now display the statements. */ | |
2470 | printf (_("\n Line Number Statements:\n")); | |
2471 | ||
2472 | while (data < end_of_sequence) | |
2473 | { | |
2474 | unsigned char op_code; | |
467c65bc NC |
2475 | dwarf_signed_vma adv; |
2476 | dwarf_vma uladv; | |
19e6b90e L |
2477 | unsigned int bytes_read; |
2478 | ||
2479 | op_code = *data++; | |
2480 | ||
91d6fa6a | 2481 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 2482 | { |
91d6fa6a | 2483 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
2484 | uladv = (op_code / linfo.li_line_range); |
2485 | if (linfo.li_max_ops_per_insn == 1) | |
2486 | { | |
2487 | uladv *= linfo.li_min_insn_length; | |
2488 | state_machine_regs.address += uladv; | |
467c65bc NC |
2489 | printf (_(" Special opcode %d: " |
2490 | "advance Address by %s to 0x%s"), | |
2491 | op_code, dwarf_vmatoa ("u", uladv), | |
2492 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
a233b20c JJ |
2493 | } |
2494 | else | |
2495 | { | |
2496 | state_machine_regs.address | |
2497 | += ((state_machine_regs.op_index + uladv) | |
2498 | / linfo.li_max_ops_per_insn) | |
2499 | * linfo.li_min_insn_length; | |
2500 | state_machine_regs.op_index | |
2501 | = (state_machine_regs.op_index + uladv) | |
2502 | % linfo.li_max_ops_per_insn; | |
467c65bc NC |
2503 | printf (_(" Special opcode %d: " |
2504 | "advance Address by %s to 0x%s[%d]"), | |
2505 | op_code, dwarf_vmatoa ("u", uladv), | |
2506 | dwarf_vmatoa ("x", state_machine_regs.address), | |
a233b20c JJ |
2507 | state_machine_regs.op_index); |
2508 | } | |
91d6fa6a | 2509 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
19e6b90e | 2510 | state_machine_regs.line += adv; |
467c65bc NC |
2511 | printf (_(" and Line by %s to %d\n"), |
2512 | dwarf_vmatoa ("d", adv), state_machine_regs.line); | |
19e6b90e L |
2513 | } |
2514 | else switch (op_code) | |
2515 | { | |
2516 | case DW_LNS_extended_op: | |
91d6fa6a | 2517 | data += process_extended_line_op (data, linfo.li_default_is_stmt); |
19e6b90e L |
2518 | break; |
2519 | ||
2520 | case DW_LNS_copy: | |
2521 | printf (_(" Copy\n")); | |
2522 | break; | |
2523 | ||
2524 | case DW_LNS_advance_pc: | |
2525 | uladv = read_leb128 (data, & bytes_read, 0); | |
19e6b90e | 2526 | data += bytes_read; |
a233b20c JJ |
2527 | if (linfo.li_max_ops_per_insn == 1) |
2528 | { | |
2529 | uladv *= linfo.li_min_insn_length; | |
2530 | state_machine_regs.address += uladv; | |
467c65bc NC |
2531 | printf (_(" Advance PC by %s to 0x%s\n"), |
2532 | dwarf_vmatoa ("u", uladv), | |
2533 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
a233b20c JJ |
2534 | } |
2535 | else | |
2536 | { | |
2537 | state_machine_regs.address | |
2538 | += ((state_machine_regs.op_index + uladv) | |
2539 | / linfo.li_max_ops_per_insn) | |
2540 | * linfo.li_min_insn_length; | |
2541 | state_machine_regs.op_index | |
2542 | = (state_machine_regs.op_index + uladv) | |
2543 | % linfo.li_max_ops_per_insn; | |
467c65bc NC |
2544 | printf (_(" Advance PC by %s to 0x%s[%d]\n"), |
2545 | dwarf_vmatoa ("u", uladv), | |
2546 | dwarf_vmatoa ("x", state_machine_regs.address), | |
a233b20c JJ |
2547 | state_machine_regs.op_index); |
2548 | } | |
19e6b90e L |
2549 | break; |
2550 | ||
2551 | case DW_LNS_advance_line: | |
467c65bc | 2552 | adv = read_sleb128 (data, & bytes_read); |
19e6b90e L |
2553 | data += bytes_read; |
2554 | state_machine_regs.line += adv; | |
467c65bc NC |
2555 | printf (_(" Advance Line by %s to %d\n"), |
2556 | dwarf_vmatoa ("d", adv), | |
2557 | state_machine_regs.line); | |
19e6b90e L |
2558 | break; |
2559 | ||
2560 | case DW_LNS_set_file: | |
2561 | adv = read_leb128 (data, & bytes_read, 0); | |
2562 | data += bytes_read; | |
467c65bc NC |
2563 | printf (_(" Set File Name to entry %s in the File Name Table\n"), |
2564 | dwarf_vmatoa ("d", adv)); | |
19e6b90e L |
2565 | state_machine_regs.file = adv; |
2566 | break; | |
2567 | ||
2568 | case DW_LNS_set_column: | |
2569 | uladv = read_leb128 (data, & bytes_read, 0); | |
2570 | data += bytes_read; | |
467c65bc NC |
2571 | printf (_(" Set column to %s\n"), |
2572 | dwarf_vmatoa ("u", uladv)); | |
19e6b90e L |
2573 | state_machine_regs.column = uladv; |
2574 | break; | |
2575 | ||
2576 | case DW_LNS_negate_stmt: | |
2577 | adv = state_machine_regs.is_stmt; | |
2578 | adv = ! adv; | |
467c65bc | 2579 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); |
19e6b90e L |
2580 | state_machine_regs.is_stmt = adv; |
2581 | break; | |
2582 | ||
2583 | case DW_LNS_set_basic_block: | |
2584 | printf (_(" Set basic block\n")); | |
2585 | state_machine_regs.basic_block = 1; | |
2586 | break; | |
2587 | ||
2588 | case DW_LNS_const_add_pc: | |
a233b20c JJ |
2589 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); |
2590 | if (linfo.li_max_ops_per_insn) | |
2591 | { | |
2592 | uladv *= linfo.li_min_insn_length; | |
2593 | state_machine_regs.address += uladv; | |
467c65bc NC |
2594 | printf (_(" Advance PC by constant %s to 0x%s\n"), |
2595 | dwarf_vmatoa ("u", uladv), | |
2596 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
a233b20c JJ |
2597 | } |
2598 | else | |
2599 | { | |
2600 | state_machine_regs.address | |
2601 | += ((state_machine_regs.op_index + uladv) | |
2602 | / linfo.li_max_ops_per_insn) | |
2603 | * linfo.li_min_insn_length; | |
2604 | state_machine_regs.op_index | |
2605 | = (state_machine_regs.op_index + uladv) | |
2606 | % linfo.li_max_ops_per_insn; | |
467c65bc NC |
2607 | printf (_(" Advance PC by constant %s to 0x%s[%d]\n"), |
2608 | dwarf_vmatoa ("u", uladv), | |
2609 | dwarf_vmatoa ("x", state_machine_regs.address), | |
a233b20c JJ |
2610 | state_machine_regs.op_index); |
2611 | } | |
19e6b90e L |
2612 | break; |
2613 | ||
2614 | case DW_LNS_fixed_advance_pc: | |
2615 | uladv = byte_get (data, 2); | |
2616 | data += 2; | |
2617 | state_machine_regs.address += uladv; | |
a233b20c | 2618 | state_machine_regs.op_index = 0; |
467c65bc NC |
2619 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), |
2620 | dwarf_vmatoa ("u", uladv), | |
2621 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
19e6b90e L |
2622 | break; |
2623 | ||
2624 | case DW_LNS_set_prologue_end: | |
2625 | printf (_(" Set prologue_end to true\n")); | |
2626 | break; | |
2627 | ||
2628 | case DW_LNS_set_epilogue_begin: | |
2629 | printf (_(" Set epilogue_begin to true\n")); | |
2630 | break; | |
2631 | ||
2632 | case DW_LNS_set_isa: | |
2633 | uladv = read_leb128 (data, & bytes_read, 0); | |
2634 | data += bytes_read; | |
467c65bc | 2635 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); |
19e6b90e L |
2636 | break; |
2637 | ||
2638 | default: | |
2639 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
2640 | ||
2641 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
2642 | { | |
467c65bc NC |
2643 | printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data, |
2644 | &bytes_read, 0)), | |
19e6b90e L |
2645 | i == 1 ? "" : ", "); |
2646 | data += bytes_read; | |
2647 | } | |
2648 | putchar ('\n'); | |
2649 | break; | |
2650 | } | |
2651 | } | |
2652 | putchar ('\n'); | |
2653 | } | |
2654 | ||
2655 | return 1; | |
2656 | } | |
2657 | ||
a262ae96 NC |
2658 | typedef struct |
2659 | { | |
467c65bc NC |
2660 | unsigned char *name; |
2661 | unsigned int directory_index; | |
2662 | unsigned int modification_date; | |
2663 | unsigned int length; | |
a262ae96 NC |
2664 | } File_Entry; |
2665 | ||
2666 | /* Output a decoded representation of the .debug_line section. */ | |
2667 | ||
2668 | static int | |
2669 | display_debug_lines_decoded (struct dwarf_section *section, | |
2670 | unsigned char *data, | |
2671 | unsigned char *end) | |
2672 | { | |
2673 | printf (_("Decoded dump of debug contents of section %s:\n\n"), | |
2674 | section->name); | |
2675 | ||
2676 | while (data < end) | |
2677 | { | |
2678 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 2679 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
2680 | unsigned char *standard_opcodes; |
2681 | unsigned char *end_of_sequence; | |
2682 | unsigned char *hdrptr; | |
2683 | int initial_length_size; | |
2684 | int offset_size; | |
2685 | int i; | |
2686 | File_Entry *file_table = NULL; | |
143a3db0 | 2687 | unsigned int n_files = 0; |
a262ae96 | 2688 | unsigned char **directory_table = NULL; |
143a3db0 | 2689 | unsigned int n_directories = 0; |
a262ae96 NC |
2690 | |
2691 | hdrptr = data; | |
2692 | ||
2693 | /* Extract information from the Line Number Program Header. | |
2694 | (section 6.2.4 in the Dwarf3 doc). */ | |
2695 | ||
2696 | /* Get the length of this CU's line number information block. */ | |
91d6fa6a | 2697 | linfo.li_length = byte_get (hdrptr, 4); |
a262ae96 NC |
2698 | hdrptr += 4; |
2699 | ||
91d6fa6a | 2700 | if (linfo.li_length == 0xffffffff) |
a262ae96 NC |
2701 | { |
2702 | /* This section is 64-bit DWARF 3. */ | |
91d6fa6a | 2703 | linfo.li_length = byte_get (hdrptr, 8); |
a262ae96 NC |
2704 | hdrptr += 8; |
2705 | offset_size = 8; | |
2706 | initial_length_size = 12; | |
2707 | } | |
2708 | else | |
2709 | { | |
2710 | offset_size = 4; | |
2711 | initial_length_size = 4; | |
2712 | } | |
2713 | ||
91d6fa6a | 2714 | if (linfo.li_length + initial_length_size > section->size) |
a262ae96 NC |
2715 | { |
2716 | warn (_("The line info appears to be corrupt - " | |
2717 | "the section is too small\n")); | |
2718 | return 0; | |
2719 | } | |
2720 | ||
2721 | /* Get this CU's Line Number Block version number. */ | |
91d6fa6a | 2722 | linfo.li_version = byte_get (hdrptr, 2); |
a262ae96 | 2723 | hdrptr += 2; |
932fd279 JJ |
2724 | if (linfo.li_version != 2 |
2725 | && linfo.li_version != 3 | |
2726 | && linfo.li_version != 4) | |
a262ae96 | 2727 | { |
932fd279 | 2728 | warn (_("Only DWARF version 2, 3 and 4 line info is currently " |
a262ae96 NC |
2729 | "supported.\n")); |
2730 | return 0; | |
2731 | } | |
2732 | ||
91d6fa6a | 2733 | linfo.li_prologue_length = byte_get (hdrptr, offset_size); |
a262ae96 | 2734 | hdrptr += offset_size; |
91d6fa6a | 2735 | linfo.li_min_insn_length = byte_get (hdrptr, 1); |
a262ae96 | 2736 | hdrptr++; |
a233b20c JJ |
2737 | if (linfo.li_version >= 4) |
2738 | { | |
2739 | linfo.li_max_ops_per_insn = byte_get (hdrptr, 1); | |
2740 | hdrptr++; | |
2741 | if (linfo.li_max_ops_per_insn == 0) | |
2742 | { | |
2743 | warn (_("Invalid maximum operations per insn.\n")); | |
2744 | return 0; | |
2745 | } | |
2746 | } | |
2747 | else | |
2748 | linfo.li_max_ops_per_insn = 1; | |
91d6fa6a | 2749 | linfo.li_default_is_stmt = byte_get (hdrptr, 1); |
a262ae96 | 2750 | hdrptr++; |
91d6fa6a | 2751 | linfo.li_line_base = byte_get (hdrptr, 1); |
a262ae96 | 2752 | hdrptr++; |
91d6fa6a | 2753 | linfo.li_line_range = byte_get (hdrptr, 1); |
a262ae96 | 2754 | hdrptr++; |
91d6fa6a | 2755 | linfo.li_opcode_base = byte_get (hdrptr, 1); |
a262ae96 NC |
2756 | hdrptr++; |
2757 | ||
2758 | /* Sign extend the line base field. */ | |
91d6fa6a NC |
2759 | linfo.li_line_base <<= 24; |
2760 | linfo.li_line_base >>= 24; | |
a262ae96 NC |
2761 | |
2762 | /* Find the end of this CU's Line Number Information Block. */ | |
91d6fa6a | 2763 | end_of_sequence = data + linfo.li_length + initial_length_size; |
a262ae96 | 2764 | |
91d6fa6a | 2765 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 NC |
2766 | |
2767 | /* Save a pointer to the contents of the Opcodes table. */ | |
2768 | standard_opcodes = hdrptr; | |
2769 | ||
2770 | /* Traverse the Directory table just to count entries. */ | |
91d6fa6a | 2771 | data = standard_opcodes + linfo.li_opcode_base - 1; |
a262ae96 NC |
2772 | if (*data != 0) |
2773 | { | |
a262ae96 | 2774 | unsigned char *ptr_directory_table = data; |
a262ae96 NC |
2775 | |
2776 | while (*data != 0) | |
2777 | { | |
2778 | data += strlen ((char *) data) + 1; | |
2779 | n_directories++; | |
2780 | } | |
2781 | ||
2782 | /* Go through the directory table again to save the directories. */ | |
3f5e193b NC |
2783 | directory_table = (unsigned char **) |
2784 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 NC |
2785 | |
2786 | i = 0; | |
2787 | while (*ptr_directory_table != 0) | |
2788 | { | |
2789 | directory_table[i] = ptr_directory_table; | |
2790 | ptr_directory_table += strlen ((char *) ptr_directory_table) + 1; | |
2791 | i++; | |
2792 | } | |
2793 | } | |
2794 | /* Skip the NUL at the end of the table. */ | |
2795 | data++; | |
2796 | ||
2797 | /* Traverse the File Name table just to count the entries. */ | |
2798 | if (*data != 0) | |
2799 | { | |
a262ae96 | 2800 | unsigned char *ptr_file_name_table = data; |
a262ae96 NC |
2801 | |
2802 | while (*data != 0) | |
2803 | { | |
2804 | unsigned int bytes_read; | |
2805 | ||
2806 | /* Skip Name, directory index, last modification time and length | |
2807 | of file. */ | |
2808 | data += strlen ((char *) data) + 1; | |
2809 | read_leb128 (data, & bytes_read, 0); | |
2810 | data += bytes_read; | |
2811 | read_leb128 (data, & bytes_read, 0); | |
2812 | data += bytes_read; | |
2813 | read_leb128 (data, & bytes_read, 0); | |
2814 | data += bytes_read; | |
2815 | ||
2816 | n_files++; | |
2817 | } | |
2818 | ||
2819 | /* Go through the file table again to save the strings. */ | |
3f5e193b | 2820 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); |
a262ae96 NC |
2821 | |
2822 | i = 0; | |
2823 | while (*ptr_file_name_table != 0) | |
2824 | { | |
2825 | unsigned int bytes_read; | |
2826 | ||
2827 | file_table[i].name = ptr_file_name_table; | |
2828 | ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1; | |
2829 | ||
2830 | /* We are not interested in directory, time or size. */ | |
2831 | file_table[i].directory_index = read_leb128 (ptr_file_name_table, | |
2832 | & bytes_read, 0); | |
2833 | ptr_file_name_table += bytes_read; | |
2834 | file_table[i].modification_date = read_leb128 (ptr_file_name_table, | |
2835 | & bytes_read, 0); | |
2836 | ptr_file_name_table += bytes_read; | |
2837 | file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0); | |
2838 | ptr_file_name_table += bytes_read; | |
2839 | i++; | |
2840 | } | |
2841 | i = 0; | |
2842 | ||
2843 | /* Print the Compilation Unit's name and a header. */ | |
2844 | if (directory_table == NULL) | |
2845 | { | |
2846 | printf (_("CU: %s:\n"), file_table[0].name); | |
2847 | printf (_("File name Line number Starting address\n")); | |
2848 | } | |
2849 | else | |
2850 | { | |
4eee63bc CD |
2851 | unsigned int ix = file_table[0].directory_index; |
2852 | const char *directory = ix ? (char *)directory_table[ix - 1] : "."; | |
2853 | if (do_wide || strlen (directory) < 76) | |
2854 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
a262ae96 | 2855 | else |
cc5914eb AM |
2856 | printf ("%s:\n", file_table[0].name); |
2857 | ||
a262ae96 NC |
2858 | printf (_("File name Line number Starting address\n")); |
2859 | } | |
2860 | } | |
2861 | ||
2862 | /* Skip the NUL at the end of the table. */ | |
2863 | data++; | |
2864 | ||
2865 | /* This loop iterates through the Dwarf Line Number Program. */ | |
2866 | while (data < end_of_sequence) | |
2867 | { | |
2868 | unsigned char op_code; | |
2869 | int adv; | |
2870 | unsigned long int uladv; | |
2871 | unsigned int bytes_read; | |
2872 | int is_special_opcode = 0; | |
2873 | ||
2874 | op_code = *data++; | |
a262ae96 | 2875 | |
91d6fa6a | 2876 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 2877 | { |
91d6fa6a | 2878 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
2879 | uladv = (op_code / linfo.li_line_range); |
2880 | if (linfo.li_max_ops_per_insn == 1) | |
2881 | { | |
2882 | uladv *= linfo.li_min_insn_length; | |
2883 | state_machine_regs.address += uladv; | |
2884 | } | |
2885 | else | |
2886 | { | |
2887 | state_machine_regs.address | |
2888 | += ((state_machine_regs.op_index + uladv) | |
2889 | / linfo.li_max_ops_per_insn) | |
2890 | * linfo.li_min_insn_length; | |
2891 | state_machine_regs.op_index | |
2892 | = (state_machine_regs.op_index + uladv) | |
2893 | % linfo.li_max_ops_per_insn; | |
2894 | } | |
a262ae96 | 2895 | |
91d6fa6a | 2896 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
a262ae96 NC |
2897 | state_machine_regs.line += adv; |
2898 | is_special_opcode = 1; | |
2899 | } | |
2900 | else switch (op_code) | |
2901 | { | |
2902 | case DW_LNS_extended_op: | |
2903 | { | |
2904 | unsigned int ext_op_code_len; | |
a262ae96 NC |
2905 | unsigned char ext_op_code; |
2906 | unsigned char *op_code_data = data; | |
2907 | ||
2908 | ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0); | |
2909 | op_code_data += bytes_read; | |
2910 | ||
2911 | if (ext_op_code_len == 0) | |
2912 | { | |
2913 | warn (_("badly formed extended line op encountered!\n")); | |
2914 | break; | |
2915 | } | |
2916 | ext_op_code_len += bytes_read; | |
2917 | ext_op_code = *op_code_data++; | |
2918 | ||
2919 | switch (ext_op_code) | |
2920 | { | |
2921 | case DW_LNE_end_sequence: | |
91d6fa6a | 2922 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 NC |
2923 | break; |
2924 | case DW_LNE_set_address: | |
2925 | state_machine_regs.address = | |
2926 | byte_get (op_code_data, ext_op_code_len - bytes_read - 1); | |
a233b20c | 2927 | state_machine_regs.op_index = 0; |
a262ae96 NC |
2928 | break; |
2929 | case DW_LNE_define_file: | |
2930 | { | |
143a3db0 TG |
2931 | file_table = (File_Entry *) xrealloc |
2932 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
a262ae96 NC |
2933 | |
2934 | ++state_machine_regs.last_file_entry; | |
143a3db0 TG |
2935 | /* Source file name. */ |
2936 | file_table[n_files].name = op_code_data; | |
a262ae96 | 2937 | op_code_data += strlen ((char *) op_code_data) + 1; |
143a3db0 TG |
2938 | /* Directory index. */ |
2939 | file_table[n_files].directory_index = | |
2940 | read_leb128 (op_code_data, & bytes_read, 0); | |
a262ae96 | 2941 | op_code_data += bytes_read; |
143a3db0 TG |
2942 | /* Last modification time. */ |
2943 | file_table[n_files].modification_date = | |
2944 | read_leb128 (op_code_data, & bytes_read, 0); | |
a262ae96 | 2945 | op_code_data += bytes_read; |
143a3db0 TG |
2946 | /* File length. */ |
2947 | file_table[n_files].length = | |
2948 | read_leb128 (op_code_data, & bytes_read, 0); | |
a262ae96 | 2949 | |
143a3db0 | 2950 | n_files++; |
a262ae96 NC |
2951 | break; |
2952 | } | |
143a3db0 TG |
2953 | case DW_LNE_set_discriminator: |
2954 | case DW_LNE_HP_set_sequence: | |
2955 | /* Simply ignored. */ | |
2956 | break; | |
2957 | ||
a262ae96 | 2958 | default: |
143a3db0 TG |
2959 | printf (_("UNKNOWN (%u): length %d\n"), |
2960 | ext_op_code, ext_op_code_len - bytes_read); | |
a262ae96 NC |
2961 | break; |
2962 | } | |
2963 | data += ext_op_code_len; | |
2964 | break; | |
2965 | } | |
2966 | case DW_LNS_copy: | |
2967 | break; | |
2968 | ||
2969 | case DW_LNS_advance_pc: | |
2970 | uladv = read_leb128 (data, & bytes_read, 0); | |
a262ae96 | 2971 | data += bytes_read; |
a233b20c JJ |
2972 | if (linfo.li_max_ops_per_insn == 1) |
2973 | { | |
2974 | uladv *= linfo.li_min_insn_length; | |
2975 | state_machine_regs.address += uladv; | |
2976 | } | |
2977 | else | |
2978 | { | |
2979 | state_machine_regs.address | |
2980 | += ((state_machine_regs.op_index + uladv) | |
2981 | / linfo.li_max_ops_per_insn) | |
2982 | * linfo.li_min_insn_length; | |
2983 | state_machine_regs.op_index | |
2984 | = (state_machine_regs.op_index + uladv) | |
2985 | % linfo.li_max_ops_per_insn; | |
2986 | } | |
a262ae96 NC |
2987 | break; |
2988 | ||
2989 | case DW_LNS_advance_line: | |
467c65bc | 2990 | adv = read_sleb128 (data, & bytes_read); |
a262ae96 NC |
2991 | data += bytes_read; |
2992 | state_machine_regs.line += adv; | |
2993 | break; | |
2994 | ||
2995 | case DW_LNS_set_file: | |
2996 | adv = read_leb128 (data, & bytes_read, 0); | |
2997 | data += bytes_read; | |
2998 | state_machine_regs.file = adv; | |
2999 | if (file_table[state_machine_regs.file - 1].directory_index == 0) | |
3000 | { | |
3001 | /* If directory index is 0, that means current directory. */ | |
cc5914eb | 3002 | printf ("\n./%s:[++]\n", |
a262ae96 NC |
3003 | file_table[state_machine_regs.file - 1].name); |
3004 | } | |
3005 | else | |
3006 | { | |
3007 | /* The directory index starts counting at 1. */ | |
cc5914eb | 3008 | printf ("\n%s/%s:\n", |
a262ae96 NC |
3009 | directory_table[file_table[state_machine_regs.file - 1].directory_index - 1], |
3010 | file_table[state_machine_regs.file - 1].name); | |
3011 | } | |
3012 | break; | |
3013 | ||
3014 | case DW_LNS_set_column: | |
3015 | uladv = read_leb128 (data, & bytes_read, 0); | |
3016 | data += bytes_read; | |
3017 | state_machine_regs.column = uladv; | |
3018 | break; | |
3019 | ||
3020 | case DW_LNS_negate_stmt: | |
3021 | adv = state_machine_regs.is_stmt; | |
3022 | adv = ! adv; | |
3023 | state_machine_regs.is_stmt = adv; | |
3024 | break; | |
3025 | ||
3026 | case DW_LNS_set_basic_block: | |
3027 | state_machine_regs.basic_block = 1; | |
3028 | break; | |
3029 | ||
3030 | case DW_LNS_const_add_pc: | |
a233b20c JJ |
3031 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); |
3032 | if (linfo.li_max_ops_per_insn == 1) | |
3033 | { | |
3034 | uladv *= linfo.li_min_insn_length; | |
3035 | state_machine_regs.address += uladv; | |
3036 | } | |
3037 | else | |
3038 | { | |
3039 | state_machine_regs.address | |
3040 | += ((state_machine_regs.op_index + uladv) | |
3041 | / linfo.li_max_ops_per_insn) | |
3042 | * linfo.li_min_insn_length; | |
3043 | state_machine_regs.op_index | |
3044 | = (state_machine_regs.op_index + uladv) | |
3045 | % linfo.li_max_ops_per_insn; | |
3046 | } | |
a262ae96 NC |
3047 | break; |
3048 | ||
3049 | case DW_LNS_fixed_advance_pc: | |
3050 | uladv = byte_get (data, 2); | |
3051 | data += 2; | |
3052 | state_machine_regs.address += uladv; | |
a233b20c | 3053 | state_machine_regs.op_index = 0; |
a262ae96 NC |
3054 | break; |
3055 | ||
3056 | case DW_LNS_set_prologue_end: | |
3057 | break; | |
3058 | ||
3059 | case DW_LNS_set_epilogue_begin: | |
3060 | break; | |
3061 | ||
3062 | case DW_LNS_set_isa: | |
3063 | uladv = read_leb128 (data, & bytes_read, 0); | |
3064 | data += bytes_read; | |
3065 | printf (_(" Set ISA to %lu\n"), uladv); | |
3066 | break; | |
3067 | ||
3068 | default: | |
3069 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
3070 | ||
3071 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
3072 | { | |
467c65bc NC |
3073 | printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data, |
3074 | &bytes_read, 0)), | |
a262ae96 NC |
3075 | i == 1 ? "" : ", "); |
3076 | data += bytes_read; | |
3077 | } | |
3078 | putchar ('\n'); | |
3079 | break; | |
3080 | } | |
3081 | ||
3082 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row | |
3083 | to the DWARF address/line matrix. */ | |
3084 | if ((is_special_opcode) || (op_code == DW_LNE_end_sequence) | |
3085 | || (op_code == DW_LNS_copy)) | |
3086 | { | |
3087 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
3088 | char *fileName = (char *)file_table[state_machine_regs.file - 1].name; | |
3089 | char *newFileName = NULL; | |
3090 | size_t fileNameLength = strlen (fileName); | |
3091 | ||
3092 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) | |
3093 | { | |
3f5e193b | 3094 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); |
a262ae96 NC |
3095 | /* Truncate file name */ |
3096 | strncpy (newFileName, | |
3097 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
3098 | MAX_FILENAME_LENGTH + 1); | |
3099 | } | |
3100 | else | |
3101 | { | |
3f5e193b | 3102 | newFileName = (char *) xmalloc (fileNameLength + 1); |
a262ae96 NC |
3103 | strncpy (newFileName, fileName, fileNameLength + 1); |
3104 | } | |
3105 | ||
3106 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) | |
3107 | { | |
a233b20c | 3108 | if (linfo.li_max_ops_per_insn == 1) |
467c65bc NC |
3109 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n", |
3110 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3111 | state_machine_regs.address); |
3112 | else | |
467c65bc NC |
3113 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n", |
3114 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3115 | state_machine_regs.address, |
3116 | state_machine_regs.op_index); | |
a262ae96 NC |
3117 | } |
3118 | else | |
3119 | { | |
a233b20c | 3120 | if (linfo.li_max_ops_per_insn == 1) |
467c65bc NC |
3121 | printf ("%s %11d %#18" DWARF_VMA_FMT "x\n", |
3122 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3123 | state_machine_regs.address); |
3124 | else | |
467c65bc NC |
3125 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n", |
3126 | newFileName, state_machine_regs.line, | |
a233b20c JJ |
3127 | state_machine_regs.address, |
3128 | state_machine_regs.op_index); | |
a262ae96 NC |
3129 | } |
3130 | ||
3131 | if (op_code == DW_LNE_end_sequence) | |
3132 | printf ("\n"); | |
3133 | ||
3134 | free (newFileName); | |
3135 | } | |
3136 | } | |
3137 | free (file_table); | |
3138 | file_table = NULL; | |
3139 | free (directory_table); | |
3140 | directory_table = NULL; | |
3141 | putchar ('\n'); | |
3142 | } | |
3143 | ||
3144 | return 1; | |
3145 | } | |
3146 | ||
3147 | static int | |
1c4cc746 | 3148 | display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) |
a262ae96 NC |
3149 | { |
3150 | unsigned char *data = section->start; | |
3151 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
3152 | int retValRaw = 1; |
3153 | int retValDecoded = 1; | |
a262ae96 | 3154 | |
008f4c78 NC |
3155 | if (do_debug_lines == 0) |
3156 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
3157 | ||
4cb93e3b | 3158 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
a262ae96 NC |
3159 | retValRaw = display_debug_lines_raw (section, data, end); |
3160 | ||
4cb93e3b | 3161 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
a262ae96 NC |
3162 | retValDecoded = display_debug_lines_decoded (section, data, end); |
3163 | ||
4cb93e3b | 3164 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
3165 | return 0; |
3166 | ||
3167 | return 1; | |
3168 | } | |
3169 | ||
6e3d6dc1 NC |
3170 | static debug_info * |
3171 | find_debug_info_for_offset (unsigned long offset) | |
3172 | { | |
3173 | unsigned int i; | |
3174 | ||
3175 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
3176 | return NULL; | |
3177 | ||
3178 | for (i = 0; i < num_debug_info_entries; i++) | |
3179 | if (debug_information[i].cu_offset == offset) | |
3180 | return debug_information + i; | |
3181 | ||
3182 | return NULL; | |
3183 | } | |
3184 | ||
19e6b90e L |
3185 | static int |
3186 | display_debug_pubnames (struct dwarf_section *section, | |
3187 | void *file ATTRIBUTE_UNUSED) | |
3188 | { | |
91d6fa6a | 3189 | DWARF2_Internal_PubNames names; |
19e6b90e L |
3190 | unsigned char *start = section->start; |
3191 | unsigned char *end = start + section->size; | |
3192 | ||
6e3d6dc1 NC |
3193 | /* It does not matter if this load fails, |
3194 | we test for that later on. */ | |
3195 | load_debug_info (file); | |
3196 | ||
19e6b90e L |
3197 | printf (_("Contents of the %s section:\n\n"), section->name); |
3198 | ||
3199 | while (start < end) | |
3200 | { | |
3201 | unsigned char *data; | |
3202 | unsigned long offset; | |
3203 | int offset_size, initial_length_size; | |
3204 | ||
3205 | data = start; | |
3206 | ||
91d6fa6a | 3207 | names.pn_length = byte_get (data, 4); |
19e6b90e | 3208 | data += 4; |
91d6fa6a | 3209 | if (names.pn_length == 0xffffffff) |
19e6b90e | 3210 | { |
91d6fa6a | 3211 | names.pn_length = byte_get (data, 8); |
19e6b90e L |
3212 | data += 8; |
3213 | offset_size = 8; | |
3214 | initial_length_size = 12; | |
3215 | } | |
3216 | else | |
3217 | { | |
3218 | offset_size = 4; | |
3219 | initial_length_size = 4; | |
3220 | } | |
3221 | ||
91d6fa6a | 3222 | names.pn_version = byte_get (data, 2); |
19e6b90e | 3223 | data += 2; |
6e3d6dc1 | 3224 | |
91d6fa6a | 3225 | names.pn_offset = byte_get (data, offset_size); |
19e6b90e | 3226 | data += offset_size; |
6e3d6dc1 NC |
3227 | |
3228 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
3229 | && num_debug_info_entries > 0 | |
91d6fa6a | 3230 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 3231 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 3232 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 3233 | |
91d6fa6a | 3234 | names.pn_size = byte_get (data, offset_size); |
19e6b90e L |
3235 | data += offset_size; |
3236 | ||
91d6fa6a | 3237 | start += names.pn_length + initial_length_size; |
19e6b90e | 3238 | |
91d6fa6a | 3239 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
3240 | { |
3241 | static int warned = 0; | |
3242 | ||
3243 | if (! warned) | |
3244 | { | |
3245 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
3246 | warned = 1; | |
3247 | } | |
3248 | ||
3249 | continue; | |
3250 | } | |
3251 | ||
3252 | printf (_(" Length: %ld\n"), | |
47704ddf | 3253 | (long) names.pn_length); |
19e6b90e | 3254 | printf (_(" Version: %d\n"), |
91d6fa6a | 3255 | names.pn_version); |
6e3d6dc1 | 3256 | printf (_(" Offset into .debug_info section: 0x%lx\n"), |
47704ddf | 3257 | (unsigned long) names.pn_offset); |
19e6b90e | 3258 | printf (_(" Size of area in .debug_info section: %ld\n"), |
47704ddf | 3259 | (long) names.pn_size); |
19e6b90e L |
3260 | |
3261 | printf (_("\n Offset\tName\n")); | |
3262 | ||
3263 | do | |
3264 | { | |
3265 | offset = byte_get (data, offset_size); | |
3266 | ||
3267 | if (offset != 0) | |
3268 | { | |
3269 | data += offset_size; | |
80c35038 | 3270 | printf (" %-6lx\t%s\n", offset, data); |
19e6b90e L |
3271 | data += strlen ((char *) data) + 1; |
3272 | } | |
3273 | } | |
3274 | while (offset != 0); | |
3275 | } | |
3276 | ||
3277 | printf ("\n"); | |
3278 | return 1; | |
3279 | } | |
3280 | ||
3281 | static int | |
3282 | display_debug_macinfo (struct dwarf_section *section, | |
3283 | void *file ATTRIBUTE_UNUSED) | |
3284 | { | |
3285 | unsigned char *start = section->start; | |
3286 | unsigned char *end = start + section->size; | |
3287 | unsigned char *curr = start; | |
3288 | unsigned int bytes_read; | |
3289 | enum dwarf_macinfo_record_type op; | |
3290 | ||
3291 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3292 | ||
3293 | while (curr < end) | |
3294 | { | |
3295 | unsigned int lineno; | |
3296 | const char *string; | |
3297 | ||
3f5e193b | 3298 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
3299 | curr++; |
3300 | ||
3301 | switch (op) | |
3302 | { | |
3303 | case DW_MACINFO_start_file: | |
3304 | { | |
3305 | unsigned int filenum; | |
3306 | ||
3307 | lineno = read_leb128 (curr, & bytes_read, 0); | |
3308 | curr += bytes_read; | |
3309 | filenum = read_leb128 (curr, & bytes_read, 0); | |
3310 | curr += bytes_read; | |
3311 | ||
3312 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), | |
3313 | lineno, filenum); | |
3314 | } | |
3315 | break; | |
3316 | ||
3317 | case DW_MACINFO_end_file: | |
3318 | printf (_(" DW_MACINFO_end_file\n")); | |
3319 | break; | |
3320 | ||
3321 | case DW_MACINFO_define: | |
3322 | lineno = read_leb128 (curr, & bytes_read, 0); | |
3323 | curr += bytes_read; | |
3324 | string = (char *) curr; | |
3325 | curr += strlen (string) + 1; | |
3326 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), | |
3327 | lineno, string); | |
3328 | break; | |
3329 | ||
3330 | case DW_MACINFO_undef: | |
3331 | lineno = read_leb128 (curr, & bytes_read, 0); | |
3332 | curr += bytes_read; | |
3333 | string = (char *) curr; | |
3334 | curr += strlen (string) + 1; | |
3335 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), | |
3336 | lineno, string); | |
3337 | break; | |
3338 | ||
3339 | case DW_MACINFO_vendor_ext: | |
3340 | { | |
3341 | unsigned int constant; | |
3342 | ||
3343 | constant = read_leb128 (curr, & bytes_read, 0); | |
3344 | curr += bytes_read; | |
3345 | string = (char *) curr; | |
3346 | curr += strlen (string) + 1; | |
3347 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), | |
3348 | constant, string); | |
3349 | } | |
3350 | break; | |
3351 | } | |
3352 | } | |
3353 | ||
3354 | return 1; | |
3355 | } | |
3356 | ||
4ccf1e31 JJ |
3357 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
3358 | filename and dirname corresponding to file name table entry with index | |
3359 | FILEIDX. Return NULL on failure. */ | |
3360 | ||
3361 | static unsigned char * | |
3362 | get_line_filename_and_dirname (dwarf_vma line_offset, dwarf_vma fileidx, | |
3363 | unsigned char **dir_name) | |
3364 | { | |
3365 | struct dwarf_section *section = &debug_displays [line].section; | |
3366 | unsigned char *hdrptr, *dirtable, *file_name; | |
3367 | unsigned int offset_size, initial_length_size; | |
3368 | unsigned int version, opcode_base, bytes_read; | |
3369 | dwarf_vma length, diridx; | |
3370 | ||
3371 | *dir_name = NULL; | |
3372 | if (section->start == NULL | |
3373 | || line_offset >= section->size | |
3374 | || fileidx == 0) | |
3375 | return NULL; | |
3376 | ||
3377 | hdrptr = section->start + line_offset; | |
3378 | length = byte_get (hdrptr, 4); | |
3379 | hdrptr += 4; | |
3380 | if (length == 0xffffffff) | |
3381 | { | |
3382 | /* This section is 64-bit DWARF 3. */ | |
3383 | length = byte_get (hdrptr, 8); | |
3384 | hdrptr += 8; | |
3385 | offset_size = 8; | |
3386 | initial_length_size = 12; | |
3387 | } | |
3388 | else | |
3389 | { | |
3390 | offset_size = 4; | |
3391 | initial_length_size = 4; | |
3392 | } | |
3393 | if (length + initial_length_size > section->size) | |
3394 | return NULL; | |
3395 | version = byte_get (hdrptr, 2); | |
3396 | hdrptr += 2; | |
3397 | if (version != 2 && version != 3 && version != 4) | |
3398 | return NULL; | |
3399 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
3400 | if (version >= 4) | |
3401 | hdrptr++; /* Skip max_ops_per_insn. */ | |
3402 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
3403 | opcode_base = byte_get (hdrptr, 1); | |
3404 | if (opcode_base == 0) | |
3405 | return NULL; | |
3406 | hdrptr++; | |
3407 | hdrptr += opcode_base - 1; | |
3408 | dirtable = hdrptr; | |
3409 | /* Skip over dirname table. */ | |
3410 | while (*hdrptr != '\0') | |
3411 | hdrptr += strlen ((char *) hdrptr) + 1; | |
3412 | hdrptr++; /* Skip the NUL at the end of the table. */ | |
3413 | /* Now skip over preceding filename table entries. */ | |
3414 | for (; *hdrptr != '\0' && fileidx > 1; fileidx--) | |
3415 | { | |
3416 | hdrptr += strlen ((char *) hdrptr) + 1; | |
3417 | read_leb128 (hdrptr, &bytes_read, 0); | |
3418 | hdrptr += bytes_read; | |
3419 | read_leb128 (hdrptr, &bytes_read, 0); | |
3420 | hdrptr += bytes_read; | |
3421 | read_leb128 (hdrptr, &bytes_read, 0); | |
3422 | hdrptr += bytes_read; | |
3423 | } | |
3424 | if (*hdrptr == '\0') | |
3425 | return NULL; | |
3426 | file_name = hdrptr; | |
3427 | hdrptr += strlen ((char *) hdrptr) + 1; | |
3428 | diridx = read_leb128 (hdrptr, &bytes_read, 0); | |
3429 | if (diridx == 0) | |
3430 | return file_name; | |
3431 | for (; *dirtable != '\0' && diridx > 1; diridx--) | |
3432 | dirtable += strlen ((char *) dirtable) + 1; | |
3433 | if (*dirtable == '\0') | |
3434 | return NULL; | |
3435 | *dir_name = dirtable; | |
3436 | return file_name; | |
3437 | } | |
3438 | ||
3439 | static int | |
3440 | display_debug_macro (struct dwarf_section *section, | |
3441 | void *file) | |
3442 | { | |
3443 | unsigned char *start = section->start; | |
3444 | unsigned char *end = start + section->size; | |
3445 | unsigned char *curr = start; | |
3446 | unsigned char *extended_op_buf[256]; | |
3447 | unsigned int bytes_read; | |
3448 | ||
3449 | load_debug_section (str, file); | |
3450 | load_debug_section (line, file); | |
3451 | ||
3452 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3453 | ||
3454 | while (curr < end) | |
3455 | { | |
3456 | unsigned int lineno, version, flags; | |
3457 | unsigned int offset_size = 4; | |
3458 | const char *string; | |
3459 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; | |
3460 | unsigned char **extended_ops = NULL; | |
3461 | ||
3462 | version = byte_get (curr, 2); | |
3463 | curr += 2; | |
3464 | ||
3465 | if (version != 4) | |
3466 | { | |
3467 | error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"), | |
3468 | section->name); | |
3469 | return 0; | |
3470 | } | |
3471 | ||
3472 | flags = byte_get (curr++, 1); | |
3473 | if (flags & 1) | |
3474 | offset_size = 8; | |
3475 | printf (_(" Offset: 0x%lx\n"), | |
3476 | (unsigned long) sec_offset); | |
3477 | printf (_(" Version: %d\n"), version); | |
3478 | printf (_(" Offset size: %d\n"), offset_size); | |
3479 | if (flags & 2) | |
3480 | { | |
3481 | line_offset = byte_get (curr, offset_size); | |
3482 | curr += offset_size; | |
3483 | printf (_(" Offset into .debug_line: 0x%lx\n"), | |
3484 | (unsigned long) line_offset); | |
3485 | } | |
3486 | if (flags & 4) | |
3487 | { | |
3488 | unsigned int i, count = byte_get (curr++, 1), op; | |
3489 | dwarf_vma nargs, n; | |
3490 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); | |
3491 | extended_ops = extended_op_buf; | |
3492 | if (count) | |
3493 | { | |
3494 | printf (_(" Extension opcode arguments:\n")); | |
3495 | for (i = 0; i < count; i++) | |
3496 | { | |
3497 | op = byte_get (curr++, 1); | |
3498 | extended_ops[op] = curr; | |
3499 | nargs = read_leb128 (curr, &bytes_read, 0); | |
3500 | curr += bytes_read; | |
3501 | if (nargs == 0) | |
3502 | printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op); | |
3503 | else | |
3504 | { | |
3505 | printf (_(" DW_MACRO_GNU_%02x arguments: "), op); | |
3506 | for (n = 0; n < nargs; n++) | |
3507 | { | |
3508 | unsigned int form = byte_get (curr++, 1); | |
3509 | printf ("%s%s", get_FORM_name (form), | |
3510 | n == nargs - 1 ? "\n" : ", "); | |
3511 | switch (form) | |
3512 | { | |
3513 | case DW_FORM_data1: | |
3514 | case DW_FORM_data2: | |
3515 | case DW_FORM_data4: | |
3516 | case DW_FORM_data8: | |
3517 | case DW_FORM_sdata: | |
3518 | case DW_FORM_udata: | |
3519 | case DW_FORM_block: | |
3520 | case DW_FORM_block1: | |
3521 | case DW_FORM_block2: | |
3522 | case DW_FORM_block4: | |
3523 | case DW_FORM_flag: | |
3524 | case DW_FORM_string: | |
3525 | case DW_FORM_strp: | |
3526 | case DW_FORM_sec_offset: | |
3527 | break; | |
3528 | default: | |
3529 | error (_("Invalid extension opcode form %s\n"), | |
3530 | get_FORM_name (form)); | |
3531 | return 0; | |
3532 | } | |
3533 | } | |
3534 | } | |
3535 | } | |
3536 | } | |
3537 | } | |
3538 | printf ("\n"); | |
3539 | ||
3540 | while (1) | |
3541 | { | |
3542 | unsigned int op; | |
3543 | ||
3544 | if (curr >= end) | |
3545 | { | |
3546 | error (_(".debug_macro section not zero terminated\n")); | |
3547 | return 0; | |
3548 | } | |
3549 | ||
3550 | op = byte_get (curr++, 1); | |
3551 | if (op == 0) | |
3552 | break; | |
3553 | ||
3554 | switch (op) | |
3555 | { | |
3556 | case DW_MACRO_GNU_start_file: | |
3557 | { | |
3558 | unsigned int filenum; | |
3559 | unsigned char *file_name = NULL, *dir_name = NULL; | |
3560 | ||
3561 | lineno = read_leb128 (curr, &bytes_read, 0); | |
3562 | curr += bytes_read; | |
3563 | filenum = read_leb128 (curr, &bytes_read, 0); | |
3564 | curr += bytes_read; | |
3565 | ||
3566 | if ((flags & 2) == 0) | |
3567 | error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n")); | |
3568 | else | |
3569 | file_name | |
3570 | = get_line_filename_and_dirname (line_offset, filenum, | |
3571 | &dir_name); | |
3572 | if (file_name == NULL) | |
3573 | printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"), | |
3574 | lineno, filenum); | |
3575 | else | |
3576 | printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), | |
3577 | lineno, filenum, | |
3578 | dir_name != NULL ? (const char *) dir_name : "", | |
3579 | dir_name != NULL ? "/" : "", file_name); | |
3580 | } | |
3581 | break; | |
3582 | ||
3583 | case DW_MACRO_GNU_end_file: | |
3584 | printf (_(" DW_MACRO_GNU_end_file\n")); | |
3585 | break; | |
3586 | ||
3587 | case DW_MACRO_GNU_define: | |
3588 | lineno = read_leb128 (curr, &bytes_read, 0); | |
3589 | curr += bytes_read; | |
3590 | string = (char *) curr; | |
3591 | curr += strlen (string) + 1; | |
3592 | printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"), | |
3593 | lineno, string); | |
3594 | break; | |
3595 | ||
3596 | case DW_MACRO_GNU_undef: | |
3597 | lineno = read_leb128 (curr, &bytes_read, 0); | |
3598 | curr += bytes_read; | |
3599 | string = (char *) curr; | |
3600 | curr += strlen (string) + 1; | |
3601 | printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"), | |
3602 | lineno, string); | |
3603 | break; | |
3604 | ||
3605 | case DW_MACRO_GNU_define_indirect: | |
3606 | lineno = read_leb128 (curr, &bytes_read, 0); | |
3607 | curr += bytes_read; | |
3608 | offset = byte_get (curr, offset_size); | |
3609 | curr += offset_size; | |
3610 | string = fetch_indirect_string (offset); | |
3611 | printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"), | |
3612 | lineno, string); | |
3613 | break; | |
3614 | ||
3615 | case DW_MACRO_GNU_undef_indirect: | |
3616 | lineno = read_leb128 (curr, &bytes_read, 0); | |
3617 | curr += bytes_read; | |
3618 | offset = byte_get (curr, offset_size); | |
3619 | curr += offset_size; | |
3620 | string = fetch_indirect_string (offset); | |
3621 | printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"), | |
3622 | lineno, string); | |
3623 | break; | |
3624 | ||
3625 | case DW_MACRO_GNU_transparent_include: | |
3626 | offset = byte_get (curr, offset_size); | |
3627 | curr += offset_size; | |
3628 | printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"), | |
3629 | (unsigned long) offset); | |
3630 | break; | |
3631 | ||
3632 | default: | |
3633 | if (extended_ops == NULL || extended_ops[op] == NULL) | |
3634 | { | |
3635 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
3636 | return 0; | |
3637 | } | |
3638 | else | |
3639 | { | |
3640 | /* Skip over unhandled opcodes. */ | |
3641 | dwarf_vma nargs, n; | |
3642 | unsigned char *desc = extended_ops[op]; | |
3643 | nargs = read_leb128 (desc, &bytes_read, 0); | |
3644 | desc += bytes_read; | |
3645 | if (nargs == 0) | |
3646 | { | |
3647 | printf (_(" DW_MACRO_GNU_%02x\n"), op); | |
3648 | break; | |
3649 | } | |
3650 | printf (_(" DW_MACRO_GNU_%02x -"), op); | |
3651 | for (n = 0; n < nargs; n++) | |
3652 | { | |
3653 | curr | |
3654 | = read_and_display_attr_value (0, byte_get (desc++, 1), | |
3655 | curr, 0, 0, offset_size, | |
3656 | version, NULL, 0, NULL); | |
3657 | if (n != nargs - 1) | |
3658 | printf (","); | |
3659 | } | |
3660 | printf ("\n"); | |
3661 | } | |
3662 | break; | |
3663 | } | |
3664 | } | |
3665 | ||
3666 | printf ("\n"); | |
3667 | } | |
3668 | ||
3669 | return 1; | |
3670 | } | |
3671 | ||
19e6b90e L |
3672 | static int |
3673 | display_debug_abbrev (struct dwarf_section *section, | |
3674 | void *file ATTRIBUTE_UNUSED) | |
3675 | { | |
3676 | abbrev_entry *entry; | |
3677 | unsigned char *start = section->start; | |
3678 | unsigned char *end = start + section->size; | |
3679 | ||
3680 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3681 | ||
3682 | do | |
3683 | { | |
3684 | free_abbrevs (); | |
3685 | ||
3686 | start = process_abbrev_section (start, end); | |
3687 | ||
3688 | if (first_abbrev == NULL) | |
3689 | continue; | |
3690 | ||
3691 | printf (_(" Number TAG\n")); | |
3692 | ||
3693 | for (entry = first_abbrev; entry; entry = entry->next) | |
3694 | { | |
3695 | abbrev_attr *attr; | |
3696 | ||
cc5914eb | 3697 | printf (" %ld %s [%s]\n", |
19e6b90e L |
3698 | entry->entry, |
3699 | get_TAG_name (entry->tag), | |
3700 | entry->children ? _("has children") : _("no children")); | |
3701 | ||
3702 | for (attr = entry->first_attr; attr; attr = attr->next) | |
cc5914eb | 3703 | printf (" %-18s %s\n", |
19e6b90e L |
3704 | get_AT_name (attr->attribute), |
3705 | get_FORM_name (attr->form)); | |
3706 | } | |
3707 | } | |
3708 | while (start); | |
3709 | ||
3710 | printf ("\n"); | |
3711 | ||
3712 | return 1; | |
3713 | } | |
3714 | ||
4723351a CC |
3715 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
3716 | ||
3717 | static void | |
3718 | display_loc_list (struct dwarf_section *section, | |
3719 | unsigned char **start_ptr, | |
3720 | int debug_info_entry, | |
3721 | unsigned long offset, | |
3722 | unsigned long base_address, | |
3723 | int has_frame_base) | |
3724 | { | |
3725 | unsigned char *start = *start_ptr; | |
3726 | unsigned char *section_end = section->start + section->size; | |
3727 | unsigned long cu_offset = debug_information [debug_info_entry].cu_offset; | |
3728 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
3729 | unsigned int offset_size = debug_information [debug_info_entry].offset_size; | |
3730 | int dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
3731 | ||
3732 | dwarf_vma begin; | |
3733 | dwarf_vma end; | |
3734 | unsigned short length; | |
3735 | int need_frame_base; | |
3736 | ||
3737 | while (1) | |
3738 | { | |
3739 | if (start + 2 * pointer_size > section_end) | |
3740 | { | |
3741 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
3742 | offset); | |
3743 | break; | |
3744 | } | |
3745 | ||
3746 | /* Note: we use sign extension here in order to be sure that we can detect | |
3747 | the -1 escape value. Sign extension into the top 32 bits of a 32-bit | |
3748 | address will not affect the values that we display since we always show | |
3749 | hex values, and always the bottom 32-bits. */ | |
3750 | begin = byte_get_signed (start, pointer_size); | |
3751 | start += pointer_size; | |
3752 | end = byte_get_signed (start, pointer_size); | |
3753 | start += pointer_size; | |
3754 | ||
3755 | printf (" %8.8lx ", offset); | |
3756 | ||
3757 | if (begin == 0 && end == 0) | |
3758 | { | |
3759 | printf (_("<End of list>\n")); | |
3760 | break; | |
3761 | } | |
3762 | ||
3763 | /* Check base address specifiers. */ | |
3764 | if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1) | |
3765 | { | |
3766 | base_address = end; | |
3767 | print_dwarf_vma (begin, pointer_size); | |
3768 | print_dwarf_vma (end, pointer_size); | |
3769 | printf (_("(base address)\n")); | |
3770 | continue; | |
3771 | } | |
3772 | ||
3773 | if (start + 2 > section_end) | |
3774 | { | |
3775 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
3776 | offset); | |
3777 | break; | |
3778 | } | |
3779 | ||
3780 | length = byte_get (start, 2); | |
3781 | start += 2; | |
3782 | ||
3783 | if (start + length > section_end) | |
3784 | { | |
3785 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
3786 | offset); | |
3787 | break; | |
3788 | } | |
3789 | ||
3790 | print_dwarf_vma (begin + base_address, pointer_size); | |
3791 | print_dwarf_vma (end + base_address, pointer_size); | |
3792 | ||
3793 | putchar ('('); | |
3794 | need_frame_base = decode_location_expression (start, | |
3795 | pointer_size, | |
3796 | offset_size, | |
3797 | dwarf_version, | |
3798 | length, | |
3799 | cu_offset, section); | |
3800 | putchar (')'); | |
3801 | ||
3802 | if (need_frame_base && !has_frame_base) | |
3803 | printf (_(" [without DW_AT_frame_base]")); | |
3804 | ||
3805 | if (begin == end) | |
3806 | fputs (_(" (start == end)"), stdout); | |
3807 | else if (begin > end) | |
3808 | fputs (_(" (start > end)"), stdout); | |
3809 | ||
3810 | putchar ('\n'); | |
3811 | ||
3812 | start += length; | |
3813 | } | |
3814 | ||
3815 | *start_ptr = start; | |
3816 | } | |
3817 | ||
3818 | /* Display a location list from a .dwo section. It uses address indexes rather | |
3819 | than embedded addresses. This code closely follows display_loc_list, but the | |
3820 | two are sufficiently different that combining things is very ugly. */ | |
3821 | ||
3822 | static void | |
3823 | display_loc_list_dwo (struct dwarf_section *section, | |
3824 | unsigned char **start_ptr, | |
3825 | int debug_info_entry, | |
3826 | unsigned long offset, | |
3827 | int has_frame_base) | |
3828 | { | |
3829 | unsigned char *start = *start_ptr; | |
3830 | unsigned char *section_end = section->start + section->size; | |
3831 | unsigned long cu_offset = debug_information [debug_info_entry].cu_offset; | |
3832 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
3833 | unsigned int offset_size = debug_information [debug_info_entry].offset_size; | |
3834 | int dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
3835 | int entry_type; | |
3836 | unsigned short length; | |
3837 | int need_frame_base; | |
3838 | dwarf_vma idx; | |
3839 | unsigned int bytes_read; | |
3840 | ||
3841 | while (1) | |
3842 | { | |
3843 | printf (" %8.8lx ", offset); | |
3844 | ||
3845 | if (start + 2 > section_end) | |
3846 | { | |
3847 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
3848 | offset); | |
3849 | break; | |
3850 | } | |
3851 | ||
3852 | entry_type = byte_get (start, 1); | |
3853 | start++; | |
3854 | switch (entry_type) | |
3855 | { | |
3856 | case 0: /* A terminating entry. */ | |
3857 | idx = byte_get (start, 1); | |
3858 | start++; | |
3859 | *start_ptr = start; | |
3860 | if (idx == 0) | |
3861 | printf (_("<End of list>\n")); | |
3862 | else | |
3863 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
3864 | offset); | |
3865 | return; | |
3866 | case 1: /* A base-address entry. */ | |
3867 | idx = read_leb128 (start, &bytes_read, 0); | |
3868 | start += bytes_read; | |
3869 | print_dwarf_vma (idx, pointer_size); | |
3870 | printf (_("(base address index)\n")); | |
3871 | continue; | |
3872 | case 2: /* A normal entry. */ | |
3873 | idx = read_leb128 (start, &bytes_read, 0); | |
3874 | start += bytes_read; | |
3875 | print_dwarf_vma (idx, pointer_size); | |
3876 | idx = read_leb128 (start, &bytes_read, 0); | |
3877 | start += bytes_read; | |
3878 | print_dwarf_vma (idx, pointer_size); | |
3879 | break; | |
3880 | default: | |
3881 | warn (_("Unknown location-list type 0x%x.\n"), entry_type); | |
3882 | *start_ptr = start; | |
3883 | return; | |
3884 | } | |
3885 | ||
3886 | if (start + 2 > section_end) | |
3887 | { | |
3888 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
3889 | offset); | |
3890 | break; | |
3891 | } | |
3892 | ||
3893 | length = byte_get (start, 2); | |
3894 | start += 2; | |
3895 | ||
3896 | if (start + length > section_end) | |
3897 | { | |
3898 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
3899 | offset); | |
3900 | break; | |
3901 | } | |
3902 | ||
3903 | putchar ('('); | |
3904 | need_frame_base = decode_location_expression (start, | |
3905 | pointer_size, | |
3906 | offset_size, | |
3907 | dwarf_version, | |
3908 | length, | |
3909 | cu_offset, section); | |
3910 | putchar (')'); | |
3911 | ||
3912 | if (need_frame_base && !has_frame_base) | |
3913 | printf (_(" [without DW_AT_frame_base]")); | |
3914 | ||
3915 | putchar ('\n'); | |
3916 | ||
3917 | start += length; | |
3918 | } | |
3919 | ||
3920 | *start_ptr = start; | |
3921 | } | |
3922 | ||
51d0d03f JJ |
3923 | /* Sort array of indexes in ascending order of loc_offsets[idx]. */ |
3924 | ||
3925 | static dwarf_vma *loc_offsets; | |
3926 | ||
3927 | static int | |
3928 | loc_offsets_compar (const void *ap, const void *bp) | |
3929 | { | |
3930 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
3931 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
3932 | ||
3933 | return (a > b) - (b > a); | |
3934 | } | |
3935 | ||
19e6b90e L |
3936 | static int |
3937 | display_debug_loc (struct dwarf_section *section, void *file) | |
3938 | { | |
3939 | unsigned char *start = section->start; | |
19e6b90e L |
3940 | unsigned long bytes; |
3941 | unsigned char *section_begin = start; | |
3942 | unsigned int num_loc_list = 0; | |
3943 | unsigned long last_offset = 0; | |
3944 | unsigned int first = 0; | |
3945 | unsigned int i; | |
3946 | unsigned int j; | |
51d0d03f | 3947 | unsigned int k; |
19e6b90e | 3948 | int seen_first_offset = 0; |
51d0d03f | 3949 | int locs_sorted = 1; |
19e6b90e | 3950 | unsigned char *next; |
51d0d03f | 3951 | unsigned int *array = NULL; |
4723351a CC |
3952 | const char *suffix = strrchr (section->name, '.'); |
3953 | int is_dwo = 0; | |
3954 | ||
3955 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
3956 | is_dwo = 1; | |
19e6b90e L |
3957 | |
3958 | bytes = section->size; | |
19e6b90e L |
3959 | |
3960 | if (bytes == 0) | |
3961 | { | |
3962 | printf (_("\nThe %s section is empty.\n"), section->name); | |
3963 | return 0; | |
3964 | } | |
3965 | ||
1febe64d NC |
3966 | if (load_debug_info (file) == 0) |
3967 | { | |
3968 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
3969 | section->name); | |
3970 | return 0; | |
3971 | } | |
19e6b90e L |
3972 | |
3973 | /* Check the order of location list in .debug_info section. If | |
3974 | offsets of location lists are in the ascending order, we can | |
3975 | use `debug_information' directly. */ | |
3976 | for (i = 0; i < num_debug_info_entries; i++) | |
3977 | { | |
3978 | unsigned int num; | |
3979 | ||
3980 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
3981 | if (num > num_loc_list) |
3982 | num_loc_list = num; | |
19e6b90e L |
3983 | |
3984 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 3985 | if (locs_sorted && num != 0) |
19e6b90e L |
3986 | { |
3987 | if (!seen_first_offset) | |
3988 | { | |
3989 | /* This is the first location list. */ | |
3990 | last_offset = debug_information [i].loc_offsets [0]; | |
3991 | first = i; | |
3992 | seen_first_offset = 1; | |
3993 | j = 1; | |
3994 | } | |
3995 | else | |
3996 | j = 0; | |
3997 | ||
3998 | for (; j < num; j++) | |
3999 | { | |
4000 | if (last_offset > | |
4001 | debug_information [i].loc_offsets [j]) | |
4002 | { | |
51d0d03f | 4003 | locs_sorted = 0; |
19e6b90e L |
4004 | break; |
4005 | } | |
4006 | last_offset = debug_information [i].loc_offsets [j]; | |
4007 | } | |
4008 | } | |
4009 | } | |
4010 | ||
19e6b90e L |
4011 | if (!seen_first_offset) |
4012 | error (_("No location lists in .debug_info section!\n")); | |
4013 | ||
bfe2612a | 4014 | /* DWARF sections under Mach-O have non-zero addresses. */ |
d4bfc77b AS |
4015 | if (debug_information [first].num_loc_offsets > 0 |
4016 | && debug_information [first].loc_offsets [0] != section->address) | |
47704ddf KT |
4017 | warn (_("Location lists in %s section start at 0x%s\n"), |
4018 | section->name, | |
4019 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 4020 | |
51d0d03f JJ |
4021 | if (!locs_sorted) |
4022 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
19e6b90e | 4023 | printf (_("Contents of the %s section:\n\n"), section->name); |
4723351a CC |
4024 | if (!is_dwo) |
4025 | printf (_(" Offset Begin End Expression\n")); | |
4026 | else | |
4027 | printf (_(" Offset Begin idx End idx Expression\n")); | |
19e6b90e L |
4028 | |
4029 | seen_first_offset = 0; | |
4030 | for (i = first; i < num_debug_info_entries; i++) | |
4031 | { | |
19e6b90e | 4032 | unsigned long offset; |
19e6b90e | 4033 | unsigned long base_address; |
19e6b90e L |
4034 | int has_frame_base; |
4035 | ||
51d0d03f JJ |
4036 | if (!locs_sorted) |
4037 | { | |
4038 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
4039 | array[k] = k; | |
4040 | loc_offsets = debug_information [i].loc_offsets; | |
4041 | qsort (array, debug_information [i].num_loc_offsets, | |
4042 | sizeof (*array), loc_offsets_compar); | |
4043 | } | |
19e6b90e | 4044 | |
51d0d03f | 4045 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 4046 | { |
51d0d03f JJ |
4047 | j = locs_sorted ? k : array[k]; |
4048 | if (k | |
4049 | && debug_information [i].loc_offsets [locs_sorted | |
4050 | ? k - 1 : array [k - 1]] | |
4051 | == debug_information [i].loc_offsets [j]) | |
4052 | continue; | |
19e6b90e | 4053 | has_frame_base = debug_information [i].have_frame_base [j]; |
bfe2612a | 4054 | /* DWARF sections under Mach-O have non-zero addresses. */ |
cecf136e | 4055 | offset = debug_information [i].loc_offsets [j] - section->address; |
19e6b90e L |
4056 | next = section_begin + offset; |
4057 | base_address = debug_information [i].base_address; | |
4058 | ||
4059 | if (!seen_first_offset) | |
4060 | seen_first_offset = 1; | |
4061 | else | |
4062 | { | |
4063 | if (start < next) | |
4064 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e AM |
4065 | (unsigned long) (start - section_begin), |
4066 | (unsigned long) (next - section_begin)); | |
19e6b90e L |
4067 | else if (start > next) |
4068 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e AM |
4069 | (unsigned long) (start - section_begin), |
4070 | (unsigned long) (next - section_begin)); | |
19e6b90e L |
4071 | } |
4072 | start = next; | |
4073 | ||
4074 | if (offset >= bytes) | |
4075 | { | |
4076 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
4077 | offset); | |
4078 | continue; | |
4079 | } | |
4080 | ||
4723351a CC |
4081 | if (is_dwo) |
4082 | display_loc_list_dwo (section, &start, i, offset, has_frame_base); | |
4083 | else | |
4084 | display_loc_list (section, &start, i, offset, base_address, | |
4085 | has_frame_base); | |
19e6b90e L |
4086 | } |
4087 | } | |
031cd65f | 4088 | |
4723351a | 4089 | if (start < section->start + section->size) |
031cd65f | 4090 | warn (_("There are %ld unused bytes at the end of section %s\n"), |
4723351a | 4091 | (long) (section->start + section->size - start), section->name); |
98fb390a | 4092 | putchar ('\n'); |
51d0d03f | 4093 | free (array); |
19e6b90e L |
4094 | return 1; |
4095 | } | |
4096 | ||
4097 | static int | |
4098 | display_debug_str (struct dwarf_section *section, | |
4099 | void *file ATTRIBUTE_UNUSED) | |
4100 | { | |
4101 | unsigned char *start = section->start; | |
4102 | unsigned long bytes = section->size; | |
4103 | dwarf_vma addr = section->address; | |
4104 | ||
4105 | if (bytes == 0) | |
4106 | { | |
4107 | printf (_("\nThe %s section is empty.\n"), section->name); | |
4108 | return 0; | |
4109 | } | |
4110 | ||
4111 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4112 | ||
4113 | while (bytes) | |
4114 | { | |
4115 | int j; | |
4116 | int k; | |
4117 | int lbytes; | |
4118 | ||
4119 | lbytes = (bytes > 16 ? 16 : bytes); | |
4120 | ||
4121 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
4122 | ||
4123 | for (j = 0; j < 16; j++) | |
4124 | { | |
4125 | if (j < lbytes) | |
4126 | printf ("%2.2x", start[j]); | |
4127 | else | |
4128 | printf (" "); | |
4129 | ||
4130 | if ((j & 3) == 3) | |
4131 | printf (" "); | |
4132 | } | |
4133 | ||
4134 | for (j = 0; j < lbytes; j++) | |
4135 | { | |
4136 | k = start[j]; | |
4137 | if (k >= ' ' && k < 0x80) | |
4138 | printf ("%c", k); | |
4139 | else | |
4140 | printf ("."); | |
4141 | } | |
4142 | ||
4143 | putchar ('\n'); | |
4144 | ||
4145 | start += lbytes; | |
4146 | addr += lbytes; | |
4147 | bytes -= lbytes; | |
4148 | } | |
4149 | ||
4150 | putchar ('\n'); | |
4151 | ||
4152 | return 1; | |
4153 | } | |
4154 | ||
19e6b90e L |
4155 | static int |
4156 | display_debug_info (struct dwarf_section *section, void *file) | |
4157 | { | |
4723351a | 4158 | return process_debug_info (section, file, section->abbrev_sec, 0, 0); |
19e6b90e L |
4159 | } |
4160 | ||
2b6f5997 CC |
4161 | static int |
4162 | display_debug_types (struct dwarf_section *section, void *file) | |
4163 | { | |
4723351a | 4164 | return process_debug_info (section, file, section->abbrev_sec, 0, 1); |
6f875884 TG |
4165 | } |
4166 | ||
4167 | static int | |
4168 | display_trace_info (struct dwarf_section *section, void *file) | |
4169 | { | |
4723351a | 4170 | return process_debug_info (section, file, section->abbrev_sec, 0, 0); |
2b6f5997 | 4171 | } |
19e6b90e L |
4172 | |
4173 | static int | |
4174 | display_debug_aranges (struct dwarf_section *section, | |
4175 | void *file ATTRIBUTE_UNUSED) | |
4176 | { | |
4177 | unsigned char *start = section->start; | |
4178 | unsigned char *end = start + section->size; | |
4179 | ||
80c35038 | 4180 | printf (_("Contents of the %s section:\n\n"), section->name); |
19e6b90e | 4181 | |
6e3d6dc1 NC |
4182 | /* It does not matter if this load fails, |
4183 | we test for that later on. */ | |
4184 | load_debug_info (file); | |
4185 | ||
19e6b90e L |
4186 | while (start < end) |
4187 | { | |
4188 | unsigned char *hdrptr; | |
4189 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 4190 | unsigned char *addr_ranges; |
2d9472a2 NC |
4191 | dwarf_vma length; |
4192 | dwarf_vma address; | |
53b8873b | 4193 | unsigned char address_size; |
19e6b90e L |
4194 | int excess; |
4195 | int offset_size; | |
4196 | int initial_length_size; | |
4197 | ||
4198 | hdrptr = start; | |
4199 | ||
4200 | arange.ar_length = byte_get (hdrptr, 4); | |
4201 | hdrptr += 4; | |
4202 | ||
4203 | if (arange.ar_length == 0xffffffff) | |
4204 | { | |
4205 | arange.ar_length = byte_get (hdrptr, 8); | |
4206 | hdrptr += 8; | |
4207 | offset_size = 8; | |
4208 | initial_length_size = 12; | |
4209 | } | |
4210 | else | |
4211 | { | |
4212 | offset_size = 4; | |
4213 | initial_length_size = 4; | |
4214 | } | |
4215 | ||
4216 | arange.ar_version = byte_get (hdrptr, 2); | |
4217 | hdrptr += 2; | |
4218 | ||
4219 | arange.ar_info_offset = byte_get (hdrptr, offset_size); | |
4220 | hdrptr += offset_size; | |
4221 | ||
6e3d6dc1 NC |
4222 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
4223 | && num_debug_info_entries > 0 | |
4224 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
4225 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 4226 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 4227 | |
19e6b90e L |
4228 | arange.ar_pointer_size = byte_get (hdrptr, 1); |
4229 | hdrptr += 1; | |
4230 | ||
4231 | arange.ar_segment_size = byte_get (hdrptr, 1); | |
4232 | hdrptr += 1; | |
4233 | ||
4234 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
4235 | { | |
4236 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
4237 | break; | |
4238 | } | |
4239 | ||
47704ddf KT |
4240 | printf (_(" Length: %ld\n"), |
4241 | (long) arange.ar_length); | |
19e6b90e | 4242 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
4243 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
4244 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
4245 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
4246 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
4247 | ||
53b8873b NC |
4248 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
4249 | ||
b3681d67 L |
4250 | if (address_size == 0) |
4251 | { | |
4252 | error (_("Invalid address size in %s section!\n"), | |
4253 | section->name); | |
4254 | break; | |
4255 | } | |
4256 | ||
53b8873b NC |
4257 | /* The DWARF spec does not require that the address size be a power |
4258 | of two, but we do. This will have to change if we ever encounter | |
4259 | an uneven architecture. */ | |
4260 | if ((address_size & (address_size - 1)) != 0) | |
4261 | { | |
4262 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
4263 | break; | |
4264 | } | |
cecf136e | 4265 | |
209c9a13 NC |
4266 | if (address_size > 4) |
4267 | printf (_("\n Address Length\n")); | |
4268 | else | |
4269 | printf (_("\n Address Length\n")); | |
19e6b90e | 4270 | |
91d6fa6a | 4271 | addr_ranges = hdrptr; |
19e6b90e | 4272 | |
53b8873b NC |
4273 | /* Must pad to an alignment boundary that is twice the address size. */ |
4274 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 4275 | if (excess) |
91d6fa6a | 4276 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 4277 | |
1617e571 AM |
4278 | start += arange.ar_length + initial_length_size; |
4279 | ||
91d6fa6a | 4280 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 4281 | { |
91d6fa6a | 4282 | address = byte_get (addr_ranges, address_size); |
19e6b90e | 4283 | |
91d6fa6a | 4284 | addr_ranges += address_size; |
19e6b90e | 4285 | |
91d6fa6a | 4286 | length = byte_get (addr_ranges, address_size); |
19e6b90e | 4287 | |
91d6fa6a | 4288 | addr_ranges += address_size; |
19e6b90e | 4289 | |
80c35038 | 4290 | printf (" "); |
2d9472a2 NC |
4291 | print_dwarf_vma (address, address_size); |
4292 | print_dwarf_vma (length, address_size); | |
4293 | putchar ('\n'); | |
19e6b90e | 4294 | } |
19e6b90e L |
4295 | } |
4296 | ||
4297 | printf ("\n"); | |
4298 | ||
4299 | return 1; | |
4300 | } | |
4301 | ||
4723351a CC |
4302 | /* Comparison function for qsort. */ |
4303 | static int | |
4304 | comp_addr_base (const void * v0, const void * v1) | |
4305 | { | |
4306 | debug_info * info0 = (debug_info *) v0; | |
4307 | debug_info * info1 = (debug_info *) v1; | |
4308 | return info0->addr_base - info1->addr_base; | |
4309 | } | |
4310 | ||
4311 | /* Display the debug_addr section. */ | |
4312 | static int | |
4313 | display_debug_addr (struct dwarf_section *section, | |
4314 | void *file) | |
4315 | { | |
4316 | debug_info **debug_addr_info; | |
4317 | unsigned char *entry; | |
4318 | unsigned char *end; | |
4319 | unsigned int i; | |
4320 | unsigned int count; | |
4321 | ||
4322 | if (section->size == 0) | |
4323 | { | |
4324 | printf (_("\nThe %s section is empty.\n"), section->name); | |
4325 | return 0; | |
4326 | } | |
4327 | ||
4328 | if (load_debug_info (file) == 0) | |
4329 | { | |
4330 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
4331 | section->name); | |
4332 | return 0; | |
4333 | } | |
4334 | ||
4335 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4336 | ||
4337 | debug_addr_info = (debug_info **) xmalloc (num_debug_info_entries + 1 | |
4338 | * sizeof (debug_info *)); | |
4339 | ||
4340 | count = 0; | |
4341 | for (i = 0; i < num_debug_info_entries; i++) | |
4342 | { | |
4343 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) | |
4344 | debug_addr_info [count++] = &debug_information [i]; | |
4345 | } | |
4346 | ||
4347 | /* Add a sentinel to make iteration convenient. */ | |
4348 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
4349 | debug_addr_info [count]->addr_base = section->size; | |
4350 | ||
4351 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); | |
4352 | for (i = 0; i < count; i++) | |
4353 | { | |
4354 | unsigned int idx; | |
4355 | ||
4356 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
4357 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); | |
4358 | ||
4359 | printf (_("\tIndex\tOffset\n")); | |
4360 | entry = section->start + debug_addr_info [i]->addr_base; | |
4361 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
4362 | idx = 0; | |
4363 | while (entry < end) | |
4364 | { | |
4365 | dwarf_vma base = byte_get (entry, debug_addr_info [i]->pointer_size); | |
4366 | printf (_("\t%d:\t%s\n"), idx, dwarf_vmatoa ("x", base)); | |
4367 | entry += debug_addr_info [i]->pointer_size; | |
4368 | idx++; | |
4369 | } | |
4370 | } | |
4371 | printf ("\n"); | |
4372 | ||
4373 | free (debug_addr_info); | |
4374 | return 1; | |
4375 | } | |
4376 | ||
4377 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
4378 | static int | |
4379 | display_debug_str_offsets (struct dwarf_section *section, | |
4380 | void *file ATTRIBUTE_UNUSED) | |
4381 | { | |
4382 | if (section->size == 0) | |
4383 | { | |
4384 | printf (_("\nThe %s section is empty.\n"), section->name); | |
4385 | return 0; | |
4386 | } | |
4387 | /* TODO: Dump the contents. This is made somewhat difficult by not knowing | |
4388 | what the offset size is for this section. */ | |
4389 | return 1; | |
4390 | } | |
4391 | ||
01a8f077 JK |
4392 | /* Each debug_information[x].range_lists[y] gets this representation for |
4393 | sorting purposes. */ | |
4394 | ||
4395 | struct range_entry | |
467c65bc NC |
4396 | { |
4397 | /* The debug_information[x].range_lists[y] value. */ | |
4398 | unsigned long ranges_offset; | |
01a8f077 | 4399 | |
467c65bc NC |
4400 | /* Original debug_information to find parameters of the data. */ |
4401 | debug_info *debug_info_p; | |
4402 | }; | |
01a8f077 JK |
4403 | |
4404 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
4405 | ||
4406 | static int | |
4407 | range_entry_compar (const void *ap, const void *bp) | |
4408 | { | |
3f5e193b NC |
4409 | const struct range_entry *a_re = (const struct range_entry *) ap; |
4410 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
01a8f077 JK |
4411 | const unsigned long a = a_re->ranges_offset; |
4412 | const unsigned long b = b_re->ranges_offset; | |
4413 | ||
4414 | return (a > b) - (b > a); | |
4415 | } | |
4416 | ||
19e6b90e L |
4417 | static int |
4418 | display_debug_ranges (struct dwarf_section *section, | |
4419 | void *file ATTRIBUTE_UNUSED) | |
4420 | { | |
4421 | unsigned char *start = section->start; | |
19e6b90e L |
4422 | unsigned long bytes; |
4423 | unsigned char *section_begin = start; | |
01a8f077 JK |
4424 | unsigned int num_range_list, i; |
4425 | struct range_entry *range_entries, *range_entry_fill; | |
19e6b90e L |
4426 | |
4427 | bytes = section->size; | |
19e6b90e L |
4428 | |
4429 | if (bytes == 0) | |
4430 | { | |
4431 | printf (_("\nThe %s section is empty.\n"), section->name); | |
4432 | return 0; | |
4433 | } | |
4434 | ||
1febe64d NC |
4435 | if (load_debug_info (file) == 0) |
4436 | { | |
4437 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
4438 | section->name); | |
4439 | return 0; | |
4440 | } | |
19e6b90e | 4441 | |
01a8f077 | 4442 | num_range_list = 0; |
19e6b90e | 4443 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 4444 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 4445 | |
01a8f077 | 4446 | if (num_range_list == 0) |
4723351a CC |
4447 | { |
4448 | /* This can happen when the file was compiled with -gsplit-debug | |
4449 | which removes references to range lists from the primary .o file. */ | |
4450 | printf (_("No range lists in .debug_info section.\n")); | |
4451 | return 1; | |
4452 | } | |
19e6b90e | 4453 | |
3f5e193b NC |
4454 | range_entries = (struct range_entry *) |
4455 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 4456 | range_entry_fill = range_entries; |
19e6b90e | 4457 | |
01a8f077 JK |
4458 | for (i = 0; i < num_debug_info_entries; i++) |
4459 | { | |
4460 | debug_info *debug_info_p = &debug_information[i]; | |
4461 | unsigned int j; | |
4462 | ||
4463 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
4464 | { | |
4465 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
4466 | range_entry_fill->debug_info_p = debug_info_p; | |
4467 | range_entry_fill++; | |
19e6b90e L |
4468 | } |
4469 | } | |
4470 | ||
01a8f077 JK |
4471 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
4472 | range_entry_compar); | |
19e6b90e | 4473 | |
bfe2612a | 4474 | /* DWARF sections under Mach-O have non-zero addresses. */ |
4723351a | 4475 | if (dwarf_check != 0 && range_entries[0].ranges_offset != section->address) |
19e6b90e | 4476 | warn (_("Range lists in %s section start at 0x%lx\n"), |
01a8f077 | 4477 | section->name, range_entries[0].ranges_offset); |
19e6b90e L |
4478 | |
4479 | printf (_("Contents of the %s section:\n\n"), section->name); | |
4480 | printf (_(" Offset Begin End\n")); | |
4481 | ||
01a8f077 | 4482 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 4483 | { |
01a8f077 JK |
4484 | struct range_entry *range_entry = &range_entries[i]; |
4485 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 4486 | unsigned int pointer_size; |
01a8f077 JK |
4487 | unsigned long offset; |
4488 | unsigned char *next; | |
19e6b90e L |
4489 | unsigned long base_address; |
4490 | ||
01a8f077 JK |
4491 | pointer_size = debug_info_p->pointer_size; |
4492 | ||
4493 | /* DWARF sections under Mach-O have non-zero addresses. */ | |
4494 | offset = range_entry->ranges_offset - section->address; | |
4495 | next = section_begin + offset; | |
4496 | base_address = debug_info_p->base_address; | |
cecf136e | 4497 | |
4723351a | 4498 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 4499 | { |
01a8f077 JK |
4500 | if (start < next) |
4501 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
4502 | (unsigned long) (start - section_begin), | |
4503 | (unsigned long) (next - section_begin), section->name); | |
4504 | else if (start > next) | |
4505 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
4506 | (unsigned long) (start - section_begin), | |
4507 | (unsigned long) (next - section_begin), section->name); | |
4508 | } | |
4509 | start = next; | |
19e6b90e | 4510 | |
01a8f077 JK |
4511 | while (1) |
4512 | { | |
4513 | dwarf_vma begin; | |
4514 | dwarf_vma end; | |
4515 | ||
4516 | /* Note: we use sign extension here in order to be sure that | |
4517 | we can detect the -1 escape value. Sign extension into the | |
4518 | top 32 bits of a 32-bit address will not affect the values | |
4519 | that we display since we always show hex values, and always | |
4520 | the bottom 32-bits. */ | |
4521 | begin = byte_get_signed (start, pointer_size); | |
4522 | start += pointer_size; | |
4523 | end = byte_get_signed (start, pointer_size); | |
4524 | start += pointer_size; | |
4525 | ||
4526 | printf (" %8.8lx ", offset); | |
4527 | ||
4528 | if (begin == 0 && end == 0) | |
19e6b90e | 4529 | { |
01a8f077 JK |
4530 | printf (_("<End of list>\n")); |
4531 | break; | |
19e6b90e | 4532 | } |
19e6b90e | 4533 | |
01a8f077 JK |
4534 | /* Check base address specifiers. */ |
4535 | if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1) | |
19e6b90e | 4536 | { |
01a8f077 JK |
4537 | base_address = end; |
4538 | print_dwarf_vma (begin, pointer_size); | |
4539 | print_dwarf_vma (end, pointer_size); | |
4540 | printf ("(base address)\n"); | |
4541 | continue; | |
4542 | } | |
19e6b90e | 4543 | |
01a8f077 JK |
4544 | print_dwarf_vma (begin + base_address, pointer_size); |
4545 | print_dwarf_vma (end + base_address, pointer_size); | |
4a149252 | 4546 | |
01a8f077 JK |
4547 | if (begin == end) |
4548 | fputs (_("(start == end)"), stdout); | |
4549 | else if (begin > end) | |
4550 | fputs (_("(start > end)"), stdout); | |
19e6b90e | 4551 | |
01a8f077 | 4552 | putchar ('\n'); |
19e6b90e L |
4553 | } |
4554 | } | |
4555 | putchar ('\n'); | |
01a8f077 JK |
4556 | |
4557 | free (range_entries); | |
4558 | ||
19e6b90e L |
4559 | return 1; |
4560 | } | |
4561 | ||
4562 | typedef struct Frame_Chunk | |
4563 | { | |
4564 | struct Frame_Chunk *next; | |
4565 | unsigned char *chunk_start; | |
4566 | int ncols; | |
4567 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ | |
4568 | short int *col_type; | |
4569 | int *col_offset; | |
4570 | char *augmentation; | |
4571 | unsigned int code_factor; | |
4572 | int data_factor; | |
4573 | unsigned long pc_begin; | |
4574 | unsigned long pc_range; | |
4575 | int cfa_reg; | |
4576 | int cfa_offset; | |
4577 | int ra; | |
4578 | unsigned char fde_encoding; | |
4579 | unsigned char cfa_exp; | |
604282a7 JJ |
4580 | unsigned char ptr_size; |
4581 | unsigned char segment_size; | |
19e6b90e L |
4582 | } |
4583 | Frame_Chunk; | |
4584 | ||
665ce1f6 L |
4585 | static const char *const *dwarf_regnames; |
4586 | static unsigned int dwarf_regnames_count; | |
4587 | ||
19e6b90e L |
4588 | /* A marker for a col_type that means this column was never referenced |
4589 | in the frame info. */ | |
4590 | #define DW_CFA_unreferenced (-1) | |
4591 | ||
665ce1f6 L |
4592 | /* Return 0 if not more space is needed, 1 if more space is needed, |
4593 | -1 for invalid reg. */ | |
4594 | ||
4595 | static int | |
4596 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e L |
4597 | { |
4598 | int prev = fc->ncols; | |
4599 | ||
665ce1f6 L |
4600 | if (reg < (unsigned int) fc->ncols) |
4601 | return 0; | |
4602 | ||
4603 | if (dwarf_regnames_count | |
4604 | && reg > dwarf_regnames_count) | |
4605 | return -1; | |
19e6b90e L |
4606 | |
4607 | fc->ncols = reg + 1; | |
3f5e193b NC |
4608 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
4609 | sizeof (short int)); | |
4610 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); | |
19e6b90e L |
4611 | |
4612 | while (prev < fc->ncols) | |
4613 | { | |
4614 | fc->col_type[prev] = DW_CFA_unreferenced; | |
4615 | fc->col_offset[prev] = 0; | |
4616 | prev++; | |
4617 | } | |
665ce1f6 | 4618 | return 1; |
19e6b90e L |
4619 | } |
4620 | ||
2dc4cec1 L |
4621 | static const char *const dwarf_regnames_i386[] = |
4622 | { | |
4623 | "eax", "ecx", "edx", "ebx", | |
4624 | "esp", "ebp", "esi", "edi", | |
4625 | "eip", "eflags", NULL, | |
4626 | "st0", "st1", "st2", "st3", | |
4627 | "st4", "st5", "st6", "st7", | |
4628 | NULL, NULL, | |
4629 | "xmm0", "xmm1", "xmm2", "xmm3", | |
4630 | "xmm4", "xmm5", "xmm6", "xmm7", | |
4631 | "mm0", "mm1", "mm2", "mm3", | |
4632 | "mm4", "mm5", "mm6", "mm7", | |
4633 | "fcw", "fsw", "mxcsr", | |
4634 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
a656ed5b | 4635 | "tr", "ldtr" |
2dc4cec1 L |
4636 | }; |
4637 | ||
b129eb0e RH |
4638 | void |
4639 | init_dwarf_regnames_i386 (void) | |
4640 | { | |
4641 | dwarf_regnames = dwarf_regnames_i386; | |
4642 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
4643 | } | |
4644 | ||
2dc4cec1 L |
4645 | static const char *const dwarf_regnames_x86_64[] = |
4646 | { | |
4647 | "rax", "rdx", "rcx", "rbx", | |
4648 | "rsi", "rdi", "rbp", "rsp", | |
4649 | "r8", "r9", "r10", "r11", | |
4650 | "r12", "r13", "r14", "r15", | |
4651 | "rip", | |
4652 | "xmm0", "xmm1", "xmm2", "xmm3", | |
4653 | "xmm4", "xmm5", "xmm6", "xmm7", | |
4654 | "xmm8", "xmm9", "xmm10", "xmm11", | |
4655 | "xmm12", "xmm13", "xmm14", "xmm15", | |
4656 | "st0", "st1", "st2", "st3", | |
4657 | "st4", "st5", "st6", "st7", | |
4658 | "mm0", "mm1", "mm2", "mm3", | |
4659 | "mm4", "mm5", "mm6", "mm7", | |
4660 | "rflags", | |
4661 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
4662 | "fs.base", "gs.base", NULL, NULL, | |
4663 | "tr", "ldtr", | |
a656ed5b | 4664 | "mxcsr", "fcw", "fsw" |
2dc4cec1 L |
4665 | }; |
4666 | ||
b129eb0e RH |
4667 | void |
4668 | init_dwarf_regnames_x86_64 (void) | |
4669 | { | |
4670 | dwarf_regnames = dwarf_regnames_x86_64; | |
4671 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
4672 | } | |
4673 | ||
2dc4cec1 L |
4674 | void |
4675 | init_dwarf_regnames (unsigned int e_machine) | |
4676 | { | |
4677 | switch (e_machine) | |
4678 | { | |
4679 | case EM_386: | |
4680 | case EM_486: | |
b129eb0e | 4681 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
4682 | break; |
4683 | ||
4684 | case EM_X86_64: | |
7f502d6c | 4685 | case EM_L1OM: |
7a9068fe | 4686 | case EM_K1OM: |
b129eb0e | 4687 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
4688 | break; |
4689 | ||
4690 | default: | |
4691 | break; | |
4692 | } | |
4693 | } | |
4694 | ||
4695 | static const char * | |
4696 | regname (unsigned int regno, int row) | |
4697 | { | |
4698 | static char reg[64]; | |
4699 | if (dwarf_regnames | |
4700 | && regno < dwarf_regnames_count | |
4701 | && dwarf_regnames [regno] != NULL) | |
4702 | { | |
4703 | if (row) | |
4704 | return dwarf_regnames [regno]; | |
4705 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, | |
4706 | dwarf_regnames [regno]); | |
4707 | } | |
4708 | else | |
4709 | snprintf (reg, sizeof (reg), "r%d", regno); | |
4710 | return reg; | |
4711 | } | |
4712 | ||
19e6b90e L |
4713 | static void |
4714 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs) | |
4715 | { | |
4716 | int r; | |
4717 | char tmp[100]; | |
4718 | ||
4719 | if (*max_regs < fc->ncols) | |
4720 | *max_regs = fc->ncols; | |
4721 | ||
4722 | if (*need_col_headers) | |
4723 | { | |
91d6fa6a | 4724 | static const char *sloc = " LOC"; |
2dc4cec1 | 4725 | |
19e6b90e L |
4726 | *need_col_headers = 0; |
4727 | ||
91d6fa6a | 4728 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
4729 | |
4730 | for (r = 0; r < *max_regs; r++) | |
4731 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
4732 | { | |
4733 | if (r == fc->ra) | |
2dc4cec1 | 4734 | printf ("ra "); |
19e6b90e | 4735 | else |
2dc4cec1 | 4736 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
4737 | } |
4738 | ||
4739 | printf ("\n"); | |
4740 | } | |
4741 | ||
2dc4cec1 | 4742 | printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin); |
19e6b90e L |
4743 | if (fc->cfa_exp) |
4744 | strcpy (tmp, "exp"); | |
4745 | else | |
2dc4cec1 | 4746 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset); |
19e6b90e L |
4747 | printf ("%-8s ", tmp); |
4748 | ||
4749 | for (r = 0; r < fc->ncols; r++) | |
4750 | { | |
4751 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
4752 | { | |
4753 | switch (fc->col_type[r]) | |
4754 | { | |
4755 | case DW_CFA_undefined: | |
4756 | strcpy (tmp, "u"); | |
4757 | break; | |
4758 | case DW_CFA_same_value: | |
4759 | strcpy (tmp, "s"); | |
4760 | break; | |
4761 | case DW_CFA_offset: | |
4762 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
4763 | break; | |
12eae2d3 JJ |
4764 | case DW_CFA_val_offset: |
4765 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
4766 | break; | |
19e6b90e | 4767 | case DW_CFA_register: |
2dc4cec1 | 4768 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
4769 | break; |
4770 | case DW_CFA_expression: | |
4771 | strcpy (tmp, "exp"); | |
4772 | break; | |
12eae2d3 JJ |
4773 | case DW_CFA_val_expression: |
4774 | strcpy (tmp, "vexp"); | |
4775 | break; | |
19e6b90e L |
4776 | default: |
4777 | strcpy (tmp, "n/a"); | |
4778 | break; | |
4779 | } | |
2dc4cec1 | 4780 | printf ("%-5s ", tmp); |
19e6b90e L |
4781 | } |
4782 | } | |
4783 | printf ("\n"); | |
4784 | } | |
4785 | ||
19e6b90e L |
4786 | #define GET(N) byte_get (start, N); start += N |
4787 | #define LEB() read_leb128 (start, & length_return, 0); start += length_return | |
467c65bc | 4788 | #define SLEB() read_sleb128 (start, & length_return); start += length_return |
19e6b90e L |
4789 | |
4790 | static int | |
4791 | display_debug_frames (struct dwarf_section *section, | |
4792 | void *file ATTRIBUTE_UNUSED) | |
4793 | { | |
4794 | unsigned char *start = section->start; | |
4795 | unsigned char *end = start + section->size; | |
4796 | unsigned char *section_start = start; | |
4797 | Frame_Chunk *chunks = 0; | |
4798 | Frame_Chunk *remembered_state = 0; | |
4799 | Frame_Chunk *rs; | |
4800 | int is_eh = strcmp (section->name, ".eh_frame") == 0; | |
4801 | unsigned int length_return; | |
4802 | int max_regs = 0; | |
665ce1f6 | 4803 | const char *bad_reg = _("bad register: "); |
604282a7 | 4804 | int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 4805 | |
80c35038 | 4806 | printf (_("Contents of the %s section:\n"), section->name); |
19e6b90e L |
4807 | |
4808 | while (start < end) | |
4809 | { | |
4810 | unsigned char *saved_start; | |
4811 | unsigned char *block_end; | |
4812 | unsigned long length; | |
4813 | unsigned long cie_id; | |
4814 | Frame_Chunk *fc; | |
4815 | Frame_Chunk *cie; | |
4816 | int need_col_headers = 1; | |
4817 | unsigned char *augmentation_data = NULL; | |
4818 | unsigned long augmentation_data_len = 0; | |
604282a7 | 4819 | int encoded_ptr_size = saved_eh_addr_size; |
19e6b90e L |
4820 | int offset_size; |
4821 | int initial_length_size; | |
4822 | ||
4823 | saved_start = start; | |
4824 | length = byte_get (start, 4); start += 4; | |
4825 | ||
4826 | if (length == 0) | |
4827 | { | |
4828 | printf ("\n%08lx ZERO terminator\n\n", | |
4829 | (unsigned long)(saved_start - section_start)); | |
b758e50f | 4830 | continue; |
19e6b90e L |
4831 | } |
4832 | ||
4833 | if (length == 0xffffffff) | |
4834 | { | |
4835 | length = byte_get (start, 8); | |
4836 | start += 8; | |
4837 | offset_size = 8; | |
4838 | initial_length_size = 12; | |
4839 | } | |
4840 | else | |
4841 | { | |
4842 | offset_size = 4; | |
4843 | initial_length_size = 4; | |
4844 | } | |
4845 | ||
4846 | block_end = saved_start + length + initial_length_size; | |
53b8873b NC |
4847 | if (block_end > end) |
4848 | { | |
4849 | warn ("Invalid length %#08lx in FDE at %#08lx\n", | |
4850 | length, (unsigned long)(saved_start - section_start)); | |
4851 | block_end = end; | |
4852 | } | |
19e6b90e L |
4853 | cie_id = byte_get (start, offset_size); start += offset_size; |
4854 | ||
4855 | if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID)) | |
4856 | { | |
4857 | int version; | |
4858 | ||
3f5e193b | 4859 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
19e6b90e L |
4860 | memset (fc, 0, sizeof (Frame_Chunk)); |
4861 | ||
4862 | fc->next = chunks; | |
4863 | chunks = fc; | |
4864 | fc->chunk_start = saved_start; | |
4865 | fc->ncols = 0; | |
3f5e193b NC |
4866 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
4867 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
cc86f28f | 4868 | frame_need_space (fc, max_regs - 1); |
19e6b90e L |
4869 | |
4870 | version = *start++; | |
4871 | ||
4872 | fc->augmentation = (char *) start; | |
4873 | start = (unsigned char *) strchr ((char *) start, '\0') + 1; | |
4874 | ||
604282a7 JJ |
4875 | if (strcmp (fc->augmentation, "eh") == 0) |
4876 | start += eh_addr_size; | |
4877 | ||
4878 | if (version >= 4) | |
19e6b90e | 4879 | { |
604282a7 JJ |
4880 | fc->ptr_size = GET (1); |
4881 | fc->segment_size = GET (1); | |
4882 | eh_addr_size = fc->ptr_size; | |
19e6b90e | 4883 | } |
604282a7 | 4884 | else |
19e6b90e | 4885 | { |
604282a7 JJ |
4886 | fc->ptr_size = eh_addr_size; |
4887 | fc->segment_size = 0; | |
4888 | } | |
4889 | fc->code_factor = LEB (); | |
4890 | fc->data_factor = SLEB (); | |
4891 | if (version == 1) | |
4892 | { | |
4893 | fc->ra = GET (1); | |
19e6b90e L |
4894 | } |
4895 | else | |
4896 | { | |
604282a7 JJ |
4897 | fc->ra = LEB (); |
4898 | } | |
4899 | ||
4900 | if (fc->augmentation[0] == 'z') | |
4901 | { | |
4902 | augmentation_data_len = LEB (); | |
4903 | augmentation_data = start; | |
4904 | start += augmentation_data_len; | |
19e6b90e L |
4905 | } |
4906 | cie = fc; | |
4907 | ||
4908 | if (do_debug_frames_interp) | |
4909 | printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n", | |
4910 | (unsigned long)(saved_start - section_start), length, cie_id, | |
4911 | fc->augmentation, fc->code_factor, fc->data_factor, | |
4912 | fc->ra); | |
4913 | else | |
4914 | { | |
4915 | printf ("\n%08lx %08lx %08lx CIE\n", | |
4916 | (unsigned long)(saved_start - section_start), length, cie_id); | |
4917 | printf (" Version: %d\n", version); | |
4918 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
4919 | if (version >= 4) |
4920 | { | |
4921 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
4922 | printf (" Segment Size: %u\n", fc->segment_size); | |
4923 | } | |
19e6b90e L |
4924 | printf (" Code alignment factor: %u\n", fc->code_factor); |
4925 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
4926 | printf (" Return address column: %d\n", fc->ra); | |
4927 | ||
4928 | if (augmentation_data_len) | |
4929 | { | |
4930 | unsigned long i; | |
4931 | printf (" Augmentation data: "); | |
4932 | for (i = 0; i < augmentation_data_len; ++i) | |
4933 | printf (" %02x", augmentation_data[i]); | |
4934 | putchar ('\n'); | |
4935 | } | |
4936 | putchar ('\n'); | |
4937 | } | |
4938 | ||
4939 | if (augmentation_data_len) | |
4940 | { | |
4941 | unsigned char *p, *q; | |
4942 | p = (unsigned char *) fc->augmentation + 1; | |
4943 | q = augmentation_data; | |
4944 | ||
4945 | while (1) | |
4946 | { | |
4947 | if (*p == 'L') | |
4948 | q++; | |
4949 | else if (*p == 'P') | |
4950 | q += 1 + size_of_encoded_value (*q); | |
4951 | else if (*p == 'R') | |
4952 | fc->fde_encoding = *q++; | |
d80e8de2 JB |
4953 | else if (*p == 'S') |
4954 | ; | |
19e6b90e L |
4955 | else |
4956 | break; | |
4957 | p++; | |
4958 | } | |
4959 | ||
4960 | if (fc->fde_encoding) | |
4961 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
4962 | } | |
4963 | ||
4964 | frame_need_space (fc, fc->ra); | |
4965 | } | |
4966 | else | |
4967 | { | |
4968 | unsigned char *look_for; | |
4969 | static Frame_Chunk fde_fc; | |
604282a7 | 4970 | unsigned long segment_selector; |
19e6b90e L |
4971 | |
4972 | fc = & fde_fc; | |
4973 | memset (fc, 0, sizeof (Frame_Chunk)); | |
4974 | ||
4975 | look_for = is_eh ? start - 4 - cie_id : section_start + cie_id; | |
4976 | ||
4977 | for (cie = chunks; cie ; cie = cie->next) | |
4978 | if (cie->chunk_start == look_for) | |
4979 | break; | |
4980 | ||
4981 | if (!cie) | |
4982 | { | |
53b8873b | 4983 | warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n", |
1617e571 | 4984 | cie_id, (unsigned long)(saved_start - section_start)); |
19e6b90e | 4985 | fc->ncols = 0; |
3f5e193b NC |
4986 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
4987 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
19e6b90e L |
4988 | frame_need_space (fc, max_regs - 1); |
4989 | cie = fc; | |
4990 | fc->augmentation = ""; | |
4991 | fc->fde_encoding = 0; | |
604282a7 JJ |
4992 | fc->ptr_size = eh_addr_size; |
4993 | fc->segment_size = 0; | |
19e6b90e L |
4994 | } |
4995 | else | |
4996 | { | |
4997 | fc->ncols = cie->ncols; | |
3f5e193b NC |
4998 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
4999 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
5000 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
5001 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
5002 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
5003 | fc->ptr_size = cie->ptr_size; |
5004 | eh_addr_size = cie->ptr_size; | |
5005 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
5006 | fc->code_factor = cie->code_factor; |
5007 | fc->data_factor = cie->data_factor; | |
5008 | fc->cfa_reg = cie->cfa_reg; | |
5009 | fc->cfa_offset = cie->cfa_offset; | |
5010 | fc->ra = cie->ra; | |
cc86f28f | 5011 | frame_need_space (fc, max_regs - 1); |
19e6b90e L |
5012 | fc->fde_encoding = cie->fde_encoding; |
5013 | } | |
5014 | ||
5015 | if (fc->fde_encoding) | |
5016 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
5017 | ||
604282a7 JJ |
5018 | segment_selector = 0; |
5019 | if (fc->segment_size) | |
5020 | { | |
5021 | segment_selector = byte_get (start, fc->segment_size); | |
5022 | start += fc->segment_size; | |
5023 | } | |
bad62cf5 | 5024 | fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section); |
19e6b90e L |
5025 | start += encoded_ptr_size; |
5026 | fc->pc_range = byte_get (start, encoded_ptr_size); | |
5027 | start += encoded_ptr_size; | |
5028 | ||
5029 | if (cie->augmentation[0] == 'z') | |
5030 | { | |
5031 | augmentation_data_len = LEB (); | |
5032 | augmentation_data = start; | |
5033 | start += augmentation_data_len; | |
5034 | } | |
5035 | ||
604282a7 | 5036 | printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=", |
19e6b90e | 5037 | (unsigned long)(saved_start - section_start), length, cie_id, |
604282a7 JJ |
5038 | (unsigned long)(cie->chunk_start - section_start)); |
5039 | if (fc->segment_size) | |
5040 | printf ("%04lx:", segment_selector); | |
5041 | printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range); | |
19e6b90e L |
5042 | if (! do_debug_frames_interp && augmentation_data_len) |
5043 | { | |
5044 | unsigned long i; | |
5045 | ||
5046 | printf (" Augmentation data: "); | |
5047 | for (i = 0; i < augmentation_data_len; ++i) | |
5048 | printf (" %02x", augmentation_data[i]); | |
5049 | putchar ('\n'); | |
5050 | putchar ('\n'); | |
5051 | } | |
5052 | } | |
5053 | ||
5054 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
5055 | we're about to interpret instructions for the chunk. */ | |
5056 | /* ??? At present we need to do this always, since this sizes the | |
5057 | fc->col_type and fc->col_offset arrays, which we write into always. | |
5058 | We should probably split the interpreted and non-interpreted bits | |
5059 | into two different routines, since there's so much that doesn't | |
5060 | really overlap between them. */ | |
5061 | if (1 || do_debug_frames_interp) | |
5062 | { | |
5063 | /* Start by making a pass over the chunk, allocating storage | |
5064 | and taking note of what registers are used. */ | |
5065 | unsigned char *tmp = start; | |
5066 | ||
5067 | while (start < block_end) | |
5068 | { | |
5069 | unsigned op, opa; | |
91d6fa6a | 5070 | unsigned long reg, temp; |
19e6b90e L |
5071 | |
5072 | op = *start++; | |
5073 | opa = op & 0x3f; | |
5074 | if (op & 0xc0) | |
5075 | op &= 0xc0; | |
5076 | ||
5077 | /* Warning: if you add any more cases to this switch, be | |
5078 | sure to add them to the corresponding switch below. */ | |
5079 | switch (op) | |
5080 | { | |
5081 | case DW_CFA_advance_loc: | |
5082 | break; | |
5083 | case DW_CFA_offset: | |
5084 | LEB (); | |
665ce1f6 L |
5085 | if (frame_need_space (fc, opa) >= 0) |
5086 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
5087 | break; |
5088 | case DW_CFA_restore: | |
665ce1f6 L |
5089 | if (frame_need_space (fc, opa) >= 0) |
5090 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
5091 | break; |
5092 | case DW_CFA_set_loc: | |
5093 | start += encoded_ptr_size; | |
5094 | break; | |
5095 | case DW_CFA_advance_loc1: | |
5096 | start += 1; | |
5097 | break; | |
5098 | case DW_CFA_advance_loc2: | |
5099 | start += 2; | |
5100 | break; | |
5101 | case DW_CFA_advance_loc4: | |
5102 | start += 4; | |
5103 | break; | |
5104 | case DW_CFA_offset_extended: | |
12eae2d3 | 5105 | case DW_CFA_val_offset: |
19e6b90e | 5106 | reg = LEB (); LEB (); |
665ce1f6 L |
5107 | if (frame_need_space (fc, reg) >= 0) |
5108 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
5109 | break; |
5110 | case DW_CFA_restore_extended: | |
5111 | reg = LEB (); | |
5112 | frame_need_space (fc, reg); | |
665ce1f6 L |
5113 | if (frame_need_space (fc, reg) >= 0) |
5114 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
5115 | break; |
5116 | case DW_CFA_undefined: | |
5117 | reg = LEB (); | |
665ce1f6 L |
5118 | if (frame_need_space (fc, reg) >= 0) |
5119 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
5120 | break; |
5121 | case DW_CFA_same_value: | |
5122 | reg = LEB (); | |
665ce1f6 L |
5123 | if (frame_need_space (fc, reg) >= 0) |
5124 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
5125 | break; |
5126 | case DW_CFA_register: | |
5127 | reg = LEB (); LEB (); | |
665ce1f6 L |
5128 | if (frame_need_space (fc, reg) >= 0) |
5129 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
5130 | break; |
5131 | case DW_CFA_def_cfa: | |
5132 | LEB (); LEB (); | |
5133 | break; | |
5134 | case DW_CFA_def_cfa_register: | |
5135 | LEB (); | |
5136 | break; | |
5137 | case DW_CFA_def_cfa_offset: | |
5138 | LEB (); | |
5139 | break; | |
5140 | case DW_CFA_def_cfa_expression: | |
91d6fa6a NC |
5141 | temp = LEB (); |
5142 | start += temp; | |
19e6b90e L |
5143 | break; |
5144 | case DW_CFA_expression: | |
12eae2d3 | 5145 | case DW_CFA_val_expression: |
19e6b90e | 5146 | reg = LEB (); |
91d6fa6a NC |
5147 | temp = LEB (); |
5148 | start += temp; | |
665ce1f6 L |
5149 | if (frame_need_space (fc, reg) >= 0) |
5150 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
5151 | break; |
5152 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 5153 | case DW_CFA_val_offset_sf: |
19e6b90e | 5154 | reg = LEB (); SLEB (); |
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_def_cfa_sf: | |
5159 | LEB (); SLEB (); | |
5160 | break; | |
5161 | case DW_CFA_def_cfa_offset_sf: | |
5162 | SLEB (); | |
5163 | break; | |
5164 | case DW_CFA_MIPS_advance_loc8: | |
5165 | start += 8; | |
5166 | break; | |
5167 | case DW_CFA_GNU_args_size: | |
5168 | LEB (); | |
5169 | break; | |
5170 | case DW_CFA_GNU_negative_offset_extended: | |
5171 | reg = LEB (); LEB (); | |
665ce1f6 L |
5172 | if (frame_need_space (fc, reg) >= 0) |
5173 | fc->col_type[reg] = DW_CFA_undefined; | |
5174 | break; | |
19e6b90e L |
5175 | default: |
5176 | break; | |
5177 | } | |
5178 | } | |
5179 | start = tmp; | |
5180 | } | |
5181 | ||
5182 | /* Now we know what registers are used, make a second pass over | |
5183 | the chunk, this time actually printing out the info. */ | |
5184 | ||
5185 | while (start < block_end) | |
5186 | { | |
5187 | unsigned op, opa; | |
5188 | unsigned long ul, reg, roffs; | |
5189 | long l, ofs; | |
5190 | dwarf_vma vma; | |
665ce1f6 | 5191 | const char *reg_prefix = ""; |
19e6b90e L |
5192 | |
5193 | op = *start++; | |
5194 | opa = op & 0x3f; | |
5195 | if (op & 0xc0) | |
5196 | op &= 0xc0; | |
5197 | ||
5198 | /* Warning: if you add any more cases to this switch, be | |
5199 | sure to add them to the corresponding switch above. */ | |
5200 | switch (op) | |
5201 | { | |
5202 | case DW_CFA_advance_loc: | |
5203 | if (do_debug_frames_interp) | |
5204 | frame_display_row (fc, &need_col_headers, &max_regs); | |
5205 | else | |
5206 | printf (" DW_CFA_advance_loc: %d to %08lx\n", | |
5207 | opa * fc->code_factor, | |
5208 | fc->pc_begin + opa * fc->code_factor); | |
5209 | fc->pc_begin += opa * fc->code_factor; | |
5210 | break; | |
5211 | ||
5212 | case DW_CFA_offset: | |
5213 | roffs = LEB (); | |
665ce1f6 L |
5214 | if (opa >= (unsigned int) fc->ncols) |
5215 | reg_prefix = bad_reg; | |
5216 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
5217 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
5218 | reg_prefix, regname (opa, 0), | |
5219 | roffs * fc->data_factor); | |
5220 | if (*reg_prefix == '\0') | |
5221 | { | |
5222 | fc->col_type[opa] = DW_CFA_offset; | |
5223 | fc->col_offset[opa] = roffs * fc->data_factor; | |
5224 | } | |
19e6b90e L |
5225 | break; |
5226 | ||
5227 | case DW_CFA_restore: | |
665ce1f6 L |
5228 | if (opa >= (unsigned int) cie->ncols |
5229 | || opa >= (unsigned int) fc->ncols) | |
5230 | reg_prefix = bad_reg; | |
5231 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
5232 | printf (" DW_CFA_restore: %s%s\n", | |
5233 | reg_prefix, regname (opa, 0)); | |
5234 | if (*reg_prefix == '\0') | |
5235 | { | |
5236 | fc->col_type[opa] = cie->col_type[opa]; | |
5237 | fc->col_offset[opa] = cie->col_offset[opa]; | |
b3f5b73b ILT |
5238 | if (do_debug_frames_interp |
5239 | && fc->col_type[opa] == DW_CFA_unreferenced) | |
5240 | fc->col_type[opa] = DW_CFA_undefined; | |
665ce1f6 | 5241 | } |
19e6b90e L |
5242 | break; |
5243 | ||
5244 | case DW_CFA_set_loc: | |
bad62cf5 | 5245 | vma = get_encoded_value (start, fc->fde_encoding, section); |
19e6b90e L |
5246 | start += encoded_ptr_size; |
5247 | if (do_debug_frames_interp) | |
5248 | frame_display_row (fc, &need_col_headers, &max_regs); | |
5249 | else | |
5250 | printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma); | |
5251 | fc->pc_begin = vma; | |
5252 | break; | |
5253 | ||
5254 | case DW_CFA_advance_loc1: | |
5255 | ofs = byte_get (start, 1); start += 1; | |
5256 | if (do_debug_frames_interp) | |
5257 | frame_display_row (fc, &need_col_headers, &max_regs); | |
5258 | else | |
5259 | printf (" DW_CFA_advance_loc1: %ld to %08lx\n", | |
5260 | ofs * fc->code_factor, | |
5261 | fc->pc_begin + ofs * fc->code_factor); | |
5262 | fc->pc_begin += ofs * fc->code_factor; | |
5263 | break; | |
5264 | ||
5265 | case DW_CFA_advance_loc2: | |
5266 | ofs = byte_get (start, 2); start += 2; | |
5267 | if (do_debug_frames_interp) | |
5268 | frame_display_row (fc, &need_col_headers, &max_regs); | |
5269 | else | |
5270 | printf (" DW_CFA_advance_loc2: %ld to %08lx\n", | |
5271 | ofs * fc->code_factor, | |
5272 | fc->pc_begin + ofs * fc->code_factor); | |
5273 | fc->pc_begin += ofs * fc->code_factor; | |
5274 | break; | |
5275 | ||
5276 | case DW_CFA_advance_loc4: | |
5277 | ofs = byte_get (start, 4); start += 4; | |
5278 | if (do_debug_frames_interp) | |
5279 | frame_display_row (fc, &need_col_headers, &max_regs); | |
5280 | else | |
5281 | printf (" DW_CFA_advance_loc4: %ld to %08lx\n", | |
5282 | ofs * fc->code_factor, | |
5283 | fc->pc_begin + ofs * fc->code_factor); | |
5284 | fc->pc_begin += ofs * fc->code_factor; | |
5285 | break; | |
5286 | ||
5287 | case DW_CFA_offset_extended: | |
5288 | reg = LEB (); | |
5289 | roffs = LEB (); | |
665ce1f6 L |
5290 | if (reg >= (unsigned int) fc->ncols) |
5291 | reg_prefix = bad_reg; | |
5292 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
5293 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
5294 | reg_prefix, regname (reg, 0), | |
5295 | roffs * fc->data_factor); | |
5296 | if (*reg_prefix == '\0') | |
5297 | { | |
5298 | fc->col_type[reg] = DW_CFA_offset; | |
5299 | fc->col_offset[reg] = roffs * fc->data_factor; | |
5300 | } | |
19e6b90e L |
5301 | break; |
5302 | ||
12eae2d3 JJ |
5303 | case DW_CFA_val_offset: |
5304 | reg = LEB (); | |
5305 | roffs = LEB (); | |
665ce1f6 L |
5306 | if (reg >= (unsigned int) fc->ncols) |
5307 | reg_prefix = bad_reg; | |
5308 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
5309 | printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n", | |
5310 | reg_prefix, regname (reg, 0), | |
5311 | roffs * fc->data_factor); | |
5312 | if (*reg_prefix == '\0') | |
5313 | { | |
5314 | fc->col_type[reg] = DW_CFA_val_offset; | |
5315 | fc->col_offset[reg] = roffs * fc->data_factor; | |
5316 | } | |
12eae2d3 JJ |
5317 | break; |
5318 | ||
19e6b90e L |
5319 | case DW_CFA_restore_extended: |
5320 | reg = LEB (); | |
665ce1f6 L |
5321 | if (reg >= (unsigned int) cie->ncols |
5322 | || reg >= (unsigned int) fc->ncols) | |
5323 | reg_prefix = bad_reg; | |
5324 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
5325 | printf (" DW_CFA_restore_extended: %s%s\n", | |
5326 | reg_prefix, regname (reg, 0)); | |
5327 | if (*reg_prefix == '\0') | |
5328 | { | |
5329 | fc->col_type[reg] = cie->col_type[reg]; | |
5330 | fc->col_offset[reg] = cie->col_offset[reg]; | |
5331 | } | |
19e6b90e L |
5332 | break; |
5333 | ||
5334 | case DW_CFA_undefined: | |
5335 | reg = LEB (); | |
665ce1f6 L |
5336 | if (reg >= (unsigned int) fc->ncols) |
5337 | reg_prefix = bad_reg; | |
5338 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
5339 | printf (" DW_CFA_undefined: %s%s\n", | |
5340 | reg_prefix, regname (reg, 0)); | |
5341 | if (*reg_prefix == '\0') | |
5342 | { | |
5343 | fc->col_type[reg] = DW_CFA_undefined; | |
5344 | fc->col_offset[reg] = 0; | |
5345 | } | |
19e6b90e L |
5346 | break; |
5347 | ||
5348 | case DW_CFA_same_value: | |
5349 | reg = LEB (); | |
665ce1f6 L |
5350 | if (reg >= (unsigned int) fc->ncols) |
5351 | reg_prefix = bad_reg; | |
5352 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
5353 | printf (" DW_CFA_same_value: %s%s\n", | |
5354 | reg_prefix, regname (reg, 0)); | |
5355 | if (*reg_prefix == '\0') | |
5356 | { | |
5357 | fc->col_type[reg] = DW_CFA_same_value; | |
5358 | fc->col_offset[reg] = 0; | |
5359 | } | |
19e6b90e L |
5360 | break; |
5361 | ||
5362 | case DW_CFA_register: | |
5363 | reg = LEB (); | |
5364 | roffs = LEB (); | |
665ce1f6 L |
5365 | if (reg >= (unsigned int) fc->ncols) |
5366 | reg_prefix = bad_reg; | |
5367 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 5368 | { |
665ce1f6 L |
5369 | printf (" DW_CFA_register: %s%s in ", |
5370 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
5371 | puts (regname (roffs, 0)); |
5372 | } | |
665ce1f6 L |
5373 | if (*reg_prefix == '\0') |
5374 | { | |
5375 | fc->col_type[reg] = DW_CFA_register; | |
5376 | fc->col_offset[reg] = roffs; | |
5377 | } | |
19e6b90e L |
5378 | break; |
5379 | ||
5380 | case DW_CFA_remember_state: | |
5381 | if (! do_debug_frames_interp) | |
5382 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 5383 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
19e6b90e | 5384 | rs->ncols = fc->ncols; |
3f5e193b NC |
5385 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
5386 | sizeof (short int)); | |
5387 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int)); | |
19e6b90e L |
5388 | memcpy (rs->col_type, fc->col_type, rs->ncols); |
5389 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int)); | |
5390 | rs->next = remembered_state; | |
5391 | remembered_state = rs; | |
5392 | break; | |
5393 | ||
5394 | case DW_CFA_restore_state: | |
5395 | if (! do_debug_frames_interp) | |
5396 | printf (" DW_CFA_restore_state\n"); | |
5397 | rs = remembered_state; | |
5398 | if (rs) | |
5399 | { | |
5400 | remembered_state = rs->next; | |
cc86f28f | 5401 | frame_need_space (fc, rs->ncols - 1); |
19e6b90e L |
5402 | memcpy (fc->col_type, rs->col_type, rs->ncols); |
5403 | memcpy (fc->col_offset, rs->col_offset, | |
5404 | rs->ncols * sizeof (int)); | |
5405 | free (rs->col_type); | |
5406 | free (rs->col_offset); | |
5407 | free (rs); | |
5408 | } | |
5409 | else if (do_debug_frames_interp) | |
5410 | printf ("Mismatched DW_CFA_restore_state\n"); | |
5411 | break; | |
5412 | ||
5413 | case DW_CFA_def_cfa: | |
5414 | fc->cfa_reg = LEB (); | |
5415 | fc->cfa_offset = LEB (); | |
5416 | fc->cfa_exp = 0; | |
5417 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
5418 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
5419 | regname (fc->cfa_reg, 0), fc->cfa_offset); | |
19e6b90e L |
5420 | break; |
5421 | ||
5422 | case DW_CFA_def_cfa_register: | |
5423 | fc->cfa_reg = LEB (); | |
5424 | fc->cfa_exp = 0; | |
5425 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
5426 | printf (" DW_CFA_def_cfa_register: %s\n", |
5427 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
5428 | break; |
5429 | ||
5430 | case DW_CFA_def_cfa_offset: | |
5431 | fc->cfa_offset = LEB (); | |
5432 | if (! do_debug_frames_interp) | |
5433 | printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset); | |
5434 | break; | |
5435 | ||
5436 | case DW_CFA_nop: | |
5437 | if (! do_debug_frames_interp) | |
5438 | printf (" DW_CFA_nop\n"); | |
5439 | break; | |
5440 | ||
5441 | case DW_CFA_def_cfa_expression: | |
5442 | ul = LEB (); | |
5443 | if (! do_debug_frames_interp) | |
5444 | { | |
5445 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
5446 | decode_location_expression (start, eh_addr_size, 0, -1, |
5447 | ul, 0, section); | |
19e6b90e L |
5448 | printf (")\n"); |
5449 | } | |
5450 | fc->cfa_exp = 1; | |
5451 | start += ul; | |
5452 | break; | |
5453 | ||
5454 | case DW_CFA_expression: | |
5455 | reg = LEB (); | |
5456 | ul = LEB (); | |
665ce1f6 L |
5457 | if (reg >= (unsigned int) fc->ncols) |
5458 | reg_prefix = bad_reg; | |
5459 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
19e6b90e | 5460 | { |
665ce1f6 L |
5461 | printf (" DW_CFA_expression: %s%s (", |
5462 | reg_prefix, regname (reg, 0)); | |
b7807392 | 5463 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 5464 | ul, 0, section); |
19e6b90e L |
5465 | printf (")\n"); |
5466 | } | |
665ce1f6 L |
5467 | if (*reg_prefix == '\0') |
5468 | fc->col_type[reg] = DW_CFA_expression; | |
19e6b90e L |
5469 | start += ul; |
5470 | break; | |
5471 | ||
12eae2d3 JJ |
5472 | case DW_CFA_val_expression: |
5473 | reg = LEB (); | |
5474 | ul = LEB (); | |
665ce1f6 L |
5475 | if (reg >= (unsigned int) fc->ncols) |
5476 | reg_prefix = bad_reg; | |
5477 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
12eae2d3 | 5478 | { |
665ce1f6 L |
5479 | printf (" DW_CFA_val_expression: %s%s (", |
5480 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
5481 | decode_location_expression (start, eh_addr_size, 0, -1, |
5482 | ul, 0, section); | |
12eae2d3 JJ |
5483 | printf (")\n"); |
5484 | } | |
665ce1f6 L |
5485 | if (*reg_prefix == '\0') |
5486 | fc->col_type[reg] = DW_CFA_val_expression; | |
12eae2d3 JJ |
5487 | start += ul; |
5488 | break; | |
5489 | ||
19e6b90e L |
5490 | case DW_CFA_offset_extended_sf: |
5491 | reg = LEB (); | |
5492 | l = SLEB (); | |
665ce1f6 L |
5493 | if (frame_need_space (fc, reg) < 0) |
5494 | reg_prefix = bad_reg; | |
5495 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
5496 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
5497 | reg_prefix, regname (reg, 0), | |
5498 | l * fc->data_factor); | |
5499 | if (*reg_prefix == '\0') | |
5500 | { | |
5501 | fc->col_type[reg] = DW_CFA_offset; | |
5502 | fc->col_offset[reg] = l * fc->data_factor; | |
5503 | } | |
19e6b90e L |
5504 | break; |
5505 | ||
12eae2d3 JJ |
5506 | case DW_CFA_val_offset_sf: |
5507 | reg = LEB (); | |
5508 | l = SLEB (); | |
665ce1f6 L |
5509 | if (frame_need_space (fc, reg) < 0) |
5510 | reg_prefix = bad_reg; | |
5511 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
5512 | printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n", | |
5513 | reg_prefix, regname (reg, 0), | |
5514 | l * fc->data_factor); | |
5515 | if (*reg_prefix == '\0') | |
5516 | { | |
5517 | fc->col_type[reg] = DW_CFA_val_offset; | |
5518 | fc->col_offset[reg] = l * fc->data_factor; | |
5519 | } | |
12eae2d3 JJ |
5520 | break; |
5521 | ||
19e6b90e L |
5522 | case DW_CFA_def_cfa_sf: |
5523 | fc->cfa_reg = LEB (); | |
5524 | fc->cfa_offset = SLEB (); | |
5525 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; | |
5526 | fc->cfa_exp = 0; | |
5527 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
5528 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
5529 | regname (fc->cfa_reg, 0), fc->cfa_offset); | |
19e6b90e L |
5530 | break; |
5531 | ||
5532 | case DW_CFA_def_cfa_offset_sf: | |
5533 | fc->cfa_offset = SLEB (); | |
5534 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; | |
5535 | if (! do_debug_frames_interp) | |
5536 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset); | |
5537 | break; | |
5538 | ||
5539 | case DW_CFA_MIPS_advance_loc8: | |
5540 | ofs = byte_get (start, 8); start += 8; | |
5541 | if (do_debug_frames_interp) | |
5542 | frame_display_row (fc, &need_col_headers, &max_regs); | |
5543 | else | |
5544 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n", | |
5545 | ofs * fc->code_factor, | |
5546 | fc->pc_begin + ofs * fc->code_factor); | |
5547 | fc->pc_begin += ofs * fc->code_factor; | |
5548 | break; | |
5549 | ||
5550 | case DW_CFA_GNU_window_save: | |
5551 | if (! do_debug_frames_interp) | |
5552 | printf (" DW_CFA_GNU_window_save\n"); | |
5553 | break; | |
5554 | ||
5555 | case DW_CFA_GNU_args_size: | |
5556 | ul = LEB (); | |
5557 | if (! do_debug_frames_interp) | |
5558 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
5559 | break; | |
5560 | ||
5561 | case DW_CFA_GNU_negative_offset_extended: | |
5562 | reg = LEB (); | |
5563 | l = - LEB (); | |
665ce1f6 L |
5564 | if (frame_need_space (fc, reg) < 0) |
5565 | reg_prefix = bad_reg; | |
5566 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
5567 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
5568 | reg_prefix, regname (reg, 0), | |
5569 | l * fc->data_factor); | |
5570 | if (*reg_prefix == '\0') | |
5571 | { | |
5572 | fc->col_type[reg] = DW_CFA_offset; | |
5573 | fc->col_offset[reg] = l * fc->data_factor; | |
5574 | } | |
19e6b90e L |
5575 | break; |
5576 | ||
5577 | default: | |
53b8873b NC |
5578 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
5579 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
5580 | else | |
cecf136e | 5581 | warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
5582 | start = block_end; |
5583 | } | |
5584 | } | |
5585 | ||
5586 | if (do_debug_frames_interp) | |
5587 | frame_display_row (fc, &need_col_headers, &max_regs); | |
5588 | ||
5589 | start = block_end; | |
604282a7 | 5590 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
5591 | } |
5592 | ||
5593 | printf ("\n"); | |
5594 | ||
5595 | return 1; | |
5596 | } | |
5597 | ||
5598 | #undef GET | |
5599 | #undef LEB | |
5600 | #undef SLEB | |
5601 | ||
5bbdf3d5 DE |
5602 | static int |
5603 | display_gdb_index (struct dwarf_section *section, | |
5604 | void *file ATTRIBUTE_UNUSED) | |
5605 | { | |
5606 | unsigned char *start = section->start; | |
5607 | uint32_t version; | |
5608 | uint32_t cu_list_offset, tu_list_offset; | |
5609 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
5610 | unsigned int cu_list_elements, tu_list_elements; | |
5611 | unsigned int address_table_size, symbol_table_slots; | |
5612 | unsigned char *cu_list, *tu_list; | |
5613 | unsigned char *address_table, *symbol_table, *constant_pool; | |
5614 | unsigned int i; | |
5615 | ||
5616 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
5617 | ||
5618 | printf (_("Contents of the %s section:\n"), section->name); | |
5619 | ||
5620 | if (section->size < 6 * sizeof (uint32_t)) | |
5621 | { | |
5622 | warn (_("Truncated header in the %s section.\n"), section->name); | |
5623 | return 0; | |
5624 | } | |
5625 | ||
5626 | version = byte_get_little_endian (start, 4); | |
da88a764 | 5627 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
5628 | |
5629 | /* Prior versions are obsolete, and future versions may not be | |
5630 | backwards compatible. */ | |
6ec8b48e | 5631 | switch (version) |
5bbdf3d5 | 5632 | { |
6ec8b48e JK |
5633 | case 3: |
5634 | warn (_("The address table data in version 3 may be wrong.\n")); | |
5635 | break; | |
5636 | case 4: | |
6adc060c JK |
5637 | warn (_("Version 4 does not support case insensitive lookups.\n")); |
5638 | break; | |
5639 | case 5: | |
658c7344 TT |
5640 | warn (_("Version 5 does not include inlined functions.\n")); |
5641 | break; | |
5642 | case 6: | |
6ec8b48e JK |
5643 | break; |
5644 | default: | |
da88a764 | 5645 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
5646 | return 0; |
5647 | } | |
5648 | ||
5649 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
5650 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
5651 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
5652 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
5653 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
5654 | ||
5655 | if (cu_list_offset > section->size | |
5656 | || tu_list_offset > section->size | |
5657 | || address_table_offset > section->size | |
5658 | || symbol_table_offset > section->size | |
5659 | || constant_pool_offset > section->size) | |
5660 | { | |
5661 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
5662 | return 0; | |
5663 | } | |
5664 | ||
5665 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; | |
5666 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; | |
5667 | address_table_size = symbol_table_offset - address_table_offset; | |
5668 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; | |
5669 | ||
5670 | cu_list = start + cu_list_offset; | |
5671 | tu_list = start + tu_list_offset; | |
5672 | address_table = start + address_table_offset; | |
5673 | symbol_table = start + symbol_table_offset; | |
5674 | constant_pool = start + constant_pool_offset; | |
5675 | ||
5676 | printf (_("\nCU table:\n")); | |
5677 | for (i = 0; i < cu_list_elements; i += 2) | |
5678 | { | |
5679 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
5680 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
5681 | ||
5682 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
5683 | (unsigned long) cu_offset, | |
5684 | (unsigned long) (cu_offset + cu_length - 1)); | |
5685 | } | |
5686 | ||
5687 | printf (_("\nTU table:\n")); | |
5688 | for (i = 0; i < tu_list_elements; i += 3) | |
5689 | { | |
5690 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
5691 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
5692 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
5693 | ||
5694 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
5695 | (unsigned long) tu_offset, | |
5696 | (unsigned long) type_offset); | |
5697 | print_dwarf_vma (signature, 8); | |
5698 | printf ("\n"); | |
5699 | } | |
5700 | ||
5701 | printf (_("\nAddress table:\n")); | |
5702 | for (i = 0; i < address_table_size; i += 2 * 8 + 4) | |
5703 | { | |
5704 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
5705 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
5706 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
5707 | ||
5708 | print_dwarf_vma (low, 8); | |
5709 | print_dwarf_vma (high, 8); | |
da88a764 | 5710 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
5711 | } |
5712 | ||
5713 | printf (_("\nSymbol table:\n")); | |
5714 | for (i = 0; i < symbol_table_slots; ++i) | |
5715 | { | |
5716 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
5717 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
5718 | uint32_t num_cus, cu; | |
5719 | ||
5720 | if (name_offset != 0 | |
5721 | || cu_vector_offset != 0) | |
5722 | { | |
5723 | unsigned int j; | |
5724 | ||
5725 | printf ("[%3u] %s:", i, constant_pool + name_offset); | |
5726 | num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4); | |
5727 | for (j = 0; j < num_cus; ++j) | |
5728 | { | |
5729 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); | |
5730 | /* Convert to TU number if it's for a type unit. */ | |
ad6b52dd CC |
5731 | if (cu >= cu_list_elements / 2) |
5732 | printf (" T%lu", (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 5733 | else |
da88a764 | 5734 | printf (" %lu", (unsigned long) cu); |
5bbdf3d5 DE |
5735 | } |
5736 | printf ("\n"); | |
5737 | } | |
5738 | } | |
5739 | ||
5740 | return 1; | |
5741 | } | |
5742 | ||
19e6b90e L |
5743 | static int |
5744 | display_debug_not_supported (struct dwarf_section *section, | |
5745 | void *file ATTRIBUTE_UNUSED) | |
5746 | { | |
5747 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
5748 | section->name); | |
5749 | ||
5750 | return 1; | |
5751 | } | |
5752 | ||
5753 | void * | |
5754 | cmalloc (size_t nmemb, size_t size) | |
5755 | { | |
5756 | /* Check for overflow. */ | |
5757 | if (nmemb >= ~(size_t) 0 / size) | |
5758 | return NULL; | |
5759 | else | |
5760 | return malloc (nmemb * size); | |
5761 | } | |
5762 | ||
5763 | void * | |
5764 | xcmalloc (size_t nmemb, size_t size) | |
5765 | { | |
5766 | /* Check for overflow. */ | |
5767 | if (nmemb >= ~(size_t) 0 / size) | |
5768 | return NULL; | |
5769 | else | |
5770 | return xmalloc (nmemb * size); | |
5771 | } | |
5772 | ||
5773 | void * | |
5774 | xcrealloc (void *ptr, size_t nmemb, size_t size) | |
5775 | { | |
5776 | /* Check for overflow. */ | |
5777 | if (nmemb >= ~(size_t) 0 / size) | |
5778 | return NULL; | |
5779 | else | |
5780 | return xrealloc (ptr, nmemb * size); | |
5781 | } | |
5782 | ||
19e6b90e L |
5783 | void |
5784 | free_debug_memory (void) | |
5785 | { | |
3f5e193b | 5786 | unsigned int i; |
19e6b90e L |
5787 | |
5788 | free_abbrevs (); | |
5789 | ||
5790 | for (i = 0; i < max; i++) | |
3f5e193b | 5791 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 5792 | |
cc86f28f | 5793 | if (debug_information != NULL) |
19e6b90e | 5794 | { |
cc86f28f | 5795 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
19e6b90e | 5796 | { |
cc86f28f | 5797 | for (i = 0; i < num_debug_info_entries; i++) |
19e6b90e | 5798 | { |
cc86f28f NC |
5799 | if (!debug_information [i].max_loc_offsets) |
5800 | { | |
5801 | free (debug_information [i].loc_offsets); | |
5802 | free (debug_information [i].have_frame_base); | |
5803 | } | |
5804 | if (!debug_information [i].max_range_lists) | |
5805 | free (debug_information [i].range_lists); | |
19e6b90e | 5806 | } |
19e6b90e | 5807 | } |
cc86f28f | 5808 | |
19e6b90e L |
5809 | free (debug_information); |
5810 | debug_information = NULL; | |
5811 | num_debug_info_entries = 0; | |
5812 | } | |
19e6b90e L |
5813 | } |
5814 | ||
4cb93e3b TG |
5815 | void |
5816 | dwarf_select_sections_by_names (const char *names) | |
5817 | { | |
5818 | typedef struct | |
5819 | { | |
5820 | const char * option; | |
5821 | int * variable; | |
f9f0e732 | 5822 | int val; |
4cb93e3b TG |
5823 | } |
5824 | debug_dump_long_opts; | |
5825 | ||
5826 | static const debug_dump_long_opts opts_table [] = | |
5827 | { | |
5828 | /* Please keep this table alpha- sorted. */ | |
5829 | { "Ranges", & do_debug_ranges, 1 }, | |
5830 | { "abbrev", & do_debug_abbrevs, 1 }, | |
5831 | { "aranges", & do_debug_aranges, 1 }, | |
5832 | { "frames", & do_debug_frames, 1 }, | |
5833 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
5834 | { "info", & do_debug_info, 1 }, | |
5835 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
5836 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, | |
5837 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
5838 | { "loc", & do_debug_loc, 1 }, | |
5839 | { "macro", & do_debug_macinfo, 1 }, | |
5840 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 5841 | { "pubtypes", & do_debug_pubtypes, 1 }, |
4cb93e3b TG |
5842 | /* This entry is for compatability |
5843 | with earlier versions of readelf. */ | |
5844 | { "ranges", & do_debug_aranges, 1 }, | |
5845 | { "str", & do_debug_str, 1 }, | |
5bbdf3d5 DE |
5846 | /* The special .gdb_index section. */ |
5847 | { "gdb_index", & do_gdb_index, 1 }, | |
6f875884 TG |
5848 | /* These trace_* sections are used by Itanium VMS. */ |
5849 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
5850 | { "trace_aranges", & do_trace_aranges, 1 }, | |
5851 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
5852 | { NULL, NULL, 0 } |
5853 | }; | |
5854 | ||
5855 | const char *p; | |
467c65bc | 5856 | |
4cb93e3b TG |
5857 | p = names; |
5858 | while (*p) | |
5859 | { | |
5860 | const debug_dump_long_opts * entry; | |
467c65bc | 5861 | |
4cb93e3b TG |
5862 | for (entry = opts_table; entry->option; entry++) |
5863 | { | |
5864 | size_t len = strlen (entry->option); | |
467c65bc | 5865 | |
4cb93e3b TG |
5866 | if (strncmp (p, entry->option, len) == 0 |
5867 | && (p[len] == ',' || p[len] == '\0')) | |
5868 | { | |
5869 | * entry->variable |= entry->val; | |
467c65bc | 5870 | |
4cb93e3b TG |
5871 | /* The --debug-dump=frames-interp option also |
5872 | enables the --debug-dump=frames option. */ | |
5873 | if (do_debug_frames_interp) | |
5874 | do_debug_frames = 1; | |
5875 | ||
5876 | p += len; | |
5877 | break; | |
5878 | } | |
5879 | } | |
467c65bc | 5880 | |
4cb93e3b TG |
5881 | if (entry->option == NULL) |
5882 | { | |
5883 | warn (_("Unrecognized debug option '%s'\n"), p); | |
5884 | p = strchr (p, ','); | |
5885 | if (p == NULL) | |
5886 | break; | |
5887 | } | |
467c65bc | 5888 | |
4cb93e3b TG |
5889 | if (*p == ',') |
5890 | p++; | |
5891 | } | |
5892 | } | |
5893 | ||
5894 | void | |
5895 | dwarf_select_sections_by_letters (const char *letters) | |
5896 | { | |
91d6fa6a | 5897 | unsigned int lindex = 0; |
4cb93e3b | 5898 | |
91d6fa6a NC |
5899 | while (letters[lindex]) |
5900 | switch (letters[lindex++]) | |
4cb93e3b TG |
5901 | { |
5902 | case 'i': | |
5903 | do_debug_info = 1; | |
5904 | break; | |
467c65bc | 5905 | |
4cb93e3b TG |
5906 | case 'a': |
5907 | do_debug_abbrevs = 1; | |
5908 | break; | |
467c65bc | 5909 | |
4cb93e3b TG |
5910 | case 'l': |
5911 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5912 | break; | |
467c65bc | 5913 | |
4cb93e3b TG |
5914 | case 'L': |
5915 | do_debug_lines |= FLAG_DEBUG_LINES_DECODED; | |
5916 | break; | |
467c65bc | 5917 | |
4cb93e3b TG |
5918 | case 'p': |
5919 | do_debug_pubnames = 1; | |
5920 | break; | |
467c65bc | 5921 | |
f9f0e732 NC |
5922 | case 't': |
5923 | do_debug_pubtypes = 1; | |
5924 | break; | |
467c65bc | 5925 | |
4cb93e3b TG |
5926 | case 'r': |
5927 | do_debug_aranges = 1; | |
5928 | break; | |
467c65bc | 5929 | |
4cb93e3b TG |
5930 | case 'R': |
5931 | do_debug_ranges = 1; | |
5932 | break; | |
467c65bc | 5933 | |
4cb93e3b TG |
5934 | case 'F': |
5935 | do_debug_frames_interp = 1; | |
5936 | case 'f': | |
5937 | do_debug_frames = 1; | |
5938 | break; | |
467c65bc | 5939 | |
4cb93e3b TG |
5940 | case 'm': |
5941 | do_debug_macinfo = 1; | |
5942 | break; | |
467c65bc | 5943 | |
4cb93e3b TG |
5944 | case 's': |
5945 | do_debug_str = 1; | |
5946 | break; | |
467c65bc | 5947 | |
4cb93e3b TG |
5948 | case 'o': |
5949 | do_debug_loc = 1; | |
5950 | break; | |
467c65bc | 5951 | |
4cb93e3b TG |
5952 | default: |
5953 | warn (_("Unrecognized debug option '%s'\n"), optarg); | |
5954 | break; | |
5955 | } | |
5956 | } | |
5957 | ||
5958 | void | |
5959 | dwarf_select_sections_all (void) | |
5960 | { | |
5961 | do_debug_info = 1; | |
5962 | do_debug_abbrevs = 1; | |
5963 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
5964 | do_debug_pubnames = 1; | |
f9f0e732 | 5965 | do_debug_pubtypes = 1; |
4cb93e3b TG |
5966 | do_debug_aranges = 1; |
5967 | do_debug_ranges = 1; | |
5968 | do_debug_frames = 1; | |
5969 | do_debug_macinfo = 1; | |
5970 | do_debug_str = 1; | |
5971 | do_debug_loc = 1; | |
5bbdf3d5 | 5972 | do_gdb_index = 1; |
6f875884 TG |
5973 | do_trace_info = 1; |
5974 | do_trace_abbrevs = 1; | |
5975 | do_trace_aranges = 1; | |
4cb93e3b TG |
5976 | } |
5977 | ||
19e6b90e L |
5978 | struct dwarf_section_display debug_displays[] = |
5979 | { | |
4723351a CC |
5980 | { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, abbrev }, |
5981 | display_debug_abbrev, &do_debug_abbrevs, 0 }, | |
5982 | { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, abbrev }, | |
5983 | display_debug_aranges, &do_debug_aranges, 1 }, | |
5984 | { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, abbrev }, | |
5985 | display_debug_frames, &do_debug_frames, 1 }, | |
5986 | { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev }, | |
5987 | display_debug_info, &do_debug_info, 1 }, | |
5988 | { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, abbrev }, | |
5989 | display_debug_lines, &do_debug_lines, 1 }, | |
5990 | { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, abbrev }, | |
5991 | display_debug_pubnames, &do_debug_pubnames, 0 }, | |
5992 | { { ".eh_frame", "", NULL, NULL, 0, 0, abbrev }, | |
5993 | display_debug_frames, &do_debug_frames, 1 }, | |
5994 | { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, abbrev }, | |
5995 | display_debug_macinfo, &do_debug_macinfo, 0 }, | |
5996 | { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, abbrev }, | |
5997 | display_debug_macro, &do_debug_macinfo, 1 }, | |
5998 | { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, abbrev }, | |
5999 | display_debug_str, &do_debug_str, 0 }, | |
6000 | { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, abbrev }, | |
6001 | display_debug_loc, &do_debug_loc, 1 }, | |
6002 | { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, abbrev }, | |
6003 | display_debug_pubnames, &do_debug_pubtypes, 0 }, | |
6004 | { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, abbrev }, | |
6005 | display_debug_ranges, &do_debug_ranges, 1 }, | |
6006 | { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, abbrev }, | |
6007 | display_debug_not_supported, NULL, 0 }, | |
6008 | { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, abbrev }, | |
6009 | display_debug_not_supported, NULL, 0 }, | |
6010 | { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev }, | |
6011 | display_debug_types, &do_debug_info, 1 }, | |
6012 | { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, abbrev }, | |
6013 | display_debug_not_supported, NULL, 0 }, | |
6014 | { { ".gdb_index", "", NULL, NULL, 0, 0, abbrev }, | |
5bbdf3d5 | 6015 | display_gdb_index, &do_gdb_index, 0 }, |
4723351a | 6016 | { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev }, |
6f875884 | 6017 | display_trace_info, &do_trace_info, 1 }, |
4723351a | 6018 | { { ".trace_abbrev", "", NULL, NULL, 0, 0, abbrev }, |
6f875884 | 6019 | display_debug_abbrev, &do_trace_abbrevs, 0 }, |
4723351a CC |
6020 | { { ".trace_aranges", "", NULL, NULL, 0, 0, abbrev }, |
6021 | display_debug_aranges, &do_trace_aranges, 0 }, | |
6022 | { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo }, | |
6023 | display_debug_info, &do_debug_info, 1 }, | |
6024 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, abbrev_dwo }, | |
6025 | display_debug_abbrev, &do_debug_abbrevs, 0 }, | |
6026 | { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo }, | |
6027 | display_debug_types, &do_debug_info, 1 }, | |
6028 | { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, abbrev_dwo }, | |
6029 | display_debug_lines, &do_debug_lines, 1 }, | |
6030 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, abbrev_dwo }, | |
6031 | display_debug_loc, &do_debug_loc, 1 }, | |
6032 | { { ".debug_macro.dwo", ".zdebug_macro.dwo",NULL, NULL, 0, 0, abbrev }, | |
6033 | display_debug_macro, &do_debug_macinfo, 1 }, | |
6034 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo",NULL, NULL, 0, 0, abbrev }, | |
6035 | display_debug_macinfo, &do_debug_macinfo, 0 }, | |
6036 | { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, str_dwo }, | |
6037 | display_debug_str, &do_debug_str, 1 }, | |
6038 | { { ".debug_str_offsets",".zdebug_str_offsets", NULL, NULL, 0, 0, abbrev }, | |
6039 | display_debug_str_offsets, NULL, 0 }, | |
6040 | { { ".debug_str_offsets.dwo",".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, | |
6041 | abbrev }, | |
6042 | display_debug_str_offsets, NULL, 0 }, | |
6043 | { { ".debug_addr",".zdebug_addr", NULL, NULL, 0, 0, debug_addr }, | |
6044 | display_debug_addr, NULL, 1 }, | |
19e6b90e | 6045 | }; |