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