LLVM  16.0.0git
DWARFDebugLoc.h
Go to the documentation of this file.
1 //===- DWARFDebugLoc.h ------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H
10 #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H
11 
12 #include "llvm/ADT/Optional.h"
13 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/Support/Errc.h"
16 #include <cstdint>
17 
18 namespace llvm {
19 class DWARFUnit;
20 class MCRegisterInfo;
21 class raw_ostream;
22 class DWARFObject;
23 struct DIDumpOptions;
24 struct DWARFLocationExpression;
25 namespace object {
26 struct SectionedAddress;
27 }
28 
29 /// A single location within a location list. Entries are stored in the DWARF5
30 /// form even if they originally come from a DWARF<=4 location list.
32  /// The entry kind (DW_LLE_***).
33  uint8_t Kind;
34 
35  /// The first value of the location entry (if applicable).
37 
38  /// The second value of the location entry (if applicable).
40 
41  /// The index of the section this entry is relative to (if applicable).
43 
44  /// The location expression itself (if applicable).
46 };
47 
48 /// An abstract base class for various kinds of location tables (.debug_loc,
49 /// .debug_loclists, and their dwo variants).
51 public:
53  virtual ~DWARFLocationTable() = default;
54 
55  /// Call the user-provided callback for each entry (including the end-of-list
56  /// entry) in the location list starting at \p Offset. The callback can return
57  /// false to terminate the iteration early. Returns an error if it was unable
58  /// to parse the entire location list correctly. Upon successful termination
59  /// \p Offset will be updated point past the end of the list.
60  virtual Error visitLocationList(
61  uint64_t *Offset,
62  function_ref<bool(const DWARFLocationEntry &)> Callback) const = 0;
63 
64  /// Dump the location list at the given \p Offset. The function returns true
65  /// iff it has successfully reched the end of the list. This means that one
66  /// can attempt to parse another list after the current one (\p Offset will be
67  /// updated to point past the end of the current list).
68  bool dumpLocationList(uint64_t *Offset, raw_ostream &OS,
70  const MCRegisterInfo *MRI, const DWARFObject &Obj,
71  DWARFUnit *U, DIDumpOptions DumpOpts,
72  unsigned Indent) const;
73 
77  function_ref<bool(Expected<DWARFLocationExpression>)> Callback) const;
78 
79  const DWARFDataExtractor &getData() { return Data; }
80 
81 protected:
83 
84  virtual void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
85  unsigned Indent, DIDumpOptions DumpOpts,
86  const DWARFObject &Obj) const = 0;
87 };
88 
89 class DWARFDebugLoc final : public DWARFLocationTable {
90 public:
91  /// A list of locations that contain one variable.
92  struct LocationList {
93  /// The beginning offset where this location list is stored in the debug_loc
94  /// section.
96  /// All the locations in which the variable is stored.
98  };
99 
100 private:
102 
103  /// A list of all the variables in the debug_loc section, each one describing
104  /// the locations in which the variable is stored.
105  LocationLists Locations;
106 
107 public:
110 
111  /// Print the location lists found within the debug_loc section.
112  void dump(raw_ostream &OS, const MCRegisterInfo *RegInfo,
113  const DWARFObject &Obj, DIDumpOptions DumpOpts,
114  Optional<uint64_t> Offset) const;
115 
117  uint64_t *Offset,
118  function_ref<bool(const DWARFLocationEntry &)> Callback) const override;
119 
120 protected:
121  void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
122  unsigned Indent, DIDumpOptions DumpOpts,
123  const DWARFObject &Obj) const override;
124 };
125 
127 public:
129  : DWARFLocationTable(std::move(Data)), Version(Version) {}
130 
132  uint64_t *Offset,
133  function_ref<bool(const DWARFLocationEntry &)> Callback) const override;
134 
135  /// Dump all location lists within the given range.
136  void dumpRange(uint64_t StartOffset, uint64_t Size, raw_ostream &OS,
137  const MCRegisterInfo *MRI, const DWARFObject &Obj,
138  DIDumpOptions DumpOpts);
139 
140 protected:
141  void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
142  unsigned Indent, DIDumpOptions DumpOpts,
143  const DWARFObject &Obj) const override;
144 
145 private:
146  uint16_t Version;
147 };
148 
149 class ResolverError : public ErrorInfo<ResolverError> {
150 public:
151  static char ID;
152 
154 
155  void log(raw_ostream &OS) const override;
156  std::error_code convertToErrorCode() const override {
158  }
159 
160 private:
161  uint32_t Index;
163 };
164 
165 } // end namespace llvm
166 
167 #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H
llvm::ResolverError
Definition: DWARFDebugLoc.h:149
llvm::errc::invalid_argument
@ invalid_argument
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Optional.h
llvm::DWARFLocationTable::DWARFLocationTable
DWARFLocationTable(DWARFDataExtractor Data)
Definition: DWARFDebugLoc.h:52
llvm::DWARFLocationEntry::Value0
uint64_t Value0
The first value of the location entry (if applicable).
Definition: DWARFDebugLoc.h:36
llvm::SmallVector< uint8_t, 4 >
llvm::DWARFLocationEntry::Kind
uint8_t Kind
The entry kind (DW_LLE_***).
Definition: DWARFDebugLoc.h:33
llvm::DWARFLocationTable::~DWARFLocationTable
virtual ~DWARFLocationTable()=default
llvm::DWARFLocationTable
An abstract base class for various kinds of location tables (.debug_loc, .debug_loclists,...
Definition: DWARFDebugLoc.h:50
Errc.h
llvm::Optional
Definition: APInt.h:33
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::DWARFDataExtractor
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
Definition: DWARFDataExtractor.h:21
llvm::dwarf::LoclistEntries
LoclistEntries
DWARF v5 loc list entry encoding values.
Definition: Dwarf.h:416
llvm::DWARFDebugLoclists::DWARFDebugLoclists
DWARFDebugLoclists(DWARFDataExtractor Data, uint16_t Version)
Definition: DWARFDebugLoc.h:128
llvm::DWARFLocationEntry::SectionIndex
uint64_t SectionIndex
The index of the section this entry is relative to (if applicable).
Definition: DWARFDebugLoc.h:42
llvm::DWARFDebugLoc::dumpRawEntry
void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, const DWARFObject &Obj) const override
Definition: DWARFDebugLoc.cpp:250
llvm::DWARFLocationEntry
A single location within a location list.
Definition: DWARFDebugLoc.h:31
llvm::DWARFDebugLoclists
Definition: DWARFDebugLoc.h:126
llvm::DWARFLocationTable::dumpLocationList
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
Dump the location list at the given Offset.
Definition: DWARFDebugLoc.cpp:123
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::DWARFObject
Definition: DWARFObject.h:25
llvm::DWARFDebugLoc::LocationList::Entries
SmallVector< DWARFLocationEntry, 2 > Entries
All the locations in which the variable is stored.
Definition: DWARFDebugLoc.h:97
llvm::DWARFDebugLoc::LocationList::Offset
uint64_t Offset
The beginning offset where this location list is stored in the debug_loc section.
Definition: DWARFDebugLoc.h:95
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
llvm::ResolverError::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: DWARFDebugLoc.cpp:410
llvm::DWARFLocationTable::visitAbsoluteLocationList
Error visitAbsoluteLocationList(uint64_t Offset, Optional< object::SectionedAddress > BaseAddr, std::function< Optional< object::SectionedAddress >(uint32_t)> LookupAddr, function_ref< bool(Expected< DWARFLocationExpression >)> Callback) const
Definition: DWARFDebugLoc.cpp:172
llvm::DWARFDebugLoc
Definition: DWARFDebugLoc.h:89
uint64_t
llvm::ResolverError::ResolverError
ResolverError(uint32_t Index, dwarf::LoclistEntries Kind)
Definition: DWARFDebugLoc.h:153
llvm::DWARFLocationTable::getData
const DWARFDataExtractor & getData()
Definition: DWARFDebugLoc.h:79
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1666
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::ErrorInfo
Base class for user error types.
Definition: Error.h:347
RegInfo
Definition: AMDGPUAsmParser.cpp:2561
llvm::DWARFLocationTable::visitLocationList
virtual Error visitLocationList(uint64_t *Offset, function_ref< bool(const DWARFLocationEntry &)> Callback) const =0
Call the user-provided callback for each entry (including the end-of-list entry) in the location list...
uint32_t
llvm::DWARFDebugLoc::DWARFDebugLoc
DWARFDebugLoc(DWARFDataExtractor Data)
Definition: DWARFDebugLoc.h:108
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition: MCRegisterInfo.h:135
llvm::DWARFDebugLoc::dump
void dump(raw_ostream &OS, const MCRegisterInfo *RegInfo, const DWARFObject &Obj, DIDumpOptions DumpOpts, Optional< uint64_t > Offset) const
Print the location lists found within the debug_loc section.
Definition: DWARFDebugLoc.cpp:187
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
std
Definition: BitVector.h:851
uint16_t
llvm::DWARFUnit
Definition: DWARFUnit.h:207
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::DWARFDebugLoc::visitLocationList
Error visitLocationList(uint64_t *Offset, function_ref< bool(const DWARFLocationEntry &)> Callback) const override
Call the user-provided callback for each entry (including the end-of-list entry) in the location list...
Definition: DWARFDebugLoc.cpp:210
llvm::DWARFLocationTable::dumpRawEntry
virtual void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, const DWARFObject &Obj) const =0
llvm::DWARFDebugLoc::LocationList
A list of locations that contain one variable.
Definition: DWARFDebugLoc.h:92
llvm::ResolverError::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: DWARFDebugLoc.h:156
SmallVector.h
llvm::DWARFLocationTable::Data
DWARFDataExtractor Data
Definition: DWARFDebugLoc.h:82
llvm::DWARFDebugLoclists::dumpRange
void dumpRange(uint64_t StartOffset, uint64_t Size, raw_ostream &OS, const MCRegisterInfo *MRI, const DWARFObject &Obj, DIDumpOptions DumpOpts)
Dump all location lists within the given range.
Definition: DWARFDebugLoc.cpp:389
llvm::DWARFLocationEntry::Value1
uint64_t Value1
The second value of the location entry (if applicable).
Definition: DWARFDebugLoc.h:39
llvm::object::SectionedAddress
Definition: ObjectFile.h:144
llvm::DWARFDebugLoclists::visitLocationList
Error visitLocationList(uint64_t *Offset, function_ref< bool(const DWARFLocationEntry &)> Callback) const override
Call the user-provided callback for each entry (including the end-of-list entry) in the location list...
Definition: DWARFDebugLoc.cpp:276
llvm::DWARFDebugLoclists::dumpRawEntry
void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, const DWARFObject &Obj) const override
Definition: DWARFDebugLoc.cpp:343
llvm::DWARFLocationEntry::Loc
SmallVector< uint8_t, 4 > Loc
The location expression itself (if applicable).
Definition: DWARFDebugLoc.h:45
llvm::ResolverError::ID
static char ID
Definition: DWARFDebugLoc.h:151
DWARFDataExtractor.h
llvm::DIDumpOptions
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:188