headers/bsd: Add sys/queue.h.
[haiku.git] / src / kits / debugger / dwarf / DwarfUtils.h
blobbdc41c0490ea461dc558f3600cafa17b4dfac7a5
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
9 #include "DebugInfoEntries.h"
12 class BString;
13 class DebugInfoEntry;
14 class DwarfFile;
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);
29 static bool GetDeclarationLocation(DwarfFile* dwarfFile,
30 const DebugInfoEntry* entry,
31 const char*& _directory,
32 const char*& _file,
33 int32& _line, int32& _column);
35 template<typename EntryType, typename Predicate>
36 static EntryType* GetDIEByPredicate(EntryType* entry,
37 const Predicate& predicate);
41 template<typename EntryType, typename Predicate>
42 /*static*/ EntryType*
43 DwarfUtils::GetDIEByPredicate(EntryType* entry, const Predicate& predicate)
45 if (predicate(entry))
46 return entry;
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;
56 // try the specification
57 if (EntryType* specification = dynamic_cast<EntryType*>(
58 entry->Specification())) {
59 entry = specification;
60 if (predicate(entry))
61 return entry;
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;
72 return NULL;
76 #endif // DWARF_UTILS_H