#ifndef DWARF_UTILS_H
#define DWARF_UTILS_H
#include "DebugInfoEntries.h"
class BString;
class DebugInfoEntry;
class DwarfFile;
class DwarfUtils {
public:
static void GetDIEName(const DebugInfoEntry* entry,
BString& _name);
static void GetDIETypeName(const DebugInfoEntry* entry,
BString& _name,
const DebugInfoEntry*
requestingEntry = NULL);
static void GetFullDIEName(const DebugInfoEntry* entry,
BString& _name);
static void GetFullyQualifiedDIEName(
const DebugInfoEntry* entry,
BString& _name,
const DebugInfoEntry*
requestingEntry = NULL);
static bool GetDeclarationLocation(DwarfFile* dwarfFile,
const DebugInfoEntry* entry,
const char*& _directory,
const char*& _file,
int32& _line, int32& _column);
template<typename EntryType, typename Predicate>
static EntryType* GetDIEByPredicate(EntryType* entry,
const Predicate& predicate);
};
template<typename EntryType, typename Predicate>
EntryType*
DwarfUtils::GetDIEByPredicate(EntryType* entry, const Predicate& predicate)
{
if (predicate(entry))
return entry;
if (EntryType* abstractOrigin = dynamic_cast<EntryType*>(
entry->AbstractOrigin())) {
entry = abstractOrigin;
if (predicate(entry))
return entry;
}
if (EntryType* specification = dynamic_cast<EntryType*>(
entry->Specification())) {
entry = specification;
if (predicate(entry))
return entry;
}
if (EntryType* signature = dynamic_cast<EntryType*>(
entry->SignatureType())) {
entry = signature;
if (predicate(entry))
return entry;
}
return NULL;
}
#endif