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