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