1/* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef DWARF_UTILS_H 6#define DWARF_UTILS_H 7 8#include "DebugInfoEntries.h" 9 10 11class BString; 12class DebugInfoEntry; 13class DwarfFile; 14 15 16class DwarfUtils { 17public: 18 static void GetDIEName(const DebugInfoEntry* entry, 19 BString& _name); 20 static void GetFullDIEName(const DebugInfoEntry* entry, 21 BString& _name); 22 static void GetFullyQualifiedDIEName( 23 const DebugInfoEntry* entry, 24 BString& _name); 25 26 static bool GetDeclarationLocation(DwarfFile* dwarfFile, 27 const DebugInfoEntry* entry, 28 const char*& _directory, 29 const char*& _file, 30 int32& _line, int32& _column); 31 32 template<typename EntryType, typename Predicate> 33 static EntryType* GetDIEByPredicate(EntryType* entry, 34 const Predicate& predicate); 35}; 36 37 38template<typename EntryType, typename Predicate> 39/*static*/ EntryType* 40DwarfUtils::GetDIEByPredicate(EntryType* entry, const Predicate& predicate) 41{ 42 if (predicate(entry)) 43 return entry; 44 45 // try the abstract origin 46 if (EntryType* abstractOrigin = dynamic_cast<EntryType*>( 47 entry->AbstractOrigin())) { 48 entry = abstractOrigin; 49 if (predicate(entry)) 50 return entry; 51 } 52 53 // try the specification 54 if (EntryType* specification = dynamic_cast<EntryType*>( 55 entry->Specification())) { 56 entry = specification; 57 if (predicate(entry)) 58 return entry; 59 } 60 61 return NULL; 62} 63 64 65#endif // DWARF_UTILS_H 66