Author: anevilyak Date: 2010-12-13 15:05:44 +0100 (Mon, 13 Dec 2010) New Revision: 39826 Changeset: http://dev.haiku-os.org/changeset/39826 Modified: haiku/trunk/src/apps/debugger/ThreadHandler.cpp haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.h haiku/trunk/src/apps/debugger/elf/ElfFile.cpp haiku/trunk/src/apps/debugger/elf/ElfFile.h Log: - More style cleanups. - Add FindSection() and IsLoaded() calls to ElfFile. - On init, cache the section start/end for the .text and .plt sections in DwarfImageDebugInfo. Use them to make the check for classifying addresses significantly cheaper. Modified: haiku/trunk/src/apps/debugger/ThreadHandler.cpp =================================================================== --- haiku/trunk/src/apps/debugger/ThreadHandler.cpp 2010-12-13 11:58:15 UTC (rev 39825) +++ haiku/trunk/src/apps/debugger/ThreadHandler.cpp 2010-12-13 14:05:44 UTC (rev 39826) @@ -590,32 +590,31 @@ if (fStepStatement->ContainsAddress(cpuState->InstructionPointer())) { _SingleStepThread(cpuState->InstructionPointer()); return true; - } else { - StackTrace* stackTrace = fThread->GetStackTrace(); - Reference<StackTrace> 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<StackTrace> 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<ImageDebugInfo>(info, true); - - if (info->GetAddressSectionType( + Reference<ImageDebugInfo>(info, true); + if (info->GetAddressSectionType( cpuState->InstructionPointer()) == ADDRESS_SECTION_TYPE_PLT) { - _SingleStepThread(cpuState->InstructionPointer()); - return true; - } + _SingleStepThread(cpuState->InstructionPointer()); + return true; } } return false; Modified: haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp =================================================================== --- haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp 2010-12-13 11:58:15 UTC (rev 39825) +++ haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp 2010-12-13 14:05:44 UTC (rev 39826) @@ -220,7 +220,11 @@ 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 @@ 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,23 +448,12 @@ 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; - } + if (address >= fPLTSectionStart && address < fPLTSectionEnd) + return ADDRESS_SECTION_TYPE_PLT; - section = file->GetSection(".plt"); - if (section != NULL && address >= section->LoadAddress() - && address < section->LoadAddress() + section->Size()) { - file->PutSection(section); - return ADDRESS_SECTION_TYPE_PLT; - } - return ADDRESS_SECTION_TYPE_UNKNOWN; } Modified: haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.h =================================================================== --- haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.h 2010-12-13 11:58:15 UTC (rev 39825) +++ haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.h 2010-12-13 14:05:44 UTC (rev 39826) @@ -108,6 +108,10 @@ DwarfFile* fFile; ElfSegment* fTextSegment; target_addr_t fRelocationDelta; + target_addr_t fTextSectionStart; + target_addr_t fTextSectionEnd; + target_addr_t fPLTSectionStart; + target_addr_t fPLTSectionEnd; }; Modified: haiku/trunk/src/apps/debugger/elf/ElfFile.cpp =================================================================== --- haiku/trunk/src/apps/debugger/elf/ElfFile.cpp 2010-12-13 11:58:15 UTC (rev 39825) +++ haiku/trunk/src/apps/debugger/elf/ElfFile.cpp 2010-12-13 14:05:44 UTC (rev 39826) @@ -293,6 +293,19 @@ } +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 { Modified: haiku/trunk/src/apps/debugger/elf/ElfFile.h =================================================================== --- haiku/trunk/src/apps/debugger/elf/ElfFile.h 2010-12-13 11:58:15 UTC (rev 39825) +++ haiku/trunk/src/apps/debugger/elf/ElfFile.h 2010-12-13 14:05:44 UTC (rev 39826) @@ -33,6 +33,7 @@ status_t Load(); void Unload(); + bool IsLoaded() const { return fLoadCount > 0; } private: const char* fName; @@ -79,6 +80,7 @@ ElfSection* GetSection(const char* name); void PutSection(ElfSection* section); + ElfSection* FindSection(const char* name) const; ElfSegment* TextSegment() const; ElfSegment* DataSegment() const;