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