Changeset 609 for branches/GNU/src/binutils/bfd/dwarf2.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/dwarf2.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* DWARF 2 support. 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 3 3 Free Software Foundation, Inc. 4 4 … … 14 14 support in dwarfread.c 15 15 16 This file is part of BFD.17 18 This program is free software; you can redistribute it and/or modify19 it under the terms of the GNU General Public License as published by20 the Free Software Foundation; either version 2 of the License, or (at21 your option) any later version.22 23 This program is distributed in the hope that it will be useful, but24 WITHOUT ANY WARRANTY; without even the implied warranty of25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU26 General Public License for more details.27 28 You should have received a copy of the GNU General Public License29 along with this program; if not, write to the Free Software30 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */16 This file is part of BFD. 17 18 This program is free software; you can redistribute it and/or modify 19 it under the terms of the GNU General Public License as published by 20 the Free Software Foundation; either version 2 of the License, or (at 21 your option) any later version. 22 23 This program is distributed in the hope that it will be useful, but 24 WITHOUT ANY WARRANTY; without even the implied warranty of 25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 26 General Public License for more details. 27 28 You should have received a copy of the GNU General Public License 29 along with this program; if not, write to the Free Software 30 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 31 31 32 32 #include "bfd.h" … … 41 41 struct line_head 42 42 { 43 unsigned inttotal_length;43 bfd_vma total_length; 44 44 unsigned short version; 45 unsigned intprologue_length;45 bfd_vma prologue_length; 46 46 unsigned char minimum_instruction_length; 47 47 unsigned char default_is_stmt; … … 97 97 char* info_ptr_end; 98 98 99 /* Pointer to the section and address of the beginning of the 100 section. */ 101 asection* sec; 102 char* sec_info_ptr; 103 104 /* Pointer to the symbol table. */ 105 asymbol** syms; 106 99 107 /* Pointer to the .debug_abbrev section loaded into memory. */ 100 108 char* dwarf_abbrev_buffer; … … 108 116 /* Length of the loaded .debug_line section. */ 109 117 unsigned long dwarf_line_size; 118 119 /* Pointer to the .debug_str section loaded into memory. */ 120 char* dwarf_str_buffer; 121 122 /* Length of the loaded .debug_str section. */ 123 unsigned long dwarf_str_size; 110 124 }; 111 125 … … 144 158 char* comp_dir; 145 159 146 /* T rueif there is a line number table associated with this comp. unit. */160 /* TRUE if there is a line number table associated with this comp. unit. */ 147 161 int stmtlist; 148 162 … … 162 176 struct funcinfo* function_table; 163 177 178 /* Pointer to dwarf2_debug structure. */ 179 struct dwarf2_debug *stash; 180 164 181 /* Address size for this unit - from unit header. */ 165 182 unsigned char addr_size; 183 184 /* Offset size for this unit - from unit header. */ 185 unsigned char offset_size; 166 186 }; 187 188 /* This data structure holds the information of an abbrev. */ 189 struct abbrev_info 190 { 191 unsigned int number; /* Number identifying abbrev. */ 192 enum dwarf_tag tag; /* DWARF tag. */ 193 int has_children; /* Boolean. */ 194 unsigned int num_attrs; /* Number of attributes. */ 195 struct attr_abbrev *attrs; /* An array of attribute descriptions. */ 196 struct abbrev_info *next; /* Next in chain. */ 197 }; 198 199 struct attr_abbrev 200 { 201 enum dwarf_attribute name; 202 enum dwarf_form form; 203 }; 204 205 #ifndef ABBREV_HASH_SIZE 206 #define ABBREV_HASH_SIZE 121 207 #endif 208 #ifndef ATTR_ALLOC_CHUNK 209 #define ATTR_ALLOC_CHUNK 4 210 #endif 211 212 static unsigned int read_1_byte PARAMS ((bfd *, char *)); 213 static int read_1_signed_byte PARAMS ((bfd *, char *)); 214 static unsigned int read_2_bytes PARAMS ((bfd *, char *)); 215 static unsigned int read_4_bytes PARAMS ((bfd *, char *)); 216 static bfd_vma read_8_bytes PARAMS ((bfd *, char *)); 217 static char *read_n_bytes PARAMS ((bfd *, char *, unsigned int)); 218 static char *read_string PARAMS ((bfd *, char *, unsigned int *)); 219 static char *read_indirect_string PARAMS ((struct comp_unit *, char *, unsigned int *)); 220 static unsigned int read_unsigned_leb128 221 PARAMS ((bfd *, char *, unsigned int *)); 222 static int read_signed_leb128 223 PARAMS ((bfd *, char *, unsigned int *)); 224 static bfd_vma read_address PARAMS ((struct comp_unit *, char *)); 225 static struct abbrev_info *lookup_abbrev 226 PARAMS ((unsigned int, struct abbrev_info **)); 227 static struct abbrev_info **read_abbrevs 228 PARAMS ((bfd *, bfd_vma, struct dwarf2_debug *)); 229 static char *read_attribute 230 PARAMS ((struct attribute *, struct attr_abbrev *, 231 struct comp_unit *, char *)); 232 static char *read_attribute_value 233 PARAMS ((struct attribute *, unsigned, 234 struct comp_unit *, char *)); 235 static void add_line_info 236 PARAMS ((struct line_info_table *, bfd_vma, char *, 237 unsigned int, unsigned int, int)); 238 static char *concat_filename PARAMS ((struct line_info_table *, unsigned int)); 239 static void arange_add PARAMS ((struct comp_unit *, bfd_vma, bfd_vma)); 240 static struct line_info_table *decode_line_info 241 PARAMS ((struct comp_unit *, struct dwarf2_debug *)); 242 static bfd_boolean lookup_address_in_line_info_table 243 PARAMS ((struct line_info_table *, bfd_vma, struct funcinfo *, 244 const char **, unsigned int *)); 245 static bfd_boolean lookup_address_in_function_table 246 PARAMS ((struct funcinfo *, bfd_vma, struct funcinfo **, const char **)); 247 static bfd_boolean scan_unit_for_functions PARAMS ((struct comp_unit *)); 248 static struct comp_unit *parse_comp_unit 249 PARAMS ((bfd *, struct dwarf2_debug *, bfd_vma, unsigned int)); 250 static bfd_boolean comp_unit_contains_address 251 PARAMS ((struct comp_unit *, bfd_vma)); 252 static bfd_boolean comp_unit_find_nearest_line 253 PARAMS ((struct comp_unit *, bfd_vma, const char **, const char **, 254 unsigned int *, struct dwarf2_debug *)); 255 static asection *find_debug_info PARAMS ((bfd *, asection *)); 167 256 168 257 /* VERBATIM … … 228 317 #endif 229 318 230 static unsigned int319 static bfd_vma 231 320 read_8_bytes (abfd, buf) 232 321 bfd *abfd; … … 254 343 unsigned int *bytes_read_ptr; 255 344 { 256 /* If the size of a host char is 8 bits, we can return a pointer 257 to the string, otherwise we have to copy the string to a buffer 258 allocated on the temporary obstack. */ 345 /* Return a pointer to the embedded string. */ 259 346 if (*buf == '\0') 260 347 { … … 264 351 265 352 *bytes_read_ptr = strlen (buf) + 1; 353 return buf; 354 } 355 356 static char * 357 read_indirect_string (unit, buf, bytes_read_ptr) 358 struct comp_unit* unit; 359 char *buf; 360 unsigned int *bytes_read_ptr; 361 { 362 bfd_vma offset; 363 struct dwarf2_debug *stash = unit->stash; 364 365 if (unit->offset_size == 4) 366 offset = read_4_bytes (unit->abfd, buf); 367 else 368 offset = read_8_bytes (unit->abfd, buf); 369 *bytes_read_ptr = unit->offset_size; 370 371 if (! stash->dwarf_str_buffer) 372 { 373 asection *msec; 374 bfd *abfd = unit->abfd; 375 376 msec = bfd_get_section_by_name (abfd, ".debug_str"); 377 if (! msec) 378 { 379 (*_bfd_error_handler) 380 (_("Dwarf Error: Can't find .debug_str section.")); 381 bfd_set_error (bfd_error_bad_value); 382 return NULL; 383 } 384 385 stash->dwarf_str_size = msec->_raw_size; 386 stash->dwarf_str_buffer = (char*) bfd_alloc (abfd, msec->_raw_size); 387 if (! stash->dwarf_abbrev_buffer) 388 return NULL; 389 390 if (! bfd_get_section_contents (abfd, msec, stash->dwarf_str_buffer, 391 (bfd_vma) 0, msec->_raw_size)) 392 return NULL; 393 } 394 395 if (offset >= stash->dwarf_str_size) 396 { 397 (*_bfd_error_handler) (_("Dwarf Error: DW_FORM_strp offset (%lu) greater than or equal to .debug_str size (%lu)."), 398 (unsigned long) offset, stash->dwarf_str_size); 399 bfd_set_error (bfd_error_bad_value); 400 return NULL; 401 } 402 403 buf = stash->dwarf_str_buffer + offset; 404 if (*buf == '\0') 405 return NULL; 266 406 return buf; 267 407 } … … 350 490 } 351 491 352 /* This data structure holds the information of an abbrev. */353 struct abbrev_info354 {355 unsigned int number; /* Number identifying abbrev. */356 enum dwarf_tag tag; /* DWARF tag. */357 int has_children; /* Boolean. */358 unsigned int num_attrs; /* Number of attributes. */359 struct attr_abbrev *attrs; /* An array of attribute descriptions. */360 struct abbrev_info *next; /* Next in chain. */361 };362 363 struct attr_abbrev364 {365 enum dwarf_attribute name;366 enum dwarf_form form;367 };368 369 #ifndef ABBREV_HASH_SIZE370 #define ABBREV_HASH_SIZE 121371 #endif372 #ifndef ATTR_ALLOC_CHUNK373 #define ATTR_ALLOC_CHUNK 4374 #endif375 376 492 /* Lookup an abbrev_info structure in the abbrev hash table. */ 377 493 … … 406 522 read_abbrevs (abfd, offset, stash) 407 523 bfd * abfd; 408 unsigned intoffset;524 bfd_vma offset; 409 525 struct dwarf2_debug *stash; 410 526 { … … 414 530 unsigned int abbrev_number, bytes_read, abbrev_name; 415 531 unsigned int abbrev_form, hash_number; 532 bfd_size_type amt; 416 533 417 534 if (! stash->dwarf_abbrev_buffer) … … 428 545 429 546 stash->dwarf_abbrev_size = msec->_raw_size; 430 stash->dwarf_abbrev_buffer = (char*) bfd_alloc (abfd, stash->dwarf_abbrev_size); 547 stash->dwarf_abbrev_buffer 548 = bfd_simple_get_relocated_section_contents (abfd, msec, NULL, 549 stash->syms); 431 550 if (! stash->dwarf_abbrev_buffer) 432 551 return 0; 433 434 if (! bfd_get_section_contents (abfd, msec,435 stash->dwarf_abbrev_buffer, 0,436 stash->dwarf_abbrev_size))437 return 0;438 552 } 439 553 440 554 if (offset >= stash->dwarf_abbrev_size) 441 555 { 442 (*_bfd_error_handler) (_("Dwarf Error: Abbrev offset (% u) greater than or equal to abbrev size (%u)."),443 offset, stash->dwarf_abbrev_size);556 (*_bfd_error_handler) (_("Dwarf Error: Abbrev offset (%lu) greater than or equal to .debug_abbrev size (%lu)."), 557 (unsigned long) offset, stash->dwarf_abbrev_size); 444 558 bfd_set_error (bfd_error_bad_value); 445 559 return 0; 446 560 } 447 561 448 abbrevs = (struct abbrev_info**) bfd_zalloc (abfd, sizeof (struct abbrev_info*) * ABBREV_HASH_SIZE); 562 amt = sizeof (struct abbrev_info*) * ABBREV_HASH_SIZE; 563 abbrevs = (struct abbrev_info**) bfd_zalloc (abfd, amt); 449 564 450 565 abbrev_ptr = stash->dwarf_abbrev_buffer + offset; … … 455 570 while (abbrev_number) 456 571 { 457 cur_abbrev = (struct abbrev_info*)bfd_zalloc (abfd, sizeof (struct abbrev_info)); 572 amt = sizeof (struct abbrev_info); 573 cur_abbrev = (struct abbrev_info *) bfd_zalloc (abfd, amt); 458 574 459 575 /* Read in abbrev header. */ 460 576 cur_abbrev->number = abbrev_number; 461 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 577 cur_abbrev->tag = (enum dwarf_tag) 578 read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 462 579 abbrev_ptr += bytes_read; 463 580 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); … … 474 591 if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0) 475 592 { 476 cur_abbrev->attrs = (struct attr_abbrev *)477 bfd_realloc (cur_abbrev->attrs,478 (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK)479 * sizeof (struct attr_abbrev));593 amt = cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK; 594 amt *= sizeof (struct attr_abbrev); 595 cur_abbrev->attrs = ((struct attr_abbrev *) 596 bfd_realloc (cur_abbrev->attrs, amt)); 480 597 if (! cur_abbrev->attrs) 481 598 return 0; 482 599 } 483 600 484 cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name; 485 cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form; 601 cur_abbrev->attrs[cur_abbrev->num_attrs].name 602 = (enum dwarf_attribute) abbrev_name; 603 cur_abbrev->attrs[cur_abbrev->num_attrs++].form 604 = (enum dwarf_form) abbrev_form; 486 605 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); 487 606 abbrev_ptr += bytes_read; … … 495 614 496 615 /* Get next abbreviation. 497 616 Under Irix6 the abbreviations for a compilation unit are not 498 617 always properly terminated with an abbrev number of 0. 499 618 Exit loop if we encounter an abbreviation which we have … … 513 632 } 514 633 515 /* Read an attribute described by an abbreviated attribute. */634 /* Read an attribute value described by an attribute form. */ 516 635 517 636 static char * 518 read_attribute (attr, abbrev, unit, info_ptr)637 read_attribute_value (attr, form, unit, info_ptr) 519 638 struct attribute *attr; 520 struct attr_abbrev *abbrev;639 unsigned form; 521 640 struct comp_unit *unit; 522 641 char *info_ptr; … … 525 644 unsigned int bytes_read; 526 645 struct dwarf_block *blk; 527 528 attr->name = abbrev->name; 529 attr->form = abbrev->form;530 531 switch ( abbrev->form)646 bfd_size_type amt; 647 648 attr->form = (enum dwarf_form) form; 649 650 switch (form) 532 651 { 533 652 case DW_FORM_addr: 653 /* FIXME: DWARF3 draft says DW_FORM_ref_addr is offset_size. */ 534 654 case DW_FORM_ref_addr: 535 655 DW_ADDR (attr) = read_address (unit, info_ptr); … … 537 657 break; 538 658 case DW_FORM_block2: 539 blk = (struct dwarf_block *) bfd_alloc (abfd, sizeof (struct dwarf_block)); 659 amt = sizeof (struct dwarf_block); 660 blk = (struct dwarf_block *) bfd_alloc (abfd, amt); 540 661 blk->size = read_2_bytes (abfd, info_ptr); 541 662 info_ptr += 2; … … 545 666 break; 546 667 case DW_FORM_block4: 547 blk = (struct dwarf_block *) bfd_alloc (abfd, sizeof (struct dwarf_block)); 668 amt = sizeof (struct dwarf_block); 669 blk = (struct dwarf_block *) bfd_alloc (abfd, amt); 548 670 blk->size = read_4_bytes (abfd, info_ptr); 549 671 info_ptr += 4; … … 568 690 info_ptr += bytes_read; 569 691 break; 692 case DW_FORM_strp: 693 DW_STRING (attr) = read_indirect_string (unit, info_ptr, &bytes_read); 694 info_ptr += bytes_read; 695 break; 570 696 case DW_FORM_block: 571 blk = (struct dwarf_block *) bfd_alloc (abfd, sizeof (struct dwarf_block)); 697 amt = sizeof (struct dwarf_block); 698 blk = (struct dwarf_block *) bfd_alloc (abfd, amt); 572 699 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); 573 700 info_ptr += bytes_read; … … 577 704 break; 578 705 case DW_FORM_block1: 579 blk = (struct dwarf_block *) bfd_alloc (abfd, sizeof (struct dwarf_block)); 706 amt = sizeof (struct dwarf_block); 707 blk = (struct dwarf_block *) bfd_alloc (abfd, amt); 580 708 blk->size = read_1_byte (abfd, info_ptr); 581 709 info_ptr += 1; … … 620 748 info_ptr += bytes_read; 621 749 break; 622 case DW_FORM_strp:623 750 case DW_FORM_indirect: 751 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); 752 info_ptr += bytes_read; 753 info_ptr = read_attribute_value (attr, form, unit, info_ptr); 754 break; 624 755 default: 625 (*_bfd_error_handler) (_("Dwarf Error: Invalid or unhandled FORM value: % d."),626 abbrev->form);756 (*_bfd_error_handler) (_("Dwarf Error: Invalid or unhandled FORM value: %u."), 757 form); 627 758 bfd_set_error (bfd_error_bad_value); 628 759 } 760 return info_ptr; 761 } 762 763 /* Read an attribute described by an abbreviated attribute. */ 764 765 static char * 766 read_attribute (attr, abbrev, unit, info_ptr) 767 struct attribute *attr; 768 struct attr_abbrev *abbrev; 769 struct comp_unit *unit; 770 char *info_ptr; 771 { 772 attr->name = abbrev->name; 773 info_ptr = read_attribute_value (attr, abbrev->form, unit, info_ptr); 629 774 return info_ptr; 630 775 } … … 661 806 char** dirs; 662 807 struct fileinfo* files; 663 struct line_info* last_line; 808 struct line_info* last_line; /* largest VMA */ 809 struct line_info* lcl_head; /* local head; used in 'add_line_info' */ 664 810 }; 811 812 struct funcinfo 813 { 814 struct funcinfo *prev_func; 815 char* name; 816 bfd_vma low; 817 bfd_vma high; 818 }; 819 820 /* Adds a new entry to the line_info list in the line_info_table, ensuring 821 that the list is sorted. Note that the line_info list is sorted from 822 highest to lowest VMA (with possible duplicates); that is, 823 line_info->prev_line always accesses an equal or smaller VMA. */ 665 824 666 825 static void … … 673 832 int end_sequence; 674 833 { 675 struct line_info* info = (struct line_info*) 676 bfd_alloc (table->abfd, sizeof (struct line_info)); 677 678 info->prev_line = table->last_line; 679 table->last_line = info; 680 834 bfd_size_type amt = sizeof (struct line_info); 835 struct line_info* info = (struct line_info*) bfd_alloc (table->abfd, amt); 836 837 /* Find the correct location for 'info'. Normally we will receive 838 new line_info data 1) in order and 2) with increasing VMAs. 839 However some compilers break the rules (cf. decode_line_info) and 840 so we include some heuristics for quickly finding the correct 841 location for 'info'. In particular, these heuristics optimize for 842 the common case in which the VMA sequence that we receive is a 843 list of locally sorted VMAs such as 844 p...z a...j (where a < j < p < z) 845 846 Note: table->lcl_head is used to head an *actual* or *possible* 847 sequence within the list (such as a...j) that is not directly 848 headed by table->last_line 849 850 Note: we may receive duplicate entries from 'decode_line_info'. */ 851 852 while (1) 853 if (!table->last_line 854 || address >= table->last_line->address) 855 { 856 /* Normal case: add 'info' to the beginning of the list */ 857 info->prev_line = table->last_line; 858 table->last_line = info; 859 860 /* lcl_head: initialize to head a *possible* sequence at the end. */ 861 if (!table->lcl_head) 862 table->lcl_head = info; 863 break; 864 } 865 else if (!table->lcl_head->prev_line 866 && table->lcl_head->address > address) 867 { 868 /* Abnormal but easy: lcl_head is 1) at the *end* of the line 869 list and 2) the head of 'info'. */ 870 info->prev_line = NULL; 871 table->lcl_head->prev_line = info; 872 break; 873 } 874 else if (table->lcl_head->prev_line 875 && table->lcl_head->address > address 876 && address >= table->lcl_head->prev_line->address) 877 { 878 /* Abnormal but easy: lcl_head is 1) in the *middle* of the line 879 list and 2) the head of 'info'. */ 880 info->prev_line = table->lcl_head->prev_line; 881 table->lcl_head->prev_line = info; 882 break; 883 } 884 else 885 { 886 /* Abnormal and hard: Neither 'last_line' nor 'lcl_head' are valid 887 heads for 'info'. Reset 'lcl_head' and repeat. */ 888 struct line_info* li2 = table->last_line; /* always non-NULL */ 889 struct line_info* li1 = li2->prev_line; 890 891 while (li1) 892 { 893 if (li2->address > address && address >= li1->address) 894 break; 895 896 li2 = li1; /* always non-NULL */ 897 li1 = li1->prev_line; 898 } 899 table->lcl_head = li2; 900 } 901 902 /* Set member data of 'info'. */ 681 903 info->address = address; 682 info->filename = filename;683 904 info->line = line; 684 905 info->column = column; 685 906 info->end_sequence = end_sequence; 686 } 907 908 amt = strlen (filename); 909 if (amt) 910 { 911 info->filename = bfd_alloc (table->abfd, amt + 1); 912 if (info->filename) 913 strcpy (info->filename, filename); 914 } 915 else 916 info->filename = NULL; 917 } 918 919 /* Extract a fully qualified filename from a line info table. 920 The returned string has been malloc'ed and it is the caller's 921 responsibility to free it. */ 687 922 688 923 static char * … … 697 932 (*_bfd_error_handler) 698 933 (_("Dwarf Error: mangled line number section (bad file number).")); 699 return "<unknown>";934 return strdup ("<unknown>"); 700 935 } 701 936 702 937 filename = table->files[file - 1].name; 703 if (IS_ABSOLUTE_PATH(filename)) 704 return filename; 705 706 else 938 939 if (! IS_ABSOLUTE_PATH (filename)) 707 940 { 708 941 char* dirname = (table->files[file - 1].dir 709 942 ? table->dirs[table->files[file - 1].dir - 1] 710 943 : table->comp_dir); 711 return (char*) concat (dirname, "/", filename, NULL); 712 } 944 945 /* Not all tools set DW_AT_comp_dir, so dirname may be unknown. 946 The best we can do is return the filename part. */ 947 if (dirname != NULL) 948 { 949 unsigned int len = strlen (dirname) + strlen (filename) + 2; 950 char * name; 951 952 name = bfd_malloc (len); 953 if (name) 954 sprintf (name, "%s/%s", dirname, filename); 955 return name; 956 } 957 } 958 959 return strdup (filename); 713 960 } 714 961 … … 750 997 751 998 /* Need to allocate a new arange and insert it into the arange list. */ 752 arange = bfd_zalloc (unit->abfd, sizeof (*arange)); 999 arange = (struct arange *) 1000 bfd_zalloc (unit->abfd, (bfd_size_type) sizeof (*arange)); 753 1001 arange->low = low_pc; 754 1002 arange->high = high_pc; … … 770 1018 char *line_end; 771 1019 struct line_head lh; 772 unsigned int i, bytes_read ;1020 unsigned int i, bytes_read, offset_size; 773 1021 char *cur_file, *cur_dir; 774 1022 unsigned char op_code, extended_op, adj_opcode; 1023 bfd_size_type amt; 775 1024 776 1025 if (! stash->dwarf_line_buffer) … … 787 1036 788 1037 stash->dwarf_line_size = msec->_raw_size; 789 stash->dwarf_line_buffer = (char *) bfd_alloc (abfd, stash->dwarf_line_size); 1038 stash->dwarf_line_buffer 1039 = bfd_simple_get_relocated_section_contents (abfd, msec, NULL, 1040 stash->syms); 790 1041 if (! stash->dwarf_line_buffer) 791 1042 return 0; 792 793 if (! bfd_get_section_contents (abfd, msec, 794 stash->dwarf_line_buffer, 0, 795 stash->dwarf_line_size)) 796 return 0; 797 798 /* FIXME: We ought to apply the relocs against this section before 799 we process it... */ 800 } 801 802 /* Since we are using un-relocated data, it is possible to get a bad value 803 for the line_offset. Validate it here so that we won't get a segfault 804 below. */ 1043 } 1044 1045 /* It is possible to get a bad value for the line_offset. Validate 1046 it here so that we won't get a segfault below. */ 805 1047 if (unit->line_offset >= stash->dwarf_line_size) 806 1048 { 807 (*_bfd_error_handler) (_("Dwarf Error: Line offset (% u) greater than or equal to line size (%u)."),1049 (*_bfd_error_handler) (_("Dwarf Error: Line offset (%lu) greater than or equal to .debug_line size (%lu)."), 808 1050 unit->line_offset, stash->dwarf_line_size); 809 1051 bfd_set_error (bfd_error_bad_value); … … 811 1053 } 812 1054 813 table = (struct line_info_table*) bfd_alloc (abfd,814 sizeof (struct line_info_table));1055 amt = sizeof (struct line_info_table); 1056 table = (struct line_info_table*) bfd_alloc (abfd, amt); 815 1057 table->abfd = abfd; 816 1058 table->comp_dir = unit->comp_dir; … … 824 1066 table->files = NULL; 825 1067 table->last_line = NULL; 1068 table->lcl_head = NULL; 826 1069 827 1070 line_ptr = stash->dwarf_line_buffer + unit->line_offset; … … 830 1073 lh.total_length = read_4_bytes (abfd, line_ptr); 831 1074 line_ptr += 4; 1075 offset_size = 4; 1076 if (lh.total_length == 0xffffffff) 1077 { 1078 lh.total_length = read_8_bytes (abfd, line_ptr); 1079 line_ptr += 8; 1080 offset_size = 8; 1081 } 1082 else if (lh.total_length == 0 && unit->addr_size == 8) 1083 { 1084 /* Handle (non-standard) 64-bit DWARF2 formats. */ 1085 lh.total_length = read_4_bytes (abfd, line_ptr); 1086 line_ptr += 4; 1087 offset_size = 8; 1088 } 832 1089 line_end = line_ptr + lh.total_length; 833 1090 lh.version = read_2_bytes (abfd, line_ptr); 834 1091 line_ptr += 2; 835 lh.prologue_length = read_4_bytes (abfd, line_ptr); 836 line_ptr += 4; 1092 if (offset_size == 4) 1093 lh.prologue_length = read_4_bytes (abfd, line_ptr); 1094 else 1095 lh.prologue_length = read_8_bytes (abfd, line_ptr); 1096 line_ptr += offset_size; 837 1097 lh.minimum_instruction_length = read_1_byte (abfd, line_ptr); 838 1098 line_ptr += 1; … … 845 1105 lh.opcode_base = read_1_byte (abfd, line_ptr); 846 1106 line_ptr += 1; 847 lh.standard_opcode_lengths = (unsigned char *)848 bfd_alloc (abfd, lh.opcode_base * sizeof (unsigned char));1107 amt = lh.opcode_base * sizeof (unsigned char); 1108 lh.standard_opcode_lengths = (unsigned char *) bfd_alloc (abfd, amt); 849 1109 850 1110 lh.standard_opcode_lengths[0] = 1; … … 863 1123 if ((table->num_dirs % DIR_ALLOC_CHUNK) == 0) 864 1124 { 865 table->dirs = (char **)866 bfd_realloc (table->dirs,867 (table->num_dirs + DIR_ALLOC_CHUNK) * sizeof (char *));1125 amt = table->num_dirs + DIR_ALLOC_CHUNK; 1126 amt *= sizeof (char *); 1127 table->dirs = (char **) bfd_realloc (table->dirs, amt); 868 1128 if (! table->dirs) 869 1129 return 0; … … 882 1142 if ((table->num_files % FILE_ALLOC_CHUNK) == 0) 883 1143 { 884 table->files = (struct fileinfo *) 885 bfd_realloc (table->files, 886 (table->num_files + FILE_ALLOC_CHUNK) 887 * sizeof (struct fileinfo)); 1144 amt = table->num_files + FILE_ALLOC_CHUNK; 1145 amt *= sizeof (struct fileinfo); 1146 table->files = (struct fileinfo *) bfd_realloc (table->files, amt); 888 1147 if (! table->files) 889 1148 return 0; … … 910 1169 /* State machine registers. */ 911 1170 bfd_vma address = 0; 912 char * filename = concat_filename (table, 1);1171 char * filename = concat_filename (table, 1); 913 1172 unsigned int line = 1; 914 1173 unsigned int column = 0; 915 1174 int is_stmt = lh.default_is_stmt; 916 1175 int basic_block = 0; 917 int end_sequence = 0, need_low_pc = 1; 918 bfd_vma low_pc = 0; 1176 int end_sequence = 0; 1177 /* eraxxon@alumni.rice.edu: Against the DWARF2 specs, some 1178 compilers generate address sequences that are wildly out of 1179 order using DW_LNE_set_address (e.g. Intel C++ 6.0 compiler 1180 for ia64-Linux). Thus, to determine the low and high 1181 address, we must compare on every DW_LNS_copy, etc. */ 1182 bfd_vma low_pc = 0; 1183 bfd_vma high_pc = 0; 919 1184 920 1185 /* Decode the table. */ … … 924 1189 line_ptr += 1; 925 1190 926 switch (op_code) 1191 if (op_code >= lh.opcode_base) 1192 { 1193 /* Special operand. */ 1194 adj_opcode = op_code - lh.opcode_base; 1195 address += (adj_opcode / lh.line_range) 1196 * lh.minimum_instruction_length; 1197 line += lh.line_base + (adj_opcode % lh.line_range); 1198 /* Append row to matrix using current values. */ 1199 add_line_info (table, address, filename, line, column, 0); 1200 basic_block = 1; 1201 if (low_pc == 0 || address < low_pc) 1202 low_pc = address; 1203 if (address > high_pc) 1204 high_pc = address; 1205 } 1206 else switch (op_code) 927 1207 { 928 1208 case DW_LNS_extended_op: 929 line_ptr += 1; /* Ignore length. */ 1209 /* Ignore length. */ 1210 line_ptr += 1; 930 1211 extended_op = read_1_byte (abfd, line_ptr); 931 1212 line_ptr += 1; 1213 932 1214 switch (extended_op) 933 1215 { … … 936 1218 add_line_info (table, address, filename, line, column, 937 1219 end_sequence); 938 if (need_low_pc) 939 { 940 need_low_pc = 0; 941 low_pc = address; 942 } 943 arange_add (unit, low_pc, address); 1220 if (low_pc == 0 || address < low_pc) 1221 low_pc = address; 1222 if (address > high_pc) 1223 high_pc = address; 1224 arange_add (unit, low_pc, high_pc); 944 1225 break; 945 1226 case DW_LNE_set_address: … … 952 1233 if ((table->num_files % FILE_ALLOC_CHUNK) == 0) 953 1234 { 954 table->files = (struct fileinfo *)955 bfd_realloc (table->files,956 (table->num_files + FILE_ALLOC_CHUNK)957 * sizeof (struct fileinfo));1235 amt = table->num_files + FILE_ALLOC_CHUNK; 1236 amt *= sizeof (struct fileinfo); 1237 table->files = 1238 (struct fileinfo *) bfd_realloc (table->files, amt); 958 1239 if (! table->files) 959 1240 return 0; … … 980 1261 add_line_info (table, address, filename, line, column, 0); 981 1262 basic_block = 0; 982 if (need_low_pc) 983 { 984 need_low_pc = 0; 985 low_pc = address; 986 } 1263 if (low_pc == 0 || address < low_pc) 1264 low_pc = address; 1265 if (address > high_pc) 1266 high_pc = address; 987 1267 break; 988 1268 case DW_LNS_advance_pc: … … 999 1279 unsigned int file; 1000 1280 1001 /* The file and directory tables are 0 based, the references1002 are 1 based. */1281 /* The file and directory tables are 0 1282 based, the references are 1 based. */ 1003 1283 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 1004 1284 line_ptr += bytes_read; 1285 if (filename) 1286 free (filename); 1005 1287 filename = concat_filename (table, file); 1006 1288 break; … … 1024 1306 line_ptr += 2; 1025 1307 break; 1026 default: /* Special operand. */ 1027 adj_opcode = op_code - lh.opcode_base; 1028 address += (adj_opcode / lh.line_range) 1029 * lh.minimum_instruction_length; 1030 line += lh.line_base + (adj_opcode % lh.line_range); 1031 /* Append row to matrix using current values. */ 1032 add_line_info (table, address, filename, line, column, 0); 1033 basic_block = 1; 1034 if (need_low_pc) 1035 { 1036 need_low_pc = 0; 1037 low_pc = address; 1038 } 1308 default: 1309 { 1310 int i; 1311 1312 /* Unknown standard opcode, ignore it. */ 1313 for (i = 0; i < lh.standard_opcode_lengths[op_code]; i++) 1314 { 1315 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); 1316 line_ptr += bytes_read; 1317 } 1318 } 1039 1319 } 1040 1320 } 1321 1322 if (filename) 1323 free (filename); 1041 1324 } 1042 1325 … … 1044 1327 } 1045 1328 1046 /* If ADDR is within TABLE set the output parameters and return true,1047 otherwise return false. The output parameters, FILENAME_PTR and1329 /* If ADDR is within TABLE set the output parameters and return TRUE, 1330 otherwise return FALSE. The output parameters, FILENAME_PTR and 1048 1331 LINENUMBER_PTR, are pointers to the objects to be filled in. */ 1049 1332 1050 static boolean 1051 lookup_address_in_line_info_table (table, 1052 addr, 1053 filename_ptr, 1333 static bfd_boolean 1334 lookup_address_in_line_info_table (table, addr, function, filename_ptr, 1054 1335 linenumber_ptr) 1055 1336 struct line_info_table* table; 1056 1337 bfd_vma addr; 1338 struct funcinfo *function; 1057 1339 const char **filename_ptr; 1058 1340 unsigned int *linenumber_ptr; 1059 1341 { 1342 /* Note: table->last_line should be a descendingly sorted list. */ 1060 1343 struct line_info* next_line = table->last_line; 1061 struct line_info* each_line; 1344 struct line_info* each_line = NULL; 1345 *filename_ptr = NULL; 1062 1346 1063 1347 if (!next_line) 1064 return false;1348 return FALSE; 1065 1349 1066 1350 each_line = next_line->prev_line; 1067 1351 1352 /* Check for large addresses */ 1353 if (addr > next_line->address) 1354 each_line = NULL; /* ensure we skip over the normal case */ 1355 1356 /* Normal case: search the list; save */ 1068 1357 while (each_line && next_line) 1069 1358 { 1070 if (!each_line->end_sequence 1071 && addr >= each_line->address && addr < next_line->address) 1072 { 1073 *filename_ptr = each_line->filename; 1074 *linenumber_ptr = each_line->line; 1075 return true; 1076 } 1359 /* If we have an address match, save this info. This allows us 1360 to return as good as results as possible for strange debugging 1361 info. */ 1362 bfd_boolean addr_match = FALSE; 1363 if (each_line->address <= addr && addr <= next_line->address) 1364 { 1365 addr_match = TRUE; 1366 1367 /* If this line appears to span functions, and addr is in the 1368 later function, return the first line of that function instead 1369 of the last line of the earlier one. This check is for GCC 1370 2.95, which emits the first line number for a function late. */ 1371 if (function != NULL 1372 && each_line->address < function->low 1373 && next_line->address > function->low) 1374 { 1375 *filename_ptr = next_line->filename; 1376 *linenumber_ptr = next_line->line; 1377 } 1378 else 1379 { 1380 *filename_ptr = each_line->filename; 1381 *linenumber_ptr = each_line->line; 1382 } 1383 } 1384 1385 if (addr_match && !each_line->end_sequence) 1386 return TRUE; /* we have definitely found what we want */ 1387 1077 1388 next_line = each_line; 1078 1389 each_line = each_line->prev_line; 1079 1390 } 1080 1391 1081 return false; 1392 /* At this point each_line is NULL but next_line is not. If we found 1393 a candidate end-of-sequence point in the loop above, we can return 1394 that (compatibility with a bug in the Intel compiler); otherwise, 1395 assuming that we found the containing function for this address in 1396 this compilation unit, return the first line we have a number for 1397 (compatibility with GCC 2.95). */ 1398 if (*filename_ptr == NULL && function != NULL) 1399 { 1400 *filename_ptr = next_line->filename; 1401 *linenumber_ptr = next_line->line; 1402 return TRUE; 1403 } 1404 1405 return FALSE; 1082 1406 } 1083 1407 1084 1408 /* Function table functions. */ 1085 1409 1086 struct funcinfo 1087 { 1088 struct funcinfo *prev_func; 1089 char* name; 1090 bfd_vma low; 1091 bfd_vma high; 1092 }; 1093 1094 /* If ADDR is within TABLE, set FUNCTIONNAME_PTR, and return true. */ 1095 1096 static boolean 1097 lookup_address_in_function_table (table, 1098 addr, 1410 /* If ADDR is within TABLE, set FUNCTIONNAME_PTR, and return TRUE. */ 1411 1412 static bfd_boolean 1413 lookup_address_in_function_table (table, addr, function_ptr, 1099 1414 functionname_ptr) 1100 1415 struct funcinfo* table; 1101 1416 bfd_vma addr; 1417 struct funcinfo** function_ptr; 1102 1418 const char **functionname_ptr; 1103 1419 { … … 1111 1427 { 1112 1428 *functionname_ptr = each_func->name; 1113 return true; 1114 } 1115 } 1116 1117 return false; 1429 *function_ptr = each_func; 1430 return TRUE; 1431 } 1432 } 1433 1434 return FALSE; 1118 1435 } 1119 1436 … … 1123 1440 to the function table. */ 1124 1441 1125 static b oolean1442 static bfd_boolean 1126 1443 scan_unit_for_functions (unit) 1127 1444 struct comp_unit *unit; … … 1151 1468 if (! abbrev) 1152 1469 { 1153 (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number % d."),1470 (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %u."), 1154 1471 abbrev_number); 1155 1472 bfd_set_error (bfd_error_bad_value); 1156 return false;1473 return FALSE; 1157 1474 } 1158 1475 1159 1476 if (abbrev->tag == DW_TAG_subprogram) 1160 1477 { 1161 func = (struct funcinfo*) bfd_zalloc (abfd, sizeof (struct funcinfo)); 1478 bfd_size_type amt = sizeof (struct funcinfo); 1479 func = (struct funcinfo *) bfd_zalloc (abfd, amt); 1162 1480 func->prev_func = unit->function_table; 1163 1481 unit->function_table = func; … … 1217 1535 } 1218 1536 1219 return true;1537 return TRUE; 1220 1538 } 1221 1539 … … 1224 1542 does not include the length field that preceeds each compilation 1225 1543 unit header. END_PTR points one past the end of this comp unit. 1226 If ABBREV_LENGTH is 0, then the length of the abbreviation offset 1227 is assumed to be four bytes. Otherwise, it it is the size given. 1544 OFFSET_SIZE is the size of DWARF2 offsets (either 4 or 8 bytes). 1228 1545 1229 1546 This routine does not read the whole compilation unit; only enough … … 1231 1548 1232 1549 static struct comp_unit * 1233 parse_comp_unit (abfd, stash, unit_length, abbrev_length)1550 parse_comp_unit (abfd, stash, unit_length, offset_size) 1234 1551 bfd* abfd; 1235 1552 struct dwarf2_debug *stash; 1236 1553 bfd_vma unit_length; 1237 unsigned int abbrev_length;1554 unsigned int offset_size; 1238 1555 { 1239 1556 struct comp_unit* unit; 1240 1241 unsigned short version; 1242 unsigned int abbrev_offset = 0; 1243 unsigned char addr_size; 1557 unsigned int version; 1558 bfd_vma abbrev_offset = 0; 1559 unsigned int addr_size; 1244 1560 struct abbrev_info** abbrevs; 1245 1246 1561 unsigned int abbrev_number, bytes_read, i; 1247 1562 struct abbrev_info *abbrev; 1248 1563 struct attribute attr; 1249 1250 1564 char *info_ptr = stash->info_ptr; 1251 1565 char *end_ptr = info_ptr + unit_length; 1566 bfd_size_type amt; 1252 1567 1253 1568 version = read_2_bytes (abfd, info_ptr); 1254 1569 info_ptr += 2; 1255 BFD_ASSERT (abbrev_length == 0 1256 || abbrev_length == 4 1257 || abbrev_length == 8); 1258 if (abbrev_length == 0 || abbrev_length == 4) 1570 BFD_ASSERT (offset_size == 4 || offset_size == 8); 1571 if (offset_size == 4) 1259 1572 abbrev_offset = read_4_bytes (abfd, info_ptr); 1260 else if (abbrev_length == 8)1573 else 1261 1574 abbrev_offset = read_8_bytes (abfd, info_ptr); 1262 info_ptr += abbrev_length;1575 info_ptr += offset_size; 1263 1576 addr_size = read_1_byte (abfd, info_ptr); 1264 1577 info_ptr += 1; … … 1266 1579 if (version != 2) 1267 1580 { 1268 (*_bfd_error_handler) (_("Dwarf Error: found dwarf version '% hu', this reader only handles version 2 information."), version);1581 (*_bfd_error_handler) (_("Dwarf Error: found dwarf version '%u', this reader only handles version 2 information."), version); 1269 1582 bfd_set_error (bfd_error_bad_value); 1270 1583 return 0; … … 1275 1588 (*_bfd_error_handler) (_("Dwarf Error: found address size '%u', this reader can not handle sizes greater than '%u'."), 1276 1589 addr_size, 1277 sizeof (bfd_vma));1590 (unsigned int) sizeof (bfd_vma)); 1278 1591 bfd_set_error (bfd_error_bad_value); 1279 1592 return 0; … … 1282 1595 if (addr_size != 2 && addr_size != 4 && addr_size != 8) 1283 1596 { 1284 (*_bfd_error_handler) ("Dwarf Error: found address size '%u', this reader can only handle address sizes '2', '4' and '8'.", addr_size 1597 (*_bfd_error_handler) ("Dwarf Error: found address size '%u', this reader can only handle address sizes '2', '4' and '8'.", addr_size); 1285 1598 bfd_set_error (bfd_error_bad_value); 1286 1599 return 0; … … 1296 1609 if (! abbrev_number) 1297 1610 { 1298 (*_bfd_error_handler) (_("Dwarf Error: Bad abbrev number: % d."),1611 (*_bfd_error_handler) (_("Dwarf Error: Bad abbrev number: %u."), 1299 1612 abbrev_number); 1300 1613 bfd_set_error (bfd_error_bad_value); … … 1305 1618 if (! abbrev) 1306 1619 { 1307 (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number % d."),1620 (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %u."), 1308 1621 abbrev_number); 1309 1622 bfd_set_error (bfd_error_bad_value); … … 1311 1624 } 1312 1625 1313 unit = (struct comp_unit*) bfd_zalloc (abfd, sizeof (struct comp_unit)); 1626 amt = sizeof (struct comp_unit); 1627 unit = (struct comp_unit*) bfd_zalloc (abfd, amt); 1314 1628 unit->abfd = abfd; 1315 1629 unit->addr_size = addr_size; 1630 unit->offset_size = offset_size; 1316 1631 unit->abbrevs = abbrevs; 1317 1632 unit->end_ptr = end_ptr; 1633 unit->stash = stash; 1318 1634 1319 1635 for (i = 0; i < abbrev->num_attrs; ++i) … … 1367 1683 } 1368 1684 1369 /* Return trueif UNIT contains the address given by ADDR. */1370 1371 static b oolean1685 /* Return TRUE if UNIT contains the address given by ADDR. */ 1686 1687 static bfd_boolean 1372 1688 comp_unit_contains_address (unit, addr) 1373 1689 struct comp_unit* unit; … … 1377 1693 1378 1694 if (unit->error) 1379 return 0;1695 return FALSE; 1380 1696 1381 1697 arange = &unit->arange; … … 1383 1699 { 1384 1700 if (addr >= arange->low && addr < arange->high) 1385 return 1;1701 return TRUE; 1386 1702 arange = arange->next; 1387 1703 } 1388 1704 while (arange); 1389 1705 1390 return 0;1706 return FALSE; 1391 1707 } 1392 1708 … … 1396 1712 to be filled in. 1397 1713 1398 Return true of UNIT contains ADDR, and no errors were encountered; 1399 false otherwise. */ 1400 1401 static boolean 1402 comp_unit_find_nearest_line (unit, addr, 1403 filename_ptr, functionname_ptr, linenumber_ptr, 1404 stash) 1714 Return TRUE if UNIT contains ADDR, and no errors were encountered; 1715 FALSE otherwise. */ 1716 1717 static bfd_boolean 1718 comp_unit_find_nearest_line (unit, addr, filename_ptr, functionname_ptr, 1719 linenumber_ptr, stash) 1405 1720 struct comp_unit* unit; 1406 1721 bfd_vma addr; … … 1410 1725 struct dwarf2_debug *stash; 1411 1726 { 1412 boolean line_p; 1413 boolean func_p; 1727 bfd_boolean line_p; 1728 bfd_boolean func_p; 1729 struct funcinfo *function; 1414 1730 1415 1731 if (unit->error) 1416 return false;1732 return FALSE; 1417 1733 1418 1734 if (! unit->line_table) … … 1421 1737 { 1422 1738 unit->error = 1; 1423 return false;1739 return FALSE; 1424 1740 } 1425 1741 … … 1429 1745 { 1430 1746 unit->error = 1; 1431 return false; 1432 } 1433 1434 if (! scan_unit_for_functions (unit)) 1747 return FALSE; 1748 } 1749 1750 if (unit->first_child_die_ptr < unit->end_ptr 1751 && ! scan_unit_for_functions (unit)) 1435 1752 { 1436 1753 unit->error = 1; 1437 return false; 1438 } 1439 } 1440 1441 line_p = lookup_address_in_line_info_table (unit->line_table, 1442 addr, 1443 filename_ptr, 1754 return FALSE; 1755 } 1756 } 1757 1758 function = NULL; 1759 func_p = lookup_address_in_function_table (unit->function_table, addr, 1760 &function, functionname_ptr); 1761 line_p = lookup_address_in_line_info_table (unit->line_table, addr, 1762 function, filename_ptr, 1444 1763 linenumber_ptr); 1445 func_p = lookup_address_in_function_table (unit->function_table,1446 addr,1447 functionname_ptr);1448 1764 return line_p || func_p; 1449 1765 } 1450 1766 1451 /* Locate a section in a BFD containing debugging info. The search starts from the 1452 section after AFTER_SEC, or from the first section in the BFD if AFTER_SEC is 1453 NULL. The search works by examining the names of the sections. There are two 1454 permissiable names. The first is .debug_info. This is the standard DWARF2 name. 1455 The second is a prefix .gnu.linkonce.wi. This is a variation on the .debug_info 1456 section which has a checksum describing the contents appended onto the name. This 1457 allows the linker to identify and discard duplicate debugging sections for 1458 different compilation units. */ 1767 /* Locate a section in a BFD containing debugging info. The search starts 1768 from the section after AFTER_SEC, or from the first section in the BFD if 1769 AFTER_SEC is NULL. The search works by examining the names of the 1770 sections. There are two permissiable names. The first is .debug_info. 1771 This is the standard DWARF2 name. The second is a prefix .gnu.linkonce.wi. 1772 This is a variation on the .debug_info section which has a checksum 1773 describing the contents appended onto the name. This allows the linker to 1774 identify and discard duplicate debugging sections for different 1775 compilation units. */ 1459 1776 #define DWARF2_DEBUG_INFO ".debug_info" 1460 1777 #define GNU_LINKONCE_INFO ".gnu.linkonce.wi." … … 1486 1803 } 1487 1804 1488 /* The DWARF2 version of find_nearest line. Return trueif the line1805 /* The DWARF2 version of find_nearest line. Return TRUE if the line 1489 1806 is found without error. ADDR_SIZE is the number of bytes in the 1490 1807 initial .debug_info length field and in the abbreviation offset. … … 1492 1809 used. */ 1493 1810 1494 b oolean1811 bfd_boolean 1495 1812 _bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset, 1496 1813 filename_ptr, functionname_ptr, 1497 linenumber_ptr, 1498 addr_size, pinfo) 1814 linenumber_ptr, addr_size, pinfo) 1499 1815 bfd *abfd; 1500 1816 asection *section; 1501 asymbol **symbols ATTRIBUTE_UNUSED;1817 asymbol **symbols; 1502 1818 bfd_vma offset; 1503 1819 const char **filename_ptr; … … 1535 1851 if (! stash) 1536 1852 { 1537 unsigned longtotal_size;1853 bfd_size_type total_size; 1538 1854 asection *msec; 1539 1540 stash = 1541 (struct dwarf2_debug*) bfd_zalloc (abfd, sizeof (struct dwarf2_debug));1855 bfd_size_type amt = sizeof (struct dwarf2_debug); 1856 1857 stash = (struct dwarf2_debug*) bfd_zalloc (abfd, amt); 1542 1858 if (! stash) 1543 return false;1859 return FALSE; 1544 1860 1545 1861 *pinfo = (PTR) stash; … … 1550 1866 has been allocated, but contains zeros, this lets 1551 1867 future calls to this function fail quicker. */ 1552 return false;1868 return FALSE; 1553 1869 1554 1870 /* There can be more than one DWARF2 info section in a BFD these days. 1555 1871 Read them all in and produce one large stash. We do this in two 1556 1872 passes - in the first pass we just accumulate the section sizes. 1557 1873 In the second pass we read in the section's contents. The allows … … 1562 1878 stash->info_ptr = (char *) bfd_alloc (abfd, total_size); 1563 1879 if (stash->info_ptr == NULL) 1564 return false;1880 return FALSE; 1565 1881 1566 1882 stash->info_ptr_end = stash->info_ptr; … … 1570 1886 msec = find_debug_info (abfd, msec)) 1571 1887 { 1572 unsigned longsize;1573 unsigned longstart;1888 bfd_size_type size; 1889 bfd_size_type start; 1574 1890 1575 1891 size = msec->_raw_size; … … 1579 1895 start = stash->info_ptr_end - stash->info_ptr; 1580 1896 1581 if (! bfd_get_section_contents (abfd, msec, stash->info_ptr + start, 0, size)) 1897 if ((bfd_simple_get_relocated_section_contents 1898 (abfd, msec, stash->info_ptr + start, symbols)) == NULL) 1582 1899 continue; 1583 1900 … … 1585 1902 } 1586 1903 1587 BFD_ASSERT (stash->info_ptr_end = stash->info_ptr + total_size); 1588 } 1589 1590 /* FIXME: There is a problem with the contents of the 1591 .debug_info section. The 'low' and 'high' addresses of the 1592 comp_units are computed by relocs against symbols in the 1593 .text segment. We need these addresses in order to determine 1594 the nearest line number, and so we have to resolve the 1595 relocs. There is a similar problem when the .debug_line 1596 section is processed as well (e.g., there may be relocs 1597 against the operand of the DW_LNE_set_address operator). 1598 1599 Unfortunately getting hold of the reloc information is hard... 1600 1601 For now, this means that disassembling object files (as 1602 opposed to fully executables) does not always work as well as 1603 we would like. */ 1904 BFD_ASSERT (stash->info_ptr_end == stash->info_ptr + total_size); 1905 1906 stash->sec = find_debug_info (abfd, NULL); 1907 stash->sec_info_ptr = stash->info_ptr; 1908 stash->syms = symbols; 1909 } 1604 1910 1605 1911 /* A null info_ptr indicates that there is no dwarf2 info 1606 1912 (or that an error occured while setting up the stash). */ 1607 1913 if (! stash->info_ptr) 1608 return false;1914 return FALSE; 1609 1915 1610 1916 /* Check the previously read comp. units first. */ … … 1618 1924 while (stash->info_ptr < stash->info_ptr_end) 1619 1925 { 1620 struct comp_unit* each;1621 1926 bfd_vma length; 1622 boolean found; 1623 1624 if (addr_size == 4) 1625 length = read_4_bytes (abfd, stash->info_ptr); 1927 bfd_boolean found; 1928 unsigned int offset_size = addr_size; 1929 1930 length = read_4_bytes (abfd, stash->info_ptr); 1931 /* A 0xffffff length is the DWARF3 way of indicating we use 1932 64-bit offsets, instead of 32-bit offsets. */ 1933 if (length == 0xffffffff) 1934 { 1935 offset_size = 8; 1936 length = read_8_bytes (abfd, stash->info_ptr + 4); 1937 stash->info_ptr += 12; 1938 } 1939 /* A zero length is the IRIX way of indicating 64-bit offsets, 1940 mostly because the 64-bit length will generally fit in 32 1941 bits, and the endianness helps. */ 1942 else if (length == 0) 1943 { 1944 offset_size = 8; 1945 length = read_4_bytes (abfd, stash->info_ptr + 4); 1946 stash->info_ptr += 8; 1947 } 1948 /* In the absence of the hints above, we assume addr_size-sized 1949 offsets, for backward-compatibility with pre-DWARF3 64-bit 1950 platforms. */ 1951 else if (addr_size == 8) 1952 { 1953 length = read_8_bytes (abfd, stash->info_ptr); 1954 stash->info_ptr += 8; 1955 } 1626 1956 else 1627 length = read_8_bytes (abfd, stash->info_ptr); 1628 stash->info_ptr += addr_size; 1957 stash->info_ptr += 4; 1629 1958 1630 1959 if (length > 0) 1631 1632 each = parse_comp_unit (abfd, stash, length, addr_size);1960 { 1961 each = parse_comp_unit (abfd, stash, length, offset_size); 1633 1962 stash->info_ptr += length; 1963 1964 if ((bfd_vma) (stash->info_ptr - stash->sec_info_ptr) 1965 == stash->sec->_raw_size) 1966 { 1967 stash->sec = find_debug_info (abfd, stash->sec); 1968 stash->sec_info_ptr = stash->info_ptr; 1969 } 1634 1970 1635 1971 if (each) … … 1647 1983 if (comp_unit_contains_address (each, addr)) 1648 1984 return comp_unit_find_nearest_line (each, addr, 1649 1650 1651 1652 1985 filename_ptr, 1986 functionname_ptr, 1987 linenumber_ptr, 1988 stash); 1653 1989 } 1654 1990 else … … 1660 1996 stash); 1661 1997 if (found) 1662 return true;1998 return TRUE; 1663 1999 } 1664 2000 } … … 1666 2002 } 1667 2003 1668 return false;1669 } 2004 return FALSE; 2005 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.