From b5713f228a44503ecb89ae98d327d93b8d4ea558 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 27 Jun 2009 23:40:32 +0000 Subject: [PATCH] Added DwarfTeamDebugInfo and DwarfImageDebugInfo, the classes to interface with the DWARF code. Not doing much yet. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31284 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/debugger/Jamfile | 8 ++ .../debug_info/DwarfImageDebugInfo.cpp | 96 +++++++++++++++++++ .../debugger/debug_info/DwarfImageDebugInfo.h | 45 +++++++++ .../debug_info/DwarfTeamDebugInfo.cpp | 75 +++++++++++++++ .../debugger/debug_info/DwarfTeamDebugInfo.h | 32 +++++++ .../debugger/debug_info/TeamDebugInfo.cpp | 17 +++- 6 files changed, 270 insertions(+), 3 deletions(-) create mode 100644 src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp create mode 100644 src/apps/debugger/debug_info/DwarfImageDebugInfo.h create mode 100644 src/apps/debugger/debug_info/DwarfTeamDebugInfo.cpp create mode 100644 src/apps/debugger/debug_info/DwarfTeamDebugInfo.h diff --git a/src/apps/debugger/Jamfile b/src/apps/debugger/Jamfile index 1a3a95a819..1b582a1333 100644 --- a/src/apps/debugger/Jamfile +++ b/src/apps/debugger/Jamfile @@ -21,6 +21,12 @@ SubDirHdrs [ FDirName $(SUBDIR) demangler ] ; SubDirHdrs [ FDirName $(HAIKU_TOP) src bin debug ] ; SubDirHdrs [ FDirName $(debugAnalyzerSources) gui ] ; +SourceHdrs + DwarfImageDebugInfo.cpp + DwarfTeamDebugInfo.cpp + : [ FDirName $(SUBDIR) dwarf ] +; + Application Debugger : BreakpointManager.cpp Debugger.cpp @@ -43,6 +49,8 @@ Application Debugger : BasicFunctionDebugInfo.cpp DebuggerImageDebugInfo.cpp DebuggerTeamDebugInfo.cpp + DwarfImageDebugInfo.cpp + DwarfTeamDebugInfo.cpp FunctionDebugInfo.cpp ImageDebugInfo.cpp ImageDebugInfoProvider.cpp diff --git a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp new file mode 100644 index 0000000000..76b36632cb --- /dev/null +++ b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp @@ -0,0 +1,96 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include "DwarfImageDebugInfo.h" + +#include + +#include + +#include + +#include "Architecture.h" +#include "CompilationUnit.h" +#include "DebugInfoEntries.h" +#include "Dwarf.h" +#include "DwarfFile.h" + + +DwarfImageDebugInfo::DwarfImageDebugInfo(const ImageInfo& imageInfo, + Architecture* architecture, DwarfFile* file) + : + fImageInfo(imageInfo), + fArchitecture(architecture), + fFile(file) +{ +} + + +DwarfImageDebugInfo::~DwarfImageDebugInfo() +{ +} + + +status_t +DwarfImageDebugInfo::Init() +{ + return B_OK; +} + + +status_t +DwarfImageDebugInfo::GetFunctions(BObjectList& functions) +{ +printf("DwarfImageDebugInfo::GetFunctions()\n"); +printf(" %ld compilation units\n", fFile->CountCompilationUnits()); + + for (int32 i = 0; CompilationUnit* unit = fFile->CompilationUnitAt(i); + i++) { + printf(" %s:\n", unit->UnitEntry()->Name()); + + for (DebugInfoEntryList::ConstIterator it + = unit->UnitEntry()->OtherChildren().GetIterator(); + DebugInfoEntry* entry = it.Next();) { + if (entry->Tag() != DW_TAG_subprogram) + continue; + + DIESubprogram* subprogramEntry = static_cast(entry); + printf(" subprogram entry: %p, name: %s, declaration: %d\n", + subprogramEntry, subprogramEntry->Name(), + subprogramEntry->IsDeclaration()); + } + } + + // TODO:... + return B_OK; +} + + +status_t +DwarfImageDebugInfo::CreateFrame(Image* image, FunctionDebugInfo* function, + CpuState* cpuState, StackFrame*& _previousFrame, + CpuState*& _previousCpuState) +{ + // TODO:... + return B_UNSUPPORTED; +} + + +status_t +DwarfImageDebugInfo::LoadSourceCode(FunctionDebugInfo* function, + SourceCode*& _sourceCode) +{ + // TODO:... + return B_UNSUPPORTED; +} + + +status_t +DwarfImageDebugInfo::GetStatement(FunctionDebugInfo* function, + target_addr_t address, Statement*& _statement) +{ + // TODO:... + return fArchitecture->GetStatement(function, address, _statement); +} diff --git a/src/apps/debugger/debug_info/DwarfImageDebugInfo.h b/src/apps/debugger/debug_info/DwarfImageDebugInfo.h new file mode 100644 index 0000000000..4f944302aa --- /dev/null +++ b/src/apps/debugger/debug_info/DwarfImageDebugInfo.h @@ -0,0 +1,45 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef DWARF_IMAGE_DEBUG_INFO_H +#define DWARF_IMAGE_DEBUG_INFO_H + +#include "ImageInfo.h" +#include "SpecificImageDebugInfo.h" + + +class Architecture; +class DwarfFile; + + +class DwarfImageDebugInfo : public SpecificImageDebugInfo { +public: + DwarfImageDebugInfo(const ImageInfo& imageInfo, + Architecture* architecture, + DwarfFile* file); + virtual ~DwarfImageDebugInfo(); + + status_t Init(); + + virtual status_t GetFunctions( + BObjectList& functions); + virtual status_t CreateFrame(Image* image, + FunctionDebugInfo* function, + CpuState* cpuState, + StackFrame*& _previousFrame, + CpuState*& _previousCpuState); + virtual status_t LoadSourceCode(FunctionDebugInfo* function, + SourceCode*& _sourceCode); + virtual status_t GetStatement(FunctionDebugInfo* function, + target_addr_t address, + Statement*& _statement); + +private: + ImageInfo fImageInfo; + Architecture* fArchitecture; + DwarfFile* fFile; +}; + + +#endif // DWARF_IMAGE_DEBUG_INFO_H diff --git a/src/apps/debugger/debug_info/DwarfTeamDebugInfo.cpp b/src/apps/debugger/debug_info/DwarfTeamDebugInfo.cpp new file mode 100644 index 0000000000..9371162e3e --- /dev/null +++ b/src/apps/debugger/debug_info/DwarfTeamDebugInfo.cpp @@ -0,0 +1,75 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include "DwarfTeamDebugInfo.h" + +#include + +#include + +#include "DwarfImageDebugInfo.h" +#include "DwarfManager.h" + + +DwarfTeamDebugInfo::DwarfTeamDebugInfo(Architecture* architecture) + : + fArchitecture(architecture), + fManager(NULL) +{ +} + + +DwarfTeamDebugInfo::~DwarfTeamDebugInfo() +{ + delete fManager; +} + + +status_t +DwarfTeamDebugInfo::Init() +{ + fManager = new(std::nothrow) DwarfManager; + if (fManager == NULL) + return B_NO_MEMORY; + + status_t error = fManager->Init(); + if (error != B_OK) + return error; + + return B_OK; +} + + +status_t +DwarfTeamDebugInfo::CreateImageDebugInfo(const ImageInfo& imageInfo, + SpecificImageDebugInfo*& _imageDebugInfo) +{ + // We only want images that belong to shared objects. + if (strchr(imageInfo.Name(), '/') == NULL) + return B_ENTRY_NOT_FOUND; + + // try to load the DWARF file + DwarfFile* file; + status_t error = fManager->LoadFile(imageInfo.Name(), file); + if (error == B_OK) + error = fManager->FinishLoading(); + if (error != B_OK) + return error; + + // create the image debug info + DwarfImageDebugInfo* debuggerInfo = new(std::nothrow) DwarfImageDebugInfo( + imageInfo, fArchitecture, file); + if (debuggerInfo == NULL) + return B_NO_MEMORY; + + error = debuggerInfo->Init(); + if (error != B_OK) { + delete debuggerInfo; + return error; + } + + _imageDebugInfo = debuggerInfo; + return B_OK; +} diff --git a/src/apps/debugger/debug_info/DwarfTeamDebugInfo.h b/src/apps/debugger/debug_info/DwarfTeamDebugInfo.h new file mode 100644 index 0000000000..f2e7a3defb --- /dev/null +++ b/src/apps/debugger/debug_info/DwarfTeamDebugInfo.h @@ -0,0 +1,32 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef DWARF_TEAM_DEBUG_INFO_H +#define DWARF_TEAM_DEBUG_INFO_H + +#include "SpecificTeamDebugInfo.h" + + +class Architecture; +class DwarfManager; +class ImageInfo; + + +class DwarfTeamDebugInfo : public SpecificTeamDebugInfo { +public: + DwarfTeamDebugInfo(Architecture* architecture); + virtual ~DwarfTeamDebugInfo(); + + status_t Init(); + + virtual status_t CreateImageDebugInfo(const ImageInfo& imageInfo, + SpecificImageDebugInfo*& _imageDebugInfo); + +private: + Architecture* fArchitecture; + DwarfManager* fManager; +}; + + +#endif // DWARF_TEAM_DEBUG_INFO_H diff --git a/src/apps/debugger/debug_info/TeamDebugInfo.cpp b/src/apps/debugger/debug_info/TeamDebugInfo.cpp index 83aa771f9a..2613b132a2 100644 --- a/src/apps/debugger/debug_info/TeamDebugInfo.cpp +++ b/src/apps/debugger/debug_info/TeamDebugInfo.cpp @@ -10,6 +10,7 @@ #include #include "DebuggerTeamDebugInfo.h" +#include "DwarfTeamDebugInfo.h" #include "ImageDebugInfo.h" #include "SpecificImageDebugInfo.h" @@ -32,10 +33,20 @@ TeamDebugInfo::~TeamDebugInfo() status_t TeamDebugInfo::Init() { - // create specific infos for all types of debug info we support + // Create specific infos for all types of debug info we support, in + // descending order of expressiveness. // DWARF - // TODO:... + DwarfTeamDebugInfo* dwarfInfo = new(std::nothrow) DwarfTeamDebugInfo( + fArchitecture); + if (dwarfInfo == NULL || !fSpecificInfos.AddItem(dwarfInfo)) { + delete dwarfInfo; + return B_NO_MEMORY; + } + + status_t error = dwarfInfo->Init(); + if (error != B_OK) + return error; // debugger based info DebuggerTeamDebugInfo* debuggerInfo @@ -46,7 +57,7 @@ TeamDebugInfo::Init() return B_NO_MEMORY; } - status_t error = debuggerInfo->Init(); + error = debuggerInfo->Init(); if (error != B_OK) return error;