status_t DwarfImageDebugInfo::Init() { status_t error = fLock.InitCheck(); if (error != B_OK) return error; fTextSegment = fFile->GetElfFile()->TextSegment(); if (fTextSegment == NULL) return B_ENTRY_NOT_FOUND; fRelocationDelta = fImageInfo.TextBase() - fTextSegment->LoadAddress(); ElfSection* section = fFile->GetElfFile()->FindSection(".text"); if (section != NULL) { fTextSectionStart = section->LoadAddress() + fRelocationDelta; fTextSectionEnd = fTextSectionStart + section->Size(); } section = fFile->GetElfFile()->FindSection(".plt"); if (section != NULL) { fPLTSectionStart = section->LoadAddress() + fRelocationDelta; fPLTSectionEnd = fPLTSectionStart + section->Size(); } return B_OK; }
status_t ElfFile::CreateSymbolLookup(uint64 textDelta, ElfSymbolLookup*& _lookup) const { // Get the symbol table + corresponding string section. There may be two // symbol tables: the dynamic and the non-dynamic one. The former contains // only the symbols needed at run-time. The latter, if existing, is likely // more complete. So try to find and use the latter one, falling back to the // former. ElfSection* symbolSection; ElfSection* stringSection; if (!_FindSymbolSections(symbolSection, stringSection, SHT_SYMTAB) && !_FindSymbolSections(symbolSection, stringSection, SHT_DYNSYM)) { return B_ENTRY_NOT_FOUND; } // create a source with a segment for each section SymbolLookupSource* source = new(std::nothrow) SymbolLookupSource(fFD); if (source == NULL) return B_NO_MEMORY; BReference<SymbolLookupSource> sourceReference(source, true); if (!source->AddSegment(symbolSection->Offset(), symbolSection->Size(), symbolSection->Offset()) || !source->AddSegment(stringSection->Offset(), stringSection->Size(), stringSection->Offset())) { return B_NO_MEMORY; } // create the lookup size_t symbolTableEntrySize = Is64Bit() ? sizeof(ElfClass64::Sym) : sizeof(ElfClass32::Sym); uint32 symbolCount = uint32(symbolSection->Size() / symbolTableEntrySize); return ElfSymbolLookup::Create(source, symbolSection->Offset(), 0, stringSection->Offset(), symbolCount, symbolTableEntrySize, textDelta, f64Bit, fSwappedByteOrder, true, _lookup); }