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 const DebugInfoEntry* 24 requestingEntry = NULL); 25 static void GetFullDIEName(const DebugInfoEntry* entry, 26 BString& _name); 27 static void GetFullyQualifiedDIEName( 28 const DebugInfoEntry* entry, 29 BString& _name, 30 const DebugInfoEntry* 31 requestingEntry = NULL); 32 33 static bool GetDeclarationLocation(DwarfFile* dwarfFile, 34 const DebugInfoEntry* entry, 35 const char*& _directory, 36 const char*& _file, 37 int32& _line, int32& _column); 38 39 template<typename EntryType, typename Predicate> 40 static EntryType* GetDIEByPredicate(EntryType* entry, 41 const Predicate& predicate); 42 }; 43 44 45 template<typename EntryType, typename Predicate> 46 /*static*/ EntryType* 47 DwarfUtils::GetDIEByPredicate(EntryType* entry, const Predicate& predicate) 48 { 49 if (predicate(entry)) 50 return entry; 51 52 // try the abstract origin 53 if (EntryType* abstractOrigin = dynamic_cast<EntryType*>( 54 entry->AbstractOrigin())) { 55 entry = abstractOrigin; 56 if (predicate(entry)) 57 return entry; 58 } 59 60 // try the specification 61 if (EntryType* specification = dynamic_cast<EntryType*>( 62 entry->Specification())) { 63 entry = specification; 64 if (predicate(entry)) 65 return entry; 66 } 67 68 // try the type unit signature 69 if (EntryType* signature = dynamic_cast<EntryType*>( 70 entry->SignatureType())) { 71 entry = signature; 72 if (predicate(entry)) 73 return entry; 74 } 75 76 return NULL; 77 } 78 79 80 #endif // DWARF_UTILS_H 81