00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "bfd.h"
00037 #include "sysdep.h"
00038 #include "libiberty.h"
00039 #include "libbfd.h"
00040 #include "elf-bfd.h"
00041 #include "elf/dwarf2.h"
00042
00043
00044
00045 struct line_head
00046 {
00047 bfd_vma total_length;
00048 unsigned short version;
00049 bfd_vma prologue_length;
00050 unsigned char minimum_instruction_length;
00051 unsigned char default_is_stmt;
00052 int line_base;
00053 unsigned char line_range;
00054 unsigned char opcode_base;
00055 unsigned char *standard_opcode_lengths;
00056 };
00057
00058
00059
00060 struct attribute
00061 {
00062 enum dwarf_attribute name;
00063 enum dwarf_form form;
00064 union
00065 {
00066 char *str;
00067 struct dwarf_block *blk;
00068 bfd_uint64_t val;
00069 bfd_int64_t sval;
00070 }
00071 u;
00072 };
00073
00074
00075 struct dwarf_block
00076 {
00077 unsigned int size;
00078 bfd_byte *data;
00079 };
00080
00081 struct dwarf2_debug
00082 {
00083
00084 struct comp_unit *all_comp_units;
00085
00086
00087
00088
00089 bfd_byte *info_ptr;
00090
00091
00092 bfd_byte *info_ptr_end;
00093
00094
00095
00096 asection *sec;
00097 bfd_byte *sec_info_ptr;
00098
00099
00100 asymbol **syms;
00101
00102
00103 bfd_byte *dwarf_abbrev_buffer;
00104
00105
00106 unsigned long dwarf_abbrev_size;
00107
00108
00109 bfd_byte *dwarf_line_buffer;
00110
00111
00112 unsigned long dwarf_line_size;
00113
00114
00115 bfd_byte *dwarf_str_buffer;
00116
00117
00118 unsigned long dwarf_str_size;
00119 };
00120
00121 struct arange
00122 {
00123 struct arange *next;
00124 bfd_vma low;
00125 bfd_vma high;
00126 };
00127
00128
00129
00130
00131 struct comp_unit
00132 {
00133
00134 struct comp_unit *next_unit;
00135
00136
00137 bfd *abfd;
00138
00139
00140
00141 struct arange arange;
00142
00143
00144 char *name;
00145
00146
00147 struct abbrev_info **abbrevs;
00148
00149
00150 int error;
00151
00152
00153 char *comp_dir;
00154
00155
00156 int stmtlist;
00157
00158
00159
00160 bfd_byte *info_ptr_unit;
00161
00162
00163 unsigned long line_offset;
00164
00165
00166 bfd_byte *first_child_die_ptr;
00167
00168
00169 bfd_byte *end_ptr;
00170
00171
00172 struct line_info_table *line_table;
00173
00174
00175 struct funcinfo *function_table;
00176
00177
00178 struct dwarf2_debug *stash;
00179
00180
00181 unsigned char addr_size;
00182
00183
00184 unsigned char offset_size;
00185 };
00186
00187
00188 struct abbrev_info
00189 {
00190 unsigned int number;
00191 enum dwarf_tag tag;
00192 int has_children;
00193 unsigned int num_attrs;
00194 struct attr_abbrev *attrs;
00195 struct abbrev_info *next;
00196 };
00197
00198 struct attr_abbrev
00199 {
00200 enum dwarf_attribute name;
00201 enum dwarf_form form;
00202 };
00203
00204 #ifndef ABBREV_HASH_SIZE
00205 #define ABBREV_HASH_SIZE 121
00206 #endif
00207 #ifndef ATTR_ALLOC_CHUNK
00208 #define ATTR_ALLOC_CHUNK 4
00209 #endif
00210
00211
00212
00213
00214
00215
00216
00217 static unsigned int
00218 read_1_byte (bfd *abfd ATTRIBUTE_UNUSED, bfd_byte *buf)
00219 {
00220 return bfd_get_8 (abfd, buf);
00221 }
00222
00223 static int
00224 read_1_signed_byte (bfd *abfd ATTRIBUTE_UNUSED, bfd_byte *buf)
00225 {
00226 return bfd_get_signed_8 (abfd, buf);
00227 }
00228
00229 static unsigned int
00230 read_2_bytes (bfd *abfd, bfd_byte *buf)
00231 {
00232 return bfd_get_16 (abfd, buf);
00233 }
00234
00235 static unsigned int
00236 read_4_bytes (bfd *abfd, bfd_byte *buf)
00237 {
00238 return bfd_get_32 (abfd, buf);
00239 }
00240
00241 static bfd_uint64_t
00242 read_8_bytes (bfd *abfd, bfd_byte *buf)
00243 {
00244 return bfd_get_64 (abfd, buf);
00245 }
00246
00247 static bfd_byte *
00248 read_n_bytes (bfd *abfd ATTRIBUTE_UNUSED,
00249 bfd_byte *buf,
00250 unsigned int size ATTRIBUTE_UNUSED)
00251 {
00252
00253
00254
00255 return buf;
00256 }
00257
00258 static char *
00259 read_string (bfd *abfd ATTRIBUTE_UNUSED,
00260 bfd_byte *buf,
00261 unsigned int *bytes_read_ptr)
00262 {
00263
00264 char *str = (char *) buf;
00265 if (*str == '\0')
00266 {
00267 *bytes_read_ptr = 1;
00268 return NULL;
00269 }
00270
00271 *bytes_read_ptr = strlen (str) + 1;
00272 return str;
00273 }
00274
00275 static char *
00276 read_indirect_string (struct comp_unit* unit,
00277 bfd_byte *buf,
00278 unsigned int *bytes_read_ptr)
00279 {
00280 bfd_uint64_t offset;
00281 struct dwarf2_debug *stash = unit->stash;
00282 char *str;
00283
00284 if (unit->offset_size == 4)
00285 offset = read_4_bytes (unit->abfd, buf);
00286 else
00287 offset = read_8_bytes (unit->abfd, buf);
00288 *bytes_read_ptr = unit->offset_size;
00289
00290 if (! stash->dwarf_str_buffer)
00291 {
00292 asection *msec;
00293 bfd *abfd = unit->abfd;
00294 bfd_size_type sz;
00295
00296 msec = bfd_get_section_by_name (abfd, ".debug_str");
00297 if (! msec)
00298 {
00299 (*_bfd_error_handler)
00300 (_("Dwarf Error: Can't find .debug_str section."));
00301 bfd_set_error (bfd_error_bad_value);
00302 return NULL;
00303 }
00304
00305 sz = msec->rawsize ? msec->rawsize : msec->size;
00306 stash->dwarf_str_size = sz;
00307 stash->dwarf_str_buffer = bfd_alloc (abfd, sz);
00308 if (! stash->dwarf_abbrev_buffer)
00309 return NULL;
00310
00311 if (! bfd_get_section_contents (abfd, msec, stash->dwarf_str_buffer,
00312 0, sz))
00313 return NULL;
00314 }
00315
00316 if (offset >= stash->dwarf_str_size)
00317 {
00318 (*_bfd_error_handler) (_("Dwarf Error: DW_FORM_strp offset (%lu) greater than or equal to .debug_str size (%lu)."),
00319 (unsigned long) offset, stash->dwarf_str_size);
00320 bfd_set_error (bfd_error_bad_value);
00321 return NULL;
00322 }
00323
00324 str = (char *) stash->dwarf_str_buffer + offset;
00325 if (*str == '\0')
00326 return NULL;
00327 return str;
00328 }
00329
00330
00331
00332 static bfd_uint64_t
00333 read_address (struct comp_unit *unit, bfd_byte *buf)
00334 {
00335 switch (unit->addr_size)
00336 {
00337 case 8:
00338 return bfd_get_64 (unit->abfd, buf);
00339 case 4:
00340 return bfd_get_32 (unit->abfd, buf);
00341 case 2:
00342 return bfd_get_16 (unit->abfd, buf);
00343 default:
00344 abort ();
00345 }
00346 }
00347
00348
00349
00350 static struct abbrev_info *
00351 lookup_abbrev (unsigned int number, struct abbrev_info **abbrevs)
00352 {
00353 unsigned int hash_number;
00354 struct abbrev_info *abbrev;
00355
00356 hash_number = number % ABBREV_HASH_SIZE;
00357 abbrev = abbrevs[hash_number];
00358
00359 while (abbrev)
00360 {
00361 if (abbrev->number == number)
00362 return abbrev;
00363 else
00364 abbrev = abbrev->next;
00365 }
00366
00367 return NULL;
00368 }
00369
00370
00371
00372
00373
00374
00375 static struct abbrev_info**
00376 read_abbrevs (bfd *abfd, bfd_uint64_t offset, struct dwarf2_debug *stash)
00377 {
00378 struct abbrev_info **abbrevs;
00379 bfd_byte *abbrev_ptr;
00380 struct abbrev_info *cur_abbrev;
00381 unsigned int abbrev_number, bytes_read, abbrev_name;
00382 unsigned int abbrev_form, hash_number;
00383 bfd_size_type amt;
00384
00385 if (! stash->dwarf_abbrev_buffer)
00386 {
00387 asection *msec;
00388
00389 msec = bfd_get_section_by_name (abfd, ".debug_abbrev");
00390 if (! msec)
00391 {
00392 (*_bfd_error_handler) (_("Dwarf Error: Can't find .debug_abbrev section."));
00393 bfd_set_error (bfd_error_bad_value);
00394 return 0;
00395 }
00396
00397 stash->dwarf_abbrev_size = msec->size;
00398 stash->dwarf_abbrev_buffer
00399 = bfd_simple_get_relocated_section_contents (abfd, msec, NULL,
00400 stash->syms);
00401 if (! stash->dwarf_abbrev_buffer)
00402 return 0;
00403 }
00404
00405 if (offset >= stash->dwarf_abbrev_size)
00406 {
00407 (*_bfd_error_handler) (_("Dwarf Error: Abbrev offset (%lu) greater than or equal to .debug_abbrev size (%lu)."),
00408 (unsigned long) offset, stash->dwarf_abbrev_size);
00409 bfd_set_error (bfd_error_bad_value);
00410 return 0;
00411 }
00412
00413 amt = sizeof (struct abbrev_info*) * ABBREV_HASH_SIZE;
00414 abbrevs = bfd_zalloc (abfd, amt);
00415
00416 abbrev_ptr = stash->dwarf_abbrev_buffer + offset;
00417 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
00418 abbrev_ptr += bytes_read;
00419
00420
00421 while (abbrev_number)
00422 {
00423 amt = sizeof (struct abbrev_info);
00424 cur_abbrev = bfd_zalloc (abfd, amt);
00425
00426
00427 cur_abbrev->number = abbrev_number;
00428 cur_abbrev->tag = (enum dwarf_tag)
00429 read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
00430 abbrev_ptr += bytes_read;
00431 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
00432 abbrev_ptr += 1;
00433
00434
00435 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
00436 abbrev_ptr += bytes_read;
00437 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
00438 abbrev_ptr += bytes_read;
00439
00440 while (abbrev_name)
00441 {
00442 if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0)
00443 {
00444 amt = cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK;
00445 amt *= sizeof (struct attr_abbrev);
00446 cur_abbrev->attrs = bfd_realloc (cur_abbrev->attrs, amt);
00447 if (! cur_abbrev->attrs)
00448 return 0;
00449 }
00450
00451 cur_abbrev->attrs[cur_abbrev->num_attrs].name
00452 = (enum dwarf_attribute) abbrev_name;
00453 cur_abbrev->attrs[cur_abbrev->num_attrs++].form
00454 = (enum dwarf_form) abbrev_form;
00455 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
00456 abbrev_ptr += bytes_read;
00457 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
00458 abbrev_ptr += bytes_read;
00459 }
00460
00461 hash_number = abbrev_number % ABBREV_HASH_SIZE;
00462 cur_abbrev->next = abbrevs[hash_number];
00463 abbrevs[hash_number] = cur_abbrev;
00464
00465
00466
00467
00468
00469
00470
00471
00472 if ((unsigned int) (abbrev_ptr - stash->dwarf_abbrev_buffer)
00473 >= stash->dwarf_abbrev_size)
00474 break;
00475 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
00476 abbrev_ptr += bytes_read;
00477 if (lookup_abbrev (abbrev_number,abbrevs) != NULL)
00478 break;
00479 }
00480
00481 return abbrevs;
00482 }
00483
00484
00485
00486 static bfd_byte *
00487 read_attribute_value (struct attribute *attr,
00488 unsigned form,
00489 struct comp_unit *unit,
00490 bfd_byte *info_ptr)
00491 {
00492 bfd *abfd = unit->abfd;
00493 unsigned int bytes_read;
00494 struct dwarf_block *blk;
00495 bfd_size_type amt;
00496
00497 attr->form = (enum dwarf_form) form;
00498
00499 switch (form)
00500 {
00501 case DW_FORM_addr:
00502
00503 case DW_FORM_ref_addr:
00504 attr->u.val = read_address (unit, info_ptr);
00505 info_ptr += unit->addr_size;
00506 break;
00507 case DW_FORM_block2:
00508 amt = sizeof (struct dwarf_block);
00509 blk = bfd_alloc (abfd, amt);
00510 blk->size = read_2_bytes (abfd, info_ptr);
00511 info_ptr += 2;
00512 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
00513 info_ptr += blk->size;
00514 attr->u.blk = blk;
00515 break;
00516 case DW_FORM_block4:
00517 amt = sizeof (struct dwarf_block);
00518 blk = bfd_alloc (abfd, amt);
00519 blk->size = read_4_bytes (abfd, info_ptr);
00520 info_ptr += 4;
00521 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
00522 info_ptr += blk->size;
00523 attr->u.blk = blk;
00524 break;
00525 case DW_FORM_data2:
00526 attr->u.val = read_2_bytes (abfd, info_ptr);
00527 info_ptr += 2;
00528 break;
00529 case DW_FORM_data4:
00530 attr->u.val = read_4_bytes (abfd, info_ptr);
00531 info_ptr += 4;
00532 break;
00533 case DW_FORM_data8:
00534 attr->u.val = read_8_bytes (abfd, info_ptr);
00535 info_ptr += 8;
00536 break;
00537 case DW_FORM_string:
00538 attr->u.str = read_string (abfd, info_ptr, &bytes_read);
00539 info_ptr += bytes_read;
00540 break;
00541 case DW_FORM_strp:
00542 attr->u.str = read_indirect_string (unit, info_ptr, &bytes_read);
00543 info_ptr += bytes_read;
00544 break;
00545 case DW_FORM_block:
00546 amt = sizeof (struct dwarf_block);
00547 blk = bfd_alloc (abfd, amt);
00548 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
00549 info_ptr += bytes_read;
00550 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
00551 info_ptr += blk->size;
00552 attr->u.blk = blk;
00553 break;
00554 case DW_FORM_block1:
00555 amt = sizeof (struct dwarf_block);
00556 blk = bfd_alloc (abfd, amt);
00557 blk->size = read_1_byte (abfd, info_ptr);
00558 info_ptr += 1;
00559 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
00560 info_ptr += blk->size;
00561 attr->u.blk = blk;
00562 break;
00563 case DW_FORM_data1:
00564 attr->u.val = read_1_byte (abfd, info_ptr);
00565 info_ptr += 1;
00566 break;
00567 case DW_FORM_flag:
00568 attr->u.val = read_1_byte (abfd, info_ptr);
00569 info_ptr += 1;
00570 break;
00571 case DW_FORM_sdata:
00572 attr->u.sval = read_signed_leb128 (abfd, info_ptr, &bytes_read);
00573 info_ptr += bytes_read;
00574 break;
00575 case DW_FORM_udata:
00576 attr->u.val = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
00577 info_ptr += bytes_read;
00578 break;
00579 case DW_FORM_ref1:
00580 attr->u.val = read_1_byte (abfd, info_ptr);
00581 info_ptr += 1;
00582 break;
00583 case DW_FORM_ref2:
00584 attr->u.val = read_2_bytes (abfd, info_ptr);
00585 info_ptr += 2;
00586 break;
00587 case DW_FORM_ref4:
00588 attr->u.val = read_4_bytes (abfd, info_ptr);
00589 info_ptr += 4;
00590 break;
00591 case DW_FORM_ref8:
00592 attr->u.val = read_8_bytes (abfd, info_ptr);
00593 info_ptr += 8;
00594 break;
00595 case DW_FORM_ref_udata:
00596 attr->u.val = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
00597 info_ptr += bytes_read;
00598 break;
00599 case DW_FORM_indirect:
00600 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
00601 info_ptr += bytes_read;
00602 info_ptr = read_attribute_value (attr, form, unit, info_ptr);
00603 break;
00604 default:
00605 (*_bfd_error_handler) (_("Dwarf Error: Invalid or unhandled FORM value: %u."),
00606 form);
00607 bfd_set_error (bfd_error_bad_value);
00608 }
00609 return info_ptr;
00610 }
00611
00612
00613
00614 static bfd_byte *
00615 read_attribute (struct attribute *attr,
00616 struct attr_abbrev *abbrev,
00617 struct comp_unit *unit,
00618 bfd_byte *info_ptr)
00619 {
00620 attr->name = abbrev->name;
00621 info_ptr = read_attribute_value (attr, abbrev->form, unit, info_ptr);
00622 return info_ptr;
00623 }
00624
00625
00626
00627 #define FILE_ALLOC_CHUNK 5
00628 #define DIR_ALLOC_CHUNK 5
00629
00630 struct line_info
00631 {
00632 struct line_info* prev_line;
00633 bfd_vma address;
00634 char *filename;
00635 unsigned int line;
00636 unsigned int column;
00637 int end_sequence;
00638 };
00639
00640 struct fileinfo
00641 {
00642 char *name;
00643 unsigned int dir;
00644 unsigned int time;
00645 unsigned int size;
00646 };
00647
00648 struct line_info_table
00649 {
00650 bfd* abfd;
00651 unsigned int num_files;
00652 unsigned int num_dirs;
00653 char *comp_dir;
00654 char **dirs;
00655 struct fileinfo* files;
00656 struct line_info* last_line;
00657 struct line_info* lcl_head;
00658 };
00659
00660 struct funcinfo
00661 {
00662 struct funcinfo *prev_func;
00663 char *name;
00664 bfd_vma low;
00665 bfd_vma high;
00666 };
00667
00668
00669
00670
00671
00672
00673 static void
00674 add_line_info (struct line_info_table *table,
00675 bfd_vma address,
00676 char *filename,
00677 unsigned int line,
00678 unsigned int column,
00679 int end_sequence)
00680 {
00681 bfd_size_type amt = sizeof (struct line_info);
00682 struct line_info* info = bfd_alloc (table->abfd, amt);
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699 while (1)
00700 if (!table->last_line
00701 || address >= table->last_line->address)
00702 {
00703
00704 info->prev_line = table->last_line;
00705 table->last_line = info;
00706
00707
00708 if (!table->lcl_head)
00709 table->lcl_head = info;
00710 break;
00711 }
00712 else if (!table->lcl_head->prev_line
00713 && table->lcl_head->address > address)
00714 {
00715
00716
00717 info->prev_line = NULL;
00718 table->lcl_head->prev_line = info;
00719 break;
00720 }
00721 else if (table->lcl_head->prev_line
00722 && table->lcl_head->address > address
00723 && address >= table->lcl_head->prev_line->address)
00724 {
00725
00726
00727 info->prev_line = table->lcl_head->prev_line;
00728 table->lcl_head->prev_line = info;
00729 break;
00730 }
00731 else
00732 {
00733
00734
00735 struct line_info* li2 = table->last_line;
00736 struct line_info* li1 = li2->prev_line;
00737
00738 while (li1)
00739 {
00740 if (li2->address > address && address >= li1->address)
00741 break;
00742
00743 li2 = li1;
00744 li1 = li1->prev_line;
00745 }
00746 table->lcl_head = li2;
00747 }
00748
00749
00750 info->address = address;
00751 info->line = line;
00752 info->column = column;
00753 info->end_sequence = end_sequence;
00754
00755 if (filename && filename[0])
00756 {
00757 info->filename = bfd_alloc (table->abfd, strlen (filename) + 1);
00758 if (info->filename)
00759 strcpy (info->filename, filename);
00760 }
00761 else
00762 info->filename = NULL;
00763 }
00764
00765
00766
00767
00768
00769 static char *
00770 concat_filename (struct line_info_table *table, unsigned int file)
00771 {
00772 char *filename;
00773
00774 if (file - 1 >= table->num_files)
00775 {
00776 (*_bfd_error_handler)
00777 (_("Dwarf Error: mangled line number section (bad file number)."));
00778 return strdup ("<unknown>");
00779 }
00780
00781 filename = table->files[file - 1].name;
00782
00783 if (! IS_ABSOLUTE_PATH (filename))
00784 {
00785 char *dirname = (table->files[file - 1].dir
00786 ? table->dirs[table->files[file - 1].dir - 1]
00787 : table->comp_dir);
00788
00789
00790
00791 if (dirname != NULL)
00792 {
00793 unsigned int len = strlen (dirname) + strlen (filename) + 2;
00794 char * name;
00795
00796 name = bfd_malloc (len);
00797 if (name)
00798 sprintf (name, "%s/%s", dirname, filename);
00799 return name;
00800 }
00801 }
00802
00803 return strdup (filename);
00804 }
00805
00806 static void
00807 arange_add (struct comp_unit *unit, bfd_vma low_pc, bfd_vma high_pc)
00808 {
00809 struct arange *arange;
00810
00811
00812 arange = &unit->arange;
00813
00814 do
00815 {
00816 if (low_pc == arange->high)
00817 {
00818 arange->high = high_pc;
00819 return;
00820 }
00821 if (high_pc == arange->low)
00822 {
00823 arange->low = low_pc;
00824 return;
00825 }
00826 arange = arange->next;
00827 }
00828 while (arange);
00829
00830 if (unit->arange.high == 0)
00831 {
00832
00833 unit->arange.next = 0;
00834 unit->arange.low = low_pc;
00835 unit->arange.high = high_pc;
00836 return;
00837 }
00838
00839
00840 arange = bfd_zalloc (unit->abfd, sizeof (*arange));
00841 arange->low = low_pc;
00842 arange->high = high_pc;
00843
00844 arange->next = unit->arange.next;
00845 unit->arange.next = arange;
00846 }
00847
00848
00849
00850 static struct line_info_table*
00851 decode_line_info (struct comp_unit *unit, struct dwarf2_debug *stash)
00852 {
00853 bfd *abfd = unit->abfd;
00854 struct line_info_table* table;
00855 bfd_byte *line_ptr;
00856 bfd_byte *line_end;
00857 struct line_head lh;
00858 unsigned int i, bytes_read, offset_size;
00859 char *cur_file, *cur_dir;
00860 unsigned char op_code, extended_op, adj_opcode;
00861 bfd_size_type amt;
00862
00863 if (! stash->dwarf_line_buffer)
00864 {
00865 asection *msec;
00866
00867 msec = bfd_get_section_by_name (abfd, ".debug_line");
00868 if (! msec)
00869 {
00870 (*_bfd_error_handler) (_("Dwarf Error: Can't find .debug_line section."));
00871 bfd_set_error (bfd_error_bad_value);
00872 return 0;
00873 }
00874
00875 stash->dwarf_line_size = msec->size;
00876 stash->dwarf_line_buffer
00877 = bfd_simple_get_relocated_section_contents (abfd, msec, NULL,
00878 stash->syms);
00879 if (! stash->dwarf_line_buffer)
00880 return 0;
00881 }
00882
00883
00884
00885 if (unit->line_offset >= stash->dwarf_line_size)
00886 {
00887 (*_bfd_error_handler) (_("Dwarf Error: Line offset (%lu) greater than or equal to .debug_line size (%lu)."),
00888 unit->line_offset, stash->dwarf_line_size);
00889 bfd_set_error (bfd_error_bad_value);
00890 return 0;
00891 }
00892
00893 amt = sizeof (struct line_info_table);
00894 table = bfd_alloc (abfd, amt);
00895 table->abfd = abfd;
00896 table->comp_dir = unit->comp_dir;
00897
00898 table->num_files = 0;
00899 table->files = NULL;
00900
00901 table->num_dirs = 0;
00902 table->dirs = NULL;
00903
00904 table->files = NULL;
00905 table->last_line = NULL;
00906 table->lcl_head = NULL;
00907
00908 line_ptr = stash->dwarf_line_buffer + unit->line_offset;
00909
00910
00911 lh.total_length = read_4_bytes (abfd, line_ptr);
00912 line_ptr += 4;
00913 offset_size = 4;
00914 if (lh.total_length == 0xffffffff)
00915 {
00916 lh.total_length = read_8_bytes (abfd, line_ptr);
00917 line_ptr += 8;
00918 offset_size = 8;
00919 }
00920 else if (lh.total_length == 0 && unit->addr_size == 8)
00921 {
00922
00923 lh.total_length = read_4_bytes (abfd, line_ptr);
00924 line_ptr += 4;
00925 offset_size = 8;
00926 }
00927 line_end = line_ptr + lh.total_length;
00928 lh.version = read_2_bytes (abfd, line_ptr);
00929 line_ptr += 2;
00930 if (offset_size == 4)
00931 lh.prologue_length = read_4_bytes (abfd, line_ptr);
00932 else
00933 lh.prologue_length = read_8_bytes (abfd, line_ptr);
00934 line_ptr += offset_size;
00935 lh.minimum_instruction_length = read_1_byte (abfd, line_ptr);
00936 line_ptr += 1;
00937 lh.default_is_stmt = read_1_byte (abfd, line_ptr);
00938 line_ptr += 1;
00939 lh.line_base = read_1_signed_byte (abfd, line_ptr);
00940 line_ptr += 1;
00941 lh.line_range = read_1_byte (abfd, line_ptr);
00942 line_ptr += 1;
00943 lh.opcode_base = read_1_byte (abfd, line_ptr);
00944 line_ptr += 1;
00945 amt = lh.opcode_base * sizeof (unsigned char);
00946 lh.standard_opcode_lengths = bfd_alloc (abfd, amt);
00947
00948 lh.standard_opcode_lengths[0] = 1;
00949
00950 for (i = 1; i < lh.opcode_base; ++i)
00951 {
00952 lh.standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
00953 line_ptr += 1;
00954 }
00955
00956
00957 while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL)
00958 {
00959 line_ptr += bytes_read;
00960
00961 if ((table->num_dirs % DIR_ALLOC_CHUNK) == 0)
00962 {
00963 amt = table->num_dirs + DIR_ALLOC_CHUNK;
00964 amt *= sizeof (char *);
00965 table->dirs = bfd_realloc (table->dirs, amt);
00966 if (! table->dirs)
00967 return 0;
00968 }
00969
00970 table->dirs[table->num_dirs++] = cur_dir;
00971 }
00972
00973 line_ptr += bytes_read;
00974
00975
00976 while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL)
00977 {
00978 line_ptr += bytes_read;
00979
00980 if ((table->num_files % FILE_ALLOC_CHUNK) == 0)
00981 {
00982 amt = table->num_files + FILE_ALLOC_CHUNK;
00983 amt *= sizeof (struct fileinfo);
00984 table->files = bfd_realloc (table->files, amt);
00985 if (! table->files)
00986 return 0;
00987 }
00988
00989 table->files[table->num_files].name = cur_file;
00990 table->files[table->num_files].dir =
00991 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
00992 line_ptr += bytes_read;
00993 table->files[table->num_files].time =
00994 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
00995 line_ptr += bytes_read;
00996 table->files[table->num_files].size =
00997 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
00998 line_ptr += bytes_read;
00999 table->num_files++;
01000 }
01001
01002 line_ptr += bytes_read;
01003
01004
01005 while (line_ptr < line_end)
01006 {
01007
01008 bfd_vma address = 0;
01009 char * filename = table->num_files ? concat_filename (table, 1) : NULL;
01010 unsigned int line = 1;
01011 unsigned int column = 0;
01012 int is_stmt = lh.default_is_stmt;
01013 int basic_block = 0;
01014 int end_sequence = 0;
01015
01016
01017
01018
01019
01020 bfd_vma low_pc = 0;
01021 bfd_vma high_pc = 0;
01022
01023
01024 while (! end_sequence)
01025 {
01026 op_code = read_1_byte (abfd, line_ptr);
01027 line_ptr += 1;
01028
01029 if (op_code >= lh.opcode_base)
01030 {
01031
01032 adj_opcode = op_code - lh.opcode_base;
01033 address += (adj_opcode / lh.line_range)
01034 * lh.minimum_instruction_length;
01035 line += lh.line_base + (adj_opcode % lh.line_range);
01036
01037 add_line_info (table, address, filename, line, column, 0);
01038 basic_block = 1;
01039 if (low_pc == 0 || address < low_pc)
01040 low_pc = address;
01041 if (address > high_pc)
01042 high_pc = address;
01043 }
01044 else switch (op_code)
01045 {
01046 case DW_LNS_extended_op:
01047
01048 line_ptr += 1;
01049 extended_op = read_1_byte (abfd, line_ptr);
01050 line_ptr += 1;
01051
01052 switch (extended_op)
01053 {
01054 case DW_LNE_end_sequence:
01055 end_sequence = 1;
01056 add_line_info (table, address, filename, line, column,
01057 end_sequence);
01058 if (low_pc == 0 || address < low_pc)
01059 low_pc = address;
01060 if (address > high_pc)
01061 high_pc = address;
01062 arange_add (unit, low_pc, high_pc);
01063 break;
01064 case DW_LNE_set_address:
01065 address = read_address (unit, line_ptr);
01066 line_ptr += unit->addr_size;
01067 break;
01068 case DW_LNE_define_file:
01069 cur_file = read_string (abfd, line_ptr, &bytes_read);
01070 line_ptr += bytes_read;
01071 if ((table->num_files % FILE_ALLOC_CHUNK) == 0)
01072 {
01073 amt = table->num_files + FILE_ALLOC_CHUNK;
01074 amt *= sizeof (struct fileinfo);
01075 table->files = bfd_realloc (table->files, amt);
01076 if (! table->files)
01077 return 0;
01078 }
01079 table->files[table->num_files].name = cur_file;
01080 table->files[table->num_files].dir =
01081 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
01082 line_ptr += bytes_read;
01083 table->files[table->num_files].time =
01084 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
01085 line_ptr += bytes_read;
01086 table->files[table->num_files].size =
01087 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
01088 line_ptr += bytes_read;
01089 table->num_files++;
01090 break;
01091 default:
01092 (*_bfd_error_handler) (_("Dwarf Error: mangled line number section."));
01093 bfd_set_error (bfd_error_bad_value);
01094 return 0;
01095 }
01096 break;
01097 case DW_LNS_copy:
01098 add_line_info (table, address, filename, line, column, 0);
01099 basic_block = 0;
01100 if (low_pc == 0 || address < low_pc)
01101 low_pc = address;
01102 if (address > high_pc)
01103 high_pc = address;
01104 break;
01105 case DW_LNS_advance_pc:
01106 address += lh.minimum_instruction_length
01107 * read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
01108 line_ptr += bytes_read;
01109 break;
01110 case DW_LNS_advance_line:
01111 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
01112 line_ptr += bytes_read;
01113 break;
01114 case DW_LNS_set_file:
01115 {
01116 unsigned int file;
01117
01118
01119
01120 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
01121 line_ptr += bytes_read;
01122 if (filename)
01123 free (filename);
01124 filename = concat_filename (table, file);
01125 break;
01126 }
01127 case DW_LNS_set_column:
01128 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
01129 line_ptr += bytes_read;
01130 break;
01131 case DW_LNS_negate_stmt:
01132 is_stmt = (!is_stmt);
01133 break;
01134 case DW_LNS_set_basic_block:
01135 basic_block = 1;
01136 break;
01137 case DW_LNS_const_add_pc:
01138 address += lh.minimum_instruction_length
01139 * ((255 - lh.opcode_base) / lh.line_range);
01140 break;
01141 case DW_LNS_fixed_advance_pc:
01142 address += read_2_bytes (abfd, line_ptr);
01143 line_ptr += 2;
01144 break;
01145 default:
01146 {
01147 int i;
01148
01149
01150 for (i = 0; i < lh.standard_opcode_lengths[op_code]; i++)
01151 {
01152 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
01153 line_ptr += bytes_read;
01154 }
01155 }
01156 }
01157 }
01158
01159 if (filename)
01160 free (filename);
01161 }
01162
01163 return table;
01164 }
01165
01166
01167
01168
01169
01170 static bfd_boolean
01171 lookup_address_in_line_info_table (struct line_info_table *table,
01172 bfd_vma addr,
01173 struct funcinfo *function,
01174 const char **filename_ptr,
01175 unsigned int *linenumber_ptr)
01176 {
01177
01178 struct line_info* next_line = table->last_line;
01179 struct line_info* each_line = NULL;
01180 *filename_ptr = NULL;
01181
01182 if (!next_line)
01183 return FALSE;
01184
01185 each_line = next_line->prev_line;
01186
01187
01188 if (addr > next_line->address)
01189 each_line = NULL;
01190
01191
01192 while (each_line && next_line)
01193 {
01194
01195
01196
01197 bfd_boolean addr_match = FALSE;
01198 if (each_line->address <= addr && addr <= next_line->address)
01199 {
01200 addr_match = TRUE;
01201
01202
01203
01204
01205
01206 if (function != NULL
01207 && each_line->address < function->low
01208 && next_line->address > function->low)
01209 {
01210 *filename_ptr = next_line->filename;
01211 *linenumber_ptr = next_line->line;
01212 }
01213 else
01214 {
01215 *filename_ptr = each_line->filename;
01216 *linenumber_ptr = each_line->line;
01217 }
01218 }
01219
01220 if (addr_match && !each_line->end_sequence)
01221 return TRUE;
01222
01223 next_line = each_line;
01224 each_line = each_line->prev_line;
01225 }
01226
01227
01228
01229
01230
01231
01232
01233 if (*filename_ptr == NULL && function != NULL)
01234 {
01235 *filename_ptr = next_line->filename;
01236 *linenumber_ptr = next_line->line;
01237 return TRUE;
01238 }
01239
01240 return FALSE;
01241 }
01242
01243
01244
01245
01246
01247 static bfd_boolean
01248 lookup_address_in_function_table (struct funcinfo *table,
01249 bfd_vma addr,
01250 struct funcinfo **function_ptr,
01251 const char **functionname_ptr)
01252 {
01253 struct funcinfo* each_func;
01254
01255 for (each_func = table;
01256 each_func;
01257 each_func = each_func->prev_func)
01258 {
01259 if (addr >= each_func->low && addr < each_func->high)
01260 {
01261 *functionname_ptr = each_func->name;
01262 *function_ptr = each_func;
01263 return TRUE;
01264 }
01265 }
01266
01267 return FALSE;
01268 }
01269
01270 static char *
01271 find_abstract_instance_name (struct comp_unit *unit, bfd_uint64_t die_ref)
01272 {
01273 bfd *abfd = unit->abfd;
01274 bfd_byte *info_ptr;
01275 unsigned int abbrev_number, bytes_read, i;
01276 struct abbrev_info *abbrev;
01277 struct attribute attr;
01278 char *name = 0;
01279
01280 info_ptr = unit->info_ptr_unit + die_ref;
01281 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
01282 info_ptr += bytes_read;
01283
01284 if (abbrev_number)
01285 {
01286 abbrev = lookup_abbrev (abbrev_number, unit->abbrevs);
01287 if (! abbrev)
01288 {
01289 (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %u."),
01290 abbrev_number);
01291 bfd_set_error (bfd_error_bad_value);
01292 }
01293 else
01294 {
01295 for (i = 0; i < abbrev->num_attrs && !name; ++i)
01296 {
01297 info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr);
01298 switch (attr.name)
01299 {
01300 case DW_AT_name:
01301 name = attr.u.str;
01302 break;
01303 case DW_AT_specification:
01304 name = find_abstract_instance_name (unit, attr.u.val);
01305 break;
01306 default:
01307 break;
01308 }
01309 }
01310 }
01311 }
01312 return (name);
01313 }
01314
01315
01316
01317
01318
01319
01320 static bfd_boolean
01321 scan_unit_for_functions (struct comp_unit *unit)
01322 {
01323 bfd *abfd = unit->abfd;
01324 bfd_byte *info_ptr = unit->first_child_die_ptr;
01325 int nesting_level = 1;
01326
01327 while (nesting_level)
01328 {
01329 unsigned int abbrev_number, bytes_read, i;
01330 struct abbrev_info *abbrev;
01331 struct attribute attr;
01332 struct funcinfo *func;
01333 char *name = 0;
01334
01335 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
01336 info_ptr += bytes_read;
01337
01338 if (! abbrev_number)
01339 {
01340 nesting_level--;
01341 continue;
01342 }
01343
01344 abbrev = lookup_abbrev (abbrev_number,unit->abbrevs);
01345 if (! abbrev)
01346 {
01347 (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %u."),
01348 abbrev_number);
01349 bfd_set_error (bfd_error_bad_value);
01350 return FALSE;
01351 }
01352
01353 if (abbrev->tag == DW_TAG_subprogram
01354 || abbrev->tag == DW_TAG_inlined_subroutine)
01355 {
01356 bfd_size_type amt = sizeof (struct funcinfo);
01357 func = bfd_zalloc (abfd, amt);
01358 func->prev_func = unit->function_table;
01359 unit->function_table = func;
01360 }
01361 else
01362 func = NULL;
01363
01364 for (i = 0; i < abbrev->num_attrs; ++i)
01365 {
01366 info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr);
01367
01368 if (func)
01369 {
01370 switch (attr.name)
01371 {
01372 case DW_AT_abstract_origin:
01373 func->name = find_abstract_instance_name (unit, attr.u.val);
01374 break;
01375
01376 case DW_AT_name:
01377
01378 name = attr.u.str;
01379
01380
01381 if (func->name == NULL)
01382 func->name = attr.u.str;
01383 break;
01384
01385 case DW_AT_MIPS_linkage_name:
01386 func->name = attr.u.str;
01387 break;
01388
01389 case DW_AT_low_pc:
01390 func->low = attr.u.val;
01391 break;
01392
01393 case DW_AT_high_pc:
01394 func->high = attr.u.val;
01395 break;
01396
01397 default:
01398 break;
01399 }
01400 }
01401 else
01402 {
01403 switch (attr.name)
01404 {
01405 case DW_AT_name:
01406 name = attr.u.str;
01407 break;
01408
01409 default:
01410 break;
01411 }
01412 }
01413 }
01414
01415 if (abbrev->has_children)
01416 nesting_level++;
01417 }
01418
01419 return TRUE;
01420 }
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431 static struct comp_unit *
01432 parse_comp_unit (bfd *abfd,
01433 struct dwarf2_debug *stash,
01434 bfd_vma unit_length,
01435 bfd_byte *info_ptr_unit,
01436 unsigned int offset_size)
01437 {
01438 struct comp_unit* unit;
01439 unsigned int version;
01440 bfd_uint64_t abbrev_offset = 0;
01441 unsigned int addr_size;
01442 struct abbrev_info** abbrevs;
01443 unsigned int abbrev_number, bytes_read, i;
01444 struct abbrev_info *abbrev;
01445 struct attribute attr;
01446 bfd_byte *info_ptr = stash->info_ptr;
01447 bfd_byte *end_ptr = info_ptr + unit_length;
01448 bfd_size_type amt;
01449
01450 version = read_2_bytes (abfd, info_ptr);
01451 info_ptr += 2;
01452 BFD_ASSERT (offset_size == 4 || offset_size == 8);
01453 if (offset_size == 4)
01454 abbrev_offset = read_4_bytes (abfd, info_ptr);
01455 else
01456 abbrev_offset = read_8_bytes (abfd, info_ptr);
01457 info_ptr += offset_size;
01458 addr_size = read_1_byte (abfd, info_ptr);
01459 info_ptr += 1;
01460
01461 if (version != 2)
01462 {
01463 (*_bfd_error_handler) (_("Dwarf Error: found dwarf version '%u', this reader only handles version 2 information."), version);
01464 bfd_set_error (bfd_error_bad_value);
01465 return 0;
01466 }
01467
01468 if (addr_size > sizeof (bfd_vma))
01469 {
01470 (*_bfd_error_handler) (_("Dwarf Error: found address size '%u', this reader can not handle sizes greater than '%u'."),
01471 addr_size,
01472 (unsigned int) sizeof (bfd_vma));
01473 bfd_set_error (bfd_error_bad_value);
01474 return 0;
01475 }
01476
01477 if (addr_size != 2 && addr_size != 4 && addr_size != 8)
01478 {
01479 (*_bfd_error_handler) ("Dwarf Error: found address size '%u', this reader can only handle address sizes '2', '4' and '8'.", addr_size);
01480 bfd_set_error (bfd_error_bad_value);
01481 return 0;
01482 }
01483
01484
01485 abbrevs = read_abbrevs (abfd, abbrev_offset, stash);
01486 if (! abbrevs)
01487 return 0;
01488
01489 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
01490 info_ptr += bytes_read;
01491 if (! abbrev_number)
01492 {
01493 (*_bfd_error_handler) (_("Dwarf Error: Bad abbrev number: %u."),
01494 abbrev_number);
01495 bfd_set_error (bfd_error_bad_value);
01496 return 0;
01497 }
01498
01499 abbrev = lookup_abbrev (abbrev_number, abbrevs);
01500 if (! abbrev)
01501 {
01502 (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %u."),
01503 abbrev_number);
01504 bfd_set_error (bfd_error_bad_value);
01505 return 0;
01506 }
01507
01508 amt = sizeof (struct comp_unit);
01509 unit = bfd_zalloc (abfd, amt);
01510 unit->abfd = abfd;
01511 unit->addr_size = addr_size;
01512 unit->offset_size = offset_size;
01513 unit->abbrevs = abbrevs;
01514 unit->end_ptr = end_ptr;
01515 unit->stash = stash;
01516 unit->info_ptr_unit = info_ptr_unit;
01517
01518 for (i = 0; i < abbrev->num_attrs; ++i)
01519 {
01520 info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr);
01521
01522
01523
01524 switch (attr.name)
01525 {
01526 case DW_AT_stmt_list:
01527 unit->stmtlist = 1;
01528 unit->line_offset = attr.u.val;
01529 break;
01530
01531 case DW_AT_name:
01532 unit->name = attr.u.str;
01533 break;
01534
01535 case DW_AT_low_pc:
01536 unit->arange.low = attr.u.val;
01537 break;
01538
01539 case DW_AT_high_pc:
01540 unit->arange.high = attr.u.val;
01541 break;
01542
01543 case DW_AT_comp_dir:
01544 {
01545 char *comp_dir = attr.u.str;
01546 if (comp_dir)
01547 {
01548
01549
01550 char *cp = strchr (comp_dir, ':');
01551
01552 if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/')
01553 comp_dir = cp + 1;
01554 }
01555 unit->comp_dir = comp_dir;
01556 break;
01557 }
01558
01559 default:
01560 break;
01561 }
01562 }
01563
01564 unit->first_child_die_ptr = info_ptr;
01565 return unit;
01566 }
01567
01568
01569
01570 static bfd_boolean
01571 comp_unit_contains_address (struct comp_unit *unit, bfd_vma addr)
01572 {
01573 struct arange *arange;
01574
01575 if (unit->error)
01576 return FALSE;
01577
01578 arange = &unit->arange;
01579 do
01580 {
01581 if (addr >= arange->low && addr < arange->high)
01582 return TRUE;
01583 arange = arange->next;
01584 }
01585 while (arange);
01586
01587 return FALSE;
01588 }
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598 static bfd_boolean
01599 comp_unit_find_nearest_line (struct comp_unit *unit,
01600 bfd_vma addr,
01601 const char **filename_ptr,
01602 const char **functionname_ptr,
01603 unsigned int *linenumber_ptr,
01604 struct dwarf2_debug *stash)
01605 {
01606 bfd_boolean line_p;
01607 bfd_boolean func_p;
01608 struct funcinfo *function;
01609
01610 if (unit->error)
01611 return FALSE;
01612
01613 if (! unit->line_table)
01614 {
01615 if (! unit->stmtlist)
01616 {
01617 unit->error = 1;
01618 return FALSE;
01619 }
01620
01621 unit->line_table = decode_line_info (unit, stash);
01622
01623 if (! unit->line_table)
01624 {
01625 unit->error = 1;
01626 return FALSE;
01627 }
01628
01629 if (unit->first_child_die_ptr < unit->end_ptr
01630 && ! scan_unit_for_functions (unit))
01631 {
01632 unit->error = 1;
01633 return FALSE;
01634 }
01635 }
01636
01637 function = NULL;
01638 func_p = lookup_address_in_function_table (unit->function_table, addr,
01639 &function, functionname_ptr);
01640 line_p = lookup_address_in_line_info_table (unit->line_table, addr,
01641 function, filename_ptr,
01642 linenumber_ptr);
01643 return line_p || func_p;
01644 }
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655 #define DWARF2_DEBUG_INFO ".debug_info"
01656 #define GNU_LINKONCE_INFO ".gnu.linkonce.wi."
01657
01658 static asection *
01659 find_debug_info (bfd *abfd, asection *after_sec)
01660 {
01661 asection * msec;
01662
01663 if (after_sec)
01664 msec = after_sec->next;
01665 else
01666 msec = abfd->sections;
01667
01668 while (msec)
01669 {
01670 if (strcmp (msec->name, DWARF2_DEBUG_INFO) == 0)
01671 return msec;
01672
01673 if (strncmp (msec->name, GNU_LINKONCE_INFO, strlen (GNU_LINKONCE_INFO)) == 0)
01674 return msec;
01675
01676 msec = msec->next;
01677 }
01678
01679 return NULL;
01680 }
01681
01682
01683
01684
01685
01686
01687
01688 bfd_boolean
01689 _bfd_dwarf2_find_nearest_line (bfd *abfd,
01690 asection *section,
01691 asymbol **symbols,
01692 bfd_vma offset,
01693 const char **filename_ptr,
01694 const char **functionname_ptr,
01695 unsigned int *linenumber_ptr,
01696 unsigned int addr_size,
01697 void **pinfo)
01698 {
01699
01700
01701
01702
01703
01704
01705
01706
01707 struct dwarf2_debug *stash;
01708
01709
01710 bfd_vma addr;
01711
01712 struct comp_unit* each;
01713
01714 stash = *pinfo;
01715 addr = offset;
01716 if (section->output_section)
01717 addr += section->output_section->vma + section->output_offset;
01718 else
01719 addr += section->vma;
01720 *filename_ptr = NULL;
01721 *functionname_ptr = NULL;
01722 *linenumber_ptr = 0;
01723
01724
01725
01726
01727 if (addr_size == 0)
01728 addr_size = 4;
01729 BFD_ASSERT (addr_size == 4 || addr_size == 8);
01730
01731 if (! stash)
01732 {
01733 bfd_size_type total_size;
01734 asection *msec;
01735 bfd_size_type amt = sizeof (struct dwarf2_debug);
01736
01737 stash = bfd_zalloc (abfd, amt);
01738 if (! stash)
01739 return FALSE;
01740
01741 *pinfo = stash;
01742
01743 msec = find_debug_info (abfd, NULL);
01744 if (! msec)
01745
01746
01747
01748 return FALSE;
01749
01750
01751
01752
01753
01754
01755 for (total_size = 0; msec; msec = find_debug_info (abfd, msec))
01756 total_size += msec->size;
01757
01758 stash->info_ptr = bfd_alloc (abfd, total_size);
01759 if (stash->info_ptr == NULL)
01760 return FALSE;
01761
01762 stash->info_ptr_end = stash->info_ptr;
01763
01764 for (msec = find_debug_info (abfd, NULL);
01765 msec;
01766 msec = find_debug_info (abfd, msec))
01767 {
01768 bfd_size_type size;
01769 bfd_size_type start;
01770
01771 size = msec->size;
01772 if (size == 0)
01773 continue;
01774
01775 start = stash->info_ptr_end - stash->info_ptr;
01776
01777 if ((bfd_simple_get_relocated_section_contents
01778 (abfd, msec, stash->info_ptr + start, symbols)) == NULL)
01779 continue;
01780
01781 stash->info_ptr_end = stash->info_ptr + start + size;
01782 }
01783
01784 BFD_ASSERT (stash->info_ptr_end == stash->info_ptr + total_size);
01785
01786 stash->sec = find_debug_info (abfd, NULL);
01787 stash->sec_info_ptr = stash->info_ptr;
01788 stash->syms = symbols;
01789 }
01790
01791
01792
01793 if (! stash->info_ptr)
01794 return FALSE;
01795
01796
01797 for (each = stash->all_comp_units; each; each = each->next_unit)
01798 if (comp_unit_contains_address (each, addr))
01799 return comp_unit_find_nearest_line (each, addr, filename_ptr,
01800 functionname_ptr, linenumber_ptr,
01801 stash);
01802
01803
01804 while (stash->info_ptr < stash->info_ptr_end)
01805 {
01806 bfd_vma length;
01807 bfd_boolean found;
01808 unsigned int offset_size = addr_size;
01809 bfd_byte *info_ptr_unit = stash->info_ptr;
01810
01811 length = read_4_bytes (abfd, stash->info_ptr);
01812
01813
01814 if (length == 0xffffffff)
01815 {
01816 offset_size = 8;
01817 length = read_8_bytes (abfd, stash->info_ptr + 4);
01818 stash->info_ptr += 12;
01819 }
01820
01821
01822
01823 else if (length == 0)
01824 {
01825 offset_size = 8;
01826 length = read_4_bytes (abfd, stash->info_ptr + 4);
01827 stash->info_ptr += 8;
01828 }
01829
01830
01831
01832 else if (addr_size == 8)
01833 {
01834 length = read_8_bytes (abfd, stash->info_ptr);
01835 stash->info_ptr += 8;
01836 }
01837 else
01838 stash->info_ptr += 4;
01839
01840 if (length > 0)
01841 {
01842 each = parse_comp_unit (abfd, stash, length, info_ptr_unit,
01843 offset_size);
01844 stash->info_ptr += length;
01845
01846 if ((bfd_vma) (stash->info_ptr - stash->sec_info_ptr)
01847 == stash->sec->size)
01848 {
01849 stash->sec = find_debug_info (abfd, stash->sec);
01850 stash->sec_info_ptr = stash->info_ptr;
01851 }
01852
01853 if (each)
01854 {
01855 each->next_unit = stash->all_comp_units;
01856 stash->all_comp_units = each;
01857
01858
01859
01860
01861
01862
01863 if (each->arange.high > 0)
01864 {
01865 if (comp_unit_contains_address (each, addr))
01866 return comp_unit_find_nearest_line (each, addr,
01867 filename_ptr,
01868 functionname_ptr,
01869 linenumber_ptr,
01870 stash);
01871 }
01872 else
01873 {
01874 found = comp_unit_find_nearest_line (each, addr,
01875 filename_ptr,
01876 functionname_ptr,
01877 linenumber_ptr,
01878 stash);
01879 if (found)
01880 return TRUE;
01881 }
01882 }
01883 }
01884 }
01885
01886 return FALSE;
01887 }