libdebug: Improve handling of stripped binaries.

- When searching for the symbol table, first see if the normal SHT_SYMTAB
  section is present. If not, fall back to trying to use SHT_DYNSYM if
  present. This allows us to resolve non-static functions/symbols
  in stripped binaries for the purposes of crash reports/disassembly.
This commit is contained in:
Rene Gollent
2013-10-18 19:07:02 -04:00
parent e9487c70c5
commit 1bcd34c4da
2 changed files with 18 additions and 4 deletions
+15 -4
View File
@@ -305,9 +305,6 @@ ImageFile::_LoadFile(const char* path, addr_t* _textAddress, size_t* _textSize,
return B_NOT_AN_EXECUTABLE;
}
elf_shdr* sectionHeaders
= (elf_shdr*)(fMappedFile + elfHeader->e_shoff);
// find the text and data segment -- we need load address and size
*_textAddress = 0;
*_textSize = 0;
@@ -328,12 +325,26 @@ ImageFile::_LoadFile(const char* path, addr_t* _textAddress, size_t* _textSize,
}
}
status_t error = _FindTableInSection(elfHeader, SHT_SYMTAB);
if (error != B_OK)
error = _FindTableInSection(elfHeader, SHT_DYNSYM);
return error;
}
status_t
ImageFile::_FindTableInSection(elf_ehdr* elfHeader, uint16 sectionType)
{
elf_shdr* sectionHeaders
= (elf_shdr*)(fMappedFile + elfHeader->e_shoff);
// find the symbol table
for (int32 i = 0; i < elfHeader->e_shnum; i++) {
elf_shdr* sectionHeader = (elf_shdr*)
((uint8*)sectionHeaders + i * elfHeader->e_shentsize);
if (sectionHeader->sh_type == SHT_SYMTAB) {
if (sectionHeader->sh_type == sectionType) {
elf_shdr& stringHeader = *(elf_shdr*)
((uint8*)sectionHeaders
+ sectionHeader->sh_link * elfHeader->e_shentsize);
+3
View File
@@ -96,6 +96,9 @@ private:
addr_t* _textAddress, size_t* _textSize,
addr_t* _dataAddress, size_t* _dataSize);
status_t _FindTableInSection(elf_ehdr* elfHeader,
uint16 sectionType);
private:
int fFD;
off_t fFileSize;