diff --git a/src/apps/debugger/ThreadHandler.cpp b/src/apps/debugger/ThreadHandler.cpp index f5b2690168..d8931b9fa8 100644 --- a/src/apps/debugger/ThreadHandler.cpp +++ b/src/apps/debugger/ThreadHandler.cpp @@ -590,32 +590,31 @@ ThreadHandler::_HandleSingleStepStep(CpuState* cpuState) if (fStepStatement->ContainsAddress(cpuState->InstructionPointer())) { _SingleStepThread(cpuState->InstructionPointer()); return true; - } else { - StackTrace* stackTrace = fThread->GetStackTrace(); - Reference stackTraceReference(stackTrace); + } - if (stackTrace == NULL && cpuState != NULL) { - if (fDebuggerInterface->GetArchitecture()->CreateStackTrace( - fThread->GetTeam(), this, cpuState, stackTrace) == B_OK) { - stackTraceReference.SetTo(stackTrace, true); - } + StackTrace* stackTrace = fThread->GetStackTrace(); + Reference stackTraceReference(stackTrace); + + if (stackTrace == NULL && cpuState != NULL) { + if (fDebuggerInterface->GetArchitecture()->CreateStackTrace( + fThread->GetTeam(), this, cpuState, stackTrace) == B_OK) { + stackTraceReference.SetTo(stackTrace, true); } + } - if (stackTrace != NULL) { - StackFrame* frame = stackTrace->FrameAt(0); - Image* image = frame->GetImage(); - ImageDebugInfo* info = NULL; - if (GetImageDebugInfo(image, info) != B_OK) - return false; + if (stackTrace != NULL) { + StackFrame* frame = stackTrace->FrameAt(0); + Image* image = frame->GetImage(); + ImageDebugInfo* info = NULL; + if (GetImageDebugInfo(image, info) != B_OK) + return false; - Reference(info, true); - - if (info->GetAddressSectionType( + Reference(info, true); + if (info->GetAddressSectionType( cpuState->InstructionPointer()) == ADDRESS_SECTION_TYPE_PLT) { - _SingleStepThread(cpuState->InstructionPointer()); - return true; - } + _SingleStepThread(cpuState->InstructionPointer()); + return true; } } return false; diff --git a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp index 7a3cab8b86..4477796030 100644 --- a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp +++ b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp @@ -220,7 +220,11 @@ DwarfImageDebugInfo::DwarfImageDebugInfo(const ImageInfo& imageInfo, fTypeCache(typeCache), fFile(file), fTextSegment(NULL), - fRelocationDelta(0) + fRelocationDelta(0), + fTextSectionStart(0), + fTextSectionEnd(0), + fPLTSectionStart(0), + fPLTSectionEnd(0) { fFile->AcquireReference(); fTypeCache->AcquireReference(); @@ -247,6 +251,18 @@ DwarfImageDebugInfo::Init() 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; } @@ -432,22 +448,11 @@ DwarfImageDebugInfo::GetType(GlobalTypeCache* cache, AddressSectionType DwarfImageDebugInfo::GetAddressSectionType(target_addr_t address) { - address -= fRelocationDelta; - ElfFile* file = fFile->GetElfFile(); + if (address >= fTextSectionStart && address < fTextSectionEnd) + return ADDRESS_SECTION_TYPE_FUNCTION; - ElfSection* section = file->GetSection(".text"); - if (section != NULL && address >= section->LoadAddress() - && address < section->LoadAddress() + section->Size()) { - file->PutSection(section); - return ADDRESS_SECTION_TYPE_FUNCTION; - } - - section = file->GetSection(".plt"); - if (section != NULL && address >= section->LoadAddress() - && address < section->LoadAddress() + section->Size()) { - file->PutSection(section); - return ADDRESS_SECTION_TYPE_PLT; - } + if (address >= fPLTSectionStart && address < fPLTSectionEnd) + return ADDRESS_SECTION_TYPE_PLT; return ADDRESS_SECTION_TYPE_UNKNOWN; } diff --git a/src/apps/debugger/debug_info/DwarfImageDebugInfo.h b/src/apps/debugger/debug_info/DwarfImageDebugInfo.h index 5dff7d7a03..74c49d905b 100644 --- a/src/apps/debugger/debug_info/DwarfImageDebugInfo.h +++ b/src/apps/debugger/debug_info/DwarfImageDebugInfo.h @@ -108,6 +108,10 @@ private: DwarfFile* fFile; ElfSegment* fTextSegment; target_addr_t fRelocationDelta; + target_addr_t fTextSectionStart; + target_addr_t fTextSectionEnd; + target_addr_t fPLTSectionStart; + target_addr_t fPLTSectionEnd; }; diff --git a/src/apps/debugger/elf/ElfFile.cpp b/src/apps/debugger/elf/ElfFile.cpp index efd797214d..1d84fc52f2 100644 --- a/src/apps/debugger/elf/ElfFile.cpp +++ b/src/apps/debugger/elf/ElfFile.cpp @@ -293,6 +293,19 @@ ElfFile::PutSection(ElfSection* section) } +ElfSection* +ElfFile::FindSection(const char* name) const +{ + for (SectionList::ConstIterator it = fSections.GetIterator(); + ElfSection* section = it.Next();) { + if (strcmp(section->Name(), name) == 0) + return section; + } + + return NULL; +} + + ElfSegment* ElfFile::TextSegment() const { diff --git a/src/apps/debugger/elf/ElfFile.h b/src/apps/debugger/elf/ElfFile.h index 543aa12f5e..c4e7665aa6 100644 --- a/src/apps/debugger/elf/ElfFile.h +++ b/src/apps/debugger/elf/ElfFile.h @@ -33,6 +33,7 @@ public: status_t Load(); void Unload(); + bool IsLoaded() const { return fLoadCount > 0; } private: const char* fName; @@ -79,6 +80,7 @@ public: ElfSection* GetSection(const char* name); void PutSection(ElfSection* section); + ElfSection* FindSection(const char* name) const; ElfSegment* TextSegment() const; ElfSegment* DataSegment() const;