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