File indexing completed on 2026-05-10 08:43:41
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H
0010 #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H
0011
0012 #include "llvm/ADT/SmallVector.h"
0013 #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
0014 #include "llvm/Support/Errc.h"
0015 #include <cstdint>
0016
0017 namespace llvm {
0018 class DWARFUnit;
0019 class MCRegisterInfo;
0020 class raw_ostream;
0021 class DWARFObject;
0022 struct DIDumpOptions;
0023 struct DWARFLocationExpression;
0024 namespace object {
0025 struct SectionedAddress;
0026 }
0027
0028
0029
0030 struct DWARFLocationEntry {
0031
0032 uint8_t Kind;
0033
0034
0035 uint64_t Value0;
0036
0037
0038 uint64_t Value1;
0039
0040
0041 uint64_t SectionIndex;
0042
0043
0044 SmallVector<uint8_t, 4> Loc;
0045 };
0046
0047
0048
0049 class DWARFLocationTable {
0050 public:
0051 DWARFLocationTable(DWARFDataExtractor Data) : Data(std::move(Data)) {}
0052 virtual ~DWARFLocationTable() = default;
0053
0054
0055
0056
0057
0058
0059 virtual Error visitLocationList(
0060 uint64_t *Offset,
0061 function_ref<bool(const DWARFLocationEntry &)> Callback) const = 0;
0062
0063
0064
0065
0066
0067 bool dumpLocationList(uint64_t *Offset, raw_ostream &OS,
0068 std::optional<object::SectionedAddress> BaseAddr,
0069 const DWARFObject &Obj, DWARFUnit *U,
0070 DIDumpOptions DumpOpts, unsigned Indent) const;
0071
0072 Error visitAbsoluteLocationList(
0073 uint64_t Offset, std::optional<object::SectionedAddress> BaseAddr,
0074 std::function<std::optional<object::SectionedAddress>(uint32_t)>
0075 LookupAddr,
0076 function_ref<bool(Expected<DWARFLocationExpression>)> Callback) const;
0077
0078 const DWARFDataExtractor &getData() { return Data; }
0079
0080 protected:
0081 DWARFDataExtractor Data;
0082
0083 virtual void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
0084 unsigned Indent, DIDumpOptions DumpOpts,
0085 const DWARFObject &Obj) const = 0;
0086 };
0087
0088 class DWARFDebugLoc final : public DWARFLocationTable {
0089 public:
0090
0091 struct LocationList {
0092
0093
0094 uint64_t Offset;
0095
0096 SmallVector<DWARFLocationEntry, 2> Entries;
0097 };
0098
0099 private:
0100 using LocationLists = SmallVector<LocationList, 4>;
0101
0102
0103
0104 LocationLists Locations;
0105
0106 public:
0107 DWARFDebugLoc(DWARFDataExtractor Data)
0108 : DWARFLocationTable(std::move(Data)) {}
0109
0110
0111 void dump(raw_ostream &OS, const DWARFObject &Obj, DIDumpOptions DumpOpts,
0112 std::optional<uint64_t> Offset) const;
0113
0114 Error visitLocationList(
0115 uint64_t *Offset,
0116 function_ref<bool(const DWARFLocationEntry &)> Callback) const override;
0117
0118 protected:
0119 void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
0120 unsigned Indent, DIDumpOptions DumpOpts,
0121 const DWARFObject &Obj) const override;
0122 };
0123
0124 class DWARFDebugLoclists final : public DWARFLocationTable {
0125 public:
0126 DWARFDebugLoclists(DWARFDataExtractor Data, uint16_t Version)
0127 : DWARFLocationTable(std::move(Data)), Version(Version) {}
0128
0129 Error visitLocationList(
0130 uint64_t *Offset,
0131 function_ref<bool(const DWARFLocationEntry &)> Callback) const override;
0132
0133
0134 void dumpRange(uint64_t StartOffset, uint64_t Size, raw_ostream &OS,
0135 const DWARFObject &Obj, DIDumpOptions DumpOpts);
0136
0137 protected:
0138 void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
0139 unsigned Indent, DIDumpOptions DumpOpts,
0140 const DWARFObject &Obj) const override;
0141
0142 private:
0143 uint16_t Version;
0144 };
0145
0146 class ResolverError : public ErrorInfo<ResolverError> {
0147 public:
0148 static char ID;
0149
0150 ResolverError(uint32_t Index, dwarf::LoclistEntries Kind) : Index(Index), Kind(Kind) {}
0151
0152 void log(raw_ostream &OS) const override;
0153 std::error_code convertToErrorCode() const override {
0154 return llvm::errc::invalid_argument;
0155 }
0156
0157 private:
0158 uint32_t Index;
0159 dwarf::LoclistEntries Kind;
0160 };
0161
0162 }
0163
0164 #endif