2017-03-07 04:52:12 +08:00
|
|
|
//===--- DWARFVisitor.h -----------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-03-07 04:52:12 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_OBJECTYAML_DWARFVISITOR_H
|
|
|
|
#define LLVM_OBJECTYAML_DWARFVISITOR_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
2017-03-07 04:52:12 +08:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
namespace DWARFYAML {
|
|
|
|
|
|
|
|
struct Data;
|
|
|
|
struct Unit;
|
|
|
|
struct Entry;
|
|
|
|
struct FormValue;
|
|
|
|
struct AttributeAbbrev;
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// A class to visits DWARFYAML Compile Units and DIEs in preorder.
|
2017-03-07 04:52:12 +08:00
|
|
|
///
|
|
|
|
/// Extensions of this class can either maintain const or non-const references
|
|
|
|
/// to the DWARFYAML::Data object.
|
|
|
|
template <typename T> class VisitorImpl {
|
|
|
|
protected:
|
|
|
|
T &DebugInfo;
|
|
|
|
|
|
|
|
/// Visitor Functions
|
|
|
|
/// @{
|
|
|
|
virtual void onStartCompileUnit(Unit &CU) {}
|
|
|
|
virtual void onEndCompileUnit(Unit &CU) {}
|
|
|
|
virtual void onStartDIE(Unit &CU, Entry &DIE) {}
|
|
|
|
virtual void onEndDIE(Unit &CU, Entry &DIE) {}
|
|
|
|
virtual void onForm(AttributeAbbrev &AttAbbrev, FormValue &Value) {}
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
/// Const Visitor Functions
|
|
|
|
/// @{
|
|
|
|
virtual void onStartCompileUnit(const Unit &CU) {}
|
|
|
|
virtual void onEndCompileUnit(const Unit &CU) {}
|
|
|
|
virtual void onStartDIE(const Unit &CU, const Entry &DIE) {}
|
|
|
|
virtual void onEndDIE(const Unit &CU, const Entry &DIE) {}
|
|
|
|
virtual void onForm(const AttributeAbbrev &AttAbbrev,
|
|
|
|
const FormValue &Value) {}
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
/// Value visitors
|
|
|
|
/// @{
|
|
|
|
virtual void onValue(const uint8_t U) {}
|
|
|
|
virtual void onValue(const uint16_t U) {}
|
|
|
|
virtual void onValue(const uint32_t U) {}
|
|
|
|
virtual void onValue(const uint64_t U, const bool LEB = false) {}
|
|
|
|
virtual void onValue(const int64_t S, const bool LEB = false) {}
|
|
|
|
virtual void onValue(const StringRef String) {}
|
|
|
|
virtual void onValue(const MemoryBufferRef MBR) {}
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
public:
|
|
|
|
VisitorImpl(T &DI) : DebugInfo(DI) {}
|
|
|
|
|
|
|
|
virtual ~VisitorImpl() {}
|
|
|
|
|
|
|
|
void traverseDebugInfo();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void onVariableSizeValue(uint64_t U, unsigned Size);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Making the visior instantiations extern and explicit in the cpp file. This
|
|
|
|
// prevents them from being instantiated in every compile unit that uses the
|
|
|
|
// visitors.
|
|
|
|
extern template class VisitorImpl<DWARFYAML::Data>;
|
|
|
|
extern template class VisitorImpl<const DWARFYAML::Data>;
|
|
|
|
|
|
|
|
class Visitor : public VisitorImpl<Data> {
|
|
|
|
public:
|
|
|
|
Visitor(Data &DI) : VisitorImpl<Data>(DI) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConstVisitor : public VisitorImpl<const Data> {
|
|
|
|
public:
|
|
|
|
ConstVisitor(const Data &DI) : VisitorImpl<const Data>(DI) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace DWARFYAML
|
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
#endif
|