LLVM 22.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
15#include "llvm/Support/Errc.h"
16#include <cstdint>
17
18namespace llvm {
19class DWARFUnit;
20class MCRegisterInfo;
21class raw_ostream;
22class DWARFObject;
23struct DIDumpOptions;
25namespace object {
26struct 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_***).
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).
51public:
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.
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 LLVM_ABI bool
70 std::optional<object::SectionedAddress> BaseAddr,
71 const DWARFObject &Obj, DWARFUnit *U, DIDumpOptions DumpOpts,
72 unsigned Indent) const;
73
75 uint64_t Offset, std::optional<object::SectionedAddress> BaseAddr,
76 std::function<std::optional<object::SectionedAddress>(uint32_t)>
77 LookupAddr,
79
80 const DWARFDataExtractor &getData() { return Data; }
81
82protected:
84
85 virtual void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
86 unsigned Indent, DIDumpOptions DumpOpts,
87 const DWARFObject &Obj) const = 0;
88};
89
91public:
92 /// A list of locations that contain one variable.
93 struct LocationList {
94 /// The beginning offset where this location list is stored in the debug_loc
95 /// section.
97 /// All the locations in which the variable is stored.
99 };
100
101private:
102 using LocationLists = SmallVector<LocationList, 4>;
103
104 /// A list of all the variables in the debug_loc section, each one describing
105 /// the locations in which the variable is stored.
106 LocationLists Locations;
107
108public:
111
112 /// Print the location lists found within the debug_loc section.
113 void dump(raw_ostream &OS, const DWARFObject &Obj, DIDumpOptions DumpOpts,
114 std::optional<uint64_t> Offset) const;
115
116 Error visitLocationList(
118 function_ref<bool(const DWARFLocationEntry &)> Callback) const override;
119
120protected:
121 void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
122 unsigned Indent, DIDumpOptions DumpOpts,
123 const DWARFObject &Obj) const override;
124};
125
127public:
130
131 Error visitLocationList(
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 DWARFObject &Obj, DIDumpOptions DumpOpts);
138
139protected:
140 void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
141 unsigned Indent, DIDumpOptions DumpOpts,
142 const DWARFObject &Obj) const override;
143
144private:
146};
147
148class LLVM_ABI ResolverError : public ErrorInfo<ResolverError> {
149public:
150 static char ID;
151
152 ResolverError(uint32_t Index, dwarf::LoclistEntries Kind) : Index(Index), Kind(Kind) {}
153
154 void log(raw_ostream &OS) const override;
155 std::error_code convertToErrorCode() const override {
157 }
158
159private:
160 uint32_t Index;
162};
163
164} // end namespace llvm
165
166#endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H
#define LLVM_ABI
Definition Compiler.h:213
This file defines the SmallVector class.
A DWARFDataExtractor (typically for an in-memory copy of an object-file section) plus a relocation ma...
DWARFDebugLoc(DWARFDataExtractor Data)
DWARFDebugLoclists(DWARFDataExtractor Data, uint16_t Version)
virtual void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, const DWARFObject &Obj) const =0
DWARFLocationTable(DWARFDataExtractor Data)
DWARFDataExtractor Data
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...
LLVM_ABI Error visitAbsoluteLocationList(uint64_t Offset, std::optional< object::SectionedAddress > BaseAddr, std::function< std::optional< object::SectionedAddress >(uint32_t)> LookupAddr, function_ref< bool(Expected< DWARFLocationExpression >)> Callback) const
LLVM_ABI bool dumpLocationList(uint64_t *Offset, raw_ostream &OS, std::optional< object::SectionedAddress > BaseAddr, const DWARFObject &Obj, DWARFUnit *U, DIDumpOptions DumpOpts, unsigned Indent) const
Dump the location list at the given Offset.
const DWARFDataExtractor & getData()
virtual ~DWARFLocationTable()=default
Base class for user error types.
Definition Error.h:354
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
ResolverError(uint32_t Index, dwarf::LoclistEntries Kind)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
LoclistEntries
DWARF v5 loc list entry encoding values.
Definition Dwarf.h:833
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
@ Offset
Definition DWP.cpp:477
@ invalid_argument
Definition Errc.h:56
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Definition InstrProf.h:302
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:1869
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:851
Container for dump options that control which debug information will be dumped.
Definition DIContext.h:196
A list of locations that contain one variable.
uint64_t Offset
The beginning offset where this location list is stored in the debug_loc section.
SmallVector< DWARFLocationEntry, 2 > Entries
All the locations in which the variable is stored.
A single location within a location list.
SmallVector< uint8_t, 4 > Loc
The location expression itself (if applicable).
uint8_t Kind
The entry kind (DW_LLE_***).
uint64_t Value1
The second value of the location entry (if applicable).
uint64_t SectionIndex
The index of the section this entry is relative to (if applicable).
uint64_t Value0
The first value of the location entry (if applicable).
Represents a single DWARF expression, whose value is location-dependent.