| 1 |
/* DWARF 2 support. |
/* DWARF 2 support. |
| 2 |
Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
| 3 |
2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
| 4 |
|
|
| 5 |
Adapted from gdb/dwarf2read.c by Gavin Koch of Cygnus Solutions |
Adapted from gdb/dwarf2read.c by Gavin Koch of Cygnus Solutions |
| 6 |
(gavin@cygnus.com). |
(gavin@cygnus.com). |
| 35 |
#include "libiberty.h" |
#include "libiberty.h" |
| 36 |
#include "libbfd.h" |
#include "libbfd.h" |
| 37 |
#include "elf-bfd.h" |
#include "elf-bfd.h" |
| 38 |
#include "elf/dwarf2.h" |
#include "dwarf2.h" |
| 39 |
|
|
| 40 |
/* The data in the .debug_line statement prologue looks like this. */ |
/* The data in the .debug_line statement prologue looks like this. */ |
| 41 |
|
|
| 417 |
bfd_boolean section_is_compressed = FALSE; |
bfd_boolean section_is_compressed = FALSE; |
| 418 |
|
|
| 419 |
/* read_section is a noop if the section has already been read. */ |
/* read_section is a noop if the section has already been read. */ |
| 420 |
if (*section_buffer) |
if (!*section_buffer) |
|
return TRUE; |
|
|
|
|
|
msec = bfd_get_section_by_name (abfd, section_name); |
|
|
if (! msec && compressed_section_name) |
|
|
{ |
|
|
msec = bfd_get_section_by_name (abfd, compressed_section_name); |
|
|
section_is_compressed = TRUE; |
|
|
} |
|
|
if (! msec) |
|
| 421 |
{ |
{ |
| 422 |
(*_bfd_error_handler) (_("Dwarf Error: Can't find %s section."), section_name); |
msec = bfd_get_section_by_name (abfd, section_name); |
| 423 |
bfd_set_error (bfd_error_bad_value); |
if (! msec && compressed_section_name) |
| 424 |
return FALSE; |
{ |
| 425 |
} |
msec = bfd_get_section_by_name (abfd, compressed_section_name); |
| 426 |
|
section_is_compressed = TRUE; |
| 427 |
|
} |
| 428 |
|
if (! msec) |
| 429 |
|
{ |
| 430 |
|
(*_bfd_error_handler) (_("Dwarf Error: Can't find %s section."), section_name); |
| 431 |
|
bfd_set_error (bfd_error_bad_value); |
| 432 |
|
return FALSE; |
| 433 |
|
} |
| 434 |
|
|
|
if (syms) |
|
|
{ |
|
|
*section_size = msec->size; |
|
|
*section_buffer |
|
|
= bfd_simple_get_relocated_section_contents (abfd, msec, NULL, syms); |
|
|
if (! *section_buffer) |
|
|
return FALSE; |
|
|
} |
|
|
else |
|
|
{ |
|
| 435 |
*section_size = msec->rawsize ? msec->rawsize : msec->size; |
*section_size = msec->rawsize ? msec->rawsize : msec->size; |
| 436 |
*section_buffer = bfd_malloc (*section_size); |
if (syms) |
| 437 |
if (! *section_buffer) |
{ |
| 438 |
return FALSE; |
*section_buffer |
| 439 |
if (! bfd_get_section_contents (abfd, msec, *section_buffer, |
= bfd_simple_get_relocated_section_contents (abfd, msec, NULL, syms); |
| 440 |
0, *section_size)) |
if (! *section_buffer) |
| 441 |
return FALSE; |
return FALSE; |
| 442 |
} |
} |
| 443 |
|
else |
| 444 |
|
{ |
| 445 |
|
*section_buffer = bfd_malloc (*section_size); |
| 446 |
|
if (! *section_buffer) |
| 447 |
|
return FALSE; |
| 448 |
|
if (! bfd_get_section_contents (abfd, msec, *section_buffer, |
| 449 |
|
0, *section_size)) |
| 450 |
|
return FALSE; |
| 451 |
|
} |
| 452 |
|
|
| 453 |
if (section_is_compressed) |
if (section_is_compressed) |
|
{ |
|
|
if (! bfd_uncompress_section_contents (section_buffer, section_size)) |
|
| 454 |
{ |
{ |
| 455 |
(*_bfd_error_handler) (_("Dwarf Error: unable to decompress %s section."), compressed_section_name); |
if (! bfd_uncompress_section_contents (section_buffer, section_size)) |
| 456 |
bfd_set_error (bfd_error_bad_value); |
{ |
| 457 |
return FALSE; |
(*_bfd_error_handler) (_("Dwarf Error: unable to decompress %s section."), compressed_section_name); |
| 458 |
|
bfd_set_error (bfd_error_bad_value); |
| 459 |
|
return FALSE; |
| 460 |
|
} |
| 461 |
} |
} |
| 462 |
} |
} |
| 463 |
|
|
| 1405 |
line_ptr += bytes_read; |
line_ptr += bytes_read; |
| 1406 |
table->num_files++; |
table->num_files++; |
| 1407 |
break; |
break; |
| 1408 |
|
case DW_LNE_set_discriminator: |
| 1409 |
|
(void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 1410 |
|
line_ptr += bytes_read; |
| 1411 |
|
break; |
| 1412 |
default: |
default: |
| 1413 |
(*_bfd_error_handler) (_("Dwarf Error: mangled line number section.")); |
(*_bfd_error_handler) (_("Dwarf Error: mangled line number section.")); |
| 1414 |
bfd_set_error (bfd_error_bad_value); |
bfd_set_error (bfd_error_bad_value); |
| 1806 |
bfd_vma low_pc; |
bfd_vma low_pc; |
| 1807 |
bfd_vma high_pc; |
bfd_vma high_pc; |
| 1808 |
|
|
| 1809 |
if (unit->addr_size == 4) |
low_pc = read_address (unit, ranges_ptr); |
| 1810 |
{ |
ranges_ptr += unit->addr_size; |
| 1811 |
low_pc = read_4_bytes (unit->abfd, ranges_ptr); |
high_pc = read_address (unit, ranges_ptr); |
| 1812 |
ranges_ptr += 4; |
ranges_ptr += unit->addr_size; |
| 1813 |
high_pc = read_4_bytes (unit->abfd, ranges_ptr); |
|
|
ranges_ptr += 4; |
|
|
} |
|
|
else |
|
|
{ |
|
|
low_pc = read_8_bytes (unit->abfd, ranges_ptr); |
|
|
ranges_ptr += 8; |
|
|
high_pc = read_8_bytes (unit->abfd, ranges_ptr); |
|
|
ranges_ptr += 8; |
|
|
} |
|
| 1814 |
if (low_pc == 0 && high_pc == 0) |
if (low_pc == 0 && high_pc == 0) |
| 1815 |
break; |
break; |
| 1816 |
if (low_pc == -1UL && high_pc != -1UL) |
if (low_pc == -1UL && high_pc != -1UL) |
| 3183 |
break; |
break; |
| 3184 |
stash->info_ptr += length; |
stash->info_ptr += length; |
| 3185 |
|
|
|
if ((bfd_vma) (stash->info_ptr - stash->sec_info_ptr) |
|
|
== stash->sec->size) |
|
|
{ |
|
|
stash->sec = find_debug_info (stash->bfd, stash->sec); |
|
|
stash->sec_info_ptr = stash->info_ptr; |
|
|
} |
|
|
|
|
| 3186 |
if (stash->all_comp_units) |
if (stash->all_comp_units) |
| 3187 |
stash->all_comp_units->prev_unit = each; |
stash->all_comp_units->prev_unit = each; |
| 3188 |
else |
else |
| 3212 |
functionname_ptr, |
functionname_ptr, |
| 3213 |
linenumber_ptr, |
linenumber_ptr, |
| 3214 |
stash)); |
stash)); |
| 3215 |
|
|
| 3216 |
|
if ((bfd_vma) (stash->info_ptr - stash->sec_info_ptr) |
| 3217 |
|
== stash->sec->size) |
| 3218 |
|
{ |
| 3219 |
|
stash->sec = find_debug_info (stash->bfd, stash->sec); |
| 3220 |
|
stash->sec_info_ptr = stash->info_ptr; |
| 3221 |
|
} |
| 3222 |
|
|
| 3223 |
if (found) |
if (found) |
| 3224 |
goto done; |
goto done; |
| 3225 |
} |
} |