1 /* dwarf.c -- display DWARF contents of a BFD binary file 2 Copyright (C) 2005-2014 Free Software Foundation, Inc. 3 4 This file is part of GNU Binutils. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 19 02110-1301, USA. */ 20 21 #include "sysdep.h" 22 #include "libiberty.h" 23 #include "bfd.h" 24 #include "bfd_stdint.h" 25 #include "bucomm.h" 26 #include "elfcomm.h" 27 #include "elf/common.h" 28 #include "dwarf2.h" 29 #include "dwarf.h" 30 #include "gdb/gdb-index.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_debug_addr; 65 int do_debug_cu_index; 66 int do_wide; 67 68 int dwarf_cutoff_level = -1; 69 unsigned long dwarf_start_die; 70 71 int dwarf_check = 0; 72 73 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index 74 sections. For version 1 package files, each set is stored in SHNDX_POOL 75 as a zero-terminated list of section indexes comprising one set of debug 76 sections from a .dwo file. */ 77 78 static int cu_tu_indexes_read = 0; 79 static unsigned int *shndx_pool = NULL; 80 static unsigned int shndx_pool_size = 0; 81 static unsigned int shndx_pool_used = 0; 82 83 /* For version 2 package files, each set contains an array of section offsets 84 and an array of section sizes, giving the offset and size of the 85 contribution from a CU or TU within one of the debug sections. 86 When displaying debug info from a package file, we need to use these 87 tables to locate the corresponding contributions to each section. */ 88 89 struct cu_tu_set 90 { 91 uint64_t signature; 92 dwarf_vma section_offsets[DW_SECT_MAX]; 93 size_t section_sizes[DW_SECT_MAX]; 94 }; 95 96 static int cu_count = 0; 97 static int tu_count = 0; 98 static struct cu_tu_set *cu_sets = NULL; 99 static struct cu_tu_set *tu_sets = NULL; 100 101 static void load_cu_tu_indexes (void *file); 102 103 /* Values for do_debug_lines. */ 104 #define FLAG_DEBUG_LINES_RAW 1 105 #define FLAG_DEBUG_LINES_DECODED 2 106 107 static int 108 size_of_encoded_value (int encoding) 109 { 110 switch (encoding & 0x7) 111 { 112 default: /* ??? */ 113 case 0: return eh_addr_size; 114 case 2: return 2; 115 case 3: return 4; 116 case 4: return 8; 117 } 118 } 119 120 static dwarf_vma 121 get_encoded_value (unsigned char **pdata, 122 int encoding, 123 struct dwarf_section *section, 124 unsigned char * end) 125 { 126 unsigned char * data = * pdata; 127 int size = size_of_encoded_value (encoding); 128 dwarf_vma val; 129 130 if (data + size >= end) 131 { 132 warn (_("Encoded value extends past end of section\n")); 133 * pdata = end; 134 return 0; 135 } 136 137 if (encoding & DW_EH_PE_signed) 138 val = byte_get_signed (data, size); 139 else 140 val = byte_get (data, size); 141 142 if ((encoding & 0x70) == DW_EH_PE_pcrel) 143 val += section->address + (data - section->start); 144 145 * pdata = data + size; 146 return val; 147 } 148 149 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2) 150 #ifndef __MINGW32__ 151 #define DWARF_VMA_FMT "ll" 152 #define DWARF_VMA_FMT_LONG "%16.16llx" 153 #else 154 #define DWARF_VMA_FMT "I64" 155 #define DWARF_VMA_FMT_LONG "%016I64x" 156 #endif 157 #else 158 #define DWARF_VMA_FMT "l" 159 #define DWARF_VMA_FMT_LONG "%16.16lx" 160 #endif 161 162 /* Convert a dwarf vma value into a string. Returns a pointer to a static 163 buffer containing the converted VALUE. The value is converted according 164 to the printf formating character FMTCH. If NUM_BYTES is non-zero then 165 it specifies the maximum number of bytes to be displayed in the converted 166 value and FMTCH is ignored - hex is always used. */ 167 168 static const char * 169 dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) 170 { 171 /* As dwarf_vmatoa is used more then once in a printf call 172 for output, we are cycling through an fixed array of pointers 173 for return address. */ 174 static int buf_pos = 0; 175 static struct dwarf_vmatoa_buf 176 { 177 char place[64]; 178 } buf[16]; 179 char *ret; 180 181 ret = buf[buf_pos++].place; 182 buf_pos %= ARRAY_SIZE (buf); 183 184 if (num_bytes) 185 { 186 /* Printf does not have a way of specifiying a maximum field width for an 187 integer value, so we print the full value into a buffer and then select 188 the precision we need. */ 189 snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); 190 if (num_bytes > 8) 191 num_bytes = 8; 192 return ret + (16 - 2 * num_bytes); 193 } 194 else 195 { 196 char fmt[32]; 197 198 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); 199 snprintf (ret, sizeof (buf[0].place), fmt, value); 200 return ret; 201 } 202 } 203 204 static inline const char * 205 dwarf_vmatoa (const char * fmtch, dwarf_vma value) 206 { 207 return dwarf_vmatoa_1 (fmtch, value, 0); 208 } 209 210 /* Print a dwarf_vma value (typically an address, offset or length) in 211 hexadecimal format, followed by a space. The length of the VALUE (and 212 hence the precision displayed) is determined by the NUM_BYTES parameter. */ 213 214 static void 215 print_dwarf_vma (dwarf_vma value, unsigned num_bytes) 216 { 217 printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); 218 } 219 220 /* Format a 64-bit value, given as two 32-bit values, in hex. 221 For reentrancy, this uses a buffer provided by the caller. */ 222 223 static const char * 224 dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, 225 unsigned int buf_len) 226 { 227 int len = 0; 228 229 if (hvalue == 0) 230 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); 231 else 232 { 233 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); 234 snprintf (buf + len, buf_len - len, 235 "%08" DWARF_VMA_FMT "x", lvalue); 236 } 237 238 return buf; 239 } 240 241 /* Read in a LEB128 encoded value starting at address DATA. 242 If SIGN is true, return a signed LEB128 value. 243 If LENGTH_RETURN is not NULL, return in it the number of bytes read. 244 No bytes will be read at address END or beyond. */ 245 246 dwarf_vma 247 read_leb128 (unsigned char *data, 248 unsigned int *length_return, 249 bfd_boolean sign, 250 const unsigned char * const end) 251 { 252 dwarf_vma result = 0; 253 unsigned int num_read = 0; 254 unsigned int shift = 0; 255 unsigned char byte = 0; 256 257 while (data < end) 258 { 259 byte = *data++; 260 num_read++; 261 262 result |= ((dwarf_vma) (byte & 0x7f)) << shift; 263 264 shift += 7; 265 if ((byte & 0x80) == 0) 266 break; 267 } 268 269 if (length_return != NULL) 270 *length_return = num_read; 271 272 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) 273 result |= (dwarf_vma) -1 << shift; 274 275 return result; 276 } 277 278 /* Create a signed version to avoid painful typecasts. */ 279 static inline dwarf_signed_vma 280 read_sleb128 (unsigned char * data, 281 unsigned int * length_return, 282 const unsigned char * const end) 283 { 284 return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end); 285 } 286 287 static inline dwarf_vma 288 read_uleb128 (unsigned char * data, 289 unsigned int * length_return, 290 const unsigned char * const end) 291 { 292 return read_leb128 (data, length_return, FALSE, end); 293 } 294 295 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ 296 do \ 297 { \ 298 int dummy [sizeof (VAL) < (AMOUNT) ? -1 : 1] ATTRIBUTE_UNUSED ; \ 299 unsigned int amount = (AMOUNT); \ 300 if (((PTR) + amount) >= (END)) \ 301 { \ 302 if ((PTR) < (END)) \ 303 amount = (END) - (PTR); \ 304 else \ 305 amount = 0; \ 306 } \ 307 if (amount) \ 308 VAL = byte_get ((PTR), amount); \ 309 else \ 310 VAL = 0; \ 311 } \ 312 while (0) 313 314 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ 315 do \ 316 { \ 317 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ 318 PTR += AMOUNT; \ 319 } \ 320 while (0) 321 322 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ 323 do \ 324 { \ 325 unsigned int amount = (AMOUNT); \ 326 if (((PTR) + amount) >= (END)) \ 327 { \ 328 if ((PTR) < (END)) \ 329 amount = (END) - (PTR); \ 330 else \ 331 amount = 0; \ 332 } \ 333 if (amount) \ 334 VAL = byte_get_signed ((PTR), amount); \ 335 else \ 336 VAL = 0; \ 337 } \ 338 while (0) 339 340 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ 341 do \ 342 { \ 343 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ 344 PTR += AMOUNT; \ 345 } \ 346 while (0) 347 348 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ 349 do \ 350 { \ 351 if (((PTR) + 8) <= (END)) \ 352 { \ 353 byte_get_64 ((PTR), (HIGH), (LOW)); \ 354 } \ 355 else \ 356 { \ 357 * (LOW) = * (HIGH) = 0; \ 358 } \ 359 } \ 360 while (0) 361 362 typedef struct State_Machine_Registers 363 { 364 dwarf_vma address; 365 unsigned int file; 366 unsigned int line; 367 unsigned int column; 368 unsigned int discriminator; 369 unsigned int context; 370 unsigned int subprogram; 371 int is_stmt; 372 int basic_block; 373 unsigned char op_index; 374 unsigned char end_sequence; 375 /* This variable hold the number of the last entry seen 376 in the File Table. */ 377 unsigned int last_file_entry; 378 } SMR; 379 380 static SMR state_machine_regs; 381 382 static void 383 reset_state_machine (int is_stmt) 384 { 385 state_machine_regs.address = 0; 386 state_machine_regs.op_index = 0; 387 state_machine_regs.file = 1; 388 state_machine_regs.line = 1; 389 state_machine_regs.column = 0; 390 state_machine_regs.discriminator = 0; 391 state_machine_regs.context = 0; 392 state_machine_regs.subprogram = 0; 393 state_machine_regs.is_stmt = is_stmt; 394 state_machine_regs.basic_block = 0; 395 state_machine_regs.end_sequence = 0; 396 state_machine_regs.last_file_entry = 0; 397 } 398 399 /* Build a logicals table for reference when reading the actuals table. */ 400 401 static SMR *logicals_table = NULL; 402 static unsigned int logicals_allocated = 0; 403 static unsigned int logicals_count = 0; 404 405 static void 406 free_logicals (void) 407 { 408 free (logicals_table); 409 logicals_allocated = 0; 410 logicals_count = 0; 411 logicals_table = NULL; 412 } 413 414 static void 415 append_logical (void) 416 { 417 if (logicals_allocated == 0) 418 { 419 logicals_allocated = 4; 420 logicals_table = (SMR *) xmalloc (logicals_allocated * sizeof (SMR)); 421 } 422 if (logicals_count >= logicals_allocated) 423 { 424 logicals_allocated *= 2; 425 logicals_table = (SMR *) 426 xrealloc (logicals_table, logicals_allocated * sizeof (SMR)); 427 } 428 logicals_table[logicals_count++] = state_machine_regs; 429 printf (_("\t\tLogical %u: 0x%s[%u] file %u line %u discrim %u context %u subprog %u is_stmt %d\n"), 430 logicals_count, 431 dwarf_vmatoa ("x", state_machine_regs.address), 432 state_machine_regs.op_index, 433 state_machine_regs.file, 434 state_machine_regs.line, 435 state_machine_regs.discriminator, 436 state_machine_regs.context, 437 state_machine_regs.subprogram, 438 state_machine_regs.is_stmt); 439 } 440 441 /* Handled an extend line op. 442 Returns the number of bytes read. */ 443 444 static int 445 process_extended_line_op (unsigned char * data, 446 int is_stmt, 447 unsigned char * end, 448 int is_logical) 449 { 450 unsigned char op_code; 451 unsigned int bytes_read; 452 unsigned int len; 453 unsigned char *name; 454 unsigned char *orig_data = data; 455 dwarf_vma adr; 456 457 len = read_uleb128 (data, & bytes_read, end); 458 data += bytes_read; 459 460 if (len == 0 || data == end) 461 { 462 warn (_("Badly formed extended line op encountered!\n")); 463 return bytes_read; 464 } 465 466 len += bytes_read; 467 op_code = *data++; 468 469 printf (_(" Extended opcode %d: "), op_code); 470 471 switch (op_code) 472 { 473 case DW_LNE_end_sequence: 474 printf (_("End of Sequence\n\n")); 475 if (is_logical) 476 append_logical (); 477 reset_state_machine (is_stmt); 478 break; 479 480 case DW_LNE_set_address: 481 SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end); 482 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); 483 state_machine_regs.address = adr; 484 state_machine_regs.op_index = 0; 485 break; 486 487 case DW_LNE_define_file: 488 printf (_("define new File Table entry\n")); 489 printf (_(" Entry\tDir\tTime\tSize\tName\n")); 490 printf (" %d\t", ++state_machine_regs.last_file_entry); 491 492 name = data; 493 data += strnlen ((char *) data, end - data) + 1; 494 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); 495 data += bytes_read; 496 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); 497 data += bytes_read; 498 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); 499 data += bytes_read; 500 printf ("%s\n\n", name); 501 502 if (((unsigned int) (data - orig_data) != len) || data == end) 503 warn (_("DW_LNE_define_file: Bad opcode length\n")); 504 break; 505 506 case DW_LNE_set_discriminator: 507 { 508 unsigned int discrim; 509 510 discrim = read_uleb128 (data, & bytes_read, end); 511 data += bytes_read; 512 printf (_("set Discriminator to %u\n"), discrim); 513 state_machine_regs.discriminator = discrim; 514 } 515 break; 516 517 /* HP extensions. */ 518 case DW_LNE_HP_negate_is_UV_update: 519 printf ("DW_LNE_HP_negate_is_UV_update\n"); 520 break; 521 case DW_LNE_HP_push_context: 522 printf ("DW_LNE_HP_push_context\n"); 523 break; 524 case DW_LNE_HP_pop_context: 525 printf ("DW_LNE_HP_pop_context\n"); 526 break; 527 case DW_LNE_HP_set_file_line_column: 528 printf ("DW_LNE_HP_set_file_line_column\n"); 529 break; 530 case DW_LNE_HP_set_routine_name: 531 printf ("DW_LNE_HP_set_routine_name\n"); 532 break; 533 case DW_LNE_HP_set_sequence: 534 printf ("DW_LNE_HP_set_sequence\n"); 535 break; 536 case DW_LNE_HP_negate_post_semantics: 537 printf ("DW_LNE_HP_negate_post_semantics\n"); 538 break; 539 case DW_LNE_HP_negate_function_exit: 540 printf ("DW_LNE_HP_negate_function_exit\n"); 541 break; 542 case DW_LNE_HP_negate_front_end_logical: 543 printf ("DW_LNE_HP_negate_front_end_logical\n"); 544 break; 545 case DW_LNE_HP_define_proc: 546 printf ("DW_LNE_HP_define_proc\n"); 547 break; 548 case DW_LNE_HP_source_file_correlation: 549 { 550 unsigned char *edata = data + len - bytes_read - 1; 551 552 printf ("DW_LNE_HP_source_file_correlation\n"); 553 554 while (data < edata) 555 { 556 unsigned int opc; 557 558 opc = read_uleb128 (data, & bytes_read, edata); 559 data += bytes_read; 560 561 switch (opc) 562 { 563 case DW_LNE_HP_SFC_formfeed: 564 printf (" DW_LNE_HP_SFC_formfeed\n"); 565 break; 566 case DW_LNE_HP_SFC_set_listing_line: 567 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", 568 dwarf_vmatoa ("u", 569 read_uleb128 (data, & bytes_read, edata))); 570 data += bytes_read; 571 break; 572 case DW_LNE_HP_SFC_associate: 573 printf (" DW_LNE_HP_SFC_associate "); 574 printf ("(%s", 575 dwarf_vmatoa ("u", 576 read_uleb128 (data, & bytes_read, edata))); 577 data += bytes_read; 578 printf (",%s", 579 dwarf_vmatoa ("u", 580 read_uleb128 (data, & bytes_read, edata))); 581 data += bytes_read; 582 printf (",%s)\n", 583 dwarf_vmatoa ("u", 584 read_uleb128 (data, & bytes_read, edata))); 585 data += bytes_read; 586 break; 587 default: 588 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); 589 data = edata; 590 break; 591 } 592 } 593 } 594 break; 595 596 default: 597 { 598 unsigned int rlen = len - bytes_read - 1; 599 600 if (op_code >= DW_LNE_lo_user 601 /* The test against DW_LNW_hi_user is redundant due to 602 the limited range of the unsigned char data type used 603 for op_code. */ 604 /*&& op_code <= DW_LNE_hi_user*/) 605 printf (_("user defined: ")); 606 else 607 printf (_("UNKNOWN: ")); 608 printf (_("length %d ["), rlen); 609 for (; rlen; rlen--) 610 printf (" %02x", *data++); 611 printf ("]\n"); 612 } 613 break; 614 } 615 616 return len; 617 } 618 619 static const unsigned char * 620 fetch_indirect_string (dwarf_vma offset) 621 { 622 struct dwarf_section *section = &debug_displays [str].section; 623 624 if (section->start == NULL) 625 return (const unsigned char *) _("<no .debug_str section>"); 626 627 if (offset >= section->size) 628 { 629 warn (_("DW_FORM_strp offset too big: %s\n"), 630 dwarf_vmatoa ("x", offset)); 631 return (const unsigned char *) _("<offset is too big>"); 632 } 633 634 return (const unsigned char *) section->start + offset; 635 } 636 637 static const unsigned char * 638 fetch_indirect_line_string (dwarf_vma offset) 639 { 640 struct dwarf_section *section = &debug_displays [line_str].section; 641 642 if (section->start == NULL) 643 return (const unsigned char *) _("<no .debug_line_str section>"); 644 645 if (offset >= section->size) 646 { 647 warn (_("DW_FORM_line_strp offset too big: %s\n"), 648 dwarf_vmatoa ("x", offset)); 649 return (const unsigned char *) _("<offset is too big>"); 650 } 651 652 return (const unsigned char *) section->start + offset; 653 } 654 655 static const char * 656 fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, 657 dwarf_vma offset_size, int dwo) 658 { 659 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; 660 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; 661 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; 662 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; 663 dwarf_vma index_offset = idx * offset_size; 664 dwarf_vma str_offset; 665 666 if (index_section->start == NULL) 667 return (dwo ? _("<no .debug_str_offsets.dwo section>") 668 : _("<no .debug_str_offsets section>")); 669 670 if (this_set != NULL) 671 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; 672 if (index_offset + offset_size > index_section->size) 673 { 674 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"), 675 dwarf_vmatoa ("x", index_offset)); 676 return _("<index offset is too big>"); 677 } 678 679 if (str_section->start == NULL) 680 return (dwo ? _("<no .debug_str.dwo section>") 681 : _("<no .debug_str section>")); 682 683 str_offset = byte_get (index_section->start + index_offset, offset_size); 684 str_offset -= str_section->address; 685 if (str_offset >= str_section->size) 686 { 687 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), 688 dwarf_vmatoa ("x", str_offset)); 689 return _("<indirect index offset is too big>"); 690 } 691 692 return (const char *) str_section->start + str_offset; 693 } 694 695 static const char * 696 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) 697 { 698 struct dwarf_section *section = &debug_displays [debug_addr].section; 699 700 if (section->start == NULL) 701 return (_("<no .debug_addr section>")); 702 703 if (offset + bytes > section->size) 704 { 705 warn (_("Offset into section %s too big: %s\n"), 706 section->name, dwarf_vmatoa ("x", offset)); 707 return "<offset too big>"; 708 } 709 710 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); 711 } 712 713 714 /* FIXME: There are better and more efficient ways to handle 715 these structures. For now though, I just want something that 716 is simple to implement. */ 717 typedef struct abbrev_attr 718 { 719 unsigned long attribute; 720 unsigned long form; 721 struct abbrev_attr *next; 722 } 723 abbrev_attr; 724 725 typedef struct abbrev_entry 726 { 727 unsigned long entry; 728 unsigned long tag; 729 int children; 730 struct abbrev_attr *first_attr; 731 struct abbrev_attr *last_attr; 732 struct abbrev_entry *next; 733 } 734 abbrev_entry; 735 736 static abbrev_entry *first_abbrev = NULL; 737 static abbrev_entry *last_abbrev = NULL; 738 739 static void 740 free_abbrevs (void) 741 { 742 abbrev_entry *abbrv; 743 744 for (abbrv = first_abbrev; abbrv;) 745 { 746 abbrev_entry *next_abbrev = abbrv->next; 747 abbrev_attr *attr; 748 749 for (attr = abbrv->first_attr; attr;) 750 { 751 abbrev_attr *next_attr = attr->next; 752 753 free (attr); 754 attr = next_attr; 755 } 756 757 free (abbrv); 758 abbrv = next_abbrev; 759 } 760 761 last_abbrev = first_abbrev = NULL; 762 } 763 764 static void 765 add_abbrev (unsigned long number, unsigned long tag, int children) 766 { 767 abbrev_entry *entry; 768 769 entry = (abbrev_entry *) malloc (sizeof (*entry)); 770 if (entry == NULL) 771 /* ugg */ 772 return; 773 774 entry->entry = number; 775 entry->tag = tag; 776 entry->children = children; 777 entry->first_attr = NULL; 778 entry->last_attr = NULL; 779 entry->next = NULL; 780 781 if (first_abbrev == NULL) 782 first_abbrev = entry; 783 else 784 last_abbrev->next = entry; 785 786 last_abbrev = entry; 787 } 788 789 static void 790 add_abbrev_attr (unsigned long attribute, unsigned long form) 791 { 792 abbrev_attr *attr; 793 794 attr = (abbrev_attr *) malloc (sizeof (*attr)); 795 if (attr == NULL) 796 /* ugg */ 797 return; 798 799 attr->attribute = attribute; 800 attr->form = form; 801 attr->next = NULL; 802 803 if (last_abbrev->first_attr == NULL) 804 last_abbrev->first_attr = attr; 805 else 806 last_abbrev->last_attr->next = attr; 807 808 last_abbrev->last_attr = attr; 809 } 810 811 /* Processes the (partial) contents of a .debug_abbrev section. 812 Returns NULL if the end of the section was encountered. 813 Returns the address after the last byte read if the end of 814 an abbreviation set was found. */ 815 816 static unsigned char * 817 process_abbrev_section (unsigned char *start, unsigned char *end) 818 { 819 if (first_abbrev != NULL) 820 return NULL; 821 822 while (start < end) 823 { 824 unsigned int bytes_read; 825 unsigned long entry; 826 unsigned long tag; 827 unsigned long attribute; 828 int children; 829 830 entry = read_uleb128 (start, & bytes_read, end); 831 start += bytes_read; 832 833 /* A single zero is supposed to end the section according 834 to the standard. If there's more, then signal that to 835 the caller. */ 836 if (start == end) 837 return NULL; 838 if (entry == 0) 839 return start; 840 841 tag = read_uleb128 (start, & bytes_read, end); 842 start += bytes_read; 843 if (start == end) 844 return NULL; 845 846 children = *start++; 847 848 add_abbrev (entry, tag, children); 849 850 do 851 { 852 unsigned long form; 853 854 attribute = read_uleb128 (start, & bytes_read, end); 855 start += bytes_read; 856 if (start == end) 857 break; 858 859 form = read_uleb128 (start, & bytes_read, end); 860 start += bytes_read; 861 if (start == end) 862 break; 863 864 add_abbrev_attr (attribute, form); 865 } 866 while (attribute != 0); 867 } 868 869 /* Report the missing single zero which ends the section. */ 870 error (_(".debug_abbrev section not zero terminated\n")); 871 872 return NULL; 873 } 874 875 static const char * 876 get_TAG_name (unsigned long tag) 877 { 878 const char *name = get_DW_TAG_name ((unsigned int)tag); 879 880 if (name == NULL) 881 { 882 static char buffer[100]; 883 884 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag); 885 return buffer; 886 } 887 888 return name; 889 } 890 891 static const char * 892 get_FORM_name (unsigned long form) 893 { 894 const char *name; 895 896 if (form == 0) 897 return "DW_FORM value: 0"; 898 899 name = get_DW_FORM_name (form); 900 if (name == NULL) 901 { 902 static char buffer[100]; 903 904 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); 905 return buffer; 906 } 907 908 return name; 909 } 910 911 static unsigned char * 912 display_block (unsigned char *data, 913 dwarf_vma length, 914 const unsigned char * const end) 915 { 916 dwarf_vma maxlen; 917 918 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length)); 919 920 maxlen = (dwarf_vma) (end - data); 921 length = length > maxlen ? maxlen : length; 922 923 while (length --) 924 printf ("%lx ", (unsigned long) byte_get (data++, 1)); 925 926 return data; 927 } 928 929 static int 930 decode_location_expression (unsigned char * data, 931 unsigned int pointer_size, 932 unsigned int offset_size, 933 int dwarf_version, 934 dwarf_vma length, 935 dwarf_vma cu_offset, 936 struct dwarf_section * section) 937 { 938 unsigned op; 939 unsigned int bytes_read; 940 dwarf_vma uvalue; 941 dwarf_signed_vma svalue; 942 unsigned char *end = data + length; 943 int need_frame_base = 0; 944 945 while (data < end) 946 { 947 op = *data++; 948 949 switch (op) 950 { 951 case DW_OP_addr: 952 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); 953 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); 954 break; 955 case DW_OP_deref: 956 printf ("DW_OP_deref"); 957 break; 958 case DW_OP_const1u: 959 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); 960 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); 961 break; 962 case DW_OP_const1s: 963 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); 964 printf ("DW_OP_const1s: %ld", (long) svalue); 965 break; 966 case DW_OP_const2u: 967 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); 968 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); 969 break; 970 case DW_OP_const2s: 971 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); 972 printf ("DW_OP_const2s: %ld", (long) svalue); 973 break; 974 case DW_OP_const4u: 975 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); 976 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); 977 break; 978 case DW_OP_const4s: 979 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); 980 printf ("DW_OP_const4s: %ld", (long) svalue); 981 break; 982 case DW_OP_const8u: 983 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); 984 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); 985 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); 986 printf ("%lu", (unsigned long) uvalue); 987 break; 988 case DW_OP_const8s: 989 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); 990 printf ("DW_OP_const8s: %ld ", (long) svalue); 991 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); 992 printf ("%ld", (long) svalue); 993 break; 994 case DW_OP_constu: 995 printf ("DW_OP_constu: %s", 996 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); 997 data += bytes_read; 998 break; 999 case DW_OP_consts: 1000 printf ("DW_OP_consts: %s", 1001 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); 1002 data += bytes_read; 1003 break; 1004 case DW_OP_dup: 1005 printf ("DW_OP_dup"); 1006 break; 1007 case DW_OP_drop: 1008 printf ("DW_OP_drop"); 1009 break; 1010 case DW_OP_over: 1011 printf ("DW_OP_over"); 1012 break; 1013 case DW_OP_pick: 1014 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); 1015 printf ("DW_OP_pick: %ld", (unsigned long) uvalue); 1016 break; 1017 case DW_OP_swap: 1018 printf ("DW_OP_swap"); 1019 break; 1020 case DW_OP_rot: 1021 printf ("DW_OP_rot"); 1022 break; 1023 case DW_OP_xderef: 1024 printf ("DW_OP_xderef"); 1025 break; 1026 case DW_OP_abs: 1027 printf ("DW_OP_abs"); 1028 break; 1029 case DW_OP_and: 1030 printf ("DW_OP_and"); 1031 break; 1032 case DW_OP_div: 1033 printf ("DW_OP_div"); 1034 break; 1035 case DW_OP_minus: 1036 printf ("DW_OP_minus"); 1037 break; 1038 case DW_OP_mod: 1039 printf ("DW_OP_mod"); 1040 break; 1041 case DW_OP_mul: 1042 printf ("DW_OP_mul"); 1043 break; 1044 case DW_OP_neg: 1045 printf ("DW_OP_neg"); 1046 break; 1047 case DW_OP_not: 1048 printf ("DW_OP_not"); 1049 break; 1050 case DW_OP_or: 1051 printf ("DW_OP_or"); 1052 break; 1053 case DW_OP_plus: 1054 printf ("DW_OP_plus"); 1055 break; 1056 case DW_OP_plus_uconst: 1057 printf ("DW_OP_plus_uconst: %s", 1058 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); 1059 data += bytes_read; 1060 break; 1061 case DW_OP_shl: 1062 printf ("DW_OP_shl"); 1063 break; 1064 case DW_OP_shr: 1065 printf ("DW_OP_shr"); 1066 break; 1067 case DW_OP_shra: 1068 printf ("DW_OP_shra"); 1069 break; 1070 case DW_OP_xor: 1071 printf ("DW_OP_xor"); 1072 break; 1073 case DW_OP_bra: 1074 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); 1075 printf ("DW_OP_bra: %ld", (long) svalue); 1076 break; 1077 case DW_OP_eq: 1078 printf ("DW_OP_eq"); 1079 break; 1080 case DW_OP_ge: 1081 printf ("DW_OP_ge"); 1082 break; 1083 case DW_OP_gt: 1084 printf ("DW_OP_gt"); 1085 break; 1086 case DW_OP_le: 1087 printf ("DW_OP_le"); 1088 break; 1089 case DW_OP_lt: 1090 printf ("DW_OP_lt"); 1091 break; 1092 case DW_OP_ne: 1093 printf ("DW_OP_ne"); 1094 break; 1095 case DW_OP_skip: 1096 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); 1097 printf ("DW_OP_skip: %ld", (long) svalue); 1098 break; 1099 1100 case DW_OP_lit0: 1101 case DW_OP_lit1: 1102 case DW_OP_lit2: 1103 case DW_OP_lit3: 1104 case DW_OP_lit4: 1105 case DW_OP_lit5: 1106 case DW_OP_lit6: 1107 case DW_OP_lit7: 1108 case DW_OP_lit8: 1109 case DW_OP_lit9: 1110 case DW_OP_lit10: 1111 case DW_OP_lit11: 1112 case DW_OP_lit12: 1113 case DW_OP_lit13: 1114 case DW_OP_lit14: 1115 case DW_OP_lit15: 1116 case DW_OP_lit16: 1117 case DW_OP_lit17: 1118 case DW_OP_lit18: 1119 case DW_OP_lit19: 1120 case DW_OP_lit20: 1121 case DW_OP_lit21: 1122 case DW_OP_lit22: 1123 case DW_OP_lit23: 1124 case DW_OP_lit24: 1125 case DW_OP_lit25: 1126 case DW_OP_lit26: 1127 case DW_OP_lit27: 1128 case DW_OP_lit28: 1129 case DW_OP_lit29: 1130 case DW_OP_lit30: 1131 case DW_OP_lit31: 1132 printf ("DW_OP_lit%d", op - DW_OP_lit0); 1133 break; 1134 1135 case DW_OP_reg0: 1136 case DW_OP_reg1: 1137 case DW_OP_reg2: 1138 case DW_OP_reg3: 1139 case DW_OP_reg4: 1140 case DW_OP_reg5: 1141 case DW_OP_reg6: 1142 case DW_OP_reg7: 1143 case DW_OP_reg8: 1144 case DW_OP_reg9: 1145 case DW_OP_reg10: 1146 case DW_OP_reg11: 1147 case DW_OP_reg12: 1148 case DW_OP_reg13: 1149 case DW_OP_reg14: 1150 case DW_OP_reg15: 1151 case DW_OP_reg16: 1152 case DW_OP_reg17: 1153 case DW_OP_reg18: 1154 case DW_OP_reg19: 1155 case DW_OP_reg20: 1156 case DW_OP_reg21: 1157 case DW_OP_reg22: 1158 case DW_OP_reg23: 1159 case DW_OP_reg24: 1160 case DW_OP_reg25: 1161 case DW_OP_reg26: 1162 case DW_OP_reg27: 1163 case DW_OP_reg28: 1164 case DW_OP_reg29: 1165 case DW_OP_reg30: 1166 case DW_OP_reg31: 1167 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, 1168 regname (op - DW_OP_reg0, 1)); 1169 break; 1170 1171 case DW_OP_breg0: 1172 case DW_OP_breg1: 1173 case DW_OP_breg2: 1174 case DW_OP_breg3: 1175 case DW_OP_breg4: 1176 case DW_OP_breg5: 1177 case DW_OP_breg6: 1178 case DW_OP_breg7: 1179 case DW_OP_breg8: 1180 case DW_OP_breg9: 1181 case DW_OP_breg10: 1182 case DW_OP_breg11: 1183 case DW_OP_breg12: 1184 case DW_OP_breg13: 1185 case DW_OP_breg14: 1186 case DW_OP_breg15: 1187 case DW_OP_breg16: 1188 case DW_OP_breg17: 1189 case DW_OP_breg18: 1190 case DW_OP_breg19: 1191 case DW_OP_breg20: 1192 case DW_OP_breg21: 1193 case DW_OP_breg22: 1194 case DW_OP_breg23: 1195 case DW_OP_breg24: 1196 case DW_OP_breg25: 1197 case DW_OP_breg26: 1198 case DW_OP_breg27: 1199 case DW_OP_breg28: 1200 case DW_OP_breg29: 1201 case DW_OP_breg30: 1202 case DW_OP_breg31: 1203 printf ("DW_OP_breg%d (%s): %s", 1204 op - DW_OP_breg0, 1205 regname (op - DW_OP_breg0, 1), 1206 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); 1207 data += bytes_read; 1208 break; 1209 1210 case DW_OP_regx: 1211 uvalue = read_uleb128 (data, &bytes_read, end); 1212 data += bytes_read; 1213 printf ("DW_OP_regx: %s (%s)", 1214 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); 1215 break; 1216 case DW_OP_fbreg: 1217 need_frame_base = 1; 1218 printf ("DW_OP_fbreg: %s", 1219 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); 1220 data += bytes_read; 1221 break; 1222 case DW_OP_bregx: 1223 uvalue = read_uleb128 (data, &bytes_read, end); 1224 data += bytes_read; 1225 printf ("DW_OP_bregx: %s (%s) %s", 1226 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), 1227 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); 1228 data += bytes_read; 1229 break; 1230 case DW_OP_piece: 1231 printf ("DW_OP_piece: %s", 1232 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); 1233 data += bytes_read; 1234 break; 1235 case DW_OP_deref_size: 1236 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); 1237 printf ("DW_OP_deref_size: %ld", (long) uvalue); 1238 break; 1239 case DW_OP_xderef_size: 1240 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); 1241 printf ("DW_OP_xderef_size: %ld", (long) uvalue); 1242 break; 1243 case DW_OP_nop: 1244 printf ("DW_OP_nop"); 1245 break; 1246 1247 /* DWARF 3 extensions. */ 1248 case DW_OP_push_object_address: 1249 printf ("DW_OP_push_object_address"); 1250 break; 1251 case DW_OP_call2: 1252 /* XXX: Strictly speaking for 64-bit DWARF3 files 1253 this ought to be an 8-byte wide computation. */ 1254 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); 1255 printf ("DW_OP_call2: <0x%s>", 1256 dwarf_vmatoa ("x", svalue + cu_offset)); 1257 break; 1258 case DW_OP_call4: 1259 /* XXX: Strictly speaking for 64-bit DWARF3 files 1260 this ought to be an 8-byte wide computation. */ 1261 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); 1262 printf ("DW_OP_call4: <0x%s>", 1263 dwarf_vmatoa ("x", svalue + cu_offset)); 1264 break; 1265 case DW_OP_call_ref: 1266 /* XXX: Strictly speaking for 64-bit DWARF3 files 1267 this ought to be an 8-byte wide computation. */ 1268 if (dwarf_version == -1) 1269 { 1270 printf (_("(DW_OP_call_ref in frame info)")); 1271 /* No way to tell where the next op is, so just bail. */ 1272 return need_frame_base; 1273 } 1274 if (dwarf_version == 2) 1275 { 1276 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); 1277 } 1278 else 1279 { 1280 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); 1281 } 1282 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); 1283 break; 1284 case DW_OP_form_tls_address: 1285 printf ("DW_OP_form_tls_address"); 1286 break; 1287 case DW_OP_call_frame_cfa: 1288 printf ("DW_OP_call_frame_cfa"); 1289 break; 1290 case DW_OP_bit_piece: 1291 printf ("DW_OP_bit_piece: "); 1292 printf (_("size: %s "), 1293 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); 1294 data += bytes_read; 1295 printf (_("offset: %s "), 1296 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); 1297 data += bytes_read; 1298 break; 1299 1300 /* DWARF 4 extensions. */ 1301 case DW_OP_stack_value: 1302 printf ("DW_OP_stack_value"); 1303 break; 1304 1305 case DW_OP_implicit_value: 1306 printf ("DW_OP_implicit_value"); 1307 uvalue = read_uleb128 (data, &bytes_read, end); 1308 data += bytes_read; 1309 display_block (data, uvalue, end); 1310 data += uvalue; 1311 break; 1312 1313 /* GNU extensions. */ 1314 case DW_OP_GNU_push_tls_address: 1315 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); 1316 break; 1317 case DW_OP_GNU_uninit: 1318 printf ("DW_OP_GNU_uninit"); 1319 /* FIXME: Is there data associated with this OP ? */ 1320 break; 1321 case DW_OP_GNU_encoded_addr: 1322 { 1323 int encoding; 1324 dwarf_vma addr; 1325 1326 encoding = *data++; 1327 addr = get_encoded_value (&data, encoding, section, end); 1328 1329 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); 1330 print_dwarf_vma (addr, pointer_size); 1331 } 1332 break; 1333 case DW_OP_GNU_implicit_pointer: 1334 /* XXX: Strictly speaking for 64-bit DWARF3 files 1335 this ought to be an 8-byte wide computation. */ 1336 if (dwarf_version == -1) 1337 { 1338 printf (_("(DW_OP_GNU_implicit_pointer in frame info)")); 1339 /* No way to tell where the next op is, so just bail. */ 1340 return need_frame_base; 1341 } 1342 if (dwarf_version == 2) 1343 { 1344 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); 1345 } 1346 else 1347 { 1348 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); 1349 } 1350 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s", 1351 dwarf_vmatoa ("x", uvalue), 1352 dwarf_vmatoa ("d", read_sleb128 (data, 1353 &bytes_read, end))); 1354 data += bytes_read; 1355 break; 1356 case DW_OP_GNU_entry_value: 1357 uvalue = read_uleb128 (data, &bytes_read, end); 1358 data += bytes_read; 1359 printf ("DW_OP_GNU_entry_value: ("); 1360 if (decode_location_expression (data, pointer_size, offset_size, 1361 dwarf_version, uvalue, 1362 cu_offset, section)) 1363 need_frame_base = 1; 1364 putchar (')'); 1365 data += uvalue; 1366 break; 1367 case DW_OP_GNU_const_type: 1368 uvalue = read_uleb128 (data, &bytes_read, end); 1369 data += bytes_read; 1370 printf ("DW_OP_GNU_const_type: <0x%s> ", 1371 dwarf_vmatoa ("x", cu_offset + uvalue)); 1372 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); 1373 display_block (data, uvalue, end); 1374 data += uvalue; 1375 break; 1376 case DW_OP_GNU_regval_type: 1377 uvalue = read_uleb128 (data, &bytes_read, end); 1378 data += bytes_read; 1379 printf ("DW_OP_GNU_regval_type: %s (%s)", 1380 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); 1381 uvalue = read_uleb128 (data, &bytes_read, end); 1382 data += bytes_read; 1383 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); 1384 break; 1385 case DW_OP_GNU_deref_type: 1386 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); 1387 printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue); 1388 uvalue = read_uleb128 (data, &bytes_read, end); 1389 data += bytes_read; 1390 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); 1391 break; 1392 case DW_OP_GNU_convert: 1393 uvalue = read_uleb128 (data, &bytes_read, end); 1394 data += bytes_read; 1395 printf ("DW_OP_GNU_convert <0x%s>", 1396 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); 1397 break; 1398 case DW_OP_GNU_reinterpret: 1399 uvalue = read_uleb128 (data, &bytes_read, end); 1400 data += bytes_read; 1401 printf ("DW_OP_GNU_reinterpret <0x%s>", 1402 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); 1403 break; 1404 case DW_OP_GNU_parameter_ref: 1405 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); 1406 printf ("DW_OP_GNU_parameter_ref: <0x%s>", 1407 dwarf_vmatoa ("x", cu_offset + uvalue)); 1408 break; 1409 case DW_OP_GNU_addr_index: 1410 uvalue = read_uleb128 (data, &bytes_read, end); 1411 data += bytes_read; 1412 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); 1413 break; 1414 case DW_OP_GNU_const_index: 1415 uvalue = read_uleb128 (data, &bytes_read, end); 1416 data += bytes_read; 1417 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); 1418 break; 1419 1420 /* HP extensions. */ 1421 case DW_OP_HP_is_value: 1422 printf ("DW_OP_HP_is_value"); 1423 /* FIXME: Is there data associated with this OP ? */ 1424 break; 1425 case DW_OP_HP_fltconst4: 1426 printf ("DW_OP_HP_fltconst4"); 1427 /* FIXME: Is there data associated with this OP ? */ 1428 break; 1429 case DW_OP_HP_fltconst8: 1430 printf ("DW_OP_HP_fltconst8"); 1431 /* FIXME: Is there data associated with this OP ? */ 1432 break; 1433 case DW_OP_HP_mod_range: 1434 printf ("DW_OP_HP_mod_range"); 1435 /* FIXME: Is there data associated with this OP ? */ 1436 break; 1437 case DW_OP_HP_unmod_range: 1438 printf ("DW_OP_HP_unmod_range"); 1439 /* FIXME: Is there data associated with this OP ? */ 1440 break; 1441 case DW_OP_HP_tls: 1442 printf ("DW_OP_HP_tls"); 1443 /* FIXME: Is there data associated with this OP ? */ 1444 break; 1445 1446 /* PGI (STMicroelectronics) extensions. */ 1447 case DW_OP_PGI_omp_thread_num: 1448 /* Pushes the thread number for the current thread as it would be 1449 returned by the standard OpenMP library function: 1450 omp_get_thread_num(). The "current thread" is the thread for 1451 which the expression is being evaluated. */ 1452 printf ("DW_OP_PGI_omp_thread_num"); 1453 break; 1454 1455 default: 1456 if (op >= DW_OP_lo_user 1457 && op <= DW_OP_hi_user) 1458 printf (_("(User defined location op)")); 1459 else 1460 printf (_("(Unknown location op)")); 1461 /* No way to tell where the next op is, so just bail. */ 1462 return need_frame_base; 1463 } 1464 1465 /* Separate the ops. */ 1466 if (data < end) 1467 printf ("; "); 1468 } 1469 1470 return need_frame_base; 1471 } 1472 1473 /* Find the CU or TU set corresponding to the given CU_OFFSET. 1474 This is used for DWARF package files. */ 1475 1476 static struct cu_tu_set * 1477 find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) 1478 { 1479 struct cu_tu_set *p; 1480 unsigned int nsets; 1481 unsigned int dw_sect; 1482 1483 if (do_types) 1484 { 1485 p = tu_sets; 1486 nsets = tu_count; 1487 dw_sect = DW_SECT_TYPES; 1488 } 1489 else 1490 { 1491 p = cu_sets; 1492 nsets = cu_count; 1493 dw_sect = DW_SECT_INFO; 1494 } 1495 while (nsets > 0) 1496 { 1497 if (p->section_offsets [dw_sect] == cu_offset) 1498 return p; 1499 p++; 1500 nsets--; 1501 } 1502 return NULL; 1503 } 1504 1505 /* Add INC to HIGH_BITS:LOW_BITS. */ 1506 static void 1507 add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) 1508 { 1509 dwarf_vma tmp = * low_bits; 1510 1511 tmp += inc; 1512 1513 /* FIXME: There is probably a better way of handling this: 1514 1515 We need to cope with dwarf_vma being a 32-bit or 64-bit 1516 type. Plus regardless of its size LOW_BITS is meant to 1517 only hold 32-bits, so if there is overflow or wrap around 1518 we must propagate into HIGH_BITS. */ 1519 if (tmp < * low_bits) 1520 { 1521 ++ * high_bits; 1522 } 1523 else if (sizeof (tmp) > 8 1524 && (tmp >> 31) > 1) 1525 { 1526 ++ * high_bits; 1527 tmp &= 0xFFFFFFFF; 1528 } 1529 1530 * low_bits = tmp; 1531 } 1532 1533 static unsigned char * 1534 read_and_display_attr_value (unsigned long attribute, 1535 unsigned long form, 1536 unsigned char * data, 1537 unsigned char * end, 1538 dwarf_vma cu_offset, 1539 dwarf_vma pointer_size, 1540 dwarf_vma offset_size, 1541 int dwarf_version, 1542 debug_info * debug_info_p, 1543 int do_loc, 1544 struct dwarf_section * section, 1545 struct cu_tu_set * this_set) 1546 { 1547 dwarf_vma uvalue = 0; 1548 unsigned char *block_start = NULL; 1549 unsigned char * orig_data = data; 1550 unsigned int bytes_read; 1551 1552 if (data > end || (data == end && form != DW_FORM_flag_present)) 1553 { 1554 warn (_("Corrupt attribute\n")); 1555 return data; 1556 } 1557 1558 switch (form) 1559 { 1560 default: 1561 break; 1562 1563 case DW_FORM_ref_addr: 1564 if (dwarf_version == 2) 1565 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); 1566 else if (dwarf_version == 3 || dwarf_version == 4) 1567 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); 1568 else 1569 error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); 1570 1571 break; 1572 1573 case DW_FORM_addr: 1574 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); 1575 break; 1576 1577 case DW_FORM_strp: 1578 case DW_FORM_sec_offset: 1579 case DW_FORM_GNU_ref_alt: 1580 case DW_FORM_GNU_strp_alt: 1581 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); 1582 break; 1583 1584 case DW_FORM_flag_present: 1585 uvalue = 1; 1586 break; 1587 1588 case DW_FORM_ref1: 1589 case DW_FORM_flag: 1590 case DW_FORM_data1: 1591 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); 1592 break; 1593 1594 case DW_FORM_ref2: 1595 case DW_FORM_data2: 1596 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); 1597 break; 1598 1599 case DW_FORM_ref4: 1600 case DW_FORM_data4: 1601 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); 1602 break; 1603 1604 case DW_FORM_sdata: 1605 uvalue = read_sleb128 (data, & bytes_read, end); 1606 data += bytes_read; 1607 break; 1608 1609 case DW_FORM_GNU_str_index: 1610 uvalue = read_uleb128 (data, & bytes_read, end); 1611 data += bytes_read; 1612 break; 1613 1614 case DW_FORM_ref_udata: 1615 case DW_FORM_udata: 1616 uvalue = read_uleb128 (data, & bytes_read, end); 1617 data += bytes_read; 1618 break; 1619 1620 case DW_FORM_indirect: 1621 form = read_uleb128 (data, & bytes_read, end); 1622 data += bytes_read; 1623 if (!do_loc) 1624 printf (" %s", get_FORM_name (form)); 1625 return read_and_display_attr_value (attribute, form, data, end, 1626 cu_offset, pointer_size, 1627 offset_size, dwarf_version, 1628 debug_info_p, do_loc, 1629 section, this_set); 1630 case DW_FORM_GNU_addr_index: 1631 uvalue = read_uleb128 (data, & bytes_read, end); 1632 data += bytes_read; 1633 break; 1634 } 1635 1636 switch (form) 1637 { 1638 case DW_FORM_ref_addr: 1639 if (!do_loc) 1640 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue)); 1641 break; 1642 1643 case DW_FORM_GNU_ref_alt: 1644 if (!do_loc) 1645 printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue)); 1646 break; 1647 1648 case DW_FORM_ref1: 1649 case DW_FORM_ref2: 1650 case DW_FORM_ref4: 1651 case DW_FORM_ref_udata: 1652 if (!do_loc) 1653 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset)); 1654 break; 1655 1656 case DW_FORM_data4: 1657 case DW_FORM_addr: 1658 case DW_FORM_sec_offset: 1659 if (!do_loc) 1660 printf (" 0x%s", dwarf_vmatoa ("x", uvalue)); 1661 break; 1662 1663 case DW_FORM_flag_present: 1664 case DW_FORM_flag: 1665 case DW_FORM_data1: 1666 case DW_FORM_data2: 1667 case DW_FORM_sdata: 1668 case DW_FORM_udata: 1669 if (!do_loc) 1670 printf (" %s", dwarf_vmatoa ("d", uvalue)); 1671 break; 1672 1673 case DW_FORM_ref8: 1674 case DW_FORM_data8: 1675 if (!do_loc) 1676 { 1677 dwarf_vma high_bits; 1678 dwarf_vma utmp; 1679 char buf[64]; 1680 1681 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); 1682 utmp = uvalue; 1683 if (form == DW_FORM_ref8) 1684 add64 (& high_bits, & utmp, cu_offset); 1685 printf (" 0x%s", 1686 dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); 1687 } 1688 1689 if ((do_loc || do_debug_loc || do_debug_ranges) 1690 && num_debug_info_entries == 0) 1691 { 1692 if (sizeof (uvalue) == 8) 1693 SAFE_BYTE_GET (uvalue, data, 8, end); 1694 else 1695 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); 1696 } 1697 1698 data += 8; 1699 break; 1700 1701 case DW_FORM_string: 1702 if (!do_loc) 1703 printf (" %.*s", (int) (end - data), data); 1704 data += strnlen ((char *) data, end - data) + 1; 1705 break; 1706 1707 case DW_FORM_block: 1708 case DW_FORM_exprloc: 1709 uvalue = read_uleb128 (data, & bytes_read, end); 1710 block_start = data + bytes_read; 1711 /* PR 17512: file: 008-103549-0.001:0.1. */ 1712 if (block_start + uvalue > end) 1713 { 1714 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); 1715 uvalue = end - block_start; 1716 } 1717 if (do_loc) 1718 data = block_start + uvalue; 1719 else 1720 data = display_block (block_start, uvalue, end); 1721 break; 1722 1723 case DW_FORM_block1: 1724 SAFE_BYTE_GET (uvalue, data, 1, end); 1725 block_start = data + 1; 1726 if (block_start + uvalue > end) 1727 { 1728 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); 1729 uvalue = end - block_start; 1730 } 1731 if (do_loc) 1732 data = block_start + uvalue; 1733 else 1734 data = display_block (block_start, uvalue, end); 1735 break; 1736 1737 case DW_FORM_block2: 1738 SAFE_BYTE_GET (uvalue, data, 2, end); 1739 block_start = data + 2; 1740 if (block_start + uvalue > end) 1741 { 1742 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); 1743 uvalue = end - block_start; 1744 } 1745 if (do_loc) 1746 data = block_start + uvalue; 1747 else 1748 data = display_block (block_start, uvalue, end); 1749 break; 1750 1751 case DW_FORM_block4: 1752 SAFE_BYTE_GET (uvalue, data, 4, end); 1753 block_start = data + 4; 1754 if (block_start + uvalue > end) 1755 { 1756 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); 1757 uvalue = end - block_start; 1758 } 1759 if (do_loc) 1760 data = block_start + uvalue; 1761 else 1762 data = display_block (block_start, uvalue, end); 1763 break; 1764 1765 case DW_FORM_strp: 1766 if (!do_loc) 1767 printf (_(" (indirect string, offset: 0x%s): %s"), 1768 dwarf_vmatoa ("x", uvalue), 1769 fetch_indirect_string (uvalue)); 1770 break; 1771 1772 case DW_FORM_GNU_str_index: 1773 if (!do_loc) 1774 { 1775 const char *suffix = strrchr (section->name, '.'); 1776 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0; 1777 1778 printf (_(" (indexed string: 0x%s): %s"), 1779 dwarf_vmatoa ("x", uvalue), 1780 fetch_indexed_string (uvalue, this_set, offset_size, dwo)); 1781 } 1782 break; 1783 1784 case DW_FORM_GNU_strp_alt: 1785 if (!do_loc) 1786 printf (_(" (alt indirect string, offset: 0x%s)"), 1787 dwarf_vmatoa ("x", uvalue)); 1788 break; 1789 1790 case DW_FORM_indirect: 1791 /* Handled above. */ 1792 break; 1793 1794 case DW_FORM_ref_sig8: 1795 if (!do_loc) 1796 { 1797 dwarf_vma high_bits; 1798 char buf[64]; 1799 1800 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); 1801 printf (" signature: 0x%s", 1802 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); 1803 } 1804 data += 8; 1805 break; 1806 1807 case DW_FORM_GNU_addr_index: 1808 if (!do_loc) 1809 printf (_(" (addr_index: 0x%s): %s"), 1810 dwarf_vmatoa ("x", uvalue), 1811 fetch_indexed_value (uvalue * pointer_size, pointer_size)); 1812 break; 1813 1814 default: 1815 warn (_("Unrecognized form: %lu\n"), form); 1816 break; 1817 } 1818 1819 if ((do_loc || do_debug_loc || do_debug_ranges) 1820 && num_debug_info_entries == 0 1821 && debug_info_p != NULL) 1822 { 1823 switch (attribute) 1824 { 1825 case DW_AT_frame_base: 1826 have_frame_base = 1; 1827 case DW_AT_location: 1828 case DW_AT_string_length: 1829 case DW_AT_return_addr: 1830 case DW_AT_data_member_location: 1831 case DW_AT_vtable_elem_location: 1832 case DW_AT_segment: 1833 case DW_AT_static_link: 1834 case DW_AT_use_location: 1835 case DW_AT_GNU_call_site_value: 1836 case DW_AT_GNU_call_site_data_value: 1837 case DW_AT_GNU_call_site_target: 1838 case DW_AT_GNU_call_site_target_clobbered: 1839 if ((dwarf_version < 4 1840 && (form == DW_FORM_data4 || form == DW_FORM_data8)) 1841 || form == DW_FORM_sec_offset) 1842 { 1843 /* Process location list. */ 1844 unsigned int lmax = debug_info_p->max_loc_offsets; 1845 unsigned int num = debug_info_p->num_loc_offsets; 1846 1847 if (lmax == 0 || num >= lmax) 1848 { 1849 lmax += 1024; 1850 debug_info_p->loc_offsets = (dwarf_vma *) 1851 xcrealloc (debug_info_p->loc_offsets, 1852 lmax, sizeof (*debug_info_p->loc_offsets)); 1853 debug_info_p->have_frame_base = (int *) 1854 xcrealloc (debug_info_p->have_frame_base, 1855 lmax, sizeof (*debug_info_p->have_frame_base)); 1856 debug_info_p->max_loc_offsets = lmax; 1857 } 1858 if (this_set != NULL) 1859 uvalue += this_set->section_offsets [DW_SECT_LOC]; 1860 debug_info_p->loc_offsets [num] = uvalue; 1861 debug_info_p->have_frame_base [num] = have_frame_base; 1862 debug_info_p->num_loc_offsets++; 1863 } 1864 break; 1865 1866 case DW_AT_low_pc: 1867 if (need_base_address) 1868 debug_info_p->base_address = uvalue; 1869 break; 1870 1871 case DW_AT_GNU_addr_base: 1872 debug_info_p->addr_base = uvalue; 1873 break; 1874 1875 case DW_AT_GNU_ranges_base: 1876 debug_info_p->ranges_base = uvalue; 1877 break; 1878 1879 case DW_AT_ranges: 1880 if ((dwarf_version < 4 1881 && (form == DW_FORM_data4 || form == DW_FORM_data8)) 1882 || form == DW_FORM_sec_offset) 1883 { 1884 /* Process range list. */ 1885 unsigned int lmax = debug_info_p->max_range_lists; 1886 unsigned int num = debug_info_p->num_range_lists; 1887 1888 if (lmax == 0 || num >= lmax) 1889 { 1890 lmax += 1024; 1891 debug_info_p->range_lists = (dwarf_vma *) 1892 xcrealloc (debug_info_p->range_lists, 1893 lmax, sizeof (*debug_info_p->range_lists)); 1894 debug_info_p->max_range_lists = lmax; 1895 } 1896 debug_info_p->range_lists [num] = uvalue; 1897 debug_info_p->num_range_lists++; 1898 } 1899 break; 1900 1901 default: 1902 break; 1903 } 1904 } 1905 1906 if (do_loc || attribute == 0) 1907 return data; 1908 1909 /* For some attributes we can display further information. */ 1910 switch (attribute) 1911 { 1912 case DW_AT_inline: 1913 printf ("\t"); 1914 switch (uvalue) 1915 { 1916 case DW_INL_not_inlined: 1917 printf (_("(not inlined)")); 1918 break; 1919 case DW_INL_inlined: 1920 printf (_("(inlined)")); 1921 break; 1922 case DW_INL_declared_not_inlined: 1923 printf (_("(declared as inline but ignored)")); 1924 break; 1925 case DW_INL_declared_inlined: 1926 printf (_("(declared as inline and inlined)")); 1927 break; 1928 default: 1929 printf (_(" (Unknown inline attribute value: %s)"), 1930 dwarf_vmatoa ("x", uvalue)); 1931 break; 1932 } 1933 break; 1934 1935 case DW_AT_language: 1936 printf ("\t"); 1937 switch (uvalue) 1938 { 1939 /* Ordered by the numeric value of these constants. */ 1940 case DW_LANG_C89: printf ("(ANSI C)"); break; 1941 case DW_LANG_C: printf ("(non-ANSI C)"); break; 1942 case DW_LANG_Ada83: printf ("(Ada)"); break; 1943 case DW_LANG_C_plus_plus: printf ("(C++)"); break; 1944 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; 1945 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; 1946 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; 1947 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; 1948 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; 1949 case DW_LANG_Modula2: printf ("(Modula 2)"); break; 1950 /* DWARF 2.1 values. */ 1951 case DW_LANG_Java: printf ("(Java)"); break; 1952 case DW_LANG_C99: printf ("(ANSI C99)"); break; 1953 case DW_LANG_Ada95: printf ("(ADA 95)"); break; 1954 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; 1955 /* DWARF 3 values. */ 1956 case DW_LANG_PLI: printf ("(PLI)"); break; 1957 case DW_LANG_ObjC: printf ("(Objective C)"); break; 1958 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; 1959 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; 1960 case DW_LANG_D: printf ("(D)"); break; 1961 /* DWARF 4 values. */ 1962 case DW_LANG_Python: printf ("(Python)"); break; 1963 /* DWARF 5 values. */ 1964 case DW_LANG_Go: printf ("(Go)"); break; 1965 /* MIPS extension. */ 1966 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; 1967 /* UPC extension. */ 1968 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; 1969 default: 1970 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) 1971 printf (_("(implementation defined: %s)"), 1972 dwarf_vmatoa ("x", uvalue)); 1973 else 1974 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); 1975 break; 1976 } 1977 break; 1978 1979 case DW_AT_encoding: 1980 printf ("\t"); 1981 switch (uvalue) 1982 { 1983 case DW_ATE_void: printf ("(void)"); break; 1984 case DW_ATE_address: printf ("(machine address)"); break; 1985 case DW_ATE_boolean: printf ("(boolean)"); break; 1986 case DW_ATE_complex_float: printf ("(complex float)"); break; 1987 case DW_ATE_float: printf ("(float)"); break; 1988 case DW_ATE_signed: printf ("(signed)"); break; 1989 case DW_ATE_signed_char: printf ("(signed char)"); break; 1990 case DW_ATE_unsigned: printf ("(unsigned)"); break; 1991 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; 1992 /* DWARF 2.1 values: */ 1993 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; 1994 case DW_ATE_decimal_float: printf ("(decimal float)"); break; 1995 /* DWARF 3 values: */ 1996 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; 1997 case DW_ATE_numeric_string: printf ("(numeric_string)"); break; 1998 case DW_ATE_edited: printf ("(edited)"); break; 1999 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; 2000 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; 2001 /* HP extensions: */ 2002 case DW_ATE_HP_float80: printf ("(HP_float80)"); break; 2003 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; 2004 case DW_ATE_HP_float128: printf ("(HP_float128)"); break; 2005 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; 2006 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; 2007 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; 2008 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; 2009 2010 default: 2011 if (uvalue >= DW_ATE_lo_user 2012 && uvalue <= DW_ATE_hi_user) 2013 printf (_("(user defined type)")); 2014 else 2015 printf (_("(unknown type)")); 2016 break; 2017 } 2018 break; 2019 2020 case DW_AT_accessibility: 2021 printf ("\t"); 2022 switch (uvalue) 2023 { 2024 case DW_ACCESS_public: printf ("(public)"); break; 2025 case DW_ACCESS_protected: printf ("(protected)"); break; 2026 case DW_ACCESS_private: printf ("(private)"); break; 2027 default: 2028 printf (_("(unknown accessibility)")); 2029 break; 2030 } 2031 break; 2032 2033 case DW_AT_visibility: 2034 printf ("\t"); 2035 switch (uvalue) 2036 { 2037 case DW_VIS_local: printf ("(local)"); break; 2038 case DW_VIS_exported: printf ("(exported)"); break; 2039 case DW_VIS_qualified: printf ("(qualified)"); break; 2040 default: printf (_("(unknown visibility)")); break; 2041 } 2042 break; 2043 2044 case DW_AT_virtuality: 2045 printf ("\t"); 2046 switch (uvalue) 2047 { 2048 case DW_VIRTUALITY_none: printf ("(none)"); break; 2049 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; 2050 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; 2051 default: printf (_("(unknown virtuality)")); break; 2052 } 2053 break; 2054 2055 case DW_AT_identifier_case: 2056 printf ("\t"); 2057 switch (uvalue) 2058 { 2059 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; 2060 case DW_ID_up_case: printf ("(up_case)"); break; 2061 case DW_ID_down_case: printf ("(down_case)"); break; 2062 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; 2063 default: printf (_("(unknown case)")); break; 2064 } 2065 break; 2066 2067 case DW_AT_calling_convention: 2068 printf ("\t"); 2069 switch (uvalue) 2070 { 2071 case DW_CC_normal: printf ("(normal)"); break; 2072 case DW_CC_program: printf ("(program)"); break; 2073 case DW_CC_nocall: printf ("(nocall)"); break; 2074 default: 2075 if (uvalue >= DW_CC_lo_user 2076 && uvalue <= DW_CC_hi_user) 2077 printf (_("(user defined)")); 2078 else 2079 printf (_("(unknown convention)")); 2080 } 2081 break; 2082 2083 case DW_AT_ordering: 2084 printf ("\t"); 2085 switch (uvalue) 2086 { 2087 case -1: printf (_("(undefined)")); break; 2088 case 0: printf ("(row major)"); break; 2089 case 1: printf ("(column major)"); break; 2090 } 2091 break; 2092 2093 case DW_AT_frame_base: 2094 have_frame_base = 1; 2095 case DW_AT_location: 2096 case DW_AT_string_length: 2097 case DW_AT_return_addr: 2098 case DW_AT_data_member_location: 2099 case DW_AT_vtable_elem_location: 2100 case DW_AT_segment: 2101 case DW_AT_static_link: 2102 case DW_AT_use_location: 2103 case DW_AT_GNU_call_site_value: 2104 case DW_AT_GNU_call_site_data_value: 2105 case DW_AT_GNU_call_site_target: 2106 case DW_AT_GNU_call_site_target_clobbered: 2107 if ((dwarf_version < 4 2108 && (form == DW_FORM_data4 || form == DW_FORM_data8)) 2109 || form == DW_FORM_sec_offset) 2110 printf (_(" (location list)")); 2111 /* Fall through. */ 2112 case DW_AT_allocated: 2113 case DW_AT_associated: 2114 case DW_AT_data_location: 2115 case DW_AT_stride: 2116 case DW_AT_upper_bound: 2117 case DW_AT_lower_bound: 2118 if (block_start) 2119 { 2120 int need_frame_base; 2121 2122 printf ("\t("); 2123 need_frame_base = decode_location_expression (block_start, 2124 pointer_size, 2125 offset_size, 2126 dwarf_version, 2127 uvalue, 2128 cu_offset, section); 2129 printf (")"); 2130 if (need_frame_base && !have_frame_base) 2131 printf (_(" [without DW_AT_frame_base]")); 2132 } 2133 break; 2134 2135 case DW_AT_import: 2136 { 2137 if (form == DW_FORM_ref_sig8 2138 || form == DW_FORM_GNU_ref_alt) 2139 break; 2140 2141 if (form == DW_FORM_ref1 2142 || form == DW_FORM_ref2 2143 || form == DW_FORM_ref4 2144 || form == DW_FORM_ref_udata) 2145 uvalue += cu_offset; 2146 2147 if (uvalue >= section->size) 2148 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"), 2149 dwarf_vmatoa ("x", uvalue), 2150 (unsigned long) (orig_data - section->start)); 2151 else 2152 { 2153 unsigned long abbrev_number; 2154 abbrev_entry * entry; 2155 2156 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end); 2157 2158 printf (_("\t[Abbrev Number: %ld"), abbrev_number); 2159 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will 2160 use different abbrev table, and we don't track .debug_info chunks 2161 yet. */ 2162 if (form != DW_FORM_ref_addr) 2163 { 2164 for (entry = first_abbrev; entry != NULL; entry = entry->next) 2165 if (entry->entry == abbrev_number) 2166 break; 2167 if (entry != NULL) 2168 printf (" (%s)", get_TAG_name (entry->tag)); 2169 } 2170 printf ("]"); 2171 } 2172 } 2173 break; 2174 2175 default: 2176 break; 2177 } 2178 2179 return data; 2180 } 2181 2182 static const char * 2183 get_AT_name (unsigned long attribute) 2184 { 2185 const char *name; 2186 2187 if (attribute == 0) 2188 return "DW_AT value: 0"; 2189 2190 /* One value is shared by the MIPS and HP extensions: */ 2191 if (attribute == DW_AT_MIPS_fde) 2192 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; 2193 2194 name = get_DW_AT_name (attribute); 2195 2196 if (name == NULL) 2197 { 2198 static char buffer[100]; 2199 2200 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), 2201 attribute); 2202 return buffer; 2203 } 2204 2205 return name; 2206 } 2207 2208 static unsigned char * 2209 read_and_display_attr (unsigned long attribute, 2210 unsigned long form, 2211 unsigned char * data, 2212 unsigned char * end, 2213 dwarf_vma cu_offset, 2214 dwarf_vma pointer_size, 2215 dwarf_vma offset_size, 2216 int dwarf_version, 2217 debug_info * debug_info_p, 2218 int do_loc, 2219 struct dwarf_section * section, 2220 struct cu_tu_set * this_set) 2221 { 2222 if (!do_loc) 2223 printf (" %-18s:", get_AT_name (attribute)); 2224 data = read_and_display_attr_value (attribute, form, data, end, 2225 cu_offset, pointer_size, offset_size, 2226 dwarf_version, debug_info_p, 2227 do_loc, section, this_set); 2228 if (!do_loc) 2229 printf ("\n"); 2230 return data; 2231 } 2232 2233 /* Process the contents of a .debug_info section. If do_loc is non-zero 2234 then we are scanning for location lists and we do not want to display 2235 anything to the user. If do_types is non-zero, we are processing 2236 a .debug_types section instead of a .debug_info section. */ 2237 2238 static int 2239 process_debug_info (struct dwarf_section *section, 2240 void *file, 2241 enum dwarf_section_display_enum abbrev_sec, 2242 int do_loc, 2243 int do_types) 2244 { 2245 unsigned char *start = section->start; 2246 unsigned char *end = start + section->size; 2247 unsigned char *section_begin; 2248 unsigned int unit; 2249 unsigned int num_units = 0; 2250 2251 if ((do_loc || do_debug_loc || do_debug_ranges) 2252 && num_debug_info_entries == 0 2253 && ! do_types) 2254 { 2255 dwarf_vma length; 2256 2257 /* First scan the section to get the number of comp units. */ 2258 for (section_begin = start, num_units = 0; section_begin < end; 2259 num_units ++) 2260 { 2261 /* Read the first 4 bytes. For a 32-bit DWARF section, this 2262 will be the length. For a 64-bit DWARF section, it'll be 2263 the escape code 0xffffffff followed by an 8 byte length. */ 2264 SAFE_BYTE_GET (length, section_begin, 4, end); 2265 2266 if (length == 0xffffffff) 2267 { 2268 SAFE_BYTE_GET (length, section_begin + 4, 8, end); 2269 section_begin += length + 12; 2270 } 2271 else if (length >= 0xfffffff0 && length < 0xffffffff) 2272 { 2273 warn (_("Reserved length value (0x%s) found in section %s\n"), 2274 dwarf_vmatoa ("x", length), section->name); 2275 return 0; 2276 } 2277 else 2278 section_begin += length + 4; 2279 2280 /* Negative values are illegal, they may even cause infinite 2281 looping. This can happen if we can't accurately apply 2282 relocations to an object file. */ 2283 if ((signed long) length <= 0) 2284 { 2285 warn (_("Corrupt unit length (0x%s) found in section %s\n"), 2286 dwarf_vmatoa ("x", length), section->name); 2287 return 0; 2288 } 2289 } 2290 2291 if (num_units == 0) 2292 { 2293 error (_("No comp units in %s section ?\n"), section->name); 2294 return 0; 2295 } 2296 2297 /* Then allocate an array to hold the information. */ 2298 debug_information = (debug_info *) cmalloc (num_units, 2299 sizeof (* debug_information)); 2300 if (debug_information == NULL) 2301 { 2302 error (_("Not enough memory for a debug info array of %u entries\n"), 2303 num_units); 2304 return 0; 2305 } 2306 } 2307 2308 if (!do_loc) 2309 { 2310 if (dwarf_start_die == 0) 2311 printf (_("Contents of the %s section:\n\n"), section->name); 2312 2313 load_debug_section (str, file); 2314 load_debug_section (str_dwo, file); 2315 load_debug_section (str_index, file); 2316 load_debug_section (str_index_dwo, file); 2317 load_debug_section (debug_addr, file); 2318 } 2319 2320 load_debug_section (abbrev_sec, file); 2321 if (debug_displays [abbrev_sec].section.start == NULL) 2322 { 2323 warn (_("Unable to locate %s section!\n"), 2324 debug_displays [abbrev_sec].section.name); 2325 return 0; 2326 } 2327 2328 for (section_begin = start, unit = 0; start < end; unit++) 2329 { 2330 DWARF2_Internal_CompUnit compunit; 2331 unsigned char *hdrptr; 2332 unsigned char *tags; 2333 int level, last_level, saved_level; 2334 dwarf_vma cu_offset; 2335 unsigned int offset_size; 2336 int initial_length_size; 2337 dwarf_vma signature_high = 0; 2338 dwarf_vma signature_low = 0; 2339 dwarf_vma type_offset = 0; 2340 struct cu_tu_set *this_set; 2341 dwarf_vma abbrev_base; 2342 size_t abbrev_size; 2343 2344 hdrptr = start; 2345 2346 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); 2347 2348 if (compunit.cu_length == 0xffffffff) 2349 { 2350 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); 2351 offset_size = 8; 2352 initial_length_size = 12; 2353 } 2354 else 2355 { 2356 offset_size = 4; 2357 initial_length_size = 4; 2358 } 2359 2360 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); 2361 2362 cu_offset = start - section_begin; 2363 2364 this_set = find_cu_tu_set_v2 (cu_offset, do_types); 2365 2366 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); 2367 2368 if (this_set == NULL) 2369 { 2370 abbrev_base = 0; 2371 abbrev_size = debug_displays [abbrev_sec].section.size; 2372 } 2373 else 2374 { 2375 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; 2376 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; 2377 } 2378 2379 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); 2380 /* PR 17512: file: 001-108546-0.001:0.1. */ 2381 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) 2382 { 2383 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), 2384 compunit.cu_pointer_size, offset_size); 2385 compunit.cu_pointer_size = offset_size; 2386 } 2387 2388 if (do_types) 2389 { 2390 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); 2391 hdrptr += 8; 2392 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); 2393 } 2394 2395 if ((do_loc || do_debug_loc || do_debug_ranges) 2396 && num_debug_info_entries == 0 2397 && ! do_types) 2398 { 2399 debug_information [unit].cu_offset = cu_offset; 2400 debug_information [unit].pointer_size 2401 = compunit.cu_pointer_size; 2402 debug_information [unit].offset_size = offset_size; 2403 debug_information [unit].dwarf_version = compunit.cu_version; 2404 debug_information [unit].base_address = 0; 2405 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; 2406 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; 2407 debug_information [unit].loc_offsets = NULL; 2408 debug_information [unit].have_frame_base = NULL; 2409 debug_information [unit].max_loc_offsets = 0; 2410 debug_information [unit].num_loc_offsets = 0; 2411 debug_information [unit].range_lists = NULL; 2412 debug_information [unit].max_range_lists= 0; 2413 debug_information [unit].num_range_lists = 0; 2414 } 2415 2416 if (!do_loc && dwarf_start_die == 0) 2417 { 2418 printf (_(" Compilation Unit @ offset 0x%s:\n"), 2419 dwarf_vmatoa ("x", cu_offset)); 2420 printf (_(" Length: 0x%s (%s)\n"), 2421 dwarf_vmatoa ("x", compunit.cu_length), 2422 offset_size == 8 ? "64-bit" : "32-bit"); 2423 printf (_(" Version: %d\n"), compunit.cu_version); 2424 printf (_(" Abbrev Offset: 0x%s\n"), 2425 dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); 2426 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); 2427 if (do_types) 2428 { 2429 char buf[64]; 2430 2431 printf (_(" Signature: 0x%s\n"), 2432 dwarf_vmatoa64 (signature_high, signature_low, 2433 buf, sizeof (buf))); 2434 printf (_(" Type Offset: 0x%s\n"), 2435 dwarf_vmatoa ("x", type_offset)); 2436 } 2437 if (this_set != NULL) 2438 { 2439 dwarf_vma *offsets = this_set->section_offsets; 2440 size_t *sizes = this_set->section_sizes; 2441 2442 printf (_(" Section contributions:\n")); 2443 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), 2444 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), 2445 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); 2446 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), 2447 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), 2448 dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); 2449 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), 2450 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), 2451 dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); 2452 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), 2453 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), 2454 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); 2455 } 2456 } 2457 2458 if (cu_offset + compunit.cu_length + initial_length_size 2459 > section->size) 2460 { 2461 warn (_("Debug info is corrupted, length of CU at %s" 2462 " extends beyond end of section (length = %s)\n"), 2463 dwarf_vmatoa ("x", cu_offset), 2464 dwarf_vmatoa ("x", compunit.cu_length)); 2465 break; 2466 } 2467 tags = hdrptr; 2468 start += compunit.cu_length + initial_length_size; 2469 2470 if (compunit.cu_version != 2 2471 && compunit.cu_version != 3 2472 && compunit.cu_version != 4) 2473 { 2474 warn (_("CU at offset %s contains corrupt or " 2475 "unsupported version number: %d.\n"), 2476 dwarf_vmatoa ("x", cu_offset), compunit.cu_version); 2477 continue; 2478 } 2479 2480 free_abbrevs (); 2481 2482 /* Process the abbrevs used by this compilation unit. */ 2483 if (compunit.cu_abbrev_offset >= abbrev_size) 2484 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), 2485 (unsigned long) compunit.cu_abbrev_offset, 2486 (unsigned long) abbrev_size); 2487 else 2488 process_abbrev_section 2489 (((unsigned char *) debug_displays [abbrev_sec].section.start 2490 + abbrev_base + compunit.cu_abbrev_offset), 2491 ((unsigned char *) debug_displays [abbrev_sec].section.start 2492 + abbrev_base + abbrev_size)); 2493 2494 level = 0; 2495 last_level = level; 2496 saved_level = -1; 2497 while (tags < start) 2498 { 2499 unsigned int bytes_read; 2500 unsigned long abbrev_number; 2501 unsigned long die_offset; 2502 abbrev_entry *entry; 2503 abbrev_attr *attr; 2504 int do_printing = 1; 2505 2506 die_offset = tags - section_begin; 2507 2508 abbrev_number = read_uleb128 (tags, & bytes_read, start); 2509 tags += bytes_read; 2510 2511 /* A null DIE marks the end of a list of siblings or it may also be 2512 a section padding. */ 2513 if (abbrev_number == 0) 2514 { 2515 /* Check if it can be a section padding for the last CU. */ 2516 if (level == 0 && start == end) 2517 { 2518 unsigned char *chk; 2519 2520 for (chk = tags; chk < start; chk++) 2521 if (*chk != 0) 2522 break; 2523 if (chk == start) 2524 break; 2525 } 2526 2527 if (!do_loc && die_offset >= dwarf_start_die 2528 && (dwarf_cutoff_level == -1 2529 || level < dwarf_cutoff_level)) 2530 printf (_(" <%d><%lx>: Abbrev Number: 0\n"), 2531 level, die_offset); 2532 2533 --level; 2534 if (level < 0) 2535 { 2536 static unsigned num_bogus_warns = 0; 2537 2538 if (num_bogus_warns < 3) 2539 { 2540 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), 2541 die_offset, section->name); 2542 num_bogus_warns ++; 2543 if (num_bogus_warns == 3) 2544 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); 2545 } 2546 } 2547 if (dwarf_start_die != 0 && level < saved_level) 2548 return 1; 2549 continue; 2550 } 2551 2552 if (!do_loc) 2553 { 2554 if (dwarf_start_die != 0 && die_offset < dwarf_start_die) 2555 do_printing = 0; 2556 else 2557 { 2558 if (dwarf_start_die != 0 && die_offset == dwarf_start_die) 2559 saved_level = level; 2560 do_printing = (dwarf_cutoff_level == -1 2561 || level < dwarf_cutoff_level); 2562 if (do_printing) 2563 printf (_(" <%d><%lx>: Abbrev Number: %lu"), 2564 level, die_offset, abbrev_number); 2565 else if (dwarf_cutoff_level == -1 2566 || last_level < dwarf_cutoff_level) 2567 printf (_(" <%d><%lx>: ...\n"), level, die_offset); 2568 last_level = level; 2569 } 2570 } 2571 2572 /* Scan through the abbreviation list until we reach the 2573 correct entry. */ 2574 for (entry = first_abbrev; 2575 entry && entry->entry != abbrev_number; 2576 entry = entry->next) 2577 continue; 2578 2579 if (entry == NULL) 2580 { 2581 if (!do_loc && do_printing) 2582 { 2583 printf ("\n"); 2584 fflush (stdout); 2585 } 2586 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"), 2587 die_offset, abbrev_number); 2588 return 0; 2589 } 2590 2591 if (!do_loc && do_printing) 2592 printf (" (%s)\n", get_TAG_name (entry->tag)); 2593 2594 switch (entry->tag) 2595 { 2596 default: 2597 need_base_address = 0; 2598 break; 2599 case DW_TAG_compile_unit: 2600 need_base_address = 1; 2601 break; 2602 case DW_TAG_entry_point: 2603 case DW_TAG_subprogram: 2604 need_base_address = 0; 2605 /* Assuming that there is no DW_AT_frame_base. */ 2606 have_frame_base = 0; 2607 break; 2608 } 2609 2610 for (attr = entry->first_attr; 2611 attr && attr->attribute; 2612 attr = attr->next) 2613 { 2614 debug_info *arg; 2615 2616 if (! do_loc && do_printing) 2617 /* Show the offset from where the tag was extracted. */ 2618 printf (" <%lx>", (unsigned long)(tags - section_begin)); 2619 2620 arg = debug_information; 2621 if (debug_information) 2622 arg += unit; 2623 2624 tags = read_and_display_attr (attr->attribute, 2625 attr->form, 2626 tags, 2627 end, 2628 cu_offset, 2629 compunit.cu_pointer_size, 2630 offset_size, 2631 compunit.cu_version, 2632 arg, 2633 do_loc || ! do_printing, 2634 section, 2635 this_set); 2636 } 2637 2638 if (entry->children) 2639 ++level; 2640 } 2641 } 2642 2643 /* Set num_debug_info_entries here so that it can be used to check if 2644 we need to process .debug_loc and .debug_ranges sections. */ 2645 if ((do_loc || do_debug_loc || do_debug_ranges) 2646 && num_debug_info_entries == 0 2647 && ! do_types) 2648 num_debug_info_entries = num_units; 2649 2650 if (!do_loc) 2651 printf ("\n"); 2652 2653 return 1; 2654 } 2655 2656 /* Locate and scan the .debug_info section in the file and record the pointer 2657 sizes and offsets for the compilation units in it. Usually an executable 2658 will have just one pointer size, but this is not guaranteed, and so we try 2659 not to make any assumptions. Returns zero upon failure, or the number of 2660 compilation units upon success. */ 2661 2662 static unsigned int 2663 load_debug_info (void * file) 2664 { 2665 /* Reset the last pointer size so that we can issue correct error 2666 messages if we are displaying the contents of more than one section. */ 2667 last_pointer_size = 0; 2668 warned_about_missing_comp_units = FALSE; 2669 2670 /* If we have already tried and failed to load the .debug_info 2671 section then do not bother to repeat the task. */ 2672 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) 2673 return 0; 2674 2675 /* If we already have the information there is nothing else to do. */ 2676 if (num_debug_info_entries > 0) 2677 return num_debug_info_entries; 2678 2679 /* If this is a DWARF package file, load the CU and TU indexes. */ 2680 load_cu_tu_indexes (file); 2681 2682 if (load_debug_section (info, file) 2683 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0)) 2684 return num_debug_info_entries; 2685 else if (load_debug_section (info_dwo, file) 2686 && process_debug_info (&debug_displays [info_dwo].section, file, 2687 abbrev_dwo, 1, 0)) 2688 return num_debug_info_entries; 2689 2690 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; 2691 return 0; 2692 } 2693 2694 /* Experimental DWARF 5 extensions. 2695 See http://wiki.dwarfstd.org/index.php?title=TwoLevelLineTables. */ 2696 #define DWARF2_LINE_EXPERIMENTAL_VERSION 0xf006 2697 2698 /* Read a DWARF .debug_line section header starting at DATA. 2699 Upon success returns an updated DATA pointer and the LINFO 2700 structure and the END_OF_SEQUENCE pointer will be filled in. 2701 Otherwise returns NULL. */ 2702 2703 static unsigned char * 2704 read_debug_line_header (struct dwarf_section * section, 2705 unsigned char * data, 2706 unsigned char * end, 2707 DWARF2_Internal_LineInfo * linfo, 2708 unsigned char ** end_of_sequence, 2709 unsigned int * pinitial_length_size, 2710 unsigned int * poffset_size) 2711 { 2712 unsigned char *hdrptr; 2713 unsigned int offset_size; 2714 unsigned int initial_length_size; 2715 2716 /* Extract information from the Line Number Program Header. 2717 (section 6.2.4 in the Dwarf3 doc). */ 2718 hdrptr = data; 2719 2720 /* Get and check the length of the block. */ 2721 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); 2722 2723 if (linfo->li_length == 0xffffffff) 2724 { 2725 /* This section is 64-bit DWARF 3. */ 2726 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); 2727 offset_size = 8; 2728 initial_length_size = 12; 2729 } 2730 else 2731 { 2732 offset_size = 4; 2733 initial_length_size = 4; 2734 } 2735 *pinitial_length_size = initial_length_size; 2736 *poffset_size = offset_size; 2737 2738 if (linfo->li_length + initial_length_size > section->size) 2739 { 2740 /* If the length is just a bias against the initial_length_size then 2741 this means that the field has a relocation against it which has not 2742 been applied. (Ie we are dealing with an object file, not a linked 2743 binary). Do not complain but instead assume that the rest of the 2744 section applies to this particular header. */ 2745 if (linfo->li_length == - initial_length_size) 2746 { 2747 linfo->li_length = section->size - initial_length_size; 2748 } 2749 else 2750 { 2751 warn (_("The line info appears to be corrupt - the section is too small\n")); 2752 return NULL; 2753 } 2754 } 2755 2756 /* Get and check the version number. */ 2757 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); 2758 2759 /* Version 0xf006 is for experimental two-level line tables. */ 2760 if (linfo->li_version != 2 2761 && linfo->li_version != 3 2762 && linfo->li_version != 4 2763 && linfo->li_version != 5 2764 && linfo->li_version != DWARF2_LINE_EXPERIMENTAL_VERSION) 2765 { 2766 warn (_("Only DWARF versions 2-5 line info are currently supported.\n")); 2767 return NULL; 2768 } 2769 2770 if (linfo->li_version < 5) 2771 { 2772 linfo->li_address_size = 0; 2773 linfo->li_segment_size = 0; 2774 } 2775 else if (linfo->li_version != DWARF2_LINE_EXPERIMENTAL_VERSION) 2776 { 2777 SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end); 2778 SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end); 2779 } 2780 2781 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, offset_size, end); 2782 2783 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); 2784 2785 if (linfo->li_version >= 4) 2786 { 2787 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); 2788 2789 if (linfo->li_max_ops_per_insn == 0) 2790 { 2791 warn (_("Invalid maximum operations per insn.\n")); 2792 return NULL; 2793 } 2794 } 2795 else 2796 linfo->li_max_ops_per_insn = 1; 2797 2798 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); 2799 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); 2800 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); 2801 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); 2802 2803 * end_of_sequence = data + linfo->li_length + initial_length_size; 2804 return hdrptr; 2805 } 2806 2807 static void 2808 display_directory_table_v4 (unsigned char *start, unsigned char *end, 2809 unsigned char **pdata) 2810 { 2811 unsigned char *data = *pdata; 2812 unsigned int last_dir_entry = 0; 2813 2814 if (*data == 0) 2815 printf (_("\n The Directory Table is empty.\n")); 2816 else 2817 { 2818 printf (_("\n The Directory Table (offset 0x%lx):\n"), 2819 (long)(data - start)); 2820 2821 while (data < end && *data != 0) 2822 { 2823 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); 2824 2825 data += strnlen ((char *) data, end - data) + 1; 2826 } 2827 } 2828 2829 /* Skip the NUL at the end of the table. */ 2830 *pdata = data + 1; 2831 } 2832 2833 static void 2834 display_file_name_table_v4 (unsigned char *start, unsigned char *end, 2835 unsigned char **pdata) 2836 { 2837 unsigned char *data = *pdata; 2838 2839 if (*data == 0) 2840 printf (_("\n The File Name Table is empty.\n")); 2841 else 2842 { 2843 printf (_("\n The File Name Table (offset 0x%lx):\n"), 2844 (long)(data - start)); 2845 printf (_(" Entry\tDir\tTime\tSize\tName\n")); 2846 2847 while (data < end && *data != 0) 2848 { 2849 unsigned char *name; 2850 unsigned int bytes_read; 2851 2852 printf (" %d\t", ++state_machine_regs.last_file_entry); 2853 name = data; 2854 data += strnlen ((char *) data, end - data) + 1; 2855 2856 printf ("%s\t", 2857 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); 2858 data += bytes_read; 2859 printf ("%s\t", 2860 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); 2861 data += bytes_read; 2862 printf ("%s\t", 2863 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); 2864 data += bytes_read; 2865 printf ("%.*s\n", (int)(end - name), name); 2866 2867 if (data == end) 2868 { 2869 warn (_("Corrupt file name table entry\n")); 2870 break; 2871 } 2872 } 2873 } 2874 2875 /* Skip the NUL at the end of the table. */ 2876 *pdata = data + 1; 2877 } 2878 2879 static int 2880 display_dir_file_table_v5 (unsigned char *start, unsigned char *end, 2881 unsigned char **pdata, char *table_name, 2882 unsigned int offset_size) 2883 { 2884 unsigned char *data = *pdata; 2885 unsigned int bytes_read; 2886 unsigned int format_count; 2887 unsigned int *content_types; 2888 unsigned int *content_forms; 2889 unsigned int entry_count; 2890 unsigned int i, j; 2891 const unsigned char *name; 2892 dwarf_vma offset; 2893 unsigned int val; 2894 2895 format_count = read_uleb128 (data, & bytes_read, end); 2896 data += bytes_read; 2897 content_types = (unsigned int *) xmalloc (format_count * 2898 sizeof (unsigned int)); 2899 content_forms = (unsigned int *) xmalloc (format_count * 2900 sizeof (unsigned int)); 2901 for (j = 0; j < format_count; j++) 2902 { 2903 content_types[j] = read_uleb128 (data, & bytes_read, end); 2904 data += bytes_read; 2905 content_forms[j] = read_uleb128 (data, & bytes_read, end); 2906 data += bytes_read; 2907 } 2908 2909 entry_count = read_uleb128 (data, & bytes_read, end); 2910 data += bytes_read; 2911 2912 if (entry_count == 0) 2913 printf (_("\n The %s Table is empty.\n"), table_name); 2914 else 2915 { 2916 printf (_("\n The %s Table (offset 0x%lx):\n"), 2917 table_name, (long)(data - start)); 2918 2919 printf (_(" Entry")); 2920 for (j = 0; j < format_count; j++) 2921 { 2922 printf ("\t"); 2923 switch (content_types[j]) 2924 { 2925 case DW_LNCT_path: 2926 printf (_("Path")); 2927 break; 2928 case DW_LNCT_subprogram_name: 2929 printf (_("Name")); 2930 break; 2931 case DW_LNCT_directory_index: 2932 printf (_("Dir")); 2933 break; 2934 case DW_LNCT_decl_file: 2935 printf (_("File")); 2936 break; 2937 case DW_LNCT_decl_line: 2938 printf (_("Line")); 2939 break; 2940 } 2941 } 2942 printf ("\n"); 2943 } 2944 2945 for (i = 0; i < entry_count; i++) 2946 { 2947 printf (" %d", i + 1); 2948 for (j = 0; j < format_count; j++) 2949 { 2950 if (data >= end) 2951 break; 2952 switch (content_forms[j]) 2953 { 2954 case DW_FORM_string: 2955 printf ("\t%.*s", (int) (end - data), data); 2956 data += strnlen ((char *) data, end - data) + 1; 2957 break; 2958 case DW_FORM_line_strp: 2959 SAFE_BYTE_GET_AND_INC (offset, data, offset_size, end); 2960 name = fetch_indirect_line_string (offset); 2961 printf ("\t%s", name); 2962 break; 2963 case DW_FORM_udata: 2964 val = read_uleb128 (data, & bytes_read, end); 2965 data += bytes_read; 2966 printf ("\t%u", val); 2967 break; 2968 default: 2969 printf ("\t%s", _("(unrecognized FORM code)")); 2970 data = end; 2971 break; 2972 } 2973 } 2974 printf ("\n"); 2975 2976 /* PR 17512: file: 002-132094-0.004. */ 2977 if (data >= end - 1) 2978 break; 2979 } 2980 2981 free (content_types); 2982 free (content_forms); 2983 2984 *pdata = data; 2985 return entry_count; 2986 } 2987 2988 static void 2989 display_line_program (unsigned char *start, unsigned char *end, 2990 unsigned char **pdata, char *table_name, 2991 DWARF2_Internal_LineInfo *linfo, 2992 unsigned char *standard_opcodes, 2993 int is_logical) 2994 { 2995 unsigned char *data = *pdata; 2996 2997 if (data >= end) 2998 { 2999 printf (_(" No %s.\n"), table_name); 3000 return; 3001 } 3002 3003 printf (" %s:\n", table_name); 3004 3005 while (data < end) 3006 { 3007 unsigned char op_code; 3008 dwarf_signed_vma adv; 3009 dwarf_vma uladv; 3010 unsigned int bytes_read; 3011 unsigned int logical; 3012 int i; 3013 3014 printf (" [0x%08lx]", (long)(data - start)); 3015 3016 op_code = *data++; 3017 3018 if (op_code >= linfo->li_opcode_base) 3019 { 3020 op_code -= linfo->li_opcode_base; 3021 uladv = (op_code / linfo->li_line_range); 3022 if (linfo->li_max_ops_per_insn == 1) 3023 { 3024 uladv *= linfo->li_min_insn_length; 3025 state_machine_regs.address += uladv; 3026 printf (_(" Special opcode %d: " 3027 "advance Address by %s to 0x%s"), 3028 op_code, dwarf_vmatoa ("u", uladv), 3029 dwarf_vmatoa ("x", state_machine_regs.address)); 3030 } 3031 else 3032 { 3033 state_machine_regs.address 3034 += ((state_machine_regs.op_index + uladv) 3035 / linfo->li_max_ops_per_insn) 3036 * linfo->li_min_insn_length; 3037 state_machine_regs.op_index 3038 = (state_machine_regs.op_index + uladv) 3039 % linfo->li_max_ops_per_insn; 3040 printf (_(" Special opcode %d: " 3041 "advance Address by %s to 0x%s[%d]"), 3042 op_code, dwarf_vmatoa ("u", uladv), 3043 dwarf_vmatoa ("x", state_machine_regs.address), 3044 state_machine_regs.op_index); 3045 } 3046 adv = (op_code % linfo->li_line_range) + linfo->li_line_base; 3047 state_machine_regs.line += adv; 3048 printf (_(" and Line by %s to %d\n"), 3049 dwarf_vmatoa ("d", adv), state_machine_regs.line); 3050 if (is_logical) 3051 append_logical (); 3052 state_machine_regs.discriminator = 0; 3053 } 3054 else 3055 { 3056 switch (op_code) 3057 { 3058 case DW_LNS_extended_op: 3059 data += process_extended_line_op (data, linfo->li_default_is_stmt, 3060 end, is_logical); 3061 break; 3062 3063 case DW_LNS_copy: 3064 printf (_(" Copy\n")); 3065 if (is_logical) 3066 append_logical (); 3067 state_machine_regs.discriminator = 0; 3068 break; 3069 3070 case DW_LNS_advance_pc: 3071 uladv = read_uleb128 (data, & bytes_read, end); 3072 data += bytes_read; 3073 if (linfo->li_max_ops_per_insn == 1) 3074 { 3075 uladv *= linfo->li_min_insn_length; 3076 state_machine_regs.address += uladv; 3077 printf (_(" Advance PC by %s to 0x%s\n"), 3078 dwarf_vmatoa ("u", uladv), 3079 dwarf_vmatoa ("x", state_machine_regs.address)); 3080 } 3081 else 3082 { 3083 state_machine_regs.address 3084 += ((state_machine_regs.op_index + uladv) 3085 / linfo->li_max_ops_per_insn) 3086 * linfo->li_min_insn_length; 3087 state_machine_regs.op_index 3088 = (state_machine_regs.op_index + uladv) 3089 % linfo->li_max_ops_per_insn; 3090 printf (_(" Advance PC by %s to 0x%s[%d]\n"), 3091 dwarf_vmatoa ("u", uladv), 3092 dwarf_vmatoa ("x", state_machine_regs.address), 3093 state_machine_regs.op_index); 3094 } 3095 break; 3096 3097 case DW_LNS_advance_line: 3098 adv = read_sleb128 (data, & bytes_read, end); 3099 data += bytes_read; 3100 state_machine_regs.line += adv; 3101 printf (_(" Advance Line by %s to %d\n"), 3102 dwarf_vmatoa ("d", adv), 3103 state_machine_regs.line); 3104 break; 3105 3106 case DW_LNS_set_file: 3107 adv = read_uleb128 (data, & bytes_read, end); 3108 data += bytes_read; 3109 printf (_(" Set File Name to entry %s in the File Name Table\n"), 3110 dwarf_vmatoa ("d", adv)); 3111 state_machine_regs.file = adv; 3112 break; 3113 3114 case DW_LNS_set_column: 3115 uladv = read_uleb128 (data, & bytes_read, end); 3116 data += bytes_read; 3117 printf (_(" Set column to %s\n"), 3118 dwarf_vmatoa ("u", uladv)); 3119 state_machine_regs.column = uladv; 3120 break; 3121 3122 case DW_LNS_negate_stmt: 3123 adv = state_machine_regs.is_stmt; 3124 adv = ! adv; 3125 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); 3126 state_machine_regs.is_stmt = adv; 3127 break; 3128 3129 case DW_LNS_set_basic_block: 3130 printf (_(" Set basic block\n")); 3131 state_machine_regs.basic_block = 1; 3132 break; 3133 3134 case DW_LNS_const_add_pc: 3135 uladv = ((255 - linfo->li_opcode_base) / linfo->li_line_range); 3136 if (linfo->li_max_ops_per_insn) 3137 { 3138 uladv *= linfo->li_min_insn_length; 3139 state_machine_regs.address += uladv; 3140 printf (_(" Advance PC by constant %s to 0x%s\n"), 3141 dwarf_vmatoa ("u", uladv), 3142 dwarf_vmatoa ("x", state_machine_regs.address)); 3143 } 3144 else 3145 { 3146 state_machine_regs.address 3147 += ((state_machine_regs.op_index + uladv) 3148 / linfo->li_max_ops_per_insn) 3149 * linfo->li_min_insn_length; 3150 state_machine_regs.op_index 3151 = (state_machine_regs.op_index + uladv) 3152 % linfo->li_max_ops_per_insn; 3153 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"), 3154 dwarf_vmatoa ("u", uladv), 3155 dwarf_vmatoa ("x", state_machine_regs.address), 3156 state_machine_regs.op_index); 3157 } 3158 break; 3159 3160 case DW_LNS_fixed_advance_pc: 3161 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); 3162 state_machine_regs.address += uladv; 3163 state_machine_regs.op_index = 0; 3164 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), 3165 dwarf_vmatoa ("u", uladv), 3166 dwarf_vmatoa ("x", state_machine_regs.address)); 3167 break; 3168 3169 case DW_LNS_set_prologue_end: 3170 printf (_(" Set prologue_end to true\n")); 3171 break; 3172 3173 case DW_LNS_set_epilogue_begin: 3174 printf (_(" Set epilogue_begin to true\n")); 3175 break; 3176 3177 case DW_LNS_set_isa: 3178 uladv = read_uleb128 (data, & bytes_read, end); 3179 data += bytes_read; 3180 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); 3181 break; 3182 3183 case DW_LNS_set_subprogram: 3184 /* This opcode is aliased with: */ 3185 /* case DW_LNS_set_address_from_logical: */ 3186 if (is_logical) 3187 { 3188 /* DW_LNS_set_subprogram */ 3189 state_machine_regs.context = 0; 3190 state_machine_regs.subprogram = read_uleb128 (data, & bytes_read, end); 3191 data += bytes_read; 3192 printf (_(" Set subprogram to %u and reset context to 0\n"), 3193 state_machine_regs.subprogram); 3194 } 3195 else 3196 { 3197 /* DW_LNS_set_address_from_logical */ 3198 adv = read_sleb128 (data, & bytes_read, end); 3199 data += bytes_read; 3200 state_machine_regs.line += adv; 3201 logical = state_machine_regs.line; 3202 if (logical - 1 < logicals_count) 3203 { 3204 state_machine_regs.address = logicals_table[logical - 1].address; 3205 state_machine_regs.op_index = logicals_table[logical - 1].op_index; 3206 } 3207 else 3208 warn (_("Logical row number outside range of logicals table\n")); 3209 printf (_(" Advance Line by %s to %u and set address from logical to 0x%s[%u]\n"), 3210 dwarf_vmatoa ("d", adv), 3211 logical, 3212 dwarf_vmatoa ("x", state_machine_regs.address), 3213 state_machine_regs.op_index); 3214 } 3215 break; 3216 3217 case DW_LNS_inlined_call: 3218 adv = read_sleb128 (data, & bytes_read, end); 3219 data += bytes_read; 3220 state_machine_regs.context = logicals_count + adv; 3221 state_machine_regs.subprogram = read_uleb128 (data, & bytes_read, end); 3222 data += bytes_read; 3223 printf (_(" Set context to %u and subprogram to %u\n"), 3224 state_machine_regs.context, 3225 state_machine_regs.subprogram); 3226 break; 3227 3228 case DW_LNS_pop_context: 3229 logical = state_machine_regs.context; 3230 printf (_(" Pop context to logical %u\n"), logical); 3231 if (logical - 1 < logicals_count) 3232 { 3233 state_machine_regs.file = logicals_table[logical - 1].file; 3234 state_machine_regs.line = logicals_table[logical - 1].line; 3235 state_machine_regs.column = logicals_table[logical - 1].column; 3236 state_machine_regs.discriminator = logicals_table[logical - 1].discriminator; 3237 state_machine_regs.is_stmt = logicals_table[logical - 1].is_stmt; 3238 state_machine_regs.context = logicals_table[logical - 1].context; 3239 state_machine_regs.subprogram = logicals_table[logical - 1].subprogram; 3240 } 3241 else 3242 warn (_("Context register outside range of logicals table\n")); 3243 break; 3244 3245 default: 3246 printf (_(" Unknown opcode %d with operands: "), op_code); 3247 3248 if (standard_opcodes != NULL) 3249 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) 3250 { 3251 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, 3252 &bytes_read, end)), 3253 i == 1 ? "" : ", "); 3254 data += bytes_read; 3255 } 3256 putchar ('\n'); 3257 break; 3258 } 3259 } 3260 } 3261 3262 putchar ('\n'); 3263 *pdata = data; 3264 } 3265 3266 static int 3267 display_debug_lines_raw (struct dwarf_section *section, 3268 unsigned char *data, 3269 unsigned char *end) 3270 { 3271 unsigned char *start = section->start; 3272 unsigned int initial_length_size; 3273 unsigned int offset_size; 3274 3275 printf (_("Raw dump of debug contents of section %s:\n\n"), 3276 section->name); 3277 3278 while (data < end) 3279 { 3280 static DWARF2_Internal_LineInfo saved_linfo; 3281 DWARF2_Internal_LineInfo linfo; 3282 unsigned int logicals_table_offset = 0; 3283 unsigned int actuals_table_offset = 0; 3284 unsigned char *end_of_header_length; 3285 unsigned char *standard_opcodes; 3286 unsigned char *start_of_line_program; 3287 unsigned char *end_of_logicals; 3288 unsigned char *end_of_sequence; 3289 int i; 3290 unsigned char *hdrptr = NULL; 3291 3292 if (const_strneq (section->name, ".debug_line.") 3293 /* Note: the following does not apply to .debug_line.dwo sections. 3294 These are full debug_line sections. */ 3295 && strcmp (section->name, ".debug_line.dwo") != 0) 3296 { 3297 /* Sections named .debug_line.<foo> are fragments of a .debug_line 3298 section containing just the Line Number Statements. They are 3299 created by the assembler and intended to be used alongside gcc's 3300 -ffunction-sections command line option. When the linker's 3301 garbage collection decides to discard a .text.<foo> section it 3302 can then also discard the line number information in .debug_line.<foo>. 3303 3304 Since the section is a fragment it does not have the details 3305 needed to fill out a LineInfo structure, so instead we use the 3306 details from the last full debug_line section that we processed. */ 3307 start_of_line_program = data; 3308 end_of_sequence = end; 3309 end_of_logicals = end; 3310 standard_opcodes = NULL; 3311 linfo = saved_linfo; 3312 reset_state_machine (linfo.li_default_is_stmt); 3313 } 3314 else 3315 { 3316 if ((hdrptr = read_debug_line_header (section, data, end, & linfo, 3317 & end_of_sequence, 3318 & initial_length_size, 3319 & offset_size)) == NULL) 3320 return 0; 3321 3322 printf (_(" Offset: 0x%lx\n"), (long)(data - start)); 3323 printf (_(" Length: %ld\n"), (long) linfo.li_length); 3324 printf (_(" DWARF Version: %d\n"), linfo.li_version); 3325 if (linfo.li_version >= 5 3326 && linfo.li_version != DWARF2_LINE_EXPERIMENTAL_VERSION) 3327 { 3328 printf (_(" Address Size: %u\n"), linfo.li_address_size); 3329 printf (_(" Segment Size: %u\n"), linfo.li_segment_size); 3330 } 3331 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length); 3332 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); 3333 if (linfo.li_version >= 4) 3334 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); 3335 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); 3336 printf (_(" Line Base: %d\n"), linfo.li_line_base); 3337 printf (_(" Line Range: %d\n"), linfo.li_line_range); 3338 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); 3339 3340 end_of_header_length = data + initial_length_size + 2 + offset_size; 3341 if (linfo.li_version >= 5 3342 && linfo.li_version != DWARF2_LINE_EXPERIMENTAL_VERSION) 3343 end_of_header_length += 2; 3344 start_of_line_program = end_of_header_length + linfo.li_prologue_length; 3345 end_of_logicals = end; 3346 3347 reset_state_machine (linfo.li_default_is_stmt); 3348 3349 /* Display the contents of the Opcodes table. */ 3350 standard_opcodes = hdrptr; 3351 3352 printf (_("\n Opcodes:\n")); 3353 3354 for (i = 1; i < linfo.li_opcode_base; i++) 3355 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]); 3356 3357 data = standard_opcodes + linfo.li_opcode_base - 1; 3358 3359 if (linfo.li_version == DWARF2_LINE_EXPERIMENTAL_VERSION) 3360 { 3361 /* Skip the fake directory and filename table. */ 3362 data += 2; 3363 3364 /* Skip the fake extended opcode that wraps the rest 3365 of the section. */ 3366 data += 5; 3367 3368 /* Read the logicals table offset and actuals table offset. */ 3369 SAFE_BYTE_GET_AND_INC (logicals_table_offset, data, offset_size, end); 3370 SAFE_BYTE_GET_AND_INC (actuals_table_offset, data, offset_size, end); 3371 3372 start_of_line_program = end_of_header_length + logicals_table_offset; 3373 3374 if (actuals_table_offset > 0) 3375 end_of_logicals = end_of_header_length + actuals_table_offset; 3376 3377 putchar ('\n'); 3378 printf (_(" Logicals Table Offset: 0x%x\n"), logicals_table_offset); 3379 printf (_(" Actuals Table Offset: 0x%x\n"), actuals_table_offset); 3380 } 3381 3382 /* Display the contents of the Directory table. */ 3383 if (linfo.li_version >= 5) 3384 display_dir_file_table_v5 (start, end, &data, _("Directory"), 3385 offset_size); 3386 else 3387 display_directory_table_v4 (start, end, &data); 3388 3389 /* PR 17512: file: 002-132094-0.004. */ 3390 if (data >= end - 1) 3391 break; 3392 3393 /* Display the contents of the File Name table. */ 3394 if (linfo.li_version >= 5) 3395 { 3396 unsigned int count; 3397 3398 count = display_dir_file_table_v5 (start, end, &data, 3399 _("File Name"), offset_size); 3400 state_machine_regs.last_file_entry = count - 1; 3401 } 3402 else 3403 display_file_name_table_v4 (start, end, &data); 3404 3405 /* Display the contents of the Subprogram table. */ 3406 if (linfo.li_version == DWARF2_LINE_EXPERIMENTAL_VERSION) 3407 display_dir_file_table_v5 (start, end, &data, _("Subprogram"), 3408 offset_size); 3409 3410 putchar ('\n'); 3411 saved_linfo = linfo; 3412 } 3413 3414 if (data > start_of_line_program) 3415 warn (_("Line table header is longer than header_length indicates\n")); 3416 else if (data < start_of_line_program) 3417 warn (_("Line table header is shorter than header_length indicates\n")); 3418 data = start_of_line_program; 3419 3420 if (linfo.li_version == DWARF2_LINE_EXPERIMENTAL_VERSION 3421 && hdrptr != NULL 3422 && actuals_table_offset > 0) 3423 { 3424 if (end_of_logicals > end) 3425 { 3426 warn (_("Actuals table offset %s extends beyond end of section\n"), 3427 dwarf_vmatoa ("u", actuals_table_offset)); 3428 end_of_logicals = end; 3429 } 3430 display_line_program (start, end_of_logicals, &data, 3431 _("Logicals Statements"), 3432 &linfo, standard_opcodes, 1); 3433 if (data > end_of_logicals) 3434 warn (_("Logicals table is longer than actuals_table_offset indicates\n")); 3435 else if (data < end_of_logicals) 3436 warn (_("Line table header is shorter than actuals_table_offset indicates\n")); 3437 data = end_of_logicals; 3438 reset_state_machine (linfo.li_default_is_stmt); 3439 display_line_program (start, end_of_sequence, &data, 3440 _("Actuals Statements"), 3441 &linfo, standard_opcodes, 0); 3442 free_logicals (); 3443 } 3444 else 3445 { 3446 display_line_program (start, end_of_sequence, &data, 3447 _("Line Number Statements"), 3448 &linfo, standard_opcodes, 0); 3449 } 3450 3451 } 3452 3453 return 1; 3454 } 3455 3456 typedef struct 3457 { 3458 unsigned char *name; 3459 unsigned int directory_index; 3460 unsigned int modification_date; 3461 unsigned int length; 3462 } File_Entry; 3463 3464 /* Output a decoded representation of the .debug_line section. */ 3465 3466 static int 3467 display_debug_lines_decoded (struct dwarf_section *section, 3468 unsigned char *data, 3469 unsigned char *end) 3470 { 3471 static DWARF2_Internal_LineInfo saved_linfo; 3472 unsigned int initial_length_size; 3473 unsigned int offset_size; 3474 3475 printf (_("Decoded dump of debug contents of section %s:\n\n"), 3476 section->name); 3477 3478 while (data < end) 3479 { 3480 /* This loop amounts to one iteration per compilation unit. */ 3481 DWARF2_Internal_LineInfo linfo; 3482 unsigned char *standard_opcodes; 3483 unsigned char *end_of_sequence; 3484 int i; 3485 File_Entry *file_table = NULL; 3486 unsigned int n_files = 0; 3487 unsigned char **directory_table = NULL; 3488 unsigned int n_directories = 0; 3489 3490 if (const_strneq (section->name, ".debug_line.") 3491 /* Note: the following does not apply to .debug_line.dwo sections. 3492 These are full debug_line sections. */ 3493 && strcmp (section->name, ".debug_line.dwo") != 0) 3494 { 3495 /* See comment in display_debug_lines_raw(). */ 3496 end_of_sequence = end; 3497 standard_opcodes = NULL; 3498 linfo = saved_linfo; 3499 reset_state_machine (linfo.li_default_is_stmt); 3500 } 3501 else 3502 { 3503 unsigned char *hdrptr; 3504 3505 if ((hdrptr = read_debug_line_header (section, data, end, & linfo, 3506 & end_of_sequence, 3507 & initial_length_size, 3508 & offset_size)) == NULL) 3509 return 0; 3510 3511 reset_state_machine (linfo.li_default_is_stmt); 3512 3513 /* Save a pointer to the contents of the Opcodes table. */ 3514 standard_opcodes = hdrptr; 3515 3516 /* Traverse the Directory table just to count entries. */ 3517 data = standard_opcodes + linfo.li_opcode_base - 1; 3518 if (*data != 0) 3519 { 3520 unsigned char *ptr_directory_table = data; 3521 3522 while (*data != 0) 3523 { 3524 data += strnlen ((char *) data, end - data) + 1; 3525 n_directories++; 3526 } 3527 3528 /* Go through the directory table again to save the directories. */ 3529 directory_table = (unsigned char **) 3530 xmalloc (n_directories * sizeof (unsigned char *)); 3531 3532 i = 0; 3533 while (*ptr_directory_table != 0) 3534 { 3535 directory_table[i] = ptr_directory_table; 3536 ptr_directory_table += strnlen ((char *) ptr_directory_table, 3537 ptr_directory_table - end) + 1; 3538 i++; 3539 } 3540 } 3541 /* Skip the NUL at the end of the table. */ 3542 data++; 3543 3544 /* Traverse the File Name table just to count the entries. */ 3545 if (*data != 0) 3546 { 3547 unsigned char *ptr_file_name_table = data; 3548 3549 while (*data != 0) 3550 { 3551 unsigned int bytes_read; 3552 3553 /* Skip Name, directory index, last modification time and length 3554 of file. */ 3555 data += strnlen ((char *) data, end - data) + 1; 3556 read_uleb128 (data, & bytes_read, end); 3557 data += bytes_read; 3558 read_uleb128 (data, & bytes_read, end); 3559 data += bytes_read; 3560 read_uleb128 (data, & bytes_read, end); 3561 data += bytes_read; 3562 3563 n_files++; 3564 } 3565 3566 /* Go through the file table again to save the strings. */ 3567 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); 3568 3569 i = 0; 3570 while (*ptr_file_name_table != 0) 3571 { 3572 unsigned int bytes_read; 3573 3574 file_table[i].name = ptr_file_name_table; 3575 ptr_file_name_table += strnlen ((char *) ptr_file_name_table, 3576 end - ptr_file_name_table) + 1; 3577 3578 /* We are not interested in directory, time or size. */ 3579 file_table[i].directory_index = read_uleb128 (ptr_file_name_table, 3580 & bytes_read, end); 3581 ptr_file_name_table += bytes_read; 3582 file_table[i].modification_date = read_uleb128 (ptr_file_name_table, 3583 & bytes_read, end); 3584 ptr_file_name_table += bytes_read; 3585 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end); 3586 ptr_file_name_table += bytes_read; 3587 i++; 3588 } 3589 i = 0; 3590 3591 /* Print the Compilation Unit's name and a header. */ 3592 if (directory_table == NULL) 3593 { 3594 printf (_("CU: %s:\n"), file_table[0].name); 3595 printf (_("File name Line number Starting address\n")); 3596 } 3597 else 3598 { 3599 unsigned int ix = file_table[0].directory_index; 3600 const char *directory = ix ? (char *)directory_table[ix - 1] : "."; 3601 3602 if (do_wide || strlen (directory) < 76) 3603 printf (_("CU: %s/%s:\n"), directory, file_table[0].name); 3604 else 3605 printf ("%s:\n", file_table[0].name); 3606 3607 printf (_("File name Line number Starting address\n")); 3608 } 3609 } 3610 3611 /* Skip the NUL at the end of the table. */ 3612 data++; 3613 3614 saved_linfo = linfo; 3615 } 3616 3617 /* This loop iterates through the Dwarf Line Number Program. */ 3618 while (data < end_of_sequence) 3619 { 3620 unsigned char op_code; 3621 int adv; 3622 unsigned long int uladv; 3623 unsigned int bytes_read; 3624 int is_special_opcode = 0; 3625 3626 op_code = *data++; 3627 3628 if (op_code >= linfo.li_opcode_base) 3629 { 3630 op_code -= linfo.li_opcode_base; 3631 uladv = (op_code / linfo.li_line_range); 3632 if (linfo.li_max_ops_per_insn == 1) 3633 { 3634 uladv *= linfo.li_min_insn_length; 3635 state_machine_regs.address += uladv; 3636 } 3637 else 3638 { 3639 state_machine_regs.address 3640 += ((state_machine_regs.op_index + uladv) 3641 / linfo.li_max_ops_per_insn) 3642 * linfo.li_min_insn_length; 3643 state_machine_regs.op_index 3644 = (state_machine_regs.op_index + uladv) 3645 % linfo.li_max_ops_per_insn; 3646 } 3647 3648 adv = (op_code % linfo.li_line_range) + linfo.li_line_base; 3649 state_machine_regs.line += adv; 3650 is_special_opcode = 1; 3651 } 3652 else switch (op_code) 3653 { 3654 case DW_LNS_extended_op: 3655 { 3656 unsigned int ext_op_code_len; 3657 unsigned char ext_op_code; 3658 unsigned char *op_code_data = data; 3659 3660 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read, 3661 end_of_sequence); 3662 op_code_data += bytes_read; 3663 3664 if (ext_op_code_len == 0) 3665 { 3666 warn (_("Badly formed extended line op encountered!\n")); 3667 break; 3668 } 3669 ext_op_code_len += bytes_read; 3670 ext_op_code = *op_code_data++; 3671 3672 switch (ext_op_code) 3673 { 3674 case DW_LNE_end_sequence: 3675 reset_state_machine (linfo.li_default_is_stmt); 3676 break; 3677 case DW_LNE_set_address: 3678 SAFE_BYTE_GET_AND_INC (state_machine_regs.address, 3679 op_code_data, 3680 ext_op_code_len - bytes_read - 1, 3681 end); 3682 state_machine_regs.op_index = 0; 3683 break; 3684 case DW_LNE_define_file: 3685 { 3686 file_table = (File_Entry *) xrealloc 3687 (file_table, (n_files + 1) * sizeof (File_Entry)); 3688 3689 ++state_machine_regs.last_file_entry; 3690 /* Source file name. */ 3691 file_table[n_files].name = op_code_data; 3692 op_code_data += strlen ((char *) op_code_data) + 1; 3693 /* Directory index. */ 3694 file_table[n_files].directory_index = 3695 read_uleb128 (op_code_data, & bytes_read, 3696 end_of_sequence); 3697 op_code_data += bytes_read; 3698 /* Last modification time. */ 3699 file_table[n_files].modification_date = 3700 read_uleb128 (op_code_data, & bytes_read, 3701 end_of_sequence); 3702 op_code_data += bytes_read; 3703 /* File length. */ 3704 file_table[n_files].length = 3705 read_uleb128 (op_code_data, & bytes_read, 3706 end_of_sequence); 3707 3708 n_files++; 3709 break; 3710 } 3711 case DW_LNE_set_discriminator: 3712 case DW_LNE_HP_set_sequence: 3713 /* Simply ignored. */ 3714 break; 3715 3716 default: 3717 printf (_("UNKNOWN (%u): length %d\n"), 3718 ext_op_code, ext_op_code_len - bytes_read); 3719 break; 3720 } 3721 data += ext_op_code_len; 3722 break; 3723 } 3724 case DW_LNS_copy: 3725 break; 3726 3727 case DW_LNS_advance_pc: 3728 uladv = read_uleb128 (data, & bytes_read, end); 3729 data += bytes_read; 3730 if (linfo.li_max_ops_per_insn == 1) 3731 { 3732 uladv *= linfo.li_min_insn_length; 3733 state_machine_regs.address += uladv; 3734 } 3735 else 3736 { 3737 state_machine_regs.address 3738 += ((state_machine_regs.op_index + uladv) 3739 / linfo.li_max_ops_per_insn) 3740 * linfo.li_min_insn_length; 3741 state_machine_regs.op_index 3742 = (state_machine_regs.op_index + uladv) 3743 % linfo.li_max_ops_per_insn; 3744 } 3745 break; 3746 3747 case DW_LNS_advance_line: 3748 adv = read_sleb128 (data, & bytes_read, end); 3749 data += bytes_read; 3750 state_machine_regs.line += adv; 3751 break; 3752 3753 case DW_LNS_set_file: 3754 adv = read_uleb128 (data, & bytes_read, end); 3755 data += bytes_read; 3756 state_machine_regs.file = adv; 3757 3758 if (file_table == NULL) 3759 printf (_("\n [Use file table entry %d]\n"), state_machine_regs.file - 1); 3760 else if (file_table[state_machine_regs.file - 1].directory_index == 0) 3761 /* If directory index is 0, that means current directory. */ 3762 printf ("\n./%s:[++]\n", 3763 file_table[state_machine_regs.file - 1].name); 3764 else if (directory_table == NULL) 3765 printf (_("\n [Use directory table entry %d]\n"), 3766 file_table[state_machine_regs.file - 1].directory_index - 1); 3767 else 3768 /* The directory index starts counting at 1. */ 3769 printf ("\n%s/%s:\n", 3770 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1], 3771 file_table[state_machine_regs.file - 1].name); 3772 break; 3773 3774 case DW_LNS_set_column: 3775 uladv = read_uleb128 (data, & bytes_read, end); 3776 data += bytes_read; 3777 state_machine_regs.column = uladv; 3778 break; 3779 3780 case DW_LNS_negate_stmt: 3781 adv = state_machine_regs.is_stmt; 3782 adv = ! adv; 3783 state_machine_regs.is_stmt = adv; 3784 break; 3785 3786 case DW_LNS_set_basic_block: 3787 state_machine_regs.basic_block = 1; 3788 break; 3789 3790 case DW_LNS_const_add_pc: 3791 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); 3792 if (linfo.li_max_ops_per_insn == 1) 3793 { 3794 uladv *= linfo.li_min_insn_length; 3795 state_machine_regs.address += uladv; 3796 } 3797 else 3798 { 3799 state_machine_regs.address 3800 += ((state_machine_regs.op_index + uladv) 3801 / linfo.li_max_ops_per_insn) 3802 * linfo.li_min_insn_length; 3803 state_machine_regs.op_index 3804 = (state_machine_regs.op_index + uladv) 3805 % linfo.li_max_ops_per_insn; 3806 } 3807 break; 3808 3809 case DW_LNS_fixed_advance_pc: 3810 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); 3811 state_machine_regs.address += uladv; 3812 state_machine_regs.op_index = 0; 3813 break; 3814 3815 case DW_LNS_set_prologue_end: 3816 break; 3817 3818 case DW_LNS_set_epilogue_begin: 3819 break; 3820 3821 case DW_LNS_set_isa: 3822 uladv = read_uleb128 (data, & bytes_read, end); 3823 data += bytes_read; 3824 printf (_(" Set ISA to %lu\n"), uladv); 3825 break; 3826 3827 default: 3828 printf (_(" Unknown opcode %d with operands: "), op_code); 3829 3830 if (standard_opcodes != NULL) 3831 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) 3832 { 3833 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, 3834 &bytes_read, end)), 3835 i == 1 ? "" : ", "); 3836 data += bytes_read; 3837 } 3838 putchar ('\n'); 3839 break; 3840 } 3841 3842 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row 3843 to the DWARF address/line matrix. */ 3844 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence) 3845 || (op_code == DW_LNS_copy)) 3846 { 3847 const unsigned int MAX_FILENAME_LENGTH = 35; 3848 char *fileName; 3849 char *newFileName = NULL; 3850 size_t fileNameLength; 3851 3852 if (file_table) 3853 fileName = (char *) file_table[state_machine_regs.file - 1].name; 3854 else 3855 fileName = "<unknown>"; 3856 3857 fileNameLength = strlen (fileName); 3858 3859 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) 3860 { 3861 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); 3862 /* Truncate file name */ 3863 strncpy (newFileName, 3864 fileName + fileNameLength - MAX_FILENAME_LENGTH, 3865 MAX_FILENAME_LENGTH + 1); 3866 } 3867 else 3868 { 3869 newFileName = (char *) xmalloc (fileNameLength + 1); 3870 strncpy (newFileName, fileName, fileNameLength + 1); 3871 } 3872 3873 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) 3874 { 3875 if (linfo.li_max_ops_per_insn == 1) 3876 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n", 3877 newFileName, state_machine_regs.line, 3878 state_machine_regs.address); 3879 else 3880 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n", 3881 newFileName, state_machine_regs.line, 3882 state_machine_regs.address, 3883 state_machine_regs.op_index); 3884 } 3885 else 3886 { 3887 if (linfo.li_max_ops_per_insn == 1) 3888 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n", 3889 newFileName, state_machine_regs.line, 3890 state_machine_regs.address); 3891 else 3892 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n", 3893 newFileName, state_machine_regs.line, 3894 state_machine_regs.address, 3895 state_machine_regs.op_index); 3896 } 3897 3898 if (op_code == DW_LNE_end_sequence) 3899 printf ("\n"); 3900 3901 free (newFileName); 3902 } 3903 } 3904 3905 if (file_table) 3906 { 3907 free (file_table); 3908 file_table = NULL; 3909 n_files = 0; 3910 } 3911 3912 if (directory_table) 3913 { 3914 free (directory_table); 3915 directory_table = NULL; 3916 n_directories = 0; 3917 } 3918 3919 putchar ('\n'); 3920 } 3921 3922 return 1; 3923 } 3924 3925 static int 3926 display_debug_lines (struct dwarf_section *section, void *file) 3927 { 3928 unsigned char *data = section->start; 3929 unsigned char *end = data + section->size; 3930 int retValRaw = 1; 3931 int retValDecoded = 1; 3932 3933 if (do_debug_lines == 0) 3934 do_debug_lines |= FLAG_DEBUG_LINES_RAW; 3935 3936 load_debug_section (line_str, file); 3937 3938 if (do_debug_lines & FLAG_DEBUG_LINES_RAW) 3939 retValRaw = display_debug_lines_raw (section, data, end); 3940 3941 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) 3942 retValDecoded = display_debug_lines_decoded (section, data, end); 3943 3944 if (!retValRaw || !retValDecoded) 3945 return 0; 3946 3947 return 1; 3948 } 3949 3950 static debug_info * 3951 find_debug_info_for_offset (unsigned long offset) 3952 { 3953 unsigned int i; 3954 3955 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) 3956 return NULL; 3957 3958 for (i = 0; i < num_debug_info_entries; i++) 3959 if (debug_information[i].cu_offset == offset) 3960 return debug_information + i; 3961 3962 return NULL; 3963 } 3964 3965 static const char * 3966 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) 3967 { 3968 /* See gdb/gdb-index.h. */ 3969 static const char * const kinds[] = 3970 { 3971 N_ ("no info"), 3972 N_ ("type"), 3973 N_ ("variable"), 3974 N_ ("function"), 3975 N_ ("other"), 3976 N_ ("unused5"), 3977 N_ ("unused6"), 3978 N_ ("unused7") 3979 }; 3980 3981 return _ (kinds[kind]); 3982 } 3983 3984 static int 3985 display_debug_pubnames_worker (struct dwarf_section *section, 3986 void *file ATTRIBUTE_UNUSED, 3987 int is_gnu) 3988 { 3989 DWARF2_Internal_PubNames names; 3990 unsigned char *start = section->start; 3991 unsigned char *end = start + section->size; 3992 3993 /* It does not matter if this load fails, 3994 we test for that later on. */ 3995 load_debug_info (file); 3996 3997 printf (_("Contents of the %s section:\n\n"), section->name); 3998 3999 while (start < end) 4000 { 4001 unsigned char *data; 4002 unsigned long offset; 4003 unsigned int offset_size, initial_length_size; 4004 4005 data = start; 4006 4007 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end); 4008 if (names.pn_length == 0xffffffff) 4009 { 4010 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end); 4011 offset_size = 8; 4012 initial_length_size = 12; 4013 } 4014 else 4015 { 4016 offset_size = 4; 4017 initial_length_size = 4; 4018 } 4019 4020 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); 4021 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); 4022 4023 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE 4024 && num_debug_info_entries > 0 4025 && find_debug_info_for_offset (names.pn_offset) == NULL) 4026 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), 4027 (unsigned long) names.pn_offset, section->name); 4028 4029 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); 4030 4031 start += names.pn_length + initial_length_size; 4032 4033 if (names.pn_version != 2 && names.pn_version != 3) 4034 { 4035 static int warned = 0; 4036 4037 if (! warned) 4038 { 4039 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); 4040 warned = 1; 4041 } 4042 4043 continue; 4044 } 4045 4046 printf (_(" Length: %ld\n"), 4047 (long) names.pn_length); 4048 printf (_(" Version: %d\n"), 4049 names.pn_version); 4050 printf (_(" Offset into .debug_info section: 0x%lx\n"), 4051 (unsigned long) names.pn_offset); 4052 printf (_(" Size of area in .debug_info section: %ld\n"), 4053 (long) names.pn_size); 4054 4055 if (is_gnu) 4056 printf (_("\n Offset Kind Name\n")); 4057 else 4058 printf (_("\n Offset\tName\n")); 4059 4060 do 4061 { 4062 bfd_size_type maxprint; 4063 4064 SAFE_BYTE_GET (offset, data, offset_size, end); 4065 4066 if (offset != 0) 4067 { 4068 data += offset_size; 4069 if (data >= end) 4070 break; 4071 maxprint = (end - data) - 1; 4072 4073 if (is_gnu) 4074 { 4075 unsigned int kind_data; 4076 gdb_index_symbol_kind kind; 4077 const char *kind_name; 4078 int is_static; 4079 4080 SAFE_BYTE_GET (kind_data, data, 1, end); 4081 data++; 4082 maxprint --; 4083 /* GCC computes the kind as the upper byte in the CU index 4084 word, and then right shifts it by the CU index size. 4085 Left shift KIND to where the gdb-index.h accessor macros 4086 can use it. */ 4087 kind_data <<= GDB_INDEX_CU_BITSIZE; 4088 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); 4089 kind_name = get_gdb_index_symbol_kind_name (kind); 4090 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); 4091 printf (" %-6lx %s,%-10s %.*s\n", 4092 offset, is_static ? _("s") : _("g"), 4093 kind_name, (int) maxprint, data); 4094 } 4095 else 4096 printf (" %-6lx\t%.*s\n", offset, (int) maxprint, data); 4097 4098 data += strnlen ((char *) data, maxprint) + 1; 4099 if (data >= end) 4100 break; 4101 } 4102 } 4103 while (offset != 0); 4104 } 4105 4106 printf ("\n"); 4107 return 1; 4108 } 4109 4110 static int 4111 display_debug_pubnames (struct dwarf_section *section, void *file) 4112 { 4113 return display_debug_pubnames_worker (section, file, 0); 4114 } 4115 4116 static int 4117 display_debug_gnu_pubnames (struct dwarf_section *section, void *file) 4118 { 4119 return display_debug_pubnames_worker (section, file, 1); 4120 } 4121 4122 static int 4123 display_debug_macinfo (struct dwarf_section *section, 4124 void *file ATTRIBUTE_UNUSED) 4125 { 4126 unsigned char *start = section->start; 4127 unsigned char *end = start + section->size; 4128 unsigned char *curr = start; 4129 unsigned int bytes_read; 4130 enum dwarf_macinfo_record_type op; 4131 4132 printf (_("Contents of the %s section:\n\n"), section->name); 4133 4134 while (curr < end) 4135 { 4136 unsigned int lineno; 4137 const unsigned char *string; 4138 4139 op = (enum dwarf_macinfo_record_type) *curr; 4140 curr++; 4141 4142 switch (op) 4143 { 4144 case DW_MACINFO_start_file: 4145 { 4146 unsigned int filenum; 4147 4148 lineno = read_uleb128 (curr, & bytes_read, end); 4149 curr += bytes_read; 4150 filenum = read_uleb128 (curr, & bytes_read, end); 4151 curr += bytes_read; 4152 4153 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), 4154 lineno, filenum); 4155 } 4156 break; 4157 4158 case DW_MACINFO_end_file: 4159 printf (_(" DW_MACINFO_end_file\n")); 4160 break; 4161 4162 case DW_MACINFO_define: 4163 lineno = read_uleb128 (curr, & bytes_read, end); 4164 curr += bytes_read; 4165 string = curr; 4166 curr += strnlen ((char *) string, end - string) + 1; 4167 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), 4168 lineno, string); 4169 break; 4170 4171 case DW_MACINFO_undef: 4172 lineno = read_uleb128 (curr, & bytes_read, end); 4173 curr += bytes_read; 4174 string = curr; 4175 curr += strnlen ((char *) string, end - string) + 1; 4176 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), 4177 lineno, string); 4178 break; 4179 4180 case DW_MACINFO_vendor_ext: 4181 { 4182 unsigned int constant; 4183 4184 constant = read_uleb128 (curr, & bytes_read, end); 4185 curr += bytes_read; 4186 string = curr; 4187 curr += strnlen ((char *) string, end - string) + 1; 4188 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), 4189 constant, string); 4190 } 4191 break; 4192 } 4193 } 4194 4195 return 1; 4196 } 4197 4198 /* Given LINE_OFFSET into the .debug_line section, attempt to return 4199 filename and dirname corresponding to file name table entry with index 4200 FILEIDX. Return NULL on failure. */ 4201 4202 static unsigned char * 4203 get_line_filename_and_dirname (dwarf_vma line_offset, 4204 dwarf_vma fileidx, 4205 unsigned char **dir_name) 4206 { 4207 struct dwarf_section *section = &debug_displays [line].section; 4208 unsigned char *hdrptr, *dirtable, *file_name; 4209 unsigned int offset_size, initial_length_size; 4210 unsigned int version, opcode_base, bytes_read; 4211 dwarf_vma length, diridx; 4212 const unsigned char * end; 4213 4214 *dir_name = NULL; 4215 if (section->start == NULL 4216 || line_offset >= section->size 4217 || fileidx == 0) 4218 return NULL; 4219 4220 hdrptr = section->start + line_offset; 4221 end = section->start + section->size; 4222 4223 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); 4224 if (length == 0xffffffff) 4225 { 4226 /* This section is 64-bit DWARF 3. */ 4227 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); 4228 offset_size = 8; 4229 initial_length_size = 12; 4230 } 4231 else 4232 { 4233 offset_size = 4; 4234 initial_length_size = 4; 4235 } 4236 if (length + initial_length_size > section->size) 4237 return NULL; 4238 4239 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); 4240 if (version != 2 && version != 3 && version != 4) 4241 return NULL; 4242 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ 4243 if (version >= 4) 4244 hdrptr++; /* Skip max_ops_per_insn. */ 4245 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ 4246 4247 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); 4248 if (opcode_base == 0) 4249 return NULL; 4250 4251 hdrptr += opcode_base - 1; 4252 dirtable = hdrptr; 4253 /* Skip over dirname table. */ 4254 while (*hdrptr != '\0') 4255 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; 4256 hdrptr++; /* Skip the NUL at the end of the table. */ 4257 /* Now skip over preceding filename table entries. */ 4258 for (; *hdrptr != '\0' && fileidx > 1; fileidx--) 4259 { 4260 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; 4261 read_uleb128 (hdrptr, &bytes_read, end); 4262 hdrptr += bytes_read; 4263 read_uleb128 (hdrptr, &bytes_read, end); 4264 hdrptr += bytes_read; 4265 read_uleb128 (hdrptr, &bytes_read, end); 4266 hdrptr += bytes_read; 4267 } 4268 if (hdrptr == end || *hdrptr == '\0') 4269 return NULL; 4270 file_name = hdrptr; 4271 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; 4272 diridx = read_uleb128 (hdrptr, &bytes_read, end); 4273 if (diridx == 0) 4274 return file_name; 4275 for (; *dirtable != '\0' && diridx > 1; diridx--) 4276 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; 4277 if (*dirtable == '\0') 4278 return NULL; 4279 *dir_name = dirtable; 4280 return file_name; 4281 } 4282 4283 static int 4284 display_debug_macro (struct dwarf_section *section, 4285 void *file) 4286 { 4287 unsigned char *start = section->start; 4288 unsigned char *end = start + section->size; 4289 unsigned char *curr = start; 4290 unsigned char *extended_op_buf[256]; 4291 unsigned int bytes_read; 4292 4293 load_debug_section (str, file); 4294 load_debug_section (line, file); 4295 4296 printf (_("Contents of the %s section:\n\n"), section->name); 4297 4298 while (curr < end) 4299 { 4300 unsigned int lineno, version, flags; 4301 unsigned int offset_size = 4; 4302 const unsigned char *string; 4303 dwarf_vma line_offset = 0, sec_offset = curr - start, offset; 4304 unsigned char **extended_ops = NULL; 4305 4306 SAFE_BYTE_GET_AND_INC (version, curr, 2, end); 4307 if (version != 4) 4308 { 4309 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"), 4310 section->name); 4311 return 0; 4312 } 4313 4314 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); 4315 if (flags & 1) 4316 offset_size = 8; 4317 printf (_(" Offset: 0x%lx\n"), 4318 (unsigned long) sec_offset); 4319 printf (_(" Version: %d\n"), version); 4320 printf (_(" Offset size: %d\n"), offset_size); 4321 if (flags & 2) 4322 { 4323 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); 4324 printf (_(" Offset into .debug_line: 0x%lx\n"), 4325 (unsigned long) line_offset); 4326 } 4327 if (flags & 4) 4328 { 4329 unsigned int i, count, op; 4330 dwarf_vma nargs, n; 4331 4332 SAFE_BYTE_GET_AND_INC (count, curr, 1, end); 4333 4334 memset (extended_op_buf, 0, sizeof (extended_op_buf)); 4335 extended_ops = extended_op_buf; 4336 if (count) 4337 { 4338 printf (_(" Extension opcode arguments:\n")); 4339 for (i = 0; i < count; i++) 4340 { 4341 SAFE_BYTE_GET_AND_INC (op, curr, 1, end); 4342 extended_ops[op] = curr; 4343 nargs = read_uleb128 (curr, &bytes_read, end); 4344 curr += bytes_read; 4345 if (nargs == 0) 4346 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op); 4347 else 4348 { 4349 printf (_(" DW_MACRO_GNU_%02x arguments: "), op); 4350 for (n = 0; n < nargs; n++) 4351 { 4352 unsigned int form; 4353 4354 SAFE_BYTE_GET_AND_INC (form, curr, 1, end); 4355 printf ("%s%s", get_FORM_name (form), 4356 n == nargs - 1 ? "\n" : ", "); 4357 switch (form) 4358 { 4359 case DW_FORM_data1: 4360 case DW_FORM_data2: 4361 case DW_FORM_data4: 4362 case DW_FORM_data8: 4363 case DW_FORM_sdata: 4364 case DW_FORM_udata: 4365 case DW_FORM_block: 4366 case DW_FORM_block1: 4367 case DW_FORM_block2: 4368 case DW_FORM_block4: 4369 case DW_FORM_flag: 4370 case DW_FORM_string: 4371 case DW_FORM_strp: 4372 case DW_FORM_sec_offset: 4373 break; 4374 default: 4375 error (_("Invalid extension opcode form %s\n"), 4376 get_FORM_name (form)); 4377 return 0; 4378 } 4379 } 4380 } 4381 } 4382 } 4383 } 4384 printf ("\n"); 4385 4386 while (1) 4387 { 4388 unsigned int op; 4389 4390 if (curr >= end) 4391 { 4392 error (_(".debug_macro section not zero terminated\n")); 4393 return 0; 4394 } 4395 4396 SAFE_BYTE_GET_AND_INC (op, curr, 1, end); 4397 if (op == 0) 4398 break; 4399 4400 switch (op) 4401 { 4402 case DW_MACRO_GNU_start_file: 4403 { 4404 unsigned int filenum; 4405 unsigned char *file_name = NULL, *dir_name = NULL; 4406 4407 lineno = read_uleb128 (curr, &bytes_read, end); 4408 curr += bytes_read; 4409 filenum = read_uleb128 (curr, &bytes_read, end); 4410 curr += bytes_read; 4411 4412 if ((flags & 2) == 0) 4413 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n")); 4414 else 4415 file_name 4416 = get_line_filename_and_dirname (line_offset, filenum, 4417 &dir_name); 4418 if (file_name == NULL) 4419 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"), 4420 lineno, filenum); 4421 else 4422 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), 4423 lineno, filenum, 4424 dir_name != NULL ? (const char *) dir_name : "", 4425 dir_name != NULL ? "/" : "", file_name); 4426 } 4427 break; 4428 4429 case DW_MACRO_GNU_end_file: 4430 printf (_(" DW_MACRO_GNU_end_file\n")); 4431 break; 4432 4433 case DW_MACRO_GNU_define: 4434 lineno = read_uleb128 (curr, &bytes_read, end); 4435 curr += bytes_read; 4436 string = curr; 4437 curr += strnlen ((char *) string, end - string) + 1; 4438 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"), 4439 lineno, string); 4440 break; 4441 4442 case DW_MACRO_GNU_undef: 4443 lineno = read_uleb128 (curr, &bytes_read, end); 4444 curr += bytes_read; 4445 string = curr; 4446 curr += strnlen ((char *) string, end - string) + 1; 4447 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"), 4448 lineno, string); 4449 break; 4450 4451 case DW_MACRO_GNU_define_indirect: 4452 lineno = read_uleb128 (curr, &bytes_read, end); 4453 curr += bytes_read; 4454 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); 4455 string = fetch_indirect_string (offset); 4456 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"), 4457 lineno, string); 4458 break; 4459 4460 case DW_MACRO_GNU_undef_indirect: 4461 lineno = read_uleb128 (curr, &bytes_read, end); 4462 curr += bytes_read; 4463 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); 4464 string = fetch_indirect_string (offset); 4465 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"), 4466 lineno, string); 4467 break; 4468 4469 case DW_MACRO_GNU_transparent_include: 4470 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); 4471 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"), 4472 (unsigned long) offset); 4473 break; 4474 4475 case DW_MACRO_GNU_define_indirect_alt: 4476 lineno = read_uleb128 (curr, &bytes_read, end); 4477 curr += bytes_read; 4478 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); 4479 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"), 4480 lineno, (unsigned long) offset); 4481 break; 4482 4483 case DW_MACRO_GNU_undef_indirect_alt: 4484 lineno = read_uleb128 (curr, &bytes_read, end); 4485 curr += bytes_read; 4486 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); 4487 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"), 4488 lineno, (unsigned long) offset); 4489 break; 4490 4491 case DW_MACRO_GNU_transparent_include_alt: 4492 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); 4493 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"), 4494 (unsigned long) offset); 4495 break; 4496 4497 default: 4498 if (extended_ops == NULL || extended_ops[op] == NULL) 4499 { 4500 error (_(" Unknown macro opcode %02x seen\n"), op); 4501 return 0; 4502 } 4503 else 4504 { 4505 /* Skip over unhandled opcodes. */ 4506 dwarf_vma nargs, n; 4507 unsigned char *desc = extended_ops[op]; 4508 nargs = read_uleb128 (desc, &bytes_read, end); 4509 desc += bytes_read; 4510 if (nargs == 0) 4511 { 4512 printf (_(" DW_MACRO_GNU_%02x\n"), op); 4513 break; 4514 } 4515 printf (_(" DW_MACRO_GNU_%02x -"), op); 4516 for (n = 0; n < nargs; n++) 4517 { 4518 int val; 4519 4520 SAFE_BYTE_GET_AND_INC (val, desc, 1, end); 4521 curr 4522 = read_and_display_attr_value (0, val, 4523 curr, end, 0, 0, offset_size, 4524 version, NULL, 0, NULL, 4525 NULL); 4526 if (n != nargs - 1) 4527 printf (","); 4528 } 4529 printf ("\n"); 4530 } 4531 break; 4532 } 4533 } 4534 4535 printf ("\n"); 4536 } 4537 4538 return 1; 4539 } 4540 4541 static int 4542 display_debug_abbrev (struct dwarf_section *section, 4543 void *file ATTRIBUTE_UNUSED) 4544 { 4545 abbrev_entry *entry; 4546 unsigned char *start = section->start; 4547 unsigned char *end = start + section->size; 4548 4549 printf (_("Contents of the %s section:\n\n"), section->name); 4550 4551 do 4552 { 4553 unsigned char *last; 4554 4555 free_abbrevs (); 4556 4557 last = start; 4558 start = process_abbrev_section (start, end); 4559 4560 if (first_abbrev == NULL) 4561 continue; 4562 4563 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); 4564 4565 for (entry = first_abbrev; entry; entry = entry->next) 4566 { 4567 abbrev_attr *attr; 4568 4569 printf (" %ld %s [%s]\n", 4570 entry->entry, 4571 get_TAG_name (entry->tag), 4572 entry->children ? _("has children") : _("no children")); 4573 4574 for (attr = entry->first_attr; attr; attr = attr->next) 4575 printf (" %-18s %s\n", 4576 get_AT_name (attr->attribute), 4577 get_FORM_name (attr->form)); 4578 } 4579 } 4580 while (start); 4581 4582 printf ("\n"); 4583 4584 return 1; 4585 } 4586 4587 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ 4588 4589 static void 4590 display_loc_list (struct dwarf_section *section, 4591 unsigned char **start_ptr, 4592 int debug_info_entry, 4593 unsigned long offset, 4594 unsigned long base_address, 4595 int has_frame_base) 4596 { 4597 unsigned char *start = *start_ptr; 4598 unsigned char *section_end = section->start + section->size; 4599 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset; 4600 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; 4601 unsigned int offset_size = debug_information [debug_info_entry].offset_size; 4602 int dwarf_version = debug_information [debug_info_entry].dwarf_version; 4603 4604 dwarf_vma begin; 4605 dwarf_vma end; 4606 unsigned short length; 4607 int need_frame_base; 4608 4609 if (pointer_size < 2 || pointer_size > 8) 4610 { 4611 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), 4612 pointer_size, debug_info_entry); 4613 return; 4614 } 4615 4616 while (1) 4617 { 4618 if (start + 2 * pointer_size > section_end) 4619 { 4620 warn (_("Location list starting at offset 0x%lx is not terminated.\n"), 4621 offset); 4622 break; 4623 } 4624 4625 printf (" %8.8lx ", offset + (start - *start_ptr)); 4626 4627 /* Note: we use sign extension here in order to be sure that we can detect 4628 the -1 escape value. Sign extension into the top 32 bits of a 32-bit 4629 address will not affect the values that we display since we always show 4630 hex values, and always the bottom 32-bits. */ 4631 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); 4632 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); 4633 4634 if (begin == 0 && end == 0) 4635 { 4636 printf (_("<End of list>\n")); 4637 break; 4638 } 4639 4640 /* Check base address specifiers. */ 4641 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1) 4642 { 4643 base_address = end; 4644 print_dwarf_vma (begin, pointer_size); 4645 print_dwarf_vma (end, pointer_size); 4646 printf (_("(base address)\n")); 4647 continue; 4648 } 4649 4650 if (start + 2 > section_end) 4651 { 4652 warn (_("Location list starting at offset 0x%lx is not terminated.\n"), 4653 offset); 4654 break; 4655 } 4656 4657 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); 4658 4659 if (start + length > section_end) 4660 { 4661 warn (_("Location list starting at offset 0x%lx is not terminated.\n"), 4662 offset); 4663 break; 4664 } 4665 4666 print_dwarf_vma (begin + base_address, pointer_size); 4667 print_dwarf_vma (end + base_address, pointer_size); 4668 4669 putchar ('('); 4670 need_frame_base = decode_location_expression (start, 4671 pointer_size, 4672 offset_size, 4673 dwarf_version, 4674 length, 4675 cu_offset, section); 4676 putchar (')'); 4677 4678 if (need_frame_base && !has_frame_base) 4679 printf (_(" [without DW_AT_frame_base]")); 4680 4681 if (begin == end) 4682 fputs (_(" (start == end)"), stdout); 4683 else if (begin > end) 4684 fputs (_(" (start > end)"), stdout); 4685 4686 putchar ('\n'); 4687 4688 start += length; 4689 } 4690 4691 *start_ptr = start; 4692 } 4693 4694 /* Print a .debug_addr table index in decimal, surrounded by square brackets, 4695 right-adjusted in a field of length LEN, and followed by a space. */ 4696 4697 static void 4698 print_addr_index (unsigned int idx, unsigned int len) 4699 { 4700 static char buf[15]; 4701 snprintf (buf, sizeof (buf), "[%d]", idx); 4702 printf ("%*s ", len, buf); 4703 } 4704 4705 /* Display a location list from a .dwo section. It uses address indexes rather 4706 than embedded addresses. This code closely follows display_loc_list, but the 4707 two are sufficiently different that combining things is very ugly. */ 4708 4709 static void 4710 display_loc_list_dwo (struct dwarf_section *section, 4711 unsigned char **start_ptr, 4712 int debug_info_entry, 4713 unsigned long offset, 4714 int has_frame_base) 4715 { 4716 unsigned char *start = *start_ptr; 4717 unsigned char *section_end = section->start + section->size; 4718 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset; 4719 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; 4720 unsigned int offset_size = debug_information [debug_info_entry].offset_size; 4721 int dwarf_version = debug_information [debug_info_entry].dwarf_version; 4722 int entry_type; 4723 unsigned short length; 4724 int need_frame_base; 4725 unsigned int idx; 4726 unsigned int bytes_read; 4727 4728 if (pointer_size < 2 || pointer_size > 8) 4729 { 4730 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), 4731 pointer_size, debug_info_entry); 4732 return; 4733 } 4734 4735 while (1) 4736 { 4737 printf (" %8.8lx ", offset + (start - *start_ptr)); 4738 4739 if (start >= section_end) 4740 { 4741 warn (_("Location list starting at offset 0x%lx is not terminated.\n"), 4742 offset); 4743 break; 4744 } 4745 4746 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); 4747 switch (entry_type) 4748 { 4749 case 0: /* A terminating entry. */ 4750 *start_ptr = start; 4751 printf (_("<End of list>\n")); 4752 return; 4753 case 1: /* A base-address entry. */ 4754 idx = read_uleb128 (start, &bytes_read, section_end); 4755 start += bytes_read; 4756 print_addr_index (idx, 8); 4757 printf (" "); 4758 printf (_("(base address selection entry)\n")); 4759 continue; 4760 case 2: /* A start/end entry. */ 4761 idx = read_uleb128 (start, &bytes_read, section_end); 4762 start += bytes_read; 4763 print_addr_index (idx, 8); 4764 idx = read_uleb128 (start, &bytes_read, section_end); 4765 start += bytes_read; 4766 print_addr_index (idx, 8); 4767 break; 4768 case 3: /* A start/length entry. */ 4769 idx = read_uleb128 (start, &bytes_read, section_end); 4770 start += bytes_read; 4771 print_addr_index (idx, 8); 4772 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); 4773 printf ("%08x ", idx); 4774 break; 4775 case 4: /* An offset pair entry. */ 4776 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); 4777 printf ("%08x ", idx); 4778 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); 4779 printf ("%08x ", idx); 4780 break; 4781 default: 4782 warn (_("Unknown location list entry type 0x%x.\n"), entry_type); 4783 *start_ptr = start; 4784 return; 4785 } 4786 4787 if (start + 2 > section_end) 4788 { 4789 warn (_("Location list starting at offset 0x%lx is not terminated.\n"), 4790 offset); 4791 break; 4792 } 4793 4794 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); 4795 if (start + length > section_end) 4796 { 4797 warn (_("Location list starting at offset 0x%lx is not terminated.\n"), 4798 offset); 4799 break; 4800 } 4801 4802 putchar ('('); 4803 need_frame_base = decode_location_expression (start, 4804 pointer_size, 4805 offset_size, 4806 dwarf_version, 4807 length, 4808 cu_offset, section); 4809 putchar (')'); 4810 4811 if (need_frame_base && !has_frame_base) 4812 printf (_(" [without DW_AT_frame_base]")); 4813 4814 putchar ('\n'); 4815 4816 start += length; 4817 } 4818 4819 *start_ptr = start; 4820 } 4821 4822 /* Sort array of indexes in ascending order of loc_offsets[idx]. */ 4823 4824 static dwarf_vma *loc_offsets; 4825 4826 static int 4827 loc_offsets_compar (const void *ap, const void *bp) 4828 { 4829 dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; 4830 dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; 4831 4832 return (a > b) - (b > a); 4833 } 4834 4835 static int 4836 display_debug_loc (struct dwarf_section *section, void *file) 4837 { 4838 unsigned char *start = section->start; 4839 unsigned long bytes; 4840 unsigned char *section_begin = start; 4841 unsigned int num_loc_list = 0; 4842 unsigned long last_offset = 0; 4843 unsigned int first = 0; 4844 unsigned int i; 4845 unsigned int j; 4846 unsigned int k; 4847 int seen_first_offset = 0; 4848 int locs_sorted = 1; 4849 unsigned char *next; 4850 unsigned int *array = NULL; 4851 const char *suffix = strrchr (section->name, '.'); 4852 int is_dwo = 0; 4853 4854 if (suffix && strcmp (suffix, ".dwo") == 0) 4855 is_dwo = 1; 4856 4857 bytes = section->size; 4858 4859 if (bytes == 0) 4860 { 4861 printf (_("\nThe %s section is empty.\n"), section->name); 4862 return 0; 4863 } 4864 4865 if (load_debug_info (file) == 0) 4866 { 4867 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), 4868 section->name); 4869 return 0; 4870 } 4871 4872 /* Check the order of location list in .debug_info section. If 4873 offsets of location lists are in the ascending order, we can 4874 use `debug_information' directly. */ 4875 for (i = 0; i < num_debug_info_entries; i++) 4876 { 4877 unsigned int num; 4878 4879 num = debug_information [i].num_loc_offsets; 4880 if (num > num_loc_list) 4881 num_loc_list = num; 4882 4883 /* Check if we can use `debug_information' directly. */ 4884 if (locs_sorted && num != 0) 4885 { 4886 if (!seen_first_offset) 4887 { 4888 /* This is the first location list. */ 4889 last_offset = debug_information [i].loc_offsets [0]; 4890 first = i; 4891 seen_first_offset = 1; 4892 j = 1; 4893 } 4894 else 4895 j = 0; 4896 4897 for (; j < num; j++) 4898 { 4899 if (last_offset > 4900 debug_information [i].loc_offsets [j]) 4901 { 4902 locs_sorted = 0; 4903 break; 4904 } 4905 last_offset = debug_information [i].loc_offsets [j]; 4906 } 4907 } 4908 } 4909 4910 if (!seen_first_offset) 4911 error (_("No location lists in .debug_info section!\n")); 4912 4913 if (debug_information [first].num_loc_offsets > 0 4914 && debug_information [first].loc_offsets [0] != 0) 4915 warn (_("Location lists in %s section start at 0x%s\n"), 4916 section->name, 4917 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); 4918 4919 if (!locs_sorted) 4920 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); 4921 printf (_("Contents of the %s section:\n\n"), section->name); 4922 printf (_(" Offset Begin End Expression\n")); 4923 4924 seen_first_offset = 0; 4925 for (i = first; i < num_debug_info_entries; i++) 4926 { 4927 unsigned long offset; 4928 unsigned long base_address; 4929 int has_frame_base; 4930 4931 if (!locs_sorted) 4932 { 4933 for (k = 0; k < debug_information [i].num_loc_offsets; k++) 4934 array[k] = k; 4935 loc_offsets = debug_information [i].loc_offsets; 4936 qsort (array, debug_information [i].num_loc_offsets, 4937 sizeof (*array), loc_offsets_compar); 4938 } 4939 4940 for (k = 0; k < debug_information [i].num_loc_offsets; k++) 4941 { 4942 j = locs_sorted ? k : array[k]; 4943 if (k 4944 && debug_information [i].loc_offsets [locs_sorted 4945 ? k - 1 : array [k - 1]] 4946 == debug_information [i].loc_offsets [j]) 4947 continue; 4948 has_frame_base = debug_information [i].have_frame_base [j]; 4949 offset = debug_information [i].loc_offsets [j]; 4950 next = section_begin + offset; 4951 base_address = debug_information [i].base_address; 4952 4953 if (!seen_first_offset) 4954 seen_first_offset = 1; 4955 else 4956 { 4957 if (start < next) 4958 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), 4959 (unsigned long) (start - section_begin), 4960 (unsigned long) (next - section_begin)); 4961 else if (start > next) 4962 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), 4963 (unsigned long) (start - section_begin), 4964 (unsigned long) (next - section_begin)); 4965 } 4966 start = next; 4967 4968 if (offset >= bytes) 4969 { 4970 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), 4971 offset); 4972 continue; 4973 } 4974 4975 if (is_dwo) 4976 display_loc_list_dwo (section, &start, i, offset, has_frame_base); 4977 else 4978 display_loc_list (section, &start, i, offset, base_address, 4979 has_frame_base); 4980 } 4981 } 4982 4983 if (start < section->start + section->size) 4984 warn (_("There are %ld unused bytes at the end of section %s\n"), 4985 (long) (section->start + section->size - start), section->name); 4986 putchar ('\n'); 4987 free (array); 4988 return 1; 4989 } 4990 4991 static int 4992 display_debug_str (struct dwarf_section *section, 4993 void *file ATTRIBUTE_UNUSED) 4994 { 4995 unsigned char *start = section->start; 4996 unsigned long bytes = section->size; 4997 dwarf_vma addr = section->address; 4998 4999 if (bytes == 0) 5000 { 5001 printf (_("\nThe %s section is empty.\n"), section->name); 5002 return 0; 5003 } 5004 5005 printf (_("Contents of the %s section:\n\n"), section->name); 5006 5007 while (bytes) 5008 { 5009 int j; 5010 int k; 5011 int lbytes; 5012 5013 lbytes = (bytes > 16 ? 16 : bytes); 5014 5015 printf (" 0x%8.8lx ", (unsigned long) addr); 5016 5017 for (j = 0; j < 16; j++) 5018 { 5019 if (j < lbytes) 5020 printf ("%2.2x", start[j]); 5021 else 5022 printf (" "); 5023 5024 if ((j & 3) == 3) 5025 printf (" "); 5026 } 5027 5028 for (j = 0; j < lbytes; j++) 5029 { 5030 k = start[j]; 5031 if (k >= ' ' && k < 0x80) 5032 printf ("%c", k); 5033 else 5034 printf ("."); 5035 } 5036 5037 putchar ('\n'); 5038 5039 start += lbytes; 5040 addr += lbytes; 5041 bytes -= lbytes; 5042 } 5043 5044 putchar ('\n'); 5045 5046 return 1; 5047 } 5048 5049 static int 5050 display_debug_info (struct dwarf_section *section, void *file) 5051 { 5052 return process_debug_info (section, file, section->abbrev_sec, 0, 0); 5053 } 5054 5055 static int 5056 display_debug_types (struct dwarf_section *section, void *file) 5057 { 5058 return process_debug_info (section, file, section->abbrev_sec, 0, 1); 5059 } 5060 5061 static int 5062 display_trace_info (struct dwarf_section *section, void *file) 5063 { 5064 return process_debug_info (section, file, section->abbrev_sec, 0, 0); 5065 } 5066 5067 static int 5068 display_debug_aranges (struct dwarf_section *section, 5069 void *file ATTRIBUTE_UNUSED) 5070 { 5071 unsigned char *start = section->start; 5072 unsigned char *end = start + section->size; 5073 5074 printf (_("Contents of the %s section:\n\n"), section->name); 5075 5076 /* It does not matter if this load fails, 5077 we test for that later on. */ 5078 load_debug_info (file); 5079 5080 while (start < end) 5081 { 5082 unsigned char *hdrptr; 5083 DWARF2_Internal_ARange arange; 5084 unsigned char *addr_ranges; 5085 dwarf_vma length; 5086 dwarf_vma address; 5087 unsigned char address_size; 5088 int excess; 5089 unsigned int offset_size; 5090 unsigned int initial_length_size; 5091 5092 hdrptr = start; 5093 5094 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); 5095 if (arange.ar_length == 0xffffffff) 5096 { 5097 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); 5098 offset_size = 8; 5099 initial_length_size = 12; 5100 } 5101 else 5102 { 5103 offset_size = 4; 5104 initial_length_size = 4; 5105 } 5106 5107 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); 5108 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); 5109 5110 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE 5111 && num_debug_info_entries > 0 5112 && find_debug_info_for_offset (arange.ar_info_offset) == NULL) 5113 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), 5114 (unsigned long) arange.ar_info_offset, section->name); 5115 5116 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); 5117 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); 5118 5119 if (arange.ar_version != 2 && arange.ar_version != 3) 5120 { 5121 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); 5122 break; 5123 } 5124 5125 printf (_(" Length: %ld\n"), 5126 (long) arange.ar_length); 5127 printf (_(" Version: %d\n"), arange.ar_version); 5128 printf (_(" Offset into .debug_info: 0x%lx\n"), 5129 (unsigned long) arange.ar_info_offset); 5130 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); 5131 printf (_(" Segment Size: %d\n"), arange.ar_segment_size); 5132 5133 address_size = arange.ar_pointer_size + arange.ar_segment_size; 5134 5135 /* PR 17512: file: 001-108546-0.001:0.1. */ 5136 if (address_size == 0 || address_size > 8) 5137 { 5138 error (_("Invalid address size in %s section!\n"), 5139 section->name); 5140 break; 5141 } 5142 5143 /* The DWARF spec does not require that the address size be a power 5144 of two, but we do. This will have to change if we ever encounter 5145 an uneven architecture. */ 5146 if ((address_size & (address_size - 1)) != 0) 5147 { 5148 warn (_("Pointer size + Segment size is not a power of two.\n")); 5149 break; 5150 } 5151 5152 if (address_size > 4) 5153 printf (_("\n Address Length\n")); 5154 else 5155 printf (_("\n Address Length\n")); 5156 5157 addr_ranges = hdrptr; 5158 5159 /* Must pad to an alignment boundary that is twice the address size. */ 5160 excess = (hdrptr - start) % (2 * address_size); 5161 if (excess) 5162 addr_ranges += (2 * address_size) - excess; 5163 5164 start += arange.ar_length + initial_length_size; 5165 5166 while (addr_ranges + 2 * address_size <= start) 5167 { 5168 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); 5169 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); 5170 5171 printf (" "); 5172 print_dwarf_vma (address, address_size); 5173 print_dwarf_vma (length, address_size); 5174 putchar ('\n'); 5175 } 5176 } 5177 5178 printf ("\n"); 5179 5180 return 1; 5181 } 5182 5183 /* Comparison function for qsort. */ 5184 static int 5185 comp_addr_base (const void * v0, const void * v1) 5186 { 5187 debug_info * info0 = (debug_info *) v0; 5188 debug_info * info1 = (debug_info *) v1; 5189 return info0->addr_base - info1->addr_base; 5190 } 5191 5192 /* Display the debug_addr section. */ 5193 static int 5194 display_debug_addr (struct dwarf_section *section, 5195 void *file) 5196 { 5197 debug_info **debug_addr_info; 5198 unsigned char *entry; 5199 unsigned char *end; 5200 unsigned int i; 5201 unsigned int count; 5202 5203 if (section->size == 0) 5204 { 5205 printf (_("\nThe %s section is empty.\n"), section->name); 5206 return 0; 5207 } 5208 5209 if (load_debug_info (file) == 0) 5210 { 5211 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), 5212 section->name); 5213 return 0; 5214 } 5215 5216 printf (_("Contents of the %s section:\n\n"), section->name); 5217 5218 debug_addr_info = (debug_info **) xmalloc ((num_debug_info_entries + 1) 5219 * sizeof (debug_info *)); 5220 5221 count = 0; 5222 for (i = 0; i < num_debug_info_entries; i++) 5223 { 5224 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) 5225 debug_addr_info [count++] = &debug_information [i]; 5226 } 5227 5228 /* Add a sentinel to make iteration convenient. */ 5229 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); 5230 debug_addr_info [count]->addr_base = section->size; 5231 5232 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); 5233 for (i = 0; i < count; i++) 5234 { 5235 unsigned int idx; 5236 unsigned int address_size = debug_addr_info [i]->pointer_size; 5237 5238 printf (_(" For compilation unit at offset 0x%s:\n"), 5239 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); 5240 5241 printf (_("\tIndex\tAddress\n")); 5242 entry = section->start + debug_addr_info [i]->addr_base; 5243 end = section->start + debug_addr_info [i + 1]->addr_base; 5244 idx = 0; 5245 while (entry < end) 5246 { 5247 dwarf_vma base = byte_get (entry, address_size); 5248 printf (_("\t%d:\t"), idx); 5249 print_dwarf_vma (base, address_size); 5250 printf ("\n"); 5251 entry += address_size; 5252 idx++; 5253 } 5254 } 5255 printf ("\n"); 5256 5257 free (debug_addr_info); 5258 return 1; 5259 } 5260 5261 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ 5262 static int 5263 display_debug_str_offsets (struct dwarf_section *section, 5264 void *file ATTRIBUTE_UNUSED) 5265 { 5266 if (section->size == 0) 5267 { 5268 printf (_("\nThe %s section is empty.\n"), section->name); 5269 return 0; 5270 } 5271 /* TODO: Dump the contents. This is made somewhat difficult by not knowing 5272 what the offset size is for this section. */ 5273 return 1; 5274 } 5275 5276 /* Each debug_information[x].range_lists[y] gets this representation for 5277 sorting purposes. */ 5278 5279 struct range_entry 5280 { 5281 /* The debug_information[x].range_lists[y] value. */ 5282 unsigned long ranges_offset; 5283 5284 /* Original debug_information to find parameters of the data. */ 5285 debug_info *debug_info_p; 5286 }; 5287 5288 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ 5289 5290 static int 5291 range_entry_compar (const void *ap, const void *bp) 5292 { 5293 const struct range_entry *a_re = (const struct range_entry *) ap; 5294 const struct range_entry *b_re = (const struct range_entry *) bp; 5295 const unsigned long a = a_re->ranges_offset; 5296 const unsigned long b = b_re->ranges_offset; 5297 5298 return (a > b) - (b > a); 5299 } 5300 5301 static int 5302 display_debug_ranges (struct dwarf_section *section, 5303 void *file ATTRIBUTE_UNUSED) 5304 { 5305 unsigned char *start = section->start; 5306 unsigned char *last_start = start; 5307 unsigned long bytes = section->size; 5308 unsigned char *section_begin = start; 5309 unsigned char *finish = start + bytes; 5310 unsigned int num_range_list, i; 5311 struct range_entry *range_entries, *range_entry_fill; 5312 5313 if (bytes == 0) 5314 { 5315 printf (_("\nThe %s section is empty.\n"), section->name); 5316 return 0; 5317 } 5318 5319 if (load_debug_info (file) == 0) 5320 { 5321 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), 5322 section->name); 5323 return 0; 5324 } 5325 5326 num_range_list = 0; 5327 for (i = 0; i < num_debug_info_entries; i++) 5328 num_range_list += debug_information [i].num_range_lists; 5329 5330 if (num_range_list == 0) 5331 { 5332 /* This can happen when the file was compiled with -gsplit-debug 5333 which removes references to range lists from the primary .o file. */ 5334 printf (_("No range lists in .debug_info section.\n")); 5335 return 1; 5336 } 5337 5338 range_entries = (struct range_entry *) 5339 xmalloc (sizeof (*range_entries) * num_range_list); 5340 range_entry_fill = range_entries; 5341 5342 for (i = 0; i < num_debug_info_entries; i++) 5343 { 5344 debug_info *debug_info_p = &debug_information[i]; 5345 unsigned int j; 5346 5347 for (j = 0; j < debug_info_p->num_range_lists; j++) 5348 { 5349 range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; 5350 range_entry_fill->debug_info_p = debug_info_p; 5351 range_entry_fill++; 5352 } 5353 } 5354 5355 qsort (range_entries, num_range_list, sizeof (*range_entries), 5356 range_entry_compar); 5357 5358 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) 5359 warn (_("Range lists in %s section start at 0x%lx\n"), 5360 section->name, range_entries[0].ranges_offset); 5361 5362 printf (_("Contents of the %s section:\n\n"), section->name); 5363 printf (_(" Offset Begin End\n")); 5364 5365 for (i = 0; i < num_range_list; i++) 5366 { 5367 struct range_entry *range_entry = &range_entries[i]; 5368 debug_info *debug_info_p = range_entry->debug_info_p; 5369 unsigned int pointer_size; 5370 unsigned long offset; 5371 unsigned char *next; 5372 unsigned long base_address; 5373 5374 pointer_size = debug_info_p->pointer_size; 5375 offset = range_entry->ranges_offset; 5376 next = section_begin + offset; 5377 base_address = debug_info_p->base_address; 5378 5379 /* PR 17512: file: 001-101485-0.001:0.1. */ 5380 if (pointer_size < 2 || pointer_size > 8) 5381 { 5382 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), 5383 pointer_size, offset); 5384 continue; 5385 } 5386 5387 if (dwarf_check != 0 && i > 0) 5388 { 5389 if (start < next) 5390 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), 5391 (unsigned long) (start - section_begin), 5392 (unsigned long) (next - section_begin), section->name); 5393 else if (start > next) 5394 { 5395 if (next == last_start) 5396 continue; 5397 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), 5398 (unsigned long) (start - section_begin), 5399 (unsigned long) (next - section_begin), section->name); 5400 } 5401 } 5402 start = next; 5403 last_start = next; 5404 5405 while (start < finish) 5406 { 5407 dwarf_vma begin; 5408 dwarf_vma end; 5409 5410 /* Note: we use sign extension here in order to be sure that 5411 we can detect the -1 escape value. Sign extension into the 5412 top 32 bits of a 32-bit address will not affect the values 5413 that we display since we always show hex values, and always 5414 the bottom 32-bits. */ 5415 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); 5416 if (start >= finish) 5417 break; 5418 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); 5419 5420 printf (" %8.8lx ", offset); 5421 5422 if (begin == 0 && end == 0) 5423 { 5424 printf (_("<End of list>\n")); 5425 break; 5426 } 5427 5428 /* Check base address specifiers. */ 5429 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1) 5430 { 5431 base_address = end; 5432 print_dwarf_vma (begin, pointer_size); 5433 print_dwarf_vma (end, pointer_size); 5434 printf ("(base address)\n"); 5435 continue; 5436 } 5437 5438 print_dwarf_vma (begin + base_address, pointer_size); 5439 print_dwarf_vma (end + base_address, pointer_size); 5440 5441 if (begin == end) 5442 fputs (_("(start == end)"), stdout); 5443 else if (begin > end) 5444 fputs (_("(start > end)"), stdout); 5445 5446 putchar ('\n'); 5447 } 5448 } 5449 putchar ('\n'); 5450 5451 free (range_entries); 5452 5453 return 1; 5454 } 5455 5456 typedef struct Frame_Chunk 5457 { 5458 struct Frame_Chunk *next; 5459 unsigned char *chunk_start; 5460 int ncols; 5461 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ 5462 short int *col_type; 5463 int *col_offset; 5464 char *augmentation; 5465 unsigned int code_factor; 5466 int data_factor; 5467 dwarf_vma pc_begin; 5468 dwarf_vma pc_range; 5469 int cfa_reg; 5470 int cfa_offset; 5471 int ra; 5472 unsigned char fde_encoding; 5473 unsigned char cfa_exp; 5474 unsigned char ptr_size; 5475 unsigned char segment_size; 5476 } 5477 Frame_Chunk; 5478 5479 static const char *const *dwarf_regnames; 5480 static unsigned int dwarf_regnames_count; 5481 5482 /* A marker for a col_type that means this column was never referenced 5483 in the frame info. */ 5484 #define DW_CFA_unreferenced (-1) 5485 5486 /* Return 0 if not more space is needed, 1 if more space is needed, 5487 -1 for invalid reg. */ 5488 5489 static int 5490 frame_need_space (Frame_Chunk *fc, unsigned int reg) 5491 { 5492 int prev = fc->ncols; 5493 5494 if (reg < (unsigned int) fc->ncols) 5495 return 0; 5496 5497 if (dwarf_regnames_count 5498 && reg > dwarf_regnames_count) 5499 return -1; 5500 5501 fc->ncols = reg + 1; 5502 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, 5503 sizeof (short int)); 5504 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); 5505 /* PR 17512: file:002-10025-0.005. */ 5506 if (fc->col_type == NULL || fc->col_offset == NULL) 5507 { 5508 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), 5509 fc->ncols); 5510 fc->ncols = 0; 5511 return -1; 5512 } 5513 5514 while (prev < fc->ncols) 5515 { 5516 fc->col_type[prev] = DW_CFA_unreferenced; 5517 fc->col_offset[prev] = 0; 5518 prev++; 5519 } 5520 return 1; 5521 } 5522 5523 static const char *const dwarf_regnames_i386[] = 5524 { 5525 "eax", "ecx", "edx", "ebx", /* 0 - 3 */ 5526 "esp", "ebp", "esi", "edi", /* 4 - 7 */ 5527 "eip", "eflags", NULL, /* 8 - 10 */ 5528 "st0", "st1", "st2", "st3", /* 11 - 14 */ 5529 "st4", "st5", "st6", "st7", /* 15 - 18 */ 5530 NULL, NULL, /* 19 - 20 */ 5531 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ 5532 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ 5533 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ 5534 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ 5535 "fcw", "fsw", "mxcsr", /* 37 - 39 */ 5536 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ 5537 "tr", "ldtr", /* 48 - 49 */ 5538 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ 5539 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ 5540 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ 5541 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ 5542 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ 5543 NULL, NULL, NULL, /* 90 - 92 */ 5544 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ 5545 }; 5546 5547 void 5548 init_dwarf_regnames_i386 (void) 5549 { 5550 dwarf_regnames = dwarf_regnames_i386; 5551 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); 5552 } 5553 5554 static const char *const dwarf_regnames_x86_64[] = 5555 { 5556 "rax", "rdx", "rcx", "rbx", 5557 "rsi", "rdi", "rbp", "rsp", 5558 "r8", "r9", "r10", "r11", 5559 "r12", "r13", "r14", "r15", 5560 "rip", 5561 "xmm0", "xmm1", "xmm2", "xmm3", 5562 "xmm4", "xmm5", "xmm6", "xmm7", 5563 "xmm8", "xmm9", "xmm10", "xmm11", 5564 "xmm12", "xmm13", "xmm14", "xmm15", 5565 "st0", "st1", "st2", "st3", 5566 "st4", "st5", "st6", "st7", 5567 "mm0", "mm1", "mm2", "mm3", 5568 "mm4", "mm5", "mm6", "mm7", 5569 "rflags", 5570 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, 5571 "fs.base", "gs.base", NULL, NULL, 5572 "tr", "ldtr", 5573 "mxcsr", "fcw", "fsw", 5574 "xmm16", "xmm17", "xmm18", "xmm19", 5575 "xmm20", "xmm21", "xmm22", "xmm23", 5576 "xmm24", "xmm25", "xmm26", "xmm27", 5577 "xmm28", "xmm29", "xmm30", "xmm31", 5578 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ 5579 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ 5580 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ 5581 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ 5582 NULL, NULL, NULL, /* 115 - 117 */ 5583 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" 5584 }; 5585 5586 void 5587 init_dwarf_regnames_x86_64 (void) 5588 { 5589 dwarf_regnames = dwarf_regnames_x86_64; 5590 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); 5591 } 5592 5593 static const char *const dwarf_regnames_aarch64[] = 5594 { 5595 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", 5596 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", 5597 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", 5598 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", 5599 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, 5600 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 5601 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 5602 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 5603 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", 5604 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", 5605 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", 5606 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", 5607 }; 5608 5609 void 5610 init_dwarf_regnames_aarch64 (void) 5611 { 5612 dwarf_regnames = dwarf_regnames_aarch64; 5613 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); 5614 } 5615 5616 void 5617 init_dwarf_regnames (unsigned int e_machine) 5618 { 5619 switch (e_machine) 5620 { 5621 case EM_386: 5622 case EM_486: 5623 init_dwarf_regnames_i386 (); 5624 break; 5625 5626 case EM_X86_64: 5627 case EM_L1OM: 5628 case EM_K1OM: 5629 init_dwarf_regnames_x86_64 (); 5630 break; 5631 5632 case EM_AARCH64: 5633 init_dwarf_regnames_aarch64 (); 5634 break; 5635 5636 default: 5637 break; 5638 } 5639 } 5640 5641 static const char * 5642 regname (unsigned int regno, int row) 5643 { 5644 static char reg[64]; 5645 if (dwarf_regnames 5646 && regno < dwarf_regnames_count 5647 && dwarf_regnames [regno] != NULL) 5648 { 5649 if (row) 5650 return dwarf_regnames [regno]; 5651 snprintf (reg, sizeof (reg), "r%d (%s)", regno, 5652 dwarf_regnames [regno]); 5653 } 5654 else 5655 snprintf (reg, sizeof (reg), "r%d", regno); 5656 return reg; 5657 } 5658 5659 static void 5660 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs) 5661 { 5662 int r; 5663 char tmp[100]; 5664 5665 if (*max_regs < fc->ncols) 5666 *max_regs = fc->ncols; 5667 5668 if (*need_col_headers) 5669 { 5670 static const char *sloc = " LOC"; 5671 5672 *need_col_headers = 0; 5673 5674 printf ("%-*s CFA ", eh_addr_size * 2, sloc); 5675 5676 for (r = 0; r < *max_regs; r++) 5677 if (fc->col_type[r] != DW_CFA_unreferenced) 5678 { 5679 if (r == fc->ra) 5680 printf ("ra "); 5681 else 5682 printf ("%-5s ", regname (r, 1)); 5683 } 5684 5685 printf ("\n"); 5686 } 5687 5688 print_dwarf_vma (fc->pc_begin, eh_addr_size); 5689 if (fc->cfa_exp) 5690 strcpy (tmp, "exp"); 5691 else 5692 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset); 5693 printf ("%-8s ", tmp); 5694 5695 for (r = 0; r < fc->ncols; r++) 5696 { 5697 if (fc->col_type[r] != DW_CFA_unreferenced) 5698 { 5699 switch (fc->col_type[r]) 5700 { 5701 case DW_CFA_undefined: 5702 strcpy (tmp, "u"); 5703 break; 5704 case DW_CFA_same_value: 5705 strcpy (tmp, "s"); 5706 break; 5707 case DW_CFA_offset: 5708 sprintf (tmp, "c%+d", fc->col_offset[r]); 5709 break; 5710 case DW_CFA_val_offset: 5711 sprintf (tmp, "v%+d", fc->col_offset[r]); 5712 break; 5713 case DW_CFA_register: 5714 sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); 5715 break; 5716 case DW_CFA_expression: 5717 strcpy (tmp, "exp"); 5718 break; 5719 case DW_CFA_val_expression: 5720 strcpy (tmp, "vexp"); 5721 break; 5722 default: 5723 strcpy (tmp, "n/a"); 5724 break; 5725 } 5726 printf ("%-5s ", tmp); 5727 } 5728 } 5729 printf ("\n"); 5730 } 5731 5732 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) 5733 #define LEB() read_uleb128 (start, & length_return, end); start += length_return 5734 #define SLEB() read_sleb128 (start, & length_return, end); start += length_return 5735 5736 static unsigned char * 5737 read_cie (unsigned char *start, unsigned char *end, 5738 Frame_Chunk **p_cie, int *p_version, 5739 unsigned long *p_aug_len, unsigned char **p_aug) 5740 { 5741 int version; 5742 Frame_Chunk *fc; 5743 unsigned int length_return; 5744 unsigned char *augmentation_data = NULL; 5745 unsigned long augmentation_data_len = 0; 5746 5747 * p_cie = NULL; 5748 /* PR 17512: file: 001-228113-0.004. */ 5749 if (start >= end) 5750 return end; 5751 5752 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); 5753 memset (fc, 0, sizeof (Frame_Chunk)); 5754 5755 fc->col_type = (short int *) xmalloc (sizeof (short int)); 5756 fc->col_offset = (int *) xmalloc (sizeof (int)); 5757 5758 version = *start++; 5759 5760 fc->augmentation = (char *) start; 5761 /* PR 17512: file: 001-228113-0.004. 5762 Skip past augmentation name, but avoid running off the end of the data. */ 5763 while (start < end) 5764 if (* start ++ == '\0') 5765 break; 5766 if (start == end) 5767 { 5768 warn (_("No terminator for augmentation name\n")); 5769 return start; 5770 } 5771 5772 if (strcmp (fc->augmentation, "eh") == 0) 5773 start += eh_addr_size; 5774 5775 if (version >= 4) 5776 { 5777 GET (fc->ptr_size, 1); 5778 GET (fc->segment_size, 1); 5779 eh_addr_size = fc->ptr_size; 5780 } 5781 else 5782 { 5783 fc->ptr_size = eh_addr_size; 5784 fc->segment_size = 0; 5785 } 5786 fc->code_factor = LEB (); 5787 fc->data_factor = SLEB (); 5788 if (version == 1) 5789 { 5790 GET (fc->ra, 1); 5791 } 5792 else 5793 { 5794 fc->ra = LEB (); 5795 } 5796 5797 if (fc->augmentation[0] == 'z') 5798 { 5799 augmentation_data_len = LEB (); 5800 augmentation_data = start; 5801 start += augmentation_data_len; 5802 } 5803 5804 if (augmentation_data_len) 5805 { 5806 unsigned char *p, *q; 5807 p = (unsigned char *) fc->augmentation + 1; 5808 q = augmentation_data; 5809 5810 while (1) 5811 { 5812 if (*p == 'L') 5813 q++; 5814 else if (*p == 'P') 5815 q += 1 + size_of_encoded_value (*q); 5816 else if (*p == 'R') 5817 fc->fde_encoding = *q++; 5818 else if (*p == 'S') 5819 ; 5820 else 5821 break; 5822 p++; 5823 } 5824 } 5825 5826 *p_cie = fc; 5827 if (p_version) 5828 *p_version = version; 5829 if (p_aug_len) 5830 { 5831 *p_aug_len = augmentation_data_len; 5832 *p_aug = augmentation_data; 5833 } 5834 return start; 5835 } 5836 5837 static int 5838 display_debug_frames (struct dwarf_section *section, 5839 void *file ATTRIBUTE_UNUSED) 5840 { 5841 unsigned char *start = section->start; 5842 unsigned char *end = start + section->size; 5843 unsigned char *section_start = start; 5844 Frame_Chunk *chunks = 0, *forward_refs = 0; 5845 Frame_Chunk *remembered_state = 0; 5846 Frame_Chunk *rs; 5847 int is_eh = strcmp (section->name, ".eh_frame") == 0; 5848 unsigned int length_return; 5849 int max_regs = 0; 5850 const char *bad_reg = _("bad register: "); 5851 int saved_eh_addr_size = eh_addr_size; 5852 5853 printf (_("Contents of the %s section:\n"), section->name); 5854 5855 while (start < end) 5856 { 5857 unsigned char *saved_start; 5858 unsigned char *block_end; 5859 dwarf_vma length; 5860 dwarf_vma cie_id; 5861 Frame_Chunk *fc; 5862 Frame_Chunk *cie; 5863 int need_col_headers = 1; 5864 unsigned char *augmentation_data = NULL; 5865 unsigned long augmentation_data_len = 0; 5866 unsigned int encoded_ptr_size = saved_eh_addr_size; 5867 unsigned int offset_size; 5868 unsigned int initial_length_size; 5869 5870 saved_start = start; 5871 5872 SAFE_BYTE_GET_AND_INC (length, start, 4, end); 5873 5874 if (length == 0) 5875 { 5876 printf ("\n%08lx ZERO terminator\n\n", 5877 (unsigned long)(saved_start - section_start)); 5878 continue; 5879 } 5880 5881 if (length == 0xffffffff) 5882 { 5883 SAFE_BYTE_GET_AND_INC (length, start, 8, end); 5884 offset_size = 8; 5885 initial_length_size = 12; 5886 } 5887 else 5888 { 5889 offset_size = 4; 5890 initial_length_size = 4; 5891 } 5892 5893 block_end = saved_start + length + initial_length_size; 5894 if (block_end > end || block_end < start) 5895 { 5896 warn ("Invalid length 0x%s in FDE at %#08lx\n", 5897 dwarf_vmatoa_1 (NULL, length, offset_size), 5898 (unsigned long) (saved_start - section_start)); 5899 block_end = end; 5900 } 5901 5902 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); 5903 5904 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) 5905 || (offset_size == 8 && cie_id == DW64_CIE_ID))) 5906 { 5907 int version; 5908 int mreg; 5909 5910 start = read_cie (start, end, &cie, &version, 5911 &augmentation_data_len, &augmentation_data); 5912 /* PR 17512: file: 027-135133-0.005. */ 5913 if (cie == NULL) 5914 break; 5915 fc = cie; 5916 fc->next = chunks; 5917 chunks = fc; 5918 fc->chunk_start = saved_start; 5919 mreg = max_regs - 1; 5920 if (mreg < fc->ra) 5921 mreg = fc->ra; 5922 frame_need_space (fc, mreg); 5923 if (fc->fde_encoding) 5924 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); 5925 5926 printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); 5927 print_dwarf_vma (length, fc->ptr_size); 5928 print_dwarf_vma (cie_id, offset_size); 5929 5930 if (do_debug_frames_interp) 5931 { 5932 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, 5933 fc->code_factor, fc->data_factor, fc->ra); 5934 } 5935 else 5936 { 5937 printf ("CIE\n"); 5938 printf (" Version: %d\n", version); 5939 printf (" Augmentation: \"%s\"\n", fc->augmentation); 5940 if (version >= 4) 5941 { 5942 printf (" Pointer Size: %u\n", fc->ptr_size); 5943 printf (" Segment Size: %u\n", fc->segment_size); 5944 } 5945 printf (" Code alignment factor: %u\n", fc->code_factor); 5946 printf (" Data alignment factor: %d\n", fc->data_factor); 5947 printf (" Return address column: %d\n", fc->ra); 5948 5949 if (augmentation_data_len) 5950 { 5951 unsigned long i; 5952 printf (" Augmentation data: "); 5953 for (i = 0; i < augmentation_data_len; ++i) 5954 printf (" %02x", augmentation_data[i]); 5955 putchar ('\n'); 5956 } 5957 putchar ('\n'); 5958 } 5959 } 5960 else 5961 { 5962 unsigned char *look_for; 5963 static Frame_Chunk fde_fc; 5964 unsigned long segment_selector; 5965 5966 if (is_eh) 5967 { 5968 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); 5969 look_for = start - 4 - ((cie_id ^ sign) - sign); 5970 } 5971 else 5972 look_for = section_start + cie_id; 5973 5974 if (look_for <= saved_start) 5975 { 5976 for (cie = chunks; cie ; cie = cie->next) 5977 if (cie->chunk_start == look_for) 5978 break; 5979 } 5980 else 5981 { 5982 for (cie = forward_refs; cie ; cie = cie->next) 5983 if (cie->chunk_start == look_for) 5984 break; 5985 if (!cie) 5986 { 5987 unsigned int off_size; 5988 unsigned char *cie_scan; 5989 5990 cie_scan = look_for; 5991 off_size = 4; 5992 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); 5993 if (length == 0xffffffff) 5994 { 5995 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); 5996 off_size = 8; 5997 } 5998 if (length != 0) 5999 { 6000 dwarf_vma c_id; 6001 6002 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); 6003 if (is_eh 6004 ? c_id == 0 6005 : ((off_size == 4 && c_id == DW_CIE_ID) 6006 || (off_size == 8 && c_id == DW64_CIE_ID))) 6007 { 6008 int version; 6009 int mreg; 6010 6011 read_cie (cie_scan, end, &cie, &version, 6012 &augmentation_data_len, &augmentation_data); 6013 cie->next = forward_refs; 6014 forward_refs = cie; 6015 cie->chunk_start = look_for; 6016 mreg = max_regs - 1; 6017 if (mreg < cie->ra) 6018 mreg = cie->ra; 6019 frame_need_space (cie, mreg); 6020 if (cie->fde_encoding) 6021 encoded_ptr_size 6022 = size_of_encoded_value (cie->fde_encoding); 6023 } 6024 } 6025 } 6026 } 6027 6028 fc = &fde_fc; 6029 memset (fc, 0, sizeof (Frame_Chunk)); 6030 6031 if (!cie) 6032 { 6033 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", 6034 dwarf_vmatoa_1 (NULL, cie_id, offset_size), 6035 (unsigned long) (saved_start - section_start)); 6036 fc->ncols = 0; 6037 fc->col_type = (short int *) xmalloc (sizeof (short int)); 6038 fc->col_offset = (int *) xmalloc (sizeof (int)); 6039 frame_need_space (fc, max_regs - 1); 6040 cie = fc; 6041 fc->augmentation = ""; 6042 fc->fde_encoding = 0; 6043 fc->ptr_size = eh_addr_size; 6044 fc->segment_size = 0; 6045 } 6046 else 6047 { 6048 fc->ncols = cie->ncols; 6049 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); 6050 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); 6051 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); 6052 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); 6053 fc->augmentation = cie->augmentation; 6054 fc->ptr_size = cie->ptr_size; 6055 eh_addr_size = cie->ptr_size; 6056 fc->segment_size = cie->segment_size; 6057 fc->code_factor = cie->code_factor; 6058 fc->data_factor = cie->data_factor; 6059 fc->cfa_reg = cie->cfa_reg; 6060 fc->cfa_offset = cie->cfa_offset; 6061 fc->ra = cie->ra; 6062 frame_need_space (fc, max_regs - 1); 6063 fc->fde_encoding = cie->fde_encoding; 6064 } 6065 6066 if (fc->fde_encoding) 6067 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); 6068 6069 segment_selector = 0; 6070 if (fc->segment_size) 6071 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); 6072 6073 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); 6074 6075 /* FIXME: It appears that sometimes the final pc_range value is 6076 encoded in less than encoded_ptr_size bytes. See the x86_64 6077 run of the "objcopy on compressed debug sections" test for an 6078 example of this. */ 6079 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); 6080 6081 if (cie->augmentation[0] == 'z') 6082 { 6083 augmentation_data_len = LEB (); 6084 augmentation_data = start; 6085 start += augmentation_data_len; 6086 } 6087 6088 printf ("\n%08lx %s %s FDE cie=%08lx pc=", 6089 (unsigned long)(saved_start - section_start), 6090 dwarf_vmatoa_1 (NULL, length, fc->ptr_size), 6091 dwarf_vmatoa_1 (NULL, cie_id, offset_size), 6092 (unsigned long)(cie->chunk_start - section_start)); 6093 6094 if (fc->segment_size) 6095 printf ("%04lx:", segment_selector); 6096 6097 printf ("%s..%s\n", 6098 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), 6099 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); 6100 6101 if (! do_debug_frames_interp && augmentation_data_len) 6102 { 6103 unsigned long i; 6104 6105 printf (" Augmentation data: "); 6106 for (i = 0; i < augmentation_data_len; ++i) 6107 printf (" %02x", augmentation_data[i]); 6108 putchar ('\n'); 6109 putchar ('\n'); 6110 } 6111 } 6112 6113 /* At this point, fc is the current chunk, cie (if any) is set, and 6114 we're about to interpret instructions for the chunk. */ 6115 /* ??? At present we need to do this always, since this sizes the 6116 fc->col_type and fc->col_offset arrays, which we write into always. 6117 We should probably split the interpreted and non-interpreted bits 6118 into two different routines, since there's so much that doesn't 6119 really overlap between them. */ 6120 if (1 || do_debug_frames_interp) 6121 { 6122 /* Start by making a pass over the chunk, allocating storage 6123 and taking note of what registers are used. */ 6124 unsigned char *tmp = start; 6125 6126 while (start < block_end) 6127 { 6128 unsigned int reg, op, opa; 6129 unsigned long temp; 6130 6131 op = *start++; 6132 opa = op & 0x3f; 6133 if (op & 0xc0) 6134 op &= 0xc0; 6135 6136 /* Warning: if you add any more cases to this switch, be 6137 sure to add them to the corresponding switch below. */ 6138 switch (op) 6139 { 6140 case DW_CFA_advance_loc: 6141 break; 6142 case DW_CFA_offset: 6143 LEB (); 6144 if (frame_need_space (fc, opa) >= 0) 6145 fc->col_type[opa] = DW_CFA_undefined; 6146 break; 6147 case DW_CFA_restore: 6148 if (frame_need_space (fc, opa) >= 0) 6149 fc->col_type[opa] = DW_CFA_undefined; 6150 break; 6151 case DW_CFA_set_loc: 6152 start += encoded_ptr_size; 6153 break; 6154 case DW_CFA_advance_loc1: 6155 start += 1; 6156 break; 6157 case DW_CFA_advance_loc2: 6158 start += 2; 6159 break; 6160 case DW_CFA_advance_loc4: 6161 start += 4; 6162 break; 6163 case DW_CFA_offset_extended: 6164 case DW_CFA_val_offset: 6165 reg = LEB (); LEB (); 6166 if (frame_need_space (fc, reg) >= 0) 6167 fc->col_type[reg] = DW_CFA_undefined; 6168 break; 6169 case DW_CFA_restore_extended: 6170 reg = LEB (); 6171 frame_need_space (fc, reg); 6172 if (frame_need_space (fc, reg) >= 0) 6173 fc->col_type[reg] = DW_CFA_undefined; 6174 break; 6175 case DW_CFA_undefined: 6176 reg = LEB (); 6177 if (frame_need_space (fc, reg) >= 0) 6178 fc->col_type[reg] = DW_CFA_undefined; 6179 break; 6180 case DW_CFA_same_value: 6181 reg = LEB (); 6182 if (frame_need_space (fc, reg) >= 0) 6183 fc->col_type[reg] = DW_CFA_undefined; 6184 break; 6185 case DW_CFA_register: 6186 reg = LEB (); LEB (); 6187 if (frame_need_space (fc, reg) >= 0) 6188 fc->col_type[reg] = DW_CFA_undefined; 6189 break; 6190 case DW_CFA_def_cfa: 6191 LEB (); LEB (); 6192 break; 6193 case DW_CFA_def_cfa_register: 6194 LEB (); 6195 break; 6196 case DW_CFA_def_cfa_offset: 6197 LEB (); 6198 break; 6199 case DW_CFA_def_cfa_expression: 6200 temp = LEB (); 6201 if (start + temp < start) 6202 { 6203 warn (_("Corrupt CFA_def expression value: %lu\n"), temp); 6204 start = block_end; 6205 } 6206 else 6207 start += temp; 6208 break; 6209 case DW_CFA_expression: 6210 case DW_CFA_val_expression: 6211 reg = LEB (); 6212 temp = LEB (); 6213 if (start + temp < start) 6214 { 6215 /* PR 17512: file:306-192417-0.005. */ 6216 warn (_("Corrupt CFA expression value: %lu\n"), temp); 6217 start = block_end; 6218 } 6219 else 6220 start += temp; 6221 if (frame_need_space (fc, reg) >= 0) 6222 fc->col_type[reg] = DW_CFA_undefined; 6223 break; 6224 case DW_CFA_offset_extended_sf: 6225 case DW_CFA_val_offset_sf: 6226 reg = LEB (); SLEB (); 6227 if (frame_need_space (fc, reg) >= 0) 6228 fc->col_type[reg] = DW_CFA_undefined; 6229 break; 6230 case DW_CFA_def_cfa_sf: 6231 LEB (); SLEB (); 6232 break; 6233 case DW_CFA_def_cfa_offset_sf: 6234 SLEB (); 6235 break; 6236 case DW_CFA_MIPS_advance_loc8: 6237 start += 8; 6238 break; 6239 case DW_CFA_GNU_args_size: 6240 LEB (); 6241 break; 6242 case DW_CFA_GNU_negative_offset_extended: 6243 reg = LEB (); LEB (); 6244 if (frame_need_space (fc, reg) >= 0) 6245 fc->col_type[reg] = DW_CFA_undefined; 6246 break; 6247 default: 6248 break; 6249 } 6250 } 6251 start = tmp; 6252 } 6253 6254 /* Now we know what registers are used, make a second pass over 6255 the chunk, this time actually printing out the info. */ 6256 6257 while (start < block_end) 6258 { 6259 unsigned op, opa; 6260 unsigned long ul, reg, roffs; 6261 long l; 6262 dwarf_vma ofs; 6263 dwarf_vma vma; 6264 const char *reg_prefix = ""; 6265 6266 op = *start++; 6267 opa = op & 0x3f; 6268 if (op & 0xc0) 6269 op &= 0xc0; 6270 6271 /* Warning: if you add any more cases to this switch, be 6272 sure to add them to the corresponding switch above. */ 6273 switch (op) 6274 { 6275 case DW_CFA_advance_loc: 6276 if (do_debug_frames_interp) 6277 frame_display_row (fc, &need_col_headers, &max_regs); 6278 else 6279 printf (" DW_CFA_advance_loc: %d to %s\n", 6280 opa * fc->code_factor, 6281 dwarf_vmatoa_1 (NULL, 6282 fc->pc_begin + opa * fc->code_factor, 6283 fc->ptr_size)); 6284 fc->pc_begin += opa * fc->code_factor; 6285 break; 6286 6287 case DW_CFA_offset: 6288 roffs = LEB (); 6289 if (opa >= (unsigned int) fc->ncols) 6290 reg_prefix = bad_reg; 6291 if (! do_debug_frames_interp || *reg_prefix != '\0') 6292 printf (" DW_CFA_offset: %s%s at cfa%+ld\n", 6293 reg_prefix, regname (opa, 0), 6294 roffs * fc->data_factor); 6295 if (*reg_prefix == '\0') 6296 { 6297 fc->col_type[opa] = DW_CFA_offset; 6298 fc->col_offset[opa] = roffs * fc->data_factor; 6299 } 6300 break; 6301 6302 case DW_CFA_restore: 6303 if (opa >= (unsigned int) cie->ncols 6304 || opa >= (unsigned int) fc->ncols) 6305 reg_prefix = bad_reg; 6306 if (! do_debug_frames_interp || *reg_prefix != '\0') 6307 printf (" DW_CFA_restore: %s%s\n", 6308 reg_prefix, regname (opa, 0)); 6309 if (*reg_prefix == '\0') 6310 { 6311 fc->col_type[opa] = cie->col_type[opa]; 6312 fc->col_offset[opa] = cie->col_offset[opa]; 6313 if (do_debug_frames_interp 6314 && fc->col_type[opa] == DW_CFA_unreferenced) 6315 fc->col_type[opa] = DW_CFA_undefined; 6316 } 6317 break; 6318 6319 case DW_CFA_set_loc: 6320 vma = get_encoded_value (&start, fc->fde_encoding, section, end); 6321 if (do_debug_frames_interp) 6322 frame_display_row (fc, &need_col_headers, &max_regs); 6323 else 6324 printf (" DW_CFA_set_loc: %s\n", 6325 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); 6326 fc->pc_begin = vma; 6327 break; 6328 6329 case DW_CFA_advance_loc1: 6330 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); 6331 if (do_debug_frames_interp) 6332 frame_display_row (fc, &need_col_headers, &max_regs); 6333 else 6334 printf (" DW_CFA_advance_loc1: %ld to %s\n", 6335 (unsigned long) (ofs * fc->code_factor), 6336 dwarf_vmatoa_1 (NULL, 6337 fc->pc_begin + ofs * fc->code_factor, 6338 fc->ptr_size)); 6339 fc->pc_begin += ofs * fc->code_factor; 6340 break; 6341 6342 case DW_CFA_advance_loc2: 6343 SAFE_BYTE_GET_AND_INC (ofs, start, 2, end); 6344 if (do_debug_frames_interp) 6345 frame_display_row (fc, &need_col_headers, &max_regs); 6346 else 6347 printf (" DW_CFA_advance_loc2: %ld to %s\n", 6348 (unsigned long) (ofs * fc->code_factor), 6349 dwarf_vmatoa_1 (NULL, 6350 fc->pc_begin + ofs * fc->code_factor, 6351 fc->ptr_size)); 6352 fc->pc_begin += ofs * fc->code_factor; 6353 break; 6354 6355 case DW_CFA_advance_loc4: 6356 SAFE_BYTE_GET_AND_INC (ofs, start, 4, end); 6357 if (do_debug_frames_interp) 6358 frame_display_row (fc, &need_col_headers, &max_regs); 6359 else 6360 printf (" DW_CFA_advance_loc4: %ld to %s\n", 6361 (unsigned long) (ofs * fc->code_factor), 6362 dwarf_vmatoa_1 (NULL, 6363 fc->pc_begin + ofs * fc->code_factor, 6364 fc->ptr_size)); 6365 fc->pc_begin += ofs * fc->code_factor; 6366 break; 6367 6368 case DW_CFA_offset_extended: 6369 reg = LEB (); 6370 roffs = LEB (); 6371 if (reg >= (unsigned int) fc->ncols) 6372 reg_prefix = bad_reg; 6373 if (! do_debug_frames_interp || *reg_prefix != '\0') 6374 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", 6375 reg_prefix, regname (reg, 0), 6376 roffs * fc->data_factor); 6377 if (*reg_prefix == '\0') 6378 { 6379 fc->col_type[reg] = DW_CFA_offset; 6380 fc->col_offset[reg] = roffs * fc->data_factor; 6381 } 6382 break; 6383 6384 case DW_CFA_val_offset: 6385 reg = LEB (); 6386 roffs = LEB (); 6387 if (reg >= (unsigned int) fc->ncols) 6388 reg_prefix = bad_reg; 6389 if (! do_debug_frames_interp || *reg_prefix != '\0') 6390 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n", 6391 reg_prefix, regname (reg, 0), 6392 roffs * fc->data_factor); 6393 if (*reg_prefix == '\0') 6394 { 6395 fc->col_type[reg] = DW_CFA_val_offset; 6396 fc->col_offset[reg] = roffs * fc->data_factor; 6397 } 6398 break; 6399 6400 case DW_CFA_restore_extended: 6401 reg = LEB (); 6402 if (reg >= (unsigned int) cie->ncols 6403 || reg >= (unsigned int) fc->ncols) 6404 reg_prefix = bad_reg; 6405 if (! do_debug_frames_interp || *reg_prefix != '\0') 6406 printf (" DW_CFA_restore_extended: %s%s\n", 6407 reg_prefix, regname (reg, 0)); 6408 if (*reg_prefix == '\0') 6409 { 6410 fc->col_type[reg] = cie->col_type[reg]; 6411 fc->col_offset[reg] = cie->col_offset[reg]; 6412 } 6413 break; 6414 6415 case DW_CFA_undefined: 6416 reg = LEB (); 6417 if (reg >= (unsigned int) fc->ncols) 6418 reg_prefix = bad_reg; 6419 if (! do_debug_frames_interp || *reg_prefix != '\0') 6420 printf (" DW_CFA_undefined: %s%s\n", 6421 reg_prefix, regname (reg, 0)); 6422 if (*reg_prefix == '\0') 6423 { 6424 fc->col_type[reg] = DW_CFA_undefined; 6425 fc->col_offset[reg] = 0; 6426 } 6427 break; 6428 6429 case DW_CFA_same_value: 6430 reg = LEB (); 6431 if (reg >= (unsigned int) fc->ncols) 6432 reg_prefix = bad_reg; 6433 if (! do_debug_frames_interp || *reg_prefix != '\0') 6434 printf (" DW_CFA_same_value: %s%s\n", 6435 reg_prefix, regname (reg, 0)); 6436 if (*reg_prefix == '\0') 6437 { 6438 fc->col_type[reg] = DW_CFA_same_value; 6439 fc->col_offset[reg] = 0; 6440 } 6441 break; 6442 6443 case DW_CFA_register: 6444 reg = LEB (); 6445 roffs = LEB (); 6446 if (reg >= (unsigned int) fc->ncols) 6447 reg_prefix = bad_reg; 6448 if (! do_debug_frames_interp || *reg_prefix != '\0') 6449 { 6450 printf (" DW_CFA_register: %s%s in ", 6451 reg_prefix, regname (reg, 0)); 6452 puts (regname (roffs, 0)); 6453 } 6454 if (*reg_prefix == '\0') 6455 { 6456 fc->col_type[reg] = DW_CFA_register; 6457 fc->col_offset[reg] = roffs; 6458 } 6459 break; 6460 6461 case DW_CFA_remember_state: 6462 if (! do_debug_frames_interp) 6463 printf (" DW_CFA_remember_state\n"); 6464 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); 6465 rs->cfa_offset = fc->cfa_offset; 6466 rs->cfa_reg = fc->cfa_reg; 6467 rs->ra = fc->ra; 6468 rs->cfa_exp = fc->cfa_exp; 6469 rs->ncols = fc->ncols; 6470 rs->col_type = (short int *) xcmalloc (rs->ncols, 6471 sizeof (* rs->col_type)); 6472 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); 6473 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); 6474 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); 6475 rs->next = remembered_state; 6476 remembered_state = rs; 6477 break; 6478 6479 case DW_CFA_restore_state: 6480 if (! do_debug_frames_interp) 6481 printf (" DW_CFA_restore_state\n"); 6482 rs = remembered_state; 6483 if (rs) 6484 { 6485 remembered_state = rs->next; 6486 fc->cfa_offset = rs->cfa_offset; 6487 fc->cfa_reg = rs->cfa_reg; 6488 fc->ra = rs->ra; 6489 fc->cfa_exp = rs->cfa_exp; 6490 frame_need_space (fc, rs->ncols - 1); 6491 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); 6492 memcpy (fc->col_offset, rs->col_offset, 6493 rs->ncols * sizeof (* rs->col_offset)); 6494 free (rs->col_type); 6495 free (rs->col_offset); 6496 free (rs); 6497 } 6498 else if (do_debug_frames_interp) 6499 printf ("Mismatched DW_CFA_restore_state\n"); 6500 break; 6501 6502 case DW_CFA_def_cfa: 6503 fc->cfa_reg = LEB (); 6504 fc->cfa_offset = LEB (); 6505 fc->cfa_exp = 0; 6506 if (! do_debug_frames_interp) 6507 printf (" DW_CFA_def_cfa: %s ofs %d\n", 6508 regname (fc->cfa_reg, 0), fc->cfa_offset); 6509 break; 6510 6511 case DW_CFA_def_cfa_register: 6512 fc->cfa_reg = LEB (); 6513 fc->cfa_exp = 0; 6514 if (! do_debug_frames_interp) 6515 printf (" DW_CFA_def_cfa_register: %s\n", 6516 regname (fc->cfa_reg, 0)); 6517 break; 6518 6519 case DW_CFA_def_cfa_offset: 6520 fc->cfa_offset = LEB (); 6521 if (! do_debug_frames_interp) 6522 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset); 6523 break; 6524 6525 case DW_CFA_nop: 6526 if (! do_debug_frames_interp) 6527 printf (" DW_CFA_nop\n"); 6528 break; 6529 6530 case DW_CFA_def_cfa_expression: 6531 ul = LEB (); 6532 if (! do_debug_frames_interp) 6533 { 6534 printf (" DW_CFA_def_cfa_expression ("); 6535 decode_location_expression (start, eh_addr_size, 0, -1, 6536 ul, 0, section); 6537 printf (")\n"); 6538 } 6539 fc->cfa_exp = 1; 6540 start += ul; 6541 break; 6542 6543 case DW_CFA_expression: 6544 reg = LEB (); 6545 ul = LEB (); 6546 if (reg >= (unsigned int) fc->ncols) 6547 reg_prefix = bad_reg; 6548 if (! do_debug_frames_interp || *reg_prefix != '\0') 6549 { 6550 printf (" DW_CFA_expression: %s%s (", 6551 reg_prefix, regname (reg, 0)); 6552 decode_location_expression (start, eh_addr_size, 0, -1, 6553 ul, 0, section); 6554 printf (")\n"); 6555 } 6556 if (*reg_prefix == '\0') 6557 fc->col_type[reg] = DW_CFA_expression; 6558 start += ul; 6559 break; 6560 6561 case DW_CFA_val_expression: 6562 reg = LEB (); 6563 ul = LEB (); 6564 if (reg >= (unsigned int) fc->ncols) 6565 reg_prefix = bad_reg; 6566 if (! do_debug_frames_interp || *reg_prefix != '\0') 6567 { 6568 printf (" DW_CFA_val_expression: %s%s (", 6569 reg_prefix, regname (reg, 0)); 6570 decode_location_expression (start, eh_addr_size, 0, -1, 6571 ul, 0, section); 6572 printf (")\n"); 6573 } 6574 if (*reg_prefix == '\0') 6575 fc->col_type[reg] = DW_CFA_val_expression; 6576 start += ul; 6577 break; 6578 6579 case DW_CFA_offset_extended_sf: 6580 reg = LEB (); 6581 l = SLEB (); 6582 if (frame_need_space (fc, reg) < 0) 6583 reg_prefix = bad_reg; 6584 if (! do_debug_frames_interp || *reg_prefix != '\0') 6585 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", 6586 reg_prefix, regname (reg, 0), 6587 l * fc->data_factor); 6588 if (*reg_prefix == '\0') 6589 { 6590 fc->col_type[reg] = DW_CFA_offset; 6591 fc->col_offset[reg] = l * fc->data_factor; 6592 } 6593 break; 6594 6595 case DW_CFA_val_offset_sf: 6596 reg = LEB (); 6597 l = SLEB (); 6598 if (frame_need_space (fc, reg) < 0) 6599 reg_prefix = bad_reg; 6600 if (! do_debug_frames_interp || *reg_prefix != '\0') 6601 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n", 6602 reg_prefix, regname (reg, 0), 6603 l * fc->data_factor); 6604 if (*reg_prefix == '\0') 6605 { 6606 fc->col_type[reg] = DW_CFA_val_offset; 6607 fc->col_offset[reg] = l * fc->data_factor; 6608 } 6609 break; 6610 6611 case DW_CFA_def_cfa_sf: 6612 fc->cfa_reg = LEB (); 6613 fc->cfa_offset = SLEB (); 6614 fc->cfa_offset = fc->cfa_offset * fc->data_factor; 6615 fc->cfa_exp = 0; 6616 if (! do_debug_frames_interp) 6617 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", 6618 regname (fc->cfa_reg, 0), fc->cfa_offset); 6619 break; 6620 6621 case DW_CFA_def_cfa_offset_sf: 6622 fc->cfa_offset = SLEB (); 6623 fc->cfa_offset = fc->cfa_offset * fc->data_factor; 6624 if (! do_debug_frames_interp) 6625 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset); 6626 break; 6627 6628 case DW_CFA_MIPS_advance_loc8: 6629 SAFE_BYTE_GET_AND_INC (ofs, start, 8, end); 6630 if (do_debug_frames_interp) 6631 frame_display_row (fc, &need_col_headers, &max_regs); 6632 else 6633 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", 6634 (unsigned long) (ofs * fc->code_factor), 6635 dwarf_vmatoa_1 (NULL, 6636 fc->pc_begin + ofs * fc->code_factor, 6637 fc->ptr_size)); 6638 fc->pc_begin += ofs * fc->code_factor; 6639 break; 6640 6641 case DW_CFA_GNU_window_save: 6642 if (! do_debug_frames_interp) 6643 printf (" DW_CFA_GNU_window_save\n"); 6644 break; 6645 6646 case DW_CFA_GNU_args_size: 6647 ul = LEB (); 6648 if (! do_debug_frames_interp) 6649 printf (" DW_CFA_GNU_args_size: %ld\n", ul); 6650 break; 6651 6652 case DW_CFA_GNU_negative_offset_extended: 6653 reg = LEB (); 6654 l = - LEB (); 6655 if (frame_need_space (fc, reg) < 0) 6656 reg_prefix = bad_reg; 6657 if (! do_debug_frames_interp || *reg_prefix != '\0') 6658 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", 6659 reg_prefix, regname (reg, 0), 6660 l * fc->data_factor); 6661 if (*reg_prefix == '\0') 6662 { 6663 fc->col_type[reg] = DW_CFA_offset; 6664 fc->col_offset[reg] = l * fc->data_factor; 6665 } 6666 break; 6667 6668 default: 6669 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) 6670 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); 6671 else 6672 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); 6673 start = block_end; 6674 } 6675 } 6676 6677 if (do_debug_frames_interp) 6678 frame_display_row (fc, &need_col_headers, &max_regs); 6679 6680 start = block_end; 6681 eh_addr_size = saved_eh_addr_size; 6682 } 6683 6684 printf ("\n"); 6685 6686 return 1; 6687 } 6688 6689 #undef GET 6690 #undef LEB 6691 #undef SLEB 6692 6693 static int 6694 display_gdb_index (struct dwarf_section *section, 6695 void *file ATTRIBUTE_UNUSED) 6696 { 6697 unsigned char *start = section->start; 6698 uint32_t version; 6699 uint32_t cu_list_offset, tu_list_offset; 6700 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; 6701 unsigned int cu_list_elements, tu_list_elements; 6702 unsigned int address_table_size, symbol_table_slots; 6703 unsigned char *cu_list, *tu_list; 6704 unsigned char *address_table, *symbol_table, *constant_pool; 6705 unsigned int i; 6706 6707 /* The documentation for the format of this file is in gdb/dwarf2read.c. */ 6708 6709 printf (_("Contents of the %s section:\n"), section->name); 6710 6711 if (section->size < 6 * sizeof (uint32_t)) 6712 { 6713 warn (_("Truncated header in the %s section.\n"), section->name); 6714 return 0; 6715 } 6716 6717 version = byte_get_little_endian (start, 4); 6718 printf (_("Version %ld\n"), (long) version); 6719 6720 /* Prior versions are obsolete, and future versions may not be 6721 backwards compatible. */ 6722 if (version < 3 || version > 8) 6723 { 6724 warn (_("Unsupported version %lu.\n"), (unsigned long) version); 6725 return 0; 6726 } 6727 if (version < 4) 6728 warn (_("The address table data in version 3 may be wrong.\n")); 6729 if (version < 5) 6730 warn (_("Version 4 does not support case insensitive lookups.\n")); 6731 if (version < 6) 6732 warn (_("Version 5 does not include inlined functions.\n")); 6733 if (version < 7) 6734 warn (_("Version 6 does not include symbol attributes.\n")); 6735 /* Version 7 indices generated by Gold have bad type unit references, 6736 PR binutils/15021. But we don't know if the index was generated by 6737 Gold or not, so to avoid worrying users with gdb-generated indices 6738 we say nothing for version 7 here. */ 6739 6740 cu_list_offset = byte_get_little_endian (start + 4, 4); 6741 tu_list_offset = byte_get_little_endian (start + 8, 4); 6742 address_table_offset = byte_get_little_endian (start + 12, 4); 6743 symbol_table_offset = byte_get_little_endian (start + 16, 4); 6744 constant_pool_offset = byte_get_little_endian (start + 20, 4); 6745 6746 if (cu_list_offset > section->size 6747 || tu_list_offset > section->size 6748 || address_table_offset > section->size 6749 || symbol_table_offset > section->size 6750 || constant_pool_offset > section->size) 6751 { 6752 warn (_("Corrupt header in the %s section.\n"), section->name); 6753 return 0; 6754 } 6755 6756 cu_list_elements = (tu_list_offset - cu_list_offset) / 8; 6757 tu_list_elements = (address_table_offset - tu_list_offset) / 8; 6758 address_table_size = symbol_table_offset - address_table_offset; 6759 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; 6760 6761 cu_list = start + cu_list_offset; 6762 tu_list = start + tu_list_offset; 6763 address_table = start + address_table_offset; 6764 symbol_table = start + symbol_table_offset; 6765 constant_pool = start + constant_pool_offset; 6766 6767 printf (_("\nCU table:\n")); 6768 for (i = 0; i < cu_list_elements; i += 2) 6769 { 6770 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); 6771 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); 6772 6773 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, 6774 (unsigned long) cu_offset, 6775 (unsigned long) (cu_offset + cu_length - 1)); 6776 } 6777 6778 printf (_("\nTU table:\n")); 6779 for (i = 0; i < tu_list_elements; i += 3) 6780 { 6781 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); 6782 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); 6783 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); 6784 6785 printf (_("[%3u] 0x%lx 0x%lx "), i / 3, 6786 (unsigned long) tu_offset, 6787 (unsigned long) type_offset); 6788 print_dwarf_vma (signature, 8); 6789 printf ("\n"); 6790 } 6791 6792 printf (_("\nAddress table:\n")); 6793 for (i = 0; i < address_table_size; i += 2 * 8 + 4) 6794 { 6795 uint64_t low = byte_get_little_endian (address_table + i, 8); 6796 uint64_t high = byte_get_little_endian (address_table + i + 8, 8); 6797 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); 6798 6799 print_dwarf_vma (low, 8); 6800 print_dwarf_vma (high, 8); 6801 printf (_("%lu\n"), (unsigned long) cu_index); 6802 } 6803 6804 printf (_("\nSymbol table:\n")); 6805 for (i = 0; i < symbol_table_slots; ++i) 6806 { 6807 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); 6808 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); 6809 uint32_t num_cus, cu; 6810 6811 if (name_offset != 0 6812 || cu_vector_offset != 0) 6813 { 6814 unsigned int j; 6815 6816 printf ("[%3u] %s:", i, constant_pool + name_offset); 6817 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4); 6818 if (num_cus > 1) 6819 printf ("\n"); 6820 for (j = 0; j < num_cus; ++j) 6821 { 6822 int is_static; 6823 gdb_index_symbol_kind kind; 6824 6825 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); 6826 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); 6827 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); 6828 cu = GDB_INDEX_CU_VALUE (cu); 6829 /* Convert to TU number if it's for a type unit. */ 6830 if (cu >= cu_list_elements / 2) 6831 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', 6832 (unsigned long) (cu - cu_list_elements / 2)); 6833 else 6834 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); 6835 6836 printf (" [%s, %s]", 6837 is_static ? _("static") : _("global"), 6838 get_gdb_index_symbol_kind_name (kind)); 6839 if (num_cus > 1) 6840 printf ("\n"); 6841 } 6842 if (num_cus <= 1) 6843 printf ("\n"); 6844 } 6845 } 6846 6847 return 1; 6848 } 6849 6850 /* Pre-allocate enough space for the CU/TU sets needed. */ 6851 6852 static void 6853 prealloc_cu_tu_list (unsigned int nshndx) 6854 { 6855 if (shndx_pool == NULL) 6856 { 6857 shndx_pool_size = nshndx; 6858 shndx_pool_used = 0; 6859 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, 6860 sizeof (unsigned int)); 6861 } 6862 else 6863 { 6864 shndx_pool_size = shndx_pool_used + nshndx; 6865 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, 6866 sizeof (unsigned int)); 6867 } 6868 } 6869 6870 static void 6871 add_shndx_to_cu_tu_entry (unsigned int shndx) 6872 { 6873 if (shndx_pool_used >= shndx_pool_size) 6874 { 6875 error (_("Internal error: out of space in the shndx pool.\n")); 6876 return; 6877 } 6878 shndx_pool [shndx_pool_used++] = shndx; 6879 } 6880 6881 static void 6882 end_cu_tu_entry (void) 6883 { 6884 if (shndx_pool_used >= shndx_pool_size) 6885 { 6886 error (_("Internal error: out of space in the shndx pool.\n")); 6887 return; 6888 } 6889 shndx_pool [shndx_pool_used++] = 0; 6890 } 6891 6892 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ 6893 6894 static const char * 6895 get_DW_SECT_short_name (unsigned int dw_sect) 6896 { 6897 static char buf[16]; 6898 6899 switch (dw_sect) 6900 { 6901 case DW_SECT_INFO: 6902 return "info"; 6903 case DW_SECT_TYPES: 6904 return "types"; 6905 case DW_SECT_ABBREV: 6906 return "abbrev"; 6907 case DW_SECT_LINE: 6908 return "line"; 6909 case DW_SECT_LOC: 6910 return "loc"; 6911 case DW_SECT_STR_OFFSETS: 6912 return "str_off"; 6913 case DW_SECT_MACINFO: 6914 return "macinfo"; 6915 case DW_SECT_MACRO: 6916 return "macro"; 6917 default: 6918 break; 6919 } 6920 6921 snprintf (buf, sizeof (buf), "%d", dw_sect); 6922 return buf; 6923 } 6924 6925 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. 6926 These sections are extensions for Fission. 6927 See http://gcc.gnu.org/wiki/DebugFissionDWP. */ 6928 6929 static int 6930 process_cu_tu_index (struct dwarf_section *section, int do_display) 6931 { 6932 unsigned char *phdr = section->start; 6933 unsigned char *limit = phdr + section->size; 6934 unsigned char *phash; 6935 unsigned char *pindex; 6936 unsigned char *ppool; 6937 unsigned int version; 6938 unsigned int ncols = 0; 6939 unsigned int nused; 6940 unsigned int nslots; 6941 unsigned int i; 6942 unsigned int j; 6943 dwarf_vma signature_high; 6944 dwarf_vma signature_low; 6945 char buf[64]; 6946 6947 version = byte_get (phdr, 4); 6948 if (version >= 2) 6949 ncols = byte_get (phdr + 4, 4); 6950 nused = byte_get (phdr + 8, 4); 6951 nslots = byte_get (phdr + 12, 4); 6952 phash = phdr + 16; 6953 pindex = phash + nslots * 8; 6954 ppool = pindex + nslots * 4; 6955 6956 if (do_display) 6957 { 6958 printf (_("Contents of the %s section:\n\n"), section->name); 6959 printf (_(" Version: %d\n"), version); 6960 if (version >= 2) 6961 printf (_(" Number of columns: %d\n"), ncols); 6962 printf (_(" Number of used entries: %d\n"), nused); 6963 printf (_(" Number of slots: %d\n\n"), nslots); 6964 } 6965 6966 if (ppool > limit) 6967 { 6968 warn (_("Section %s too small for %d hash table entries\n"), 6969 section->name, nslots); 6970 return 0; 6971 } 6972 6973 if (version == 1) 6974 { 6975 if (!do_display) 6976 prealloc_cu_tu_list ((limit - ppool) / 4); 6977 for (i = 0; i < nslots; i++) 6978 { 6979 unsigned char *shndx_list; 6980 unsigned int shndx; 6981 6982 byte_get_64 (phash, &signature_high, &signature_low); 6983 if (signature_high != 0 || signature_low != 0) 6984 { 6985 j = byte_get (pindex, 4); 6986 shndx_list = ppool + j * 4; 6987 if (do_display) 6988 printf (_(" [%3d] Signature: 0x%s Sections: "), 6989 i, dwarf_vmatoa64 (signature_high, signature_low, 6990 buf, sizeof (buf))); 6991 for (;;) 6992 { 6993 if (shndx_list >= limit) 6994 { 6995 warn (_("Section %s too small for shndx pool\n"), 6996 section->name); 6997 return 0; 6998 } 6999 shndx = byte_get (shndx_list, 4); 7000 if (shndx == 0) 7001 break; 7002 if (do_display) 7003 printf (" %d", shndx); 7004 else 7005 add_shndx_to_cu_tu_entry (shndx); 7006 shndx_list += 4; 7007 } 7008 if (do_display) 7009 printf ("\n"); 7010 else 7011 end_cu_tu_entry (); 7012 } 7013 phash += 8; 7014 pindex += 4; 7015 } 7016 } 7017 else if (version == 2) 7018 { 7019 unsigned int val; 7020 unsigned int dw_sect; 7021 unsigned char *ph = phash; 7022 unsigned char *pi = pindex; 7023 unsigned char *poffsets = ppool + ncols * 4; 7024 unsigned char *psizes = poffsets + nused * ncols * 4; 7025 unsigned char *pend = psizes + nused * ncols * 4; 7026 bfd_boolean is_tu_index; 7027 struct cu_tu_set *this_set = NULL; 7028 unsigned int row; 7029 unsigned char *prow; 7030 7031 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; 7032 7033 if (pend > limit) 7034 { 7035 warn (_("Section %s too small for offset and size tables\n"), 7036 section->name); 7037 return 0; 7038 } 7039 7040 if (do_display) 7041 { 7042 printf (_(" Offset table\n")); 7043 printf (" slot %-16s ", 7044 is_tu_index ? _("signature") : _("dwo_id")); 7045 } 7046 else 7047 { 7048 if (is_tu_index) 7049 { 7050 tu_count = nused; 7051 tu_sets = xcmalloc (nused, sizeof (struct cu_tu_set)); 7052 this_set = tu_sets; 7053 } 7054 else 7055 { 7056 cu_count = nused; 7057 cu_sets = xcmalloc (nused, sizeof (struct cu_tu_set)); 7058 this_set = cu_sets; 7059 } 7060 } 7061 if (do_display) 7062 { 7063 for (j = 0; j < ncols; j++) 7064 { 7065 dw_sect = byte_get (ppool + j * 4, 4); 7066 printf (" %8s", get_DW_SECT_short_name (dw_sect)); 7067 } 7068 printf ("\n"); 7069 } 7070 for (i = 0; i < nslots; i++) 7071 { 7072 byte_get_64 (ph, &signature_high, &signature_low); 7073 row = byte_get (pi, 4); 7074 if (row != 0) 7075 { 7076 if (!do_display) 7077 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t)); 7078 prow = poffsets + (row - 1) * ncols * 4; 7079 if (do_display) 7080 printf (_(" [%3d] 0x%s"), 7081 i, dwarf_vmatoa64 (signature_high, signature_low, 7082 buf, sizeof (buf))); 7083 for (j = 0; j < ncols; j++) 7084 { 7085 val = byte_get (prow + j * 4, 4); 7086 if (do_display) 7087 printf (" %8d", val); 7088 else 7089 { 7090 dw_sect = byte_get (ppool + j * 4, 4); 7091 this_set [row - 1].section_offsets [dw_sect] = val; 7092 } 7093 } 7094 if (do_display) 7095 printf ("\n"); 7096 } 7097 ph += 8; 7098 pi += 4; 7099 } 7100 7101 ph = phash; 7102 pi = pindex; 7103 if (do_display) 7104 { 7105 printf ("\n"); 7106 printf (_(" Size table\n")); 7107 printf (" slot %-16s ", 7108 is_tu_index ? _("signature") : _("dwo_id")); 7109 } 7110 for (j = 0; j < ncols; j++) 7111 { 7112 val = byte_get (ppool + j * 4, 4); 7113 if (do_display) 7114 printf (" %8s", get_DW_SECT_short_name (val)); 7115 } 7116 if (do_display) 7117 printf ("\n"); 7118 for (i = 0; i < nslots; i++) 7119 { 7120 byte_get_64 (ph, &signature_high, &signature_low); 7121 row = byte_get (pi, 4); 7122 if (row != 0) 7123 { 7124 prow = psizes + (row - 1) * ncols * 4; 7125 if (do_display) 7126 printf (_(" [%3d] 0x%s"), 7127 i, dwarf_vmatoa64 (signature_high, signature_low, 7128 buf, sizeof (buf))); 7129 for (j = 0; j < ncols; j++) 7130 { 7131 val = byte_get (prow + j * 4, 4); 7132 if (do_display) 7133 printf (" %8d", val); 7134 else 7135 { 7136 dw_sect = byte_get (ppool + j * 4, 4); 7137 this_set [row - 1].section_sizes [dw_sect] = val; 7138 } 7139 } 7140 if (do_display) 7141 printf ("\n"); 7142 } 7143 ph += 8; 7144 pi += 4; 7145 } 7146 } 7147 else if (do_display) 7148 printf (_(" Unsupported version\n")); 7149 7150 if (do_display) 7151 printf ("\n"); 7152 7153 return 1; 7154 } 7155 7156 /* Load the CU and TU indexes if present. This will build a list of 7157 section sets that we can use to associate a .debug_info.dwo section 7158 with its associated .debug_abbrev.dwo section in a .dwp file. */ 7159 7160 static void 7161 load_cu_tu_indexes (void *file) 7162 { 7163 /* If we have already loaded (or tried to load) the CU and TU indexes 7164 then do not bother to repeat the task. */ 7165 if (cu_tu_indexes_read) 7166 return; 7167 7168 if (load_debug_section (dwp_cu_index, file)) 7169 process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0); 7170 7171 if (load_debug_section (dwp_tu_index, file)) 7172 process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0); 7173 7174 cu_tu_indexes_read = 1; 7175 } 7176 7177 /* Find the set of sections that includes section SHNDX. */ 7178 7179 unsigned int * 7180 find_cu_tu_set (void *file, unsigned int shndx) 7181 { 7182 unsigned int i; 7183 7184 load_cu_tu_indexes (file); 7185 7186 /* Find SHNDX in the shndx pool. */ 7187 for (i = 0; i < shndx_pool_used; i++) 7188 if (shndx_pool [i] == shndx) 7189 break; 7190 7191 if (i >= shndx_pool_used) 7192 return NULL; 7193 7194 /* Now backup to find the first entry in the set. */ 7195 while (i > 0 && shndx_pool [i - 1] != 0) 7196 i--; 7197 7198 return shndx_pool + i; 7199 } 7200 7201 /* Display a .debug_cu_index or .debug_tu_index section. */ 7202 7203 static int 7204 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) 7205 { 7206 return process_cu_tu_index (section, 1); 7207 } 7208 7209 static int 7210 display_debug_not_supported (struct dwarf_section *section, 7211 void *file ATTRIBUTE_UNUSED) 7212 { 7213 printf (_("Displaying the debug contents of section %s is not yet supported.\n"), 7214 section->name); 7215 7216 return 1; 7217 } 7218 7219 void * 7220 cmalloc (size_t nmemb, size_t size) 7221 { 7222 /* Check for overflow. */ 7223 if (nmemb >= ~(size_t) 0 / size) 7224 return NULL; 7225 else 7226 return malloc (nmemb * size); 7227 } 7228 7229 void * 7230 xcmalloc (size_t nmemb, size_t size) 7231 { 7232 /* Check for overflow. */ 7233 if (nmemb >= ~(size_t) 0 / size) 7234 return NULL; 7235 else 7236 return xmalloc (nmemb * size); 7237 } 7238 7239 void * 7240 xcrealloc (void *ptr, size_t nmemb, size_t size) 7241 { 7242 /* Check for overflow. */ 7243 if (nmemb >= ~(size_t) 0 / size) 7244 return NULL; 7245 else 7246 return xrealloc (ptr, nmemb * size); 7247 } 7248 7249 void 7250 free_debug_memory (void) 7251 { 7252 unsigned int i; 7253 7254 free_abbrevs (); 7255 7256 for (i = 0; i < max; i++) 7257 free_debug_section ((enum dwarf_section_display_enum) i); 7258 7259 if (debug_information != NULL) 7260 { 7261 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) 7262 { 7263 for (i = 0; i < num_debug_info_entries; i++) 7264 { 7265 if (!debug_information [i].max_loc_offsets) 7266 { 7267 free (debug_information [i].loc_offsets); 7268 free (debug_information [i].have_frame_base); 7269 } 7270 if (!debug_information [i].max_range_lists) 7271 free (debug_information [i].range_lists); 7272 } 7273 } 7274 7275 free (debug_information); 7276 debug_information = NULL; 7277 num_debug_info_entries = 0; 7278 } 7279 } 7280 7281 void 7282 dwarf_select_sections_by_names (const char *names) 7283 { 7284 typedef struct 7285 { 7286 const char * option; 7287 int * variable; 7288 int val; 7289 } 7290 debug_dump_long_opts; 7291 7292 static const debug_dump_long_opts opts_table [] = 7293 { 7294 /* Please keep this table alpha- sorted. */ 7295 { "Ranges", & do_debug_ranges, 1 }, 7296 { "abbrev", & do_debug_abbrevs, 1 }, 7297 { "addr", & do_debug_addr, 1 }, 7298 { "aranges", & do_debug_aranges, 1 }, 7299 { "cu_index", & do_debug_cu_index, 1 }, 7300 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, 7301 { "frames", & do_debug_frames, 1 }, 7302 { "frames-interp", & do_debug_frames_interp, 1 }, 7303 /* The special .gdb_index section. */ 7304 { "gdb_index", & do_gdb_index, 1 }, 7305 { "info", & do_debug_info, 1 }, 7306 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ 7307 { "loc", & do_debug_loc, 1 }, 7308 { "macro", & do_debug_macinfo, 1 }, 7309 { "pubnames", & do_debug_pubnames, 1 }, 7310 { "pubtypes", & do_debug_pubtypes, 1 }, 7311 /* This entry is for compatability 7312 with earlier versions of readelf. */ 7313 { "ranges", & do_debug_aranges, 1 }, 7314 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, 7315 { "str", & do_debug_str, 1 }, 7316 /* These trace_* sections are used by Itanium VMS. */ 7317 { "trace_abbrev", & do_trace_abbrevs, 1 }, 7318 { "trace_aranges", & do_trace_aranges, 1 }, 7319 { "trace_info", & do_trace_info, 1 }, 7320 { NULL, NULL, 0 } 7321 }; 7322 7323 const char *p; 7324 7325 p = names; 7326 while (*p) 7327 { 7328 const debug_dump_long_opts * entry; 7329 7330 for (entry = opts_table; entry->option; entry++) 7331 { 7332 size_t len = strlen (entry->option); 7333 7334 if (strncmp (p, entry->option, len) == 0 7335 && (p[len] == ',' || p[len] == '\0')) 7336 { 7337 * entry->variable |= entry->val; 7338 7339 /* The --debug-dump=frames-interp option also 7340 enables the --debug-dump=frames option. */ 7341 if (do_debug_frames_interp) 7342 do_debug_frames = 1; 7343 7344 p += len; 7345 break; 7346 } 7347 } 7348 7349 if (entry->option == NULL) 7350 { 7351 warn (_("Unrecognized debug option '%s'\n"), p); 7352 p = strchr (p, ','); 7353 if (p == NULL) 7354 break; 7355 } 7356 7357 if (*p == ',') 7358 p++; 7359 } 7360 } 7361 7362 void 7363 dwarf_select_sections_by_letters (const char *letters) 7364 { 7365 unsigned int lindex = 0; 7366 7367 while (letters[lindex]) 7368 switch (letters[lindex++]) 7369 { 7370 case 'i': 7371 do_debug_info = 1; 7372 break; 7373 7374 case 'a': 7375 do_debug_abbrevs = 1; 7376 break; 7377 7378 case 'l': 7379 do_debug_lines |= FLAG_DEBUG_LINES_RAW; 7380 break; 7381 7382 case 'L': 7383 do_debug_lines |= FLAG_DEBUG_LINES_DECODED; 7384 break; 7385 7386 case 'p': 7387 do_debug_pubnames = 1; 7388 break; 7389 7390 case 't': 7391 do_debug_pubtypes = 1; 7392 break; 7393 7394 case 'r': 7395 do_debug_aranges = 1; 7396 break; 7397 7398 case 'R': 7399 do_debug_ranges = 1; 7400 break; 7401 7402 case 'F': 7403 do_debug_frames_interp = 1; 7404 case 'f': 7405 do_debug_frames = 1; 7406 break; 7407 7408 case 'm': 7409 do_debug_macinfo = 1; 7410 break; 7411 7412 case 's': 7413 do_debug_str = 1; 7414 break; 7415 7416 case 'o': 7417 do_debug_loc = 1; 7418 break; 7419 7420 default: 7421 warn (_("Unrecognized debug option '%s'\n"), optarg); 7422 break; 7423 } 7424 } 7425 7426 void 7427 dwarf_select_sections_all (void) 7428 { 7429 do_debug_info = 1; 7430 do_debug_abbrevs = 1; 7431 do_debug_lines = FLAG_DEBUG_LINES_RAW; 7432 do_debug_pubnames = 1; 7433 do_debug_pubtypes = 1; 7434 do_debug_aranges = 1; 7435 do_debug_ranges = 1; 7436 do_debug_frames = 1; 7437 do_debug_macinfo = 1; 7438 do_debug_str = 1; 7439 do_debug_loc = 1; 7440 do_gdb_index = 1; 7441 do_trace_info = 1; 7442 do_trace_abbrevs = 1; 7443 do_trace_aranges = 1; 7444 do_debug_addr = 1; 7445 do_debug_cu_index = 1; 7446 } 7447 7448 struct dwarf_section_display debug_displays[] = 7449 { 7450 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0 }, 7451 display_debug_abbrev, &do_debug_abbrevs, 0 }, 7452 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0 }, 7453 display_debug_aranges, &do_debug_aranges, 1 }, 7454 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0 }, 7455 display_debug_frames, &do_debug_frames, 1 }, 7456 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev }, 7457 display_debug_info, &do_debug_info, 1 }, 7458 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0 }, 7459 display_debug_lines, &do_debug_lines, 1 }, 7460 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0 }, 7461 display_debug_pubnames, &do_debug_pubnames, 0 }, 7462 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0 }, 7463 display_debug_gnu_pubnames, &do_debug_pubnames, 0 }, 7464 { { ".eh_frame", "", NULL, NULL, 0, 0, 0 }, 7465 display_debug_frames, &do_debug_frames, 1 }, 7466 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0 }, 7467 display_debug_macinfo, &do_debug_macinfo, 0 }, 7468 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0 }, 7469 display_debug_macro, &do_debug_macinfo, 1 }, 7470 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0 }, 7471 display_debug_str, &do_debug_str, 0 }, 7472 { { ".debug_line_str", ".zdebug_line_str", NULL, NULL, 0, 0, 0 }, 7473 display_debug_str, &do_debug_str, 0 }, 7474 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0 }, 7475 display_debug_loc, &do_debug_loc, 1 }, 7476 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0 }, 7477 display_debug_pubnames, &do_debug_pubtypes, 0 }, 7478 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0 }, 7479 display_debug_gnu_pubnames, &do_debug_pubtypes, 0 }, 7480 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0 }, 7481 display_debug_ranges, &do_debug_ranges, 1 }, 7482 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0 }, 7483 display_debug_not_supported, NULL, 0 }, 7484 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0 }, 7485 display_debug_not_supported, NULL, 0 }, 7486 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev }, 7487 display_debug_types, &do_debug_info, 1 }, 7488 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0 }, 7489 display_debug_not_supported, NULL, 0 }, 7490 { { ".gdb_index", "", NULL, NULL, 0, 0, 0 }, 7491 display_gdb_index, &do_gdb_index, 0 }, 7492 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev }, 7493 display_trace_info, &do_trace_info, 1 }, 7494 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0 }, 7495 display_debug_abbrev, &do_trace_abbrevs, 0 }, 7496 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0 }, 7497 display_debug_aranges, &do_trace_aranges, 0 }, 7498 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo }, 7499 display_debug_info, &do_debug_info, 1 }, 7500 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0 }, 7501 display_debug_abbrev, &do_debug_abbrevs, 0 }, 7502 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo }, 7503 display_debug_types, &do_debug_info, 1 }, 7504 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0 }, 7505 display_debug_lines, &do_debug_lines, 1 }, 7506 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0 }, 7507 display_debug_loc, &do_debug_loc, 1 }, 7508 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0 }, 7509 display_debug_macro, &do_debug_macinfo, 1 }, 7510 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0 }, 7511 display_debug_macinfo, &do_debug_macinfo, 0 }, 7512 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0 }, 7513 display_debug_str, &do_debug_str, 1 }, 7514 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0 }, 7515 display_debug_str_offsets, NULL, 0 }, 7516 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0 }, 7517 display_debug_str_offsets, NULL, 0 }, 7518 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0 }, 7519 display_debug_addr, &do_debug_addr, 1 }, 7520 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0 }, 7521 display_cu_index, &do_debug_cu_index, 0 }, 7522 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0 }, 7523 display_cu_index, &do_debug_cu_index, 0 }, 7524 }; 7525