[Haiku-commits] r31251 - in haiku/trunk/src/apps/debugger: arch debug_info
bonefish at BerliOS
bonefish at mail.berlios.de
Fri Jun 26 15:12:07 CEST 2009
Author: bonefish
Date: 2009-06-26 15:12:06 +0200 (Fri, 26 Jun 2009)
New Revision: 31251
ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=31251&view=rev
Modified:
haiku/trunk/src/apps/debugger/arch/Architecture.cpp
haiku/trunk/src/apps/debugger/debug_info/DebugInfo.h
haiku/trunk/src/apps/debugger/debug_info/DebuggerDebugInfo.cpp
haiku/trunk/src/apps/debugger/debug_info/DebuggerDebugInfo.h
haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.cpp
haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.h
Log:
ImageDebugInfo does now gather function debug infos from all available sources
on init, keeping the most expressive one for each function. The interface
changed accordingly, i.e. it is now possible to iterate through the functions
and FindFunction() is now called FunctionAtAddress(), not returning a reference
anymore.
Modified: haiku/trunk/src/apps/debugger/arch/Architecture.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/arch/Architecture.cpp 2009-06-26 11:58:43 UTC (rev 31250)
+++ haiku/trunk/src/apps/debugger/arch/Architecture.cpp 2009-06-26 13:12:06 UTC (rev 31251)
@@ -74,10 +74,12 @@
Reference<ImageDebugInfo> imageDebugInfoReference(imageDebugInfo, true);
// get the function
+ teamLocker.Lock();
FunctionDebugInfo* function = NULL;
if (imageDebugInfo != NULL)
- function = imageDebugInfo->FindFunction(instructionPointer);
- Reference<FunctionDebugInfo> functionReference(function, true);
+ function = imageDebugInfo->FunctionAtAddress(instructionPointer);
+ Reference<FunctionDebugInfo> functionReference(function);
+ teamLocker.Unlock();
// If the last frame had been created by the architecture, we update the
// CPU state.
Modified: haiku/trunk/src/apps/debugger/debug_info/DebugInfo.h
===================================================================
--- haiku/trunk/src/apps/debugger/debug_info/DebugInfo.h 2009-06-26 11:58:43 UTC (rev 31250)
+++ haiku/trunk/src/apps/debugger/debug_info/DebugInfo.h 2009-06-26 13:12:06 UTC (rev 31251)
@@ -5,6 +5,7 @@
#ifndef DEBUG_INFO_H
#define DEBUG_INFO_H
+#include <ObjectList.h>
#include <Referenceable.h>
#include "ArchitectureTypes.h"
@@ -24,8 +25,10 @@
public:
virtual ~DebugInfo();
- virtual FunctionDebugInfo* FindFunction(target_addr_t address) = 0;
- // returns a reference
+ virtual status_t GetFunctions(
+ BObjectList<FunctionDebugInfo>& functions)
+ = 0;
+ // returns references
virtual status_t CreateFrame(Image* image,
FunctionDebugInfo* function,
Modified: haiku/trunk/src/apps/debugger/debug_info/DebuggerDebugInfo.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/debug_info/DebuggerDebugInfo.cpp 2009-06-26 11:58:43 UTC (rev 31250)
+++ haiku/trunk/src/apps/debugger/debug_info/DebuggerDebugInfo.cpp 2009-06-26 13:12:06 UTC (rev 31251)
@@ -22,8 +22,7 @@
:
fImageInfo(imageInfo),
fDebuggerInterface(debuggerInterface),
- fArchitecture(architecture),
- fSymbols(20, true)
+ fArchitecture(architecture)
{
}
@@ -36,33 +35,43 @@
status_t
DebuggerDebugInfo::Init()
{
- // TODO: Extend DebuggerInterface to find a symbol on demand!
+ return B_OK;
+}
+
+status_t
+DebuggerDebugInfo::GetFunctions(BObjectList<FunctionDebugInfo>& functions)
+{
+ BObjectList<SymbolInfo> symbols(20, true);
status_t error = fDebuggerInterface->GetSymbolInfos(fImageInfo.TeamID(),
- fImageInfo.ImageID(), fSymbols);
+ fImageInfo.ImageID(), symbols);
if (error != B_OK)
return error;
- // sort the symbols
- fSymbols.SortItems(&_CompareSymbols);
+ // sort the symbols -- not necessary, but a courtesy to ImageDebugInfo which
+ // will peform better when inserting functions at the end of a list
+ symbols.SortItems(&_CompareSymbols);
+ // create the function infos
+ for (int32 i = 0; SymbolInfo* symbol = symbols.ItemAt(i); i++) {
+ FunctionDebugInfo* function = new(std::nothrow) BasicFunctionDebugInfo(
+ this, symbol->Address(), symbol->Size(), symbol->Name(),
+ Demangler::Demangle(symbol->Name()));
+ if (function == NULL || !functions.AddItem(function)) {
+ delete function;
+ int32 index = functions.CountItems() - 1;
+ for (i--; i >= 0; i--, index--) {
+ function = functions.RemoveItemAt(index);
+ delete function;
+ }
+ return B_NO_MEMORY;
+ }
+ }
+
return B_OK;
}
-FunctionDebugInfo*
-DebuggerDebugInfo::FindFunction(target_addr_t address)
-{
- SymbolInfo* symbolInfo = _FindSymbol(address);
- if (symbolInfo == NULL || symbolInfo->Type() != B_SYMBOL_TYPE_TEXT)
- return NULL;
-
- return new(std::nothrow) BasicFunctionDebugInfo(this, symbolInfo->Address(),
- symbolInfo->Size(), symbolInfo->Name(),
- Demangler::Demangle(symbolInfo->Name()));
-}
-
-
status_t
DebuggerDebugInfo::CreateFrame(Image* image, FunctionDebugInfo* function,
CpuState* cpuState, StackFrame*& _previousFrame,
@@ -103,26 +112,9 @@
}
-SymbolInfo*
-DebuggerDebugInfo::_FindSymbol(target_addr_t address)
-{
- return fSymbols.BinarySearchByKey(address, &_CompareAddressSymbol);
-}
-
-
/*static*/ int
DebuggerDebugInfo::_CompareSymbols(const SymbolInfo* a, const SymbolInfo* b)
{
return a->Address() < b->Address()
? -1 : (a->Address() == b->Address() ? 0 : 1);
}
-
-
-/*static*/ int
-DebuggerDebugInfo::_CompareAddressSymbol(const target_addr_t* address,
- const SymbolInfo* info)
-{
- if (*address < info->Address())
- return -1;
- return *address < info->Address() + info->Size() ? 0 : 1;
-}
Modified: haiku/trunk/src/apps/debugger/debug_info/DebuggerDebugInfo.h
===================================================================
--- haiku/trunk/src/apps/debugger/debug_info/DebuggerDebugInfo.h 2009-06-26 11:58:43 UTC (rev 31250)
+++ haiku/trunk/src/apps/debugger/debug_info/DebuggerDebugInfo.h 2009-06-26 13:12:06 UTC (rev 31251)
@@ -7,8 +7,6 @@
#include <String.h>
-#include <ObjectList.h>
-
#include "DebugInfo.h"
#include "ImageInfo.h"
@@ -28,7 +26,8 @@
status_t Init();
- virtual FunctionDebugInfo* FindFunction(target_addr_t address);
+ virtual status_t GetFunctions(
+ BObjectList<FunctionDebugInfo>& functions);
virtual status_t CreateFrame(Image* image,
FunctionDebugInfo* function,
CpuState* cpuState,
@@ -41,23 +40,13 @@
Statement*& _statement);
private:
- typedef BObjectList<SymbolInfo> SymbolList;
-
- struct FindByAddressPredicate;
-
-private:
- SymbolInfo* _FindSymbol(target_addr_t address);
static int _CompareSymbols(const SymbolInfo* a,
const SymbolInfo* b);
- static int _CompareAddressSymbol(
- const target_addr_t* address,
- const SymbolInfo* info);
private:
ImageInfo fImageInfo;
DebuggerInterface* fDebuggerInterface;
Architecture* fArchitecture;
- SymbolList fSymbols;
};
Modified: haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.cpp 2009-06-26 11:58:43 UTC (rev 31250)
+++ haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.cpp 2009-06-26 13:12:06 UTC (rev 31251)
@@ -8,6 +8,7 @@
#include <new>
#include "DebuggerDebugInfo.h"
+#include "FunctionDebugInfo.h"
ImageDebugInfo::ImageDebugInfo(const ImageInfo& imageInfo,
@@ -22,6 +23,8 @@
ImageDebugInfo::~ImageDebugInfo()
{
+ for (int32 i = 0; FunctionDebugInfo* function = fFunctions.ItemAt(i); i++)
+ function->RemoveReference();
}
@@ -50,18 +53,67 @@
// only "no memory" is fatal
}
+ // 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++) {
+ FunctionList functions;
+ status_t error = debugInfo->GetFunctions(functions);
+ if (error != B_OK)
+ return error;
+
+ for (int32 k = 0; FunctionDebugInfo* function = functions.ItemAt(k);
+ k++) {
+ if (FunctionAtAddress(function->Address()) == NULL) {
+ if (!fFunctions.BinaryInsert(function, &_CompareFunctions)) {
+ for (; (function = functions.ItemAt(k)); k++) {
+ function->RemoveReference();
+ return B_NO_MEMORY;
+ }
+ }
+ } else
+ function->RemoveReference();
+ }
+ }
+
return B_OK;
}
+int32
+ImageDebugInfo::CountFunctions() const
+{
+ return fFunctions.CountItems();
+}
+
+
FunctionDebugInfo*
-ImageDebugInfo::FindFunction(target_addr_t address)
+ImageDebugInfo::FunctionAt(int32 index) const
{
- for (int32 i = 0; DebugInfo* debugInfo = fDebugInfos.ItemAt(i); i++) {
- FunctionDebugInfo* functionInfo = debugInfo->FindFunction(address);
- if (functionInfo)
- return functionInfo;
- }
+ return fFunctions.ItemAt(index);
+}
- return NULL;
+
+FunctionDebugInfo*
+ImageDebugInfo::FunctionAtAddress(target_addr_t address) const
+{
+ return fFunctions.BinarySearchByKey(address, &_CompareAddressFunction);
}
+
+
+/*static*/ int
+ImageDebugInfo::_CompareFunctions(const FunctionDebugInfo* a,
+ const FunctionDebugInfo* b)
+{
+ return a->Address() < b->Address()
+ ? -1 : (a->Address() == b->Address() ? 0 : 1);
+}
+
+
+/*static*/ int
+ImageDebugInfo::_CompareAddressFunction(const target_addr_t* address,
+ const FunctionDebugInfo* function)
+{
+ if (*address < function->Address())
+ return -1;
+ return *address < function->Address() + function->Size() ? 0 : 1;
+}
Modified: haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.h
===================================================================
--- haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.h 2009-06-26 11:58:43 UTC (rev 31250)
+++ haiku/trunk/src/apps/debugger/debug_info/ImageDebugInfo.h 2009-06-26 13:12:06 UTC (rev 31251)
@@ -29,17 +29,27 @@
status_t Init();
- FunctionDebugInfo* FindFunction(target_addr_t address);
- // returns a reference
+ int32 CountFunctions() const;
+ FunctionDebugInfo* FunctionAt(int32 index) const;
+ FunctionDebugInfo* FunctionAtAddress(target_addr_t address) const;
private:
typedef BObjectList<DebugInfo> DebugInfoList;
+ typedef BObjectList<FunctionDebugInfo> FunctionList;
private:
+ static int _CompareFunctions(const FunctionDebugInfo* a,
+ const FunctionDebugInfo* b);
+ static int _CompareAddressFunction(
+ const target_addr_t* address,
+ const FunctionDebugInfo* function);
+
+private:
ImageInfo fImageInfo;
DebuggerInterface* fDebuggerInterface;
Architecture* fArchitecture;
DebugInfoList fDebugInfos;
+ FunctionList fFunctions;
};
More information about the Haiku-commits
mailing list