From 671ef9b08426d9131bbea63d1ba4177c6f497d70 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 27 Jun 2009 21:09:21 +0000 Subject: [PATCH] * Some moving and renaming. * Added TeamDebugInfo which serves as factory for ImageDebugInfos. * Added the DWARF code to the build again. It's not used yet, though. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31278 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/debugger/Jamfile | 31 ++++--- src/apps/debugger/Jobs.cpp | 34 +++---- src/apps/debugger/Jobs.h | 11 +-- src/apps/debugger/TeamDebugger.cpp | 38 +++++--- src/apps/debugger/TeamDebugger.h | 2 + src/apps/debugger/ThreadHandler.cpp | 4 +- src/apps/debugger/arch/Architecture.cpp | 6 +- .../debug_info/BasicFunctionDebugInfo.cpp | 20 ++--- .../debug_info/BasicFunctionDebugInfo.h | 6 +- ...bugInfo.cpp => DebuggerImageDebugInfo.cpp} | 19 ++-- ...erDebugInfo.h => DebuggerImageDebugInfo.h} | 15 ++-- .../debug_info/DebuggerTeamDebugInfo.cpp | 52 +++++++++++ .../debug_info/DebuggerTeamDebugInfo.h | 36 ++++++++ .../debugger/debug_info/FunctionDebugInfo.h | 4 +- .../debugger/debug_info/ImageDebugInfo.cpp | 43 +++------ src/apps/debugger/debug_info/ImageDebugInfo.h | 15 ++-- .../debug_info/SpecificImageDebugInfo.cpp | 11 +++ .../{DebugInfo.h => SpecificImageDebugInfo.h} | 10 +-- ...ebugInfo.cpp => SpecificTeamDebugInfo.cpp} | 4 +- .../debug_info/SpecificTeamDebugInfo.h | 25 ++++++ .../debugger/debug_info/TeamDebugInfo.cpp | 88 +++++++++++++++++++ src/apps/debugger/debug_info/TeamDebugInfo.h | 43 +++++++++ src/apps/debugger/{ => elf}/ElfFile.cpp | 0 src/apps/debugger/{ => elf}/ElfFile.h | 0 src/apps/debugger/model/Team.cpp | 10 ++- src/apps/debugger/model/Team.h | 9 +- 26 files changed, 394 insertions(+), 142 deletions(-) rename src/apps/debugger/debug_info/{DebuggerDebugInfo.cpp => DebuggerImageDebugInfo.cpp} (81%) rename src/apps/debugger/debug_info/{DebuggerDebugInfo.h => DebuggerImageDebugInfo.h} (77%) create mode 100644 src/apps/debugger/debug_info/DebuggerTeamDebugInfo.cpp create mode 100644 src/apps/debugger/debug_info/DebuggerTeamDebugInfo.h create mode 100644 src/apps/debugger/debug_info/SpecificImageDebugInfo.cpp rename src/apps/debugger/debug_info/{DebugInfo.h => SpecificImageDebugInfo.h} (84%) rename src/apps/debugger/debug_info/{DebugInfo.cpp => SpecificTeamDebugInfo.cpp} (59%) create mode 100644 src/apps/debugger/debug_info/SpecificTeamDebugInfo.h create mode 100644 src/apps/debugger/debug_info/TeamDebugInfo.cpp create mode 100644 src/apps/debugger/debug_info/TeamDebugInfo.h rename src/apps/debugger/{ => elf}/ElfFile.cpp (100%) rename src/apps/debugger/{ => elf}/ElfFile.h (100%) diff --git a/src/apps/debugger/Jamfile b/src/apps/debugger/Jamfile index 5594501c54..9d3e369766 100644 --- a/src/apps/debugger/Jamfile +++ b/src/apps/debugger/Jamfile @@ -10,6 +10,8 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) arch ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) arch x86 ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) debug_info ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) debugger_interface ] ; +SEARCH_SOURCE += [ FDirName $(SUBDIR) dwarf ] ; +SEARCH_SOURCE += [ FDirName $(SUBDIR) elf ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) gui team_window ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) model ] ; @@ -23,7 +25,6 @@ SubDirHdrs [ FDirName $(debugAnalyzerSources) gui ] ; Application Debugger : BreakpointManager.cpp Debugger.cpp -# ElfFile.cpp Jobs.cpp TeamDebugger.cpp ThreadHandler.cpp @@ -41,16 +42,31 @@ Application Debugger : # debug_info BasicFunctionDebugInfo.cpp - DebuggerDebugInfo.cpp - DebugInfo.cpp + DebuggerImageDebugInfo.cpp + DebuggerTeamDebugInfo.cpp FunctionDebugInfo.cpp ImageDebugInfo.cpp ImageDebugInfoProvider.cpp + SpecificImageDebugInfo.cpp + SpecificTeamDebugInfo.cpp + TeamDebugInfo.cpp # debugger_interface DebugEvent.cpp DebuggerInterface.cpp + # dwarf + attribute_classes.cpp + AttributeValue.cpp + DebugInfoEntries.cpp + DebugInfoEntry.cpp + DwarfManager.cpp + SourceLanguageInfo.cpp + tag_names.cpp + + # elf + ElfFile.cpp + # gui/team_window ImageFunctionsView.cpp ImageListView.cpp @@ -76,15 +92,6 @@ Application Debugger : Thread.cpp ThreadInfo.cpp -# DWARF -# attribute_classes.cpp -# AttributeValue.cpp -# DebugInfoEntries.cpp -# DebugInfoEntry.cpp -# DwarfManager.cpp -# SourceLanguageInfo.cpp -# tag_names.cpp - : Debugger_demangler.o Debugger_disasm_x86.o diff --git a/src/apps/debugger/Jobs.cpp b/src/apps/debugger/Jobs.cpp index 878f26e419..466e2268f3 100644 --- a/src/apps/debugger/Jobs.cpp +++ b/src/apps/debugger/Jobs.cpp @@ -12,13 +12,14 @@ #include "Architecture.h" #include "CpuState.h" #include "DebuggerInterface.h" -#include "DebugInfo.h" #include "FunctionDebugInfo.h" #include "Image.h" #include "ImageDebugInfo.h" #include "SourceCode.h" +#include "SpecificImageDebugInfo.h" #include "StackTrace.h" #include "Team.h" +#include "TeamDebugInfo.h" #include "Thread.h" @@ -182,8 +183,8 @@ GetStackTraceJob::GetImageDebugInfo(Image* image, ImageDebugInfo*& _info) while (image->GetImageDebugInfo() == NULL) { // schedule a job, if not loaded ImageDebugInfo* info; - status_t error = LoadImageDebugInfoJob::ScheduleIfNecessary( - fDebuggerInterface, fArchitecture, GetWorker(), image, &info); + status_t error = LoadImageDebugInfoJob::ScheduleIfNecessary(GetWorker(), + image, &info); if (error != B_OK) return error; @@ -220,12 +221,8 @@ GetStackTraceJob::GetImageDebugInfo(Image* image, ImageDebugInfo*& _info) // #pragma mark - LoadImageDebugInfoJob -LoadImageDebugInfoJob::LoadImageDebugInfoJob( - DebuggerInterface* debuggerInterface, Architecture* architecture, - Image* image) +LoadImageDebugInfoJob::LoadImageDebugInfoJob(Image* image) : - fDebuggerInterface(debuggerInterface), - fArchitecture(architecture), fImage(image) { fImage->AddReference(); @@ -254,14 +251,9 @@ LoadImageDebugInfoJob::Do() locker.Unlock(); // create the debug info - ImageDebugInfo* debugInfo = new(std::nothrow) ImageDebugInfo(imageInfo, - fDebuggerInterface, fArchitecture); - - status_t error;; - if (debugInfo != NULL) - error = debugInfo->Init(); - else - error = B_NO_MEMORY; + ImageDebugInfo* debugInfo; + status_t error = fImage->GetTeam()->DebugInfo()->LoadImageDebugInfo( + imageInfo, debugInfo); // set the result locker.Lock(); @@ -278,8 +270,7 @@ LoadImageDebugInfoJob::Do() /*static*/ status_t -LoadImageDebugInfoJob::ScheduleIfNecessary(DebuggerInterface* debuggerInterface, - Architecture* architecture, Worker* worker, Image* image, +LoadImageDebugInfoJob::ScheduleIfNecessary(Worker* worker, Image* image, ImageDebugInfo** _imageDebugInfo) { AutoLocker teamLocker(image->GetTeam()); @@ -305,8 +296,7 @@ LoadImageDebugInfoJob::ScheduleIfNecessary(DebuggerInterface* debuggerInterface, return B_ERROR; // schedule a job - LoadImageDebugInfoJob* job = new(std::nothrow) LoadImageDebugInfoJob( - debuggerInterface, architecture, image); + LoadImageDebugInfoJob* job = new(std::nothrow) LoadImageDebugInfoJob(image); if (job == NULL) return B_NO_MEMORY; @@ -358,8 +348,8 @@ LoadSourceCodeJob::Do() { // load the source code, if we can SourceCode* sourceCode = NULL; - status_t error = fFunction->GetDebugInfo()->LoadSourceCode(fFunction, - sourceCode); + status_t error = fFunction->GetSpecificImageDebugInfo()->LoadSourceCode( + fFunction, sourceCode); // set the result AutoLocker locker(fTeam); diff --git a/src/apps/debugger/Jobs.h b/src/apps/debugger/Jobs.h index d268b69735..ce9e270323 100644 --- a/src/apps/debugger/Jobs.h +++ b/src/apps/debugger/Jobs.h @@ -86,18 +86,13 @@ private: class LoadImageDebugInfoJob : public Job { public: - LoadImageDebugInfoJob( - DebuggerInterface* debuggerInterface, - Architecture* architecture, - Image* image); + LoadImageDebugInfoJob(Image* image); virtual ~LoadImageDebugInfoJob(); virtual JobKey Key() const; virtual status_t Do(); - static status_t ScheduleIfNecessary( - DebuggerInterface* debuggerInterface, - Architecture* architecture, Worker* worker, + static status_t ScheduleIfNecessary(Worker* worker, Image* image, ImageDebugInfo** _imageDebugInfo = NULL); // If already loaded returns a @@ -109,8 +104,6 @@ public: // earlier. private: - DebuggerInterface* fDebuggerInterface; - Architecture* fArchitecture; Image* fImage; }; diff --git a/src/apps/debugger/TeamDebugger.cpp b/src/apps/debugger/TeamDebugger.cpp index 6398d786dd..d16ff5153d 100644 --- a/src/apps/debugger/TeamDebugger.cpp +++ b/src/apps/debugger/TeamDebugger.cpp @@ -23,6 +23,7 @@ #include "Jobs.h" #include "MessageCodes.h" #include "Statement.h" +#include "TeamDebugInfo.h" #include "TeamDebugModel.h" @@ -91,14 +92,35 @@ TeamDebugger::Init(team_id teamID, thread_id threadID, bool stopInMain) { fTeamID = teamID; + // create debugger interface + fDebuggerInterface = new(std::nothrow) DebuggerInterface(fTeamID); + if (fDebuggerInterface == NULL) + return B_NO_MEMORY; + + status_t error = fDebuggerInterface->Init(); + if (error != B_OK) + return error; + + // create team debug info + TeamDebugInfo* teamDebugInfo = new(std::nothrow) TeamDebugInfo( + fDebuggerInterface, fDebuggerInterface->GetArchitecture()); + if (teamDebugInfo == NULL) + return B_NO_MEMORY; + Reference teamDebugInfoReference(teamDebugInfo); + + error = teamDebugInfo->Init(); + if (error != B_OK) + return error; + // check whether the team exists at all + // TODO: That should be done in the debugger interface! team_info teamInfo; - status_t error = get_team_info(fTeamID, &teamInfo); + error = get_team_info(fTeamID, &teamInfo); if (error != B_OK) return error; // create a team object - fTeam = new(std::nothrow) ::Team(fTeamID); + fTeam = new(std::nothrow) ::Team(fTeamID, teamDebugInfo); if (fTeam == NULL) return B_NO_MEMORY; @@ -124,15 +146,6 @@ TeamDebugger::Init(team_id teamID, thread_id threadID, bool stopInMain) if (error != B_OK) return error; - // create debugger interface - fDebuggerInterface = new(std::nothrow) DebuggerInterface(fTeamID); - if (fDebuggerInterface == NULL) - return B_NO_MEMORY; - - error = fDebuggerInterface->Init(); - if (error != B_OK) - return error; - // create the team debug model fDebugModel = new(std::nothrow) TeamDebugModel(fTeam, fDebuggerInterface, fDebuggerInterface->GetArchitecture()); @@ -351,8 +364,7 @@ TeamDebugger::FunctionSourceCodeRequested(TeamWindow* window, void TeamDebugger::ImageDebugInfoRequested(TeamWindow* window, Image* image) { - LoadImageDebugInfoJob::ScheduleIfNecessary(fDebuggerInterface, - fDebuggerInterface->GetArchitecture(), fWorker, image); + LoadImageDebugInfoJob::ScheduleIfNecessary(fWorker, image); } diff --git a/src/apps/debugger/TeamDebugger.h b/src/apps/debugger/TeamDebugger.h index b1ae083e12..353be20a8c 100644 --- a/src/apps/debugger/TeamDebugger.h +++ b/src/apps/debugger/TeamDebugger.h @@ -18,6 +18,7 @@ class DebuggerInterface; +class TeamDebugInfo; class TeamDebugModel; @@ -97,6 +98,7 @@ private: ThreadHandlerTable fThreadHandlers; // protected by the team lock DebuggerInterface* fDebuggerInterface; + TeamDebugInfo* fTeamDebugInfo; Worker* fWorker; BreakpointManager* fBreakpointManager; thread_id fDebugEventListener; diff --git a/src/apps/debugger/ThreadHandler.cpp b/src/apps/debugger/ThreadHandler.cpp index 641b90a143..7093ae4ea8 100644 --- a/src/apps/debugger/ThreadHandler.cpp +++ b/src/apps/debugger/ThreadHandler.cpp @@ -15,13 +15,13 @@ #include "BreakpointManager.h" #include "CpuState.h" #include "DebuggerInterface.h" -#include "DebugInfo.h" #include "FunctionDebugInfo.h" #include "ImageDebugInfo.h" #include "InstructionInfo.h" #include "Jobs.h" #include "MessageCodes.h" #include "SourceCode.h" +#include "SpecificImageDebugInfo.h" #include "StackTrace.h" #include "Statement.h" #include "Team.h" @@ -381,7 +381,7 @@ ThreadHandler::_GetStatementAtInstructionPointer(StackFrame* frame) // We need to get the statement from the debug info of the function. Statement* statement; - if (function->GetDebugInfo()->GetStatement(function, + if (function->GetSpecificImageDebugInfo()->GetStatement(function, frame->InstructionPointer(), statement) != B_OK) { return NULL; } diff --git a/src/apps/debugger/arch/Architecture.cpp b/src/apps/debugger/arch/Architecture.cpp index 5ed743a0d7..a7a8f14ddd 100644 --- a/src/apps/debugger/arch/Architecture.cpp +++ b/src/apps/debugger/arch/Architecture.cpp @@ -11,11 +11,11 @@ #include #include "CpuState.h" -#include "DebugInfo.h" #include "FunctionDebugInfo.h" #include "Image.h" #include "ImageDebugInfo.h" #include "ImageDebugInfoProvider.h" +#include "SpecificImageDebugInfo.h" #include "StackTrace.h" #include "Team.h" @@ -90,8 +90,8 @@ Architecture::CreateStackTrace(Team* team, StackFrame* previousFrame = NULL; CpuState* previousCpuState = NULL; if (function != NULL) { - status_t error = function->GetDebugInfo()->CreateFrame(image, - function, cpuState, previousFrame, previousCpuState); + status_t error = function->GetSpecificImageDebugInfo()->CreateFrame( + image, function, cpuState, previousFrame, previousCpuState); if (error != B_OK && error != B_UNSUPPORTED) break; } diff --git a/src/apps/debugger/debug_info/BasicFunctionDebugInfo.cpp b/src/apps/debugger/debug_info/BasicFunctionDebugInfo.cpp index 3de6b06629..0818347c81 100644 --- a/src/apps/debugger/debug_info/BasicFunctionDebugInfo.cpp +++ b/src/apps/debugger/debug_info/BasicFunctionDebugInfo.cpp @@ -5,33 +5,33 @@ #include "BasicFunctionDebugInfo.h" -#include "DebugInfo.h" +#include "SpecificImageDebugInfo.h" -BasicFunctionDebugInfo::BasicFunctionDebugInfo(DebugInfo* debugInfo, - target_addr_t address, target_size_t size, const BString& name, - const BString& prettyName) +BasicFunctionDebugInfo::BasicFunctionDebugInfo( + SpecificImageDebugInfo* debugInfo, target_addr_t address, + target_size_t size, const BString& name, const BString& prettyName) : - fDebugInfo(debugInfo), + fImageDebugInfo(debugInfo), fAddress(address), fSize(size), fName(name), fPrettyName(prettyName) { - fDebugInfo->AddReference(); + fImageDebugInfo->AddReference(); } BasicFunctionDebugInfo::~BasicFunctionDebugInfo() { - fDebugInfo->RemoveReference(); + fImageDebugInfo->RemoveReference(); } -DebugInfo* -BasicFunctionDebugInfo::GetDebugInfo() const +SpecificImageDebugInfo* +BasicFunctionDebugInfo::GetSpecificImageDebugInfo() const { - return fDebugInfo; + return fImageDebugInfo; } diff --git a/src/apps/debugger/debug_info/BasicFunctionDebugInfo.h b/src/apps/debugger/debug_info/BasicFunctionDebugInfo.h index ec4e915e15..3c574b1757 100644 --- a/src/apps/debugger/debug_info/BasicFunctionDebugInfo.h +++ b/src/apps/debugger/debug_info/BasicFunctionDebugInfo.h @@ -13,14 +13,14 @@ class BasicFunctionDebugInfo : public FunctionDebugInfo { public: BasicFunctionDebugInfo( - DebugInfo* debugInfo, + SpecificImageDebugInfo* imageDebugInfo, target_addr_t address, target_size_t size, const BString& name, const BString& prettyName); virtual ~BasicFunctionDebugInfo(); - virtual DebugInfo* GetDebugInfo() const; + virtual SpecificImageDebugInfo* GetSpecificImageDebugInfo() const; virtual target_addr_t Address() const; virtual target_size_t Size() const; virtual const char* Name() const; @@ -31,7 +31,7 @@ public: virtual SourceLocation SourceEndLocation() const; private: - DebugInfo* fDebugInfo; + SpecificImageDebugInfo* fImageDebugInfo; target_addr_t fAddress; target_size_t fSize; const BString fName; diff --git a/src/apps/debugger/debug_info/DebuggerDebugInfo.cpp b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp similarity index 81% rename from src/apps/debugger/debug_info/DebuggerDebugInfo.cpp rename to src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp index 387f16cb7d..17dc3ba1c1 100644 --- a/src/apps/debugger/debug_info/DebuggerDebugInfo.cpp +++ b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp @@ -3,7 +3,7 @@ * Distributed under the terms of the MIT License. */ -#include "DebuggerDebugInfo.h" +#include "DebuggerImageDebugInfo.h" #include #include @@ -17,7 +17,7 @@ #include "SymbolInfo.h" -DebuggerDebugInfo::DebuggerDebugInfo(const ImageInfo& imageInfo, +DebuggerImageDebugInfo::DebuggerImageDebugInfo(const ImageInfo& imageInfo, DebuggerInterface* debuggerInterface, Architecture* architecture) : fImageInfo(imageInfo), @@ -27,20 +27,20 @@ DebuggerDebugInfo::DebuggerDebugInfo(const ImageInfo& imageInfo, } -DebuggerDebugInfo::~DebuggerDebugInfo() +DebuggerImageDebugInfo::~DebuggerImageDebugInfo() { } status_t -DebuggerDebugInfo::Init() +DebuggerImageDebugInfo::Init() { return B_OK; } status_t -DebuggerDebugInfo::GetFunctions(BObjectList& functions) +DebuggerImageDebugInfo::GetFunctions(BObjectList& functions) { BObjectList symbols(20, true); status_t error = fDebuggerInterface->GetSymbolInfos(fImageInfo.TeamID(), @@ -79,7 +79,7 @@ DebuggerDebugInfo::GetFunctions(BObjectList& functions) status_t -DebuggerDebugInfo::CreateFrame(Image* image, FunctionDebugInfo* function, +DebuggerImageDebugInfo::CreateFrame(Image* image, FunctionDebugInfo* function, CpuState* cpuState, StackFrame*& _previousFrame, CpuState*& _previousCpuState) { @@ -88,7 +88,7 @@ DebuggerDebugInfo::CreateFrame(Image* image, FunctionDebugInfo* function, status_t -DebuggerDebugInfo::LoadSourceCode(FunctionDebugInfo* function, +DebuggerImageDebugInfo::LoadSourceCode(FunctionDebugInfo* function, SourceCode*& _sourceCode) { // allocate a buffer for the function code @@ -111,7 +111,7 @@ DebuggerDebugInfo::LoadSourceCode(FunctionDebugInfo* function, status_t -DebuggerDebugInfo::GetStatement(FunctionDebugInfo* function, +DebuggerImageDebugInfo::GetStatement(FunctionDebugInfo* function, target_addr_t address, Statement*& _statement) { return fArchitecture->GetStatement(function, address, _statement); @@ -119,7 +119,8 @@ DebuggerDebugInfo::GetStatement(FunctionDebugInfo* function, /*static*/ int -DebuggerDebugInfo::_CompareSymbols(const SymbolInfo* a, const SymbolInfo* b) +DebuggerImageDebugInfo::_CompareSymbols(const SymbolInfo* a, + const SymbolInfo* b) { return a->Address() < b->Address() ? -1 : (a->Address() == b->Address() ? 0 : 1); diff --git a/src/apps/debugger/debug_info/DebuggerDebugInfo.h b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h similarity index 77% rename from src/apps/debugger/debug_info/DebuggerDebugInfo.h rename to src/apps/debugger/debug_info/DebuggerImageDebugInfo.h index a74f17f27d..b484633291 100644 --- a/src/apps/debugger/debug_info/DebuggerDebugInfo.h +++ b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h @@ -2,13 +2,13 @@ * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. * Distributed under the terms of the MIT License. */ -#ifndef DEBUGGER_DEBUG_INFO_H -#define DEBUGGER_DEBUG_INFO_H +#ifndef DEBUGGER_IMAGE_DEBUG_INFO_H +#define DEBUGGER_IMAGE_DEBUG_INFO_H #include -#include "DebugInfo.h" #include "ImageInfo.h" +#include "SpecificImageDebugInfo.h" class Architecture; @@ -17,12 +17,13 @@ class FunctionDebugInfo; class SymbolInfo; -class DebuggerDebugInfo : public DebugInfo { +class DebuggerImageDebugInfo : public SpecificImageDebugInfo { public: - DebuggerDebugInfo(const ImageInfo& imageInfo, + DebuggerImageDebugInfo( + const ImageInfo& imageInfo, DebuggerInterface* debuggerInterface, Architecture* architecture); - virtual ~DebuggerDebugInfo(); + virtual ~DebuggerImageDebugInfo(); status_t Init(); @@ -50,4 +51,4 @@ private: }; -#endif // DEBUGGER_DEBUG_INFO_H +#endif // DEBUGGER_IMAGE_DEBUG_INFO_H diff --git a/src/apps/debugger/debug_info/DebuggerTeamDebugInfo.cpp b/src/apps/debugger/debug_info/DebuggerTeamDebugInfo.cpp new file mode 100644 index 0000000000..40ef0cc1de --- /dev/null +++ b/src/apps/debugger/debug_info/DebuggerTeamDebugInfo.cpp @@ -0,0 +1,52 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include "DebuggerTeamDebugInfo.h" + +#include + +#include "DebuggerImageDebugInfo.h" + + +DebuggerTeamDebugInfo::DebuggerTeamDebugInfo( + DebuggerInterface* debuggerInterface, Architecture* architecture) + : + fDebuggerInterface(debuggerInterface), + fArchitecture(architecture) +{ +} + + +DebuggerTeamDebugInfo::~DebuggerTeamDebugInfo() +{ +} + + +status_t +DebuggerTeamDebugInfo::Init() +{ + return B_OK; +} + + +status_t +DebuggerTeamDebugInfo::CreateImageDebugInfo(const ImageInfo& imageInfo, + SpecificImageDebugInfo*& _imageDebugInfo) +{ + DebuggerImageDebugInfo* debuggerInfo + = new(std::nothrow) DebuggerImageDebugInfo(imageInfo, + fDebuggerInterface, fArchitecture); + if (debuggerInfo == NULL) + return B_NO_MEMORY; + + status_t error = debuggerInfo->Init(); + if (error != B_OK) { + delete debuggerInfo; + return error; + } + + _imageDebugInfo = debuggerInfo; + return B_OK; +} diff --git a/src/apps/debugger/debug_info/DebuggerTeamDebugInfo.h b/src/apps/debugger/debug_info/DebuggerTeamDebugInfo.h new file mode 100644 index 0000000000..6673984eb8 --- /dev/null +++ b/src/apps/debugger/debug_info/DebuggerTeamDebugInfo.h @@ -0,0 +1,36 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef DEBUGGER_TEAM_DEBUG_INFO_H +#define DEBUGGER_TEAM_DEBUG_INFO_H + +#include "SpecificTeamDebugInfo.h" + + +class Architecture; +class DebuggerInterface; +class FunctionDebugInfo; +class ImageInfo; + + +class DebuggerTeamDebugInfo : public SpecificTeamDebugInfo { +public: + DebuggerTeamDebugInfo( + DebuggerInterface* debuggerInterface, + Architecture* architecture); + virtual ~DebuggerTeamDebugInfo(); + + status_t Init(); + + virtual status_t CreateImageDebugInfo(const ImageInfo& imageInfo, + SpecificImageDebugInfo*& _imageDebugInfo); + + +private: + DebuggerInterface* fDebuggerInterface; + Architecture* fArchitecture; +}; + + +#endif // DEBUGGER_TEAM_DEBUG_INFO_H diff --git a/src/apps/debugger/debug_info/FunctionDebugInfo.h b/src/apps/debugger/debug_info/FunctionDebugInfo.h index ff9c18fc8c..8204ebf440 100644 --- a/src/apps/debugger/debug_info/FunctionDebugInfo.h +++ b/src/apps/debugger/debug_info/FunctionDebugInfo.h @@ -20,8 +20,8 @@ enum function_source_state { }; -class DebugInfo; class SourceCode; +class SpecificImageDebugInfo; class FunctionDebugInfo : public Referenceable { @@ -32,7 +32,7 @@ public: FunctionDebugInfo(); virtual ~FunctionDebugInfo(); - virtual DebugInfo* GetDebugInfo() const = 0; + virtual SpecificImageDebugInfo* GetSpecificImageDebugInfo() const = 0; virtual target_addr_t Address() const = 0; virtual target_size_t Size() const = 0; virtual const char* Name() const = 0; diff --git a/src/apps/debugger/debug_info/ImageDebugInfo.cpp b/src/apps/debugger/debug_info/ImageDebugInfo.cpp index 5713358411..27050c0fce 100644 --- a/src/apps/debugger/debug_info/ImageDebugInfo.cpp +++ b/src/apps/debugger/debug_info/ImageDebugInfo.cpp @@ -7,16 +7,13 @@ #include -#include "DebuggerDebugInfo.h" #include "FunctionDebugInfo.h" +#include "SpecificImageDebugInfo.h" -ImageDebugInfo::ImageDebugInfo(const ImageInfo& imageInfo, - DebuggerInterface* debuggerInterface, Architecture* architecture) +ImageDebugInfo::ImageDebugInfo(const ImageInfo& imageInfo) : - fImageInfo(imageInfo), - fDebuggerInterface(debuggerInterface), - fArchitecture(architecture) + fImageInfo(imageInfo) { } @@ -28,36 +25,22 @@ ImageDebugInfo::~ImageDebugInfo() } -status_t -ImageDebugInfo::Init() +bool +ImageDebugInfo::AddSpecificInfo(SpecificImageDebugInfo* info) { - // Create debug infos for every kind debug info available, sorted - // descendingly by expressiveness. + return fSpecificInfos.AddItem(info); +} - // TODO: DWARF, etc. - - // debugger based info - DebuggerDebugInfo* debuggerDebugInfo = new(std::nothrow) DebuggerDebugInfo( - fImageInfo, fDebuggerInterface, fArchitecture); - if (debuggerDebugInfo == NULL) - return B_NO_MEMORY; - - status_t error = debuggerDebugInfo->Init(); - if (error == B_OK && !fDebugInfos.AddItem(debuggerDebugInfo)) - error = B_NO_MEMORY; - - if (error != B_OK) { - delete debuggerDebugInfo; - if (error == B_NO_MEMORY) - return error; - // only "no memory" is fatal - } +status_t +ImageDebugInfo::FinishInit() +{ // get functions -- get them from most expressive debug info first and add // missing functions from less expressive debug infos - for (int32 i = 0; DebugInfo* debugInfo = fDebugInfos.ItemAt(i); i++) { + for (int32 i = 0; SpecificImageDebugInfo* specificInfo + = fSpecificInfos.ItemAt(i); i++) { FunctionList functions; - status_t error = debugInfo->GetFunctions(functions); + status_t error = specificInfo->GetFunctions(functions); if (error != B_OK) return error; diff --git a/src/apps/debugger/debug_info/ImageDebugInfo.h b/src/apps/debugger/debug_info/ImageDebugInfo.h index ff8d3b6531..42616029a3 100644 --- a/src/apps/debugger/debug_info/ImageDebugInfo.h +++ b/src/apps/debugger/debug_info/ImageDebugInfo.h @@ -16,25 +16,24 @@ class Architecture; class DebuggerInterface; -class DebugInfo; class FunctionDebugInfo; +class SpecificImageDebugInfo; class ImageDebugInfo : public Referenceable { public: - ImageDebugInfo(const ImageInfo& imageInfo, - DebuggerInterface* debuggerInterface, - Architecture* architecture); + ImageDebugInfo(const ImageInfo& imageInfo), ~ImageDebugInfo(); - status_t Init(); + bool AddSpecificInfo(SpecificImageDebugInfo* info); + status_t FinishInit(); int32 CountFunctions() const; FunctionDebugInfo* FunctionAt(int32 index) const; FunctionDebugInfo* FunctionAtAddress(target_addr_t address) const; private: - typedef BObjectList DebugInfoList; + typedef BObjectList SpecificInfoList; typedef BObjectList FunctionList; private: @@ -46,9 +45,7 @@ private: private: ImageInfo fImageInfo; - DebuggerInterface* fDebuggerInterface; - Architecture* fArchitecture; - DebugInfoList fDebugInfos; + SpecificInfoList fSpecificInfos; FunctionList fFunctions; }; diff --git a/src/apps/debugger/debug_info/SpecificImageDebugInfo.cpp b/src/apps/debugger/debug_info/SpecificImageDebugInfo.cpp new file mode 100644 index 0000000000..ef402cdf40 --- /dev/null +++ b/src/apps/debugger/debug_info/SpecificImageDebugInfo.cpp @@ -0,0 +1,11 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include "SpecificImageDebugInfo.h" + + +SpecificImageDebugInfo::~SpecificImageDebugInfo() +{ +} diff --git a/src/apps/debugger/debug_info/DebugInfo.h b/src/apps/debugger/debug_info/SpecificImageDebugInfo.h similarity index 84% rename from src/apps/debugger/debug_info/DebugInfo.h rename to src/apps/debugger/debug_info/SpecificImageDebugInfo.h index 73af62c001..863acbfacf 100644 --- a/src/apps/debugger/debug_info/DebugInfo.h +++ b/src/apps/debugger/debug_info/SpecificImageDebugInfo.h @@ -2,8 +2,8 @@ * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. * Distributed under the terms of the MIT License. */ -#ifndef DEBUG_INFO_H -#define DEBUG_INFO_H +#ifndef SPECIFIC_IMAGE_DEBUG_INFO_H +#define SPECIFIC_IMAGE_DEBUG_INFO_H #include #include @@ -21,9 +21,9 @@ class StackFrame; class Statement; -class DebugInfo : public Referenceable { +class SpecificImageDebugInfo : public Referenceable { public: - virtual ~DebugInfo(); + virtual ~SpecificImageDebugInfo(); virtual status_t GetFunctions( BObjectList& functions) @@ -48,4 +48,4 @@ public: }; -#endif // DEBUG_INFO_H +#endif // SPECIFIC_IMAGE_DEBUG_INFO_H diff --git a/src/apps/debugger/debug_info/DebugInfo.cpp b/src/apps/debugger/debug_info/SpecificTeamDebugInfo.cpp similarity index 59% rename from src/apps/debugger/debug_info/DebugInfo.cpp rename to src/apps/debugger/debug_info/SpecificTeamDebugInfo.cpp index 91cf5974da..f70c5af790 100644 --- a/src/apps/debugger/debug_info/DebugInfo.cpp +++ b/src/apps/debugger/debug_info/SpecificTeamDebugInfo.cpp @@ -3,9 +3,9 @@ * Distributed under the terms of the MIT License. */ -#include "DebugInfo.h" +#include "SpecificTeamDebugInfo.h" -DebugInfo::~DebugInfo() +SpecificTeamDebugInfo::~SpecificTeamDebugInfo() { } diff --git a/src/apps/debugger/debug_info/SpecificTeamDebugInfo.h b/src/apps/debugger/debug_info/SpecificTeamDebugInfo.h new file mode 100644 index 0000000000..59f2755e93 --- /dev/null +++ b/src/apps/debugger/debug_info/SpecificTeamDebugInfo.h @@ -0,0 +1,25 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef SPECIFIC_TEAM_DEBUG_INFO_H +#define SPECIFIC_TEAM_DEBUG_INFO_H + +#include + + +class ImageInfo; +class SpecificImageDebugInfo; + + +class SpecificTeamDebugInfo { +public: + virtual ~SpecificTeamDebugInfo(); + + virtual status_t CreateImageDebugInfo(const ImageInfo& imageInfo, + SpecificImageDebugInfo*& _imageDebugInfo) + = 0; +}; + + +#endif // SPECIFIC_TEAM_DEBUG_INFO_H diff --git a/src/apps/debugger/debug_info/TeamDebugInfo.cpp b/src/apps/debugger/debug_info/TeamDebugInfo.cpp new file mode 100644 index 0000000000..83aa771f9a --- /dev/null +++ b/src/apps/debugger/debug_info/TeamDebugInfo.cpp @@ -0,0 +1,88 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include "TeamDebugInfo.h" + +#include + +#include + +#include "DebuggerTeamDebugInfo.h" +#include "ImageDebugInfo.h" +#include "SpecificImageDebugInfo.h" + + +TeamDebugInfo::TeamDebugInfo(DebuggerInterface* debuggerInterface, + Architecture* architecture) + : + fDebuggerInterface(debuggerInterface), + fArchitecture(architecture), + fSpecificInfos(10, true) +{ +} + + +TeamDebugInfo::~TeamDebugInfo() +{ +} + + +status_t +TeamDebugInfo::Init() +{ + // create specific infos for all types of debug info we support + + // DWARF + // TODO:... + + // debugger based info + DebuggerTeamDebugInfo* debuggerInfo + = new(std::nothrow) DebuggerTeamDebugInfo(fDebuggerInterface, + fArchitecture); + if (debuggerInfo == NULL || !fSpecificInfos.AddItem(debuggerInfo)) { + delete debuggerInfo; + return B_NO_MEMORY; + } + + status_t error = debuggerInfo->Init(); + if (error != B_OK) + return error; + + return B_OK; +} + + +status_t +TeamDebugInfo::LoadImageDebugInfo(const ImageInfo& imageInfo, + ImageDebugInfo*& _imageDebugInfo) +{ + ImageDebugInfo* imageDebugInfo = new(std::nothrow) ImageDebugInfo( + imageInfo); + if (imageDebugInfo == NULL) + return B_NO_MEMORY; + ObjectDeleter imageDebugInfoDeleter(imageDebugInfo); + + for (int32 i = 0; SpecificTeamDebugInfo* specificTeamInfo + = fSpecificInfos.ItemAt(i); i++) { + SpecificImageDebugInfo* specificImageInfo; + status_t error = specificTeamInfo->CreateImageDebugInfo(imageInfo, + specificImageInfo); + if (error == B_OK) { + if (!imageDebugInfo->AddSpecificInfo(specificImageInfo)) { + delete specificImageInfo; + return B_NO_MEMORY; + } + } else if (error == B_NO_MEMORY) + return error; + // fail only when out of memory + } + + status_t error = imageDebugInfo->FinishInit(); + if (error != B_OK) + return error; + + _imageDebugInfo = imageDebugInfoDeleter.Detach(); + return B_OK; +} diff --git a/src/apps/debugger/debug_info/TeamDebugInfo.h b/src/apps/debugger/debug_info/TeamDebugInfo.h new file mode 100644 index 0000000000..bdc3e28803 --- /dev/null +++ b/src/apps/debugger/debug_info/TeamDebugInfo.h @@ -0,0 +1,43 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef TEAM_DEBUG_INFO_H +#define TEAM_DEBUG_INFO_H + +#include +#include + +#include "ImageInfo.h" + + +class Architecture; +class DebuggerInterface; +class ImageDebugInfo; +class ImageInfo; +class SpecificTeamDebugInfo; + + +class TeamDebugInfo : public Referenceable { +public: + TeamDebugInfo( + DebuggerInterface* debuggerInterface, + Architecture* architecture); + ~TeamDebugInfo(); + + status_t Init(); + + status_t LoadImageDebugInfo(const ImageInfo& imageInfo, + ImageDebugInfo*& _imageDebugInfo); + +private: + typedef BObjectList SpecificInfoList; + +private: + DebuggerInterface* fDebuggerInterface; + Architecture* fArchitecture; + SpecificInfoList fSpecificInfos; +}; + + +#endif // TEAM_DEBUG_INFO_H diff --git a/src/apps/debugger/ElfFile.cpp b/src/apps/debugger/elf/ElfFile.cpp similarity index 100% rename from src/apps/debugger/ElfFile.cpp rename to src/apps/debugger/elf/ElfFile.cpp diff --git a/src/apps/debugger/ElfFile.h b/src/apps/debugger/elf/ElfFile.h similarity index 100% rename from src/apps/debugger/ElfFile.h rename to src/apps/debugger/elf/ElfFile.h diff --git a/src/apps/debugger/model/Team.cpp b/src/apps/debugger/model/Team.cpp index d0c46ae670..dc519d869e 100644 --- a/src/apps/debugger/model/Team.cpp +++ b/src/apps/debugger/model/Team.cpp @@ -9,14 +9,18 @@ #include +#include "TeamDebugInfo.h" + // #pragma mark - Team -Team::Team(team_id teamID) +Team::Team(team_id teamID, TeamDebugInfo* debugInfo) : - fID(teamID) + fID(teamID), + fDebugInfo(debugInfo) { + fDebugInfo->AddReference(); } @@ -27,6 +31,8 @@ Team::~Team() while (Thread* thread = fThreads.RemoveHead()) thread->RemoveReference(); + + fDebugInfo->RemoveReference(); } diff --git a/src/apps/debugger/model/Team.h b/src/apps/debugger/model/Team.h index 85419c12e7..5cc1736552 100644 --- a/src/apps/debugger/model/Team.h +++ b/src/apps/debugger/model/Team.h @@ -28,6 +28,9 @@ enum { }; +class TeamDebugInfo; + + class Team : public BLocker { public: class Event; @@ -36,12 +39,13 @@ public: class Listener; public: - Team(team_id teamID); + Team(team_id teamID, TeamDebugInfo* debugInfo); ~Team(); status_t Init(); - team_id ID() const { return fID; } + team_id ID() const { return fID; } + TeamDebugInfo* DebugInfo() const { return fDebugInfo; } const char* Name() const { return fName.String(); } void SetName(const BString& name); @@ -85,6 +89,7 @@ private: private: team_id fID; + TeamDebugInfo* fDebugInfo; BString fName; ThreadList fThreads; ImageList fImages;