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