#ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H
#define LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
#include "llvm/Support/Errc.h"
#include <cstdint>
namespace llvm {
class DWARFUnit;
class MCRegisterInfo;
class raw_ostream;
class DWARFObject;
struct DIDumpOptions;
struct DWARFLocationExpression;
namespace object {
struct SectionedAddress;
}
struct DWARFLocationEntry {
uint8_t Kind;
uint64_t Value0;
uint64_t Value1;
uint64_t SectionIndex;
SmallVector<uint8_t, 4> Loc;
};
class DWARFLocationTable {
public:
DWARFLocationTable(DWARFDataExtractor Data) : Data(std::move(Data)) {}
virtual ~DWARFLocationTable() = default;
virtual Error visitLocationList(
uint64_t *Offset,
function_ref<bool(const DWARFLocationEntry &)> Callback) const = 0;
bool dumpLocationList(uint64_t *Offset, raw_ostream &OS,
Optional<object::SectionedAddress> BaseAddr,
const MCRegisterInfo *MRI, const DWARFObject &Obj,
DWARFUnit *U, DIDumpOptions DumpOpts,
unsigned Indent) const;
Error visitAbsoluteLocationList(
uint64_t Offset, Optional<object::SectionedAddress> BaseAddr,
std::function<Optional<object::SectionedAddress>(uint32_t)> LookupAddr,
function_ref<bool(Expected<DWARFLocationExpression>)> Callback) const;
const DWARFDataExtractor &getData() { return Data; }
protected:
DWARFDataExtractor Data;
virtual void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
unsigned Indent, DIDumpOptions DumpOpts,
const DWARFObject &Obj) const = 0;
};
class DWARFDebugLoc final : public DWARFLocationTable {
public:
struct LocationList {
uint64_t Offset;
SmallVector<DWARFLocationEntry, 2> Entries;
};
private:
using LocationLists = SmallVector<LocationList, 4>;
LocationLists Locations;
public:
DWARFDebugLoc(DWARFDataExtractor Data)
: DWARFLocationTable(std::move(Data)) {}
void dump(raw_ostream &OS, const MCRegisterInfo *RegInfo,
const DWARFObject &Obj, DIDumpOptions DumpOpts,
Optional<uint64_t> Offset) const;
Error visitLocationList(
uint64_t *Offset,
function_ref<bool(const DWARFLocationEntry &)> Callback) const override;
protected:
void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
unsigned Indent, DIDumpOptions DumpOpts,
const DWARFObject &Obj) const override;
};
class DWARFDebugLoclists final : public DWARFLocationTable {
public:
DWARFDebugLoclists(DWARFDataExtractor Data, uint16_t Version)
: DWARFLocationTable(std::move(Data)), Version(Version) {}
Error visitLocationList(
uint64_t *Offset,
function_ref<bool(const DWARFLocationEntry &)> Callback) const override;
void dumpRange(uint64_t StartOffset, uint64_t Size, raw_ostream &OS,
const MCRegisterInfo *MRI, const DWARFObject &Obj,
DIDumpOptions DumpOpts);
protected:
void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
unsigned Indent, DIDumpOptions DumpOpts,
const DWARFObject &Obj) const override;
private:
uint16_t Version;
};
class ResolverError : public ErrorInfo<ResolverError> {
public:
static char ID;
ResolverError(uint32_t Index, dwarf::LoclistEntries Kind) : Index(Index), Kind(Kind) {}
void log(raw_ostream &OS) const override;
std::error_code convertToErrorCode() const override {
return llvm::errc::invalid_argument;
}
private:
uint32_t Index;
dwarf::LoclistEntries Kind;
};
}
#endif