From 9774f385b5b79b1128c47b270f9c9ec54fc1cd90 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 3 Jul 2009 14:20:27 +0000 Subject: [PATCH] Added debug_get_symbol(). It's not implemented particularly efficiently, though. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31392 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/debug/debug_support.h | 3 +++ src/kits/debug/Image.cpp | 29 +++++++++++++++++++++++++++ src/kits/debug/Image.h | 4 ++++ src/kits/debug/SymbolLookup.cpp | 14 +++++++++++++ src/kits/debug/SymbolLookup.h | 3 +++ src/kits/debug/debug_support.cpp | 16 +++++++++++++++ 6 files changed, 69 insertions(+) diff --git a/headers/private/debug/debug_support.h b/headers/private/debug/debug_support.h index 4af72ed208..0ed3c6e6ee 100644 --- a/headers/private/debug/debug_support.h +++ b/headers/private/debug/debug_support.h @@ -62,6 +62,9 @@ status_t debug_create_symbol_lookup_context(team_id team, void debug_delete_symbol_lookup_context( debug_symbol_lookup_context *lookupContext); +status_t debug_get_symbol(debug_symbol_lookup_context* lookupContext, + image_id image, const char* name, int32 symbolType, + void** _symbolLocation, size_t* _symbolSize, int32* _symbolType); status_t debug_lookup_symbol_address(debug_symbol_lookup_context *lookupContext, const void *address, void **baseAddress, char *symbolName, int32 symbolNameSize, char *imageName, int32 imageNameSize, diff --git a/src/kits/debug/Image.cpp b/src/kits/debug/Image.cpp index 36fd88e26d..4075b482cc 100644 --- a/src/kits/debug/Image.cpp +++ b/src/kits/debug/Image.cpp @@ -34,6 +34,35 @@ Image::~Image() } +status_t +Image::GetSymbol(const char* name, int32 symbolType, void** _symbolLocation, + size_t* _symbolSize, int32* _symbolType) const +{ + // TODO: At least for ImageFile we could do hash lookups! + int32 iterator = 0; + const char* foundName; + size_t foundNameLen; + addr_t foundAddress; + size_t foundSize; + int32 foundType; + while (NextSymbol(iterator, &foundName, &foundNameLen, &foundAddress, + &foundSize, &foundType) == B_OK) { + if ((symbolType == B_SYMBOL_TYPE_ANY || symbolType == foundType) + && strcmp(name, foundName) == 0) { + if (_symbolLocation != NULL) + *_symbolLocation = (void*)foundAddress; + if (_symbolSize != NULL) + *_symbolSize = foundSize; + if (_symbolType != NULL) + *_symbolType = foundType; + return B_OK; + } + } + + return B_ENTRY_NOT_FOUND; +} + + // #pragma mark - SymbolTableBasedImage diff --git a/src/kits/debug/Image.h b/src/kits/debug/Image.h index 82394a8035..5a691defd6 100644 --- a/src/kits/debug/Image.h +++ b/src/kits/debug/Image.h @@ -46,6 +46,10 @@ public: addr_t* _symbolAddress, size_t* _symbolSize, int32* _symbolType) const = 0; + virtual status_t GetSymbol(const char* name, int32 symbolType, + void** _symbolLocation, size_t* _symbolSize, + int32* _symbolType) const; + protected: image_info fInfo; }; diff --git a/src/kits/debug/SymbolLookup.cpp b/src/kits/debug/SymbolLookup.cpp index a331329425..930ac95a9f 100644 --- a/src/kits/debug/SymbolLookup.cpp +++ b/src/kits/debug/SymbolLookup.cpp @@ -426,6 +426,20 @@ SymbolLookup::NextSymbol(SymbolIterator& iterator, const char** _symbolName, } +// GetSymbol +status_t +SymbolLookup::GetSymbol(image_id imageID, const char* name, int32 symbolType, + void** _symbolLocation, size_t* _symbolSize, int32* _symbolType) const +{ + Image* image = _FindImageByID(imageID); + if (image == NULL) + return B_ENTRY_NOT_FOUND; + + return image->GetSymbol(name, symbolType, _symbolLocation, _symbolSize, + _symbolType); +} + + // _FindLoadedImageAtAddress const image_t * SymbolLookup::_FindLoadedImageAtAddress(addr_t address) const diff --git a/src/kits/debug/SymbolLookup.h b/src/kits/debug/SymbolLookup.h index d512b467b4..b2c78bb7f3 100644 --- a/src/kits/debug/SymbolLookup.h +++ b/src/kits/debug/SymbolLookup.h @@ -154,6 +154,9 @@ public: size_t* _symbolNameLen, addr_t* _symbolAddress, size_t* _symbolSize, int32* _symbolType) const; + status_t GetSymbol(image_id imageID, const char* name, int32 symbolType, + void** _symbolLocation, size_t* _symbolSize, int32* _symbolType) const; + private: class LoadedImage; friend class LoadedImage; diff --git a/src/kits/debug/debug_support.cpp b/src/kits/debug/debug_support.cpp index 081c850f71..1389899249 100644 --- a/src/kits/debug/debug_support.cpp +++ b/src/kits/debug/debug_support.cpp @@ -318,6 +318,22 @@ debug_delete_symbol_lookup_context(debug_symbol_lookup_context *lookupContext) } } + +// debug_get_symbol +status_t +debug_get_symbol(debug_symbol_lookup_context* lookupContext, image_id image, + const char* name, int32 symbolType, void** _symbolLocation, + size_t* _symbolSize, int32* _symbolType) +{ + if (!lookupContext || !lookupContext->lookup) + return B_BAD_VALUE; + SymbolLookup* lookup = lookupContext->lookup; + + return lookup->GetSymbol(image, name, symbolType, _symbolLocation, + _symbolSize, _symbolType); +} + + // debug_lookup_symbol_address status_t debug_lookup_symbol_address(debug_symbol_lookup_context *lookupContext,