LLVM  14.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"
18 #include <cstdint>
19 
20 namespace llvm {
21 class DWARFUnit;
22 class MCRegisterInfo;
23 class raw_ostream;
24 
25 /// A single location within a location list. Entries are stored in the DWARF5
26 /// form even if they originally come from a DWARF<=4 location list.
28  /// The entry kind (DW_LLE_***).
29  uint8_t Kind;
30 
31  /// The first value of the location entry (if applicable).
33 
34  /// The second value of the location entry (if applicable).
36 
37  /// The index of the section this entry is relative to (if applicable).
39 
40  /// The location expression itself (if applicable).
42 };
43 
44 /// An abstract base class for various kinds of location tables (.debug_loc,
45 /// .debug_loclists, and their dwo variants).
47 public:
49  virtual ~DWARFLocationTable() = default;
50 
51  /// Call the user-provided callback for each entry (including the end-of-list
52  /// entry) in the location list starting at \p Offset. The callback can return
53  /// false to terminate the iteration early. Returns an error if it was unable
54  /// to parse the entire location list correctly. Upon successful termination
55  /// \p Offset will be updated point past the end of the list.
56  virtual Error visitLocationList(
58  function_ref<bool(const DWARFLocationEntry &)> Callback) const = 0;
59 
60  /// Dump the location list at the given \p Offset. The function returns true
61  /// iff it has successfully reched the end of the list. This means that one
62  /// can attempt to parse another list after the current one (\p Offset will be
63  /// updated to point past the end of the current list).
66  const MCRegisterInfo *MRI, const DWARFObject &Obj,
67  DWARFUnit *U, DIDumpOptions DumpOpts,
68  unsigned Indent) const;
69 
73  function_ref<bool(Expected<DWARFLocationExpression>)> Callback) const;
74 
75  const DWARFDataExtractor &getData() { return Data; }
76 
77 protected:
79 
80  virtual void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
81  unsigned Indent, DIDumpOptions DumpOpts,
82  const DWARFObject &Obj) const = 0;
83 };
84 
85 class DWARFDebugLoc final : public DWARFLocationTable {
86 public:
87  /// A list of locations that contain one variable.
88  struct LocationList {
89  /// The beginning offset where this location list is stored in the debug_loc
90  /// section.
92  /// All the locations in which the variable is stored.
94  };
95 
96 private:
98 
99  /// A list of all the variables in the debug_loc section, each one describing
100  /// the locations in which the variable is stored.
101  LocationLists Locations;
102 
103 public:
106 
107  /// Print the location lists found within the debug_loc section.
108  void dump(raw_ostream &OS, const MCRegisterInfo *RegInfo,
109  const DWARFObject &Obj, DIDumpOptions DumpOpts,
110  Optional<uint64_t> Offset) const;
111 
113  uint64_t *Offset,
114  function_ref<bool(const DWARFLocationEntry &)> Callback) const override;
115 
116 protected:
117  void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
118  unsigned Indent, DIDumpOptions DumpOpts,
119  const DWARFObject &Obj) const override;
120 };
121 
123 public:
125  : DWARFLocationTable(std::move(Data)), Version(Version) {}
126 
128  uint64_t *Offset,
129  function_ref<bool(const DWARFLocationEntry &)> Callback) const override;
130 
131  /// Dump all location lists within the given range.
132  void dumpRange(uint64_t StartOffset, uint64_t Size, raw_ostream &OS,
133  const MCRegisterInfo *MRI, const DWARFObject &Obj,
134  DIDumpOptions DumpOpts);
135 
136 protected:
137  void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
138  unsigned Indent, DIDumpOptions DumpOpts,
139  const DWARFObject &Obj) const override;
140 
141 private:
142  uint16_t Version;
143 };
144 
145 } // end namespace llvm
146 
147 #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
Optional.h
llvm::DWARFLocationTable::DWARFLocationTable
DWARFLocationTable(DWARFDataExtractor Data)
Definition: DWARFDebugLoc.h:48
llvm::DWARFLocationEntry::Value0
uint64_t Value0
The first value of the location entry (if applicable).
Definition: DWARFDebugLoc.h:32
llvm::SmallVector< uint8_t, 4 >
llvm::DWARFLocationEntry::Kind
uint8_t Kind
The entry kind (DW_LLE_***).
Definition: DWARFDebugLoc.h:29
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:46
DWARFRelocMap.h
llvm::Optional
Definition: APInt.h:33
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
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::DWARFDebugLoclists::DWARFDebugLoclists
DWARFDebugLoclists(DWARFDataExtractor Data, uint16_t Version)
Definition: DWARFDebugLoc.h:124
llvm::DWARFLocationEntry::SectionIndex
uint64_t SectionIndex
The index of the section this entry is relative to (if applicable).
Definition: DWARFDebugLoc.h:38
llvm::DWARFDebugLoc::dumpRawEntry
void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, const DWARFObject &Obj) const override
Definition: DWARFDebugLoc.cpp:248
llvm::DWARFLocationEntry
A single location within a location list.
Definition: DWARFDebugLoc.h:27
llvm::DWARFDebugLoclists
Definition: DWARFDebugLoc.h:122
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:121
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
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:93
llvm::DWARFDebugLoc::LocationList::Offset
uint64_t Offset
The beginning offset where this location list is stored in the debug_loc section.
Definition: DWARFDebugLoc.h:91
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:168
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:170
llvm::DWARFDebugLoc
Definition: DWARFDebugLoc.h:85
uint64_t
llvm::DWARFLocationTable::getData
const DWARFDataExtractor & getData()
Definition: DWARFDebugLoc.h:75
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:1639
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
RegInfo
Definition: AMDGPUAsmParser.cpp:2384
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:104
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition: MCRegisterInfo.h:135
DWARFLocationExpression.h
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:185
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
DIContext.h
std
Definition: BitVector.h:838
uint16_t
llvm::DWARFUnit
Definition: DWARFUnit.h:203
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
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:208
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:88
SmallVector.h
llvm::DWARFLocationTable::Data
DWARFDataExtractor Data
Definition: DWARFDebugLoc.h:78
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:387
llvm::DWARFLocationEntry::Value1
uint64_t Value1
The second value of the location entry (if applicable).
Definition: DWARFDebugLoc.h:35
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:274
llvm::DWARFDebugLoclists::dumpRawEntry
void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, const DWARFObject &Obj) const override
Definition: DWARFDebugLoc.cpp:341
llvm::DWARFLocationEntry::Loc
SmallVector< uint8_t, 4 > Loc
The location expression itself (if applicable).
Definition: DWARFDebugLoc.h:41
DWARFDataExtractor.h
llvm::DIDumpOptions
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:180