From 99fac5a9dc24d3a68ba97af9a7b6be740fa580b1 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Tue, 30 Apr 2013 22:42:35 -0400 Subject: [PATCH] Extend SpecificImageDebugInfo::GetFunctions() ... ...to also take the list of symbols in the image as a parameter. This allows us to prefetch the symbols once in ImageInfo::FinishInit() for each image and then let each specific info subclass use them if/as needed, rather than having to do the entire symbol lookup/sort twice for every image. - Adjust callers accordingly. --- .../debug_info/DebuggerImageDebugInfo.cpp | 6 +++-- .../debug_info/DebuggerImageDebugInfo.h | 2 ++ .../debug_info/DwarfImageDebugInfo.cpp | 7 +++--- .../debugger/debug_info/DwarfImageDebugInfo.h | 3 ++- .../debugger/debug_info/ImageDebugInfo.cpp | 23 ++++++++++++++++--- src/apps/debugger/debug_info/ImageDebugInfo.h | 7 ++++-- .../debug_info/SpecificImageDebugInfo.cpp | 20 ++-------------- .../debug_info/SpecificImageDebugInfo.h | 6 ++--- .../debugger/debug_info/TeamDebugInfo.cpp | 4 ++-- 9 files changed, 44 insertions(+), 34 deletions(-) diff --git a/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp index 8aa49b4c48..4cd65c460e 100644 --- a/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp +++ b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp @@ -1,5 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2013, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -42,9 +43,10 @@ DebuggerImageDebugInfo::Init() status_t -DebuggerImageDebugInfo::GetFunctions(BObjectList& functions) +DebuggerImageDebugInfo::GetFunctions(const BObjectList& symbols, + BObjectList& functions) { - return SpecificImageDebugInfo::GetFunctionsFromSymbols(functions, + return SpecificImageDebugInfo::GetFunctionsFromSymbols(symbols, functions, fDebuggerInterface, fImageInfo, this); } diff --git a/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h index efe5816b58..e491f50c98 100644 --- a/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h +++ b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h @@ -1,5 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2013, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ #ifndef DEBUGGER_IMAGE_DEBUG_INFO_H @@ -26,6 +27,7 @@ public: status_t Init(); virtual status_t GetFunctions( + const BObjectList& symbols, BObjectList& functions); virtual status_t GetType(GlobalTypeCache* cache, const BString& name, diff --git a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp index 67b2f5451c..2ec64052f9 100644 --- a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp +++ b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp @@ -1,6 +1,6 @@ /* * Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2012, Rene Gollent, rene@gollent.com. + * Copyright 2012-2013, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -299,7 +299,8 @@ DwarfImageDebugInfo::Init() status_t -DwarfImageDebugInfo::GetFunctions(BObjectList& functions) +DwarfImageDebugInfo::GetFunctions(const BObjectList& symbols, + BObjectList& functions) { TRACE_IMAGES("DwarfImageDebugInfo::GetFunctions()\n"); TRACE_IMAGES(" %" B_PRId32 " compilation units\n", @@ -414,7 +415,7 @@ DwarfImageDebugInfo::GetFunctions(BObjectList& functions) // if we had no compilation units, fall back to providing basic // debug infos with DWARF-supported call frame unwinding - return SpecificImageDebugInfo::GetFunctionsFromSymbols(functions, + return SpecificImageDebugInfo::GetFunctionsFromSymbols(symbols, functions, fDebuggerInterface, fImageInfo, this); } diff --git a/src/apps/debugger/debug_info/DwarfImageDebugInfo.h b/src/apps/debugger/debug_info/DwarfImageDebugInfo.h index 422925a9b9..0a2daf2e48 100644 --- a/src/apps/debugger/debug_info/DwarfImageDebugInfo.h +++ b/src/apps/debugger/debug_info/DwarfImageDebugInfo.h @@ -1,6 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2010-2012, Rene Gollent, rene@gollent.com. + * Copyright 2010-2013, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ #ifndef DWARF_IMAGE_DEBUG_INFO_H @@ -52,6 +52,7 @@ public: { return fRelocationDelta; } virtual status_t GetFunctions( + const BObjectList& symbols, BObjectList& functions); virtual status_t GetType(GlobalTypeCache* cache, const BString& name, diff --git a/src/apps/debugger/debug_info/ImageDebugInfo.cpp b/src/apps/debugger/debug_info/ImageDebugInfo.cpp index 2a39419a19..feeb5df0ff 100644 --- a/src/apps/debugger/debug_info/ImageDebugInfo.cpp +++ b/src/apps/debugger/debug_info/ImageDebugInfo.cpp @@ -1,6 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2010, Rene Gollent, rene@gollent.com. + * Copyright 2010-2013, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -8,9 +8,11 @@ #include +#include "DebuggerInterface.h" #include "FunctionDebugInfo.h" #include "FunctionInstance.h" #include "SpecificImageDebugInfo.h" +#include "SymbolInfo.h" ImageDebugInfo::ImageDebugInfo(const ImageInfo& imageInfo) @@ -35,14 +37,21 @@ ImageDebugInfo::AddSpecificInfo(SpecificImageDebugInfo* info) status_t -ImageDebugInfo::FinishInit() +ImageDebugInfo::FinishInit(DebuggerInterface* interface) { + BObjectList symbols(50, true); + status_t error = interface->GetSymbolInfos(fImageInfo.TeamID(), + fImageInfo.ImageID(), symbols); + if (error != B_OK) + return error; + symbols.SortItems(&_CompareSymbols); + // get functions -- get them from most expressive debug info first and add // missing functions from less expressive debug infos for (int32 i = 0; SpecificImageDebugInfo* specificInfo = fSpecificInfos.ItemAt(i); i++) { BObjectList functions; - status_t error = specificInfo->GetFunctions(functions); + error = specificInfo->GetFunctions(symbols, functions); if (error != B_OK) return error; @@ -175,3 +184,11 @@ ImageDebugInfo::_CompareAddressFunction(const target_addr_t* address, return -1; return *address < function->Address() + function->Size() ? 0 : 1; } + + +/*static*/ int +ImageDebugInfo::_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/ImageDebugInfo.h b/src/apps/debugger/debug_info/ImageDebugInfo.h index 5f30ace950..395dfe2347 100644 --- a/src/apps/debugger/debug_info/ImageDebugInfo.h +++ b/src/apps/debugger/debug_info/ImageDebugInfo.h @@ -1,6 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2010, Rene Gollent, rene@gollent.com. + * Copyright 2010-2013, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ #ifndef IMAGE_DEBUG_INFO_H @@ -25,6 +25,7 @@ class FunctionInstance; class GlobalTypeCache; class LocatableFile; class SpecificImageDebugInfo; +class SymbolInfo; class Type; class TypeLookupConstraints; @@ -37,7 +38,7 @@ public: const ImageInfo& GetImageInfo() const { return fImageInfo; } bool AddSpecificInfo(SpecificImageDebugInfo* info); - status_t FinishInit(); + status_t FinishInit(DebuggerInterface* interface); status_t GetType(GlobalTypeCache* cache, const BString& name, @@ -65,6 +66,8 @@ private: static int _CompareAddressFunction( const target_addr_t* address, const FunctionInstance* function); + static int _CompareSymbols(const SymbolInfo* a, + const SymbolInfo* b); private: ImageInfo fImageInfo; diff --git a/src/apps/debugger/debug_info/SpecificImageDebugInfo.cpp b/src/apps/debugger/debug_info/SpecificImageDebugInfo.cpp index b2e363abf2..0be04e63fd 100644 --- a/src/apps/debugger/debug_info/SpecificImageDebugInfo.cpp +++ b/src/apps/debugger/debug_info/SpecificImageDebugInfo.cpp @@ -1,5 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2013, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -19,19 +20,10 @@ SpecificImageDebugInfo::~SpecificImageDebugInfo() /*static*/ status_t SpecificImageDebugInfo::GetFunctionsFromSymbols( + const BObjectList& symbols, BObjectList& functions, DebuggerInterface* interface, const ImageInfo& imageInfo, SpecificImageDebugInfo* info) { - BObjectList symbols(20, true); - status_t error = interface->GetSymbolInfos(imageInfo.TeamID(), - imageInfo.ImageID(), symbols); - if (error != B_OK) - return error; - - // 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 int32 functionsAdded = 0; for (int32 i = 0; SymbolInfo* symbol = symbols.ItemAt(i); i++) { @@ -56,11 +48,3 @@ SpecificImageDebugInfo::GetFunctionsFromSymbols( return B_OK; } - -/*static*/ int -SpecificImageDebugInfo::_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/SpecificImageDebugInfo.h b/src/apps/debugger/debug_info/SpecificImageDebugInfo.h index 02a1fa92e6..40d9f83a88 100644 --- a/src/apps/debugger/debug_info/SpecificImageDebugInfo.h +++ b/src/apps/debugger/debug_info/SpecificImageDebugInfo.h @@ -1,5 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2013, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ #ifndef SPECIFIC_IMAGE_DEBUG_INFO_H @@ -41,6 +42,7 @@ public: virtual ~SpecificImageDebugInfo(); virtual status_t GetFunctions( + const BObjectList& symbols, BObjectList& functions) = 0; // returns references @@ -87,14 +89,12 @@ public: protected: static status_t GetFunctionsFromSymbols( + const BObjectList& symbols, BObjectList& functions, DebuggerInterface* interface, const ImageInfo& imageInfo, SpecificImageDebugInfo* info); -private: - static int _CompareSymbols(const SymbolInfo* a, - const SymbolInfo* b); }; diff --git a/src/apps/debugger/debug_info/TeamDebugInfo.cpp b/src/apps/debugger/debug_info/TeamDebugInfo.cpp index 9a22093933..d44158587e 100644 --- a/src/apps/debugger/debug_info/TeamDebugInfo.cpp +++ b/src/apps/debugger/debug_info/TeamDebugInfo.cpp @@ -1,6 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2012, Rene Gollent, rene@gollent.com. + * Copyright 2012-2013, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -448,7 +448,7 @@ TeamDebugInfo::LoadImageDebugInfo(const ImageInfo& imageInfo, // fail only when out of memory } - status_t error = imageDebugInfo->FinishInit(); + status_t error = imageDebugInfo->FinishInit(fDebuggerInterface); if (error != B_OK) return error;