1/* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6#include "SpecificImageDebugInfo.h" 7 8#include "BasicFunctionDebugInfo.h" 9#include "DebuggerInterface.h" 10#include "Demangler.h" 11#include "ImageInfo.h" 12#include "SymbolInfo.h" 13 14 15SpecificImageDebugInfo::~SpecificImageDebugInfo() 16{ 17} 18 19 20/*static*/ status_t 21SpecificImageDebugInfo::GetFunctionsFromSymbols( 22 BObjectList<FunctionDebugInfo>& functions, DebuggerInterface* interface, 23 const ImageInfo& imageInfo, SpecificImageDebugInfo* info) 24{ 25 BObjectList<SymbolInfo> symbols(20, true); 26 status_t error = interface->GetSymbolInfos(imageInfo.TeamID(), 27 imageInfo.ImageID(), symbols); 28 if (error != B_OK) 29 return error; 30 31 // sort the symbols -- not necessary, but a courtesy to ImageDebugInfo which 32 // will peform better when inserting functions at the end of a list 33 symbols.SortItems(&_CompareSymbols); 34 35 // create the function infos 36 int32 functionsAdded = 0; 37 for (int32 i = 0; SymbolInfo* symbol = symbols.ItemAt(i); i++) { 38 if (symbol->Type() != B_SYMBOL_TYPE_TEXT) 39 continue; 40 41 FunctionDebugInfo* function = new(std::nothrow) BasicFunctionDebugInfo( 42 info, symbol->Address(), symbol->Size(), symbol->Name(), 43 Demangler::Demangle(symbol->Name())); 44 if (function == NULL || !functions.AddItem(function)) { 45 delete function; 46 int32 index = functions.CountItems() - 1; 47 for (; functionsAdded >= 0; functionsAdded--, index--) { 48 function = functions.RemoveItemAt(index); 49 delete function; 50 } 51 return B_NO_MEMORY; 52 } 53 54 functionsAdded++; 55 } 56 57 return B_OK; 58} 59 60/*static*/ int 61SpecificImageDebugInfo::_CompareSymbols(const SymbolInfo* a, 62 const SymbolInfo* b) 63{ 64 return a->Address() < b->Address() 65 ? -1 : (a->Address() == b->Address() ? 0 : 1); 66} 67