LLVM 17.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
14#include "llvm/Support/Errc.h"
15#include <cstdint>
16
17namespace llvm {
18class DWARFUnit;
19class MCRegisterInfo;
20class raw_ostream;
21class DWARFObject;
22struct DIDumpOptions;
23struct DWARFLocationExpression;
24namespace object {
25struct SectionedAddress;
26}
27
28/// A single location within a location list. Entries are stored in the DWARF5
29/// form even if they originally come from a DWARF<=4 location list.
31 /// The entry kind (DW_LLE_***).
32 uint8_t Kind;
33
34 /// The first value of the location entry (if applicable).
36
37 /// The second value of the location entry (if applicable).
39
40 /// The index of the section this entry is relative to (if applicable).
42
43 /// The location expression itself (if applicable).
45};
46
47/// An abstract base class for various kinds of location tables (.debug_loc,
48/// .debug_loclists, and their dwo variants).
50public:
52 virtual ~DWARFLocationTable() = default;
53
54 /// Call the user-provided callback for each entry (including the end-of-list
55 /// entry) in the location list starting at \p Offset. The callback can return
56 /// false to terminate the iteration early. Returns an error if it was unable
57 /// to parse the entire location list correctly. Upon successful termination
58 /// \p Offset will be updated point past the end of the list.
61 function_ref<bool(const DWARFLocationEntry &)> Callback) const = 0;
62
63 /// Dump the location list at the given \p Offset. The function returns true
64 /// iff it has successfully reched the end of the list. This means that one
65 /// can attempt to parse another list after the current one (\p Offset will be
66 /// updated to point past the end of the current list).
68 std::optional<object::SectionedAddress> BaseAddr,
69 const DWARFObject &Obj, DWARFUnit *U,
70 DIDumpOptions DumpOpts, unsigned Indent) const;
71
73 uint64_t Offset, std::optional<object::SectionedAddress> BaseAddr,
74 std::function<std::optional<object::SectionedAddress>(uint32_t)>
75 LookupAddr,
77
78 const DWARFDataExtractor &getData() { return Data; }
79
80protected:
82
83 virtual void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
84 unsigned Indent, DIDumpOptions DumpOpts,
85 const DWARFObject &Obj) const = 0;
86};
87
88class DWARFDebugLoc final : public DWARFLocationTable {
89public:
90 /// A list of locations that contain one variable.
91 struct LocationList {
92 /// The beginning offset where this location list is stored in the debug_loc
93 /// section.
95 /// All the locations in which the variable is stored.
97 };
98
99private:
101
102 /// A list of all the variables in the debug_loc section, each one describing
103 /// the locations in which the variable is stored.
104 LocationLists Locations;
105
106public:
109
110 /// Print the location lists found within the debug_loc section.
111 void dump(raw_ostream &OS, const DWARFObject &Obj, DIDumpOptions DumpOpts,
112 std::optional<uint64_t> Offset) const;
113
116 function_ref<bool(const DWARFLocationEntry &)> Callback) const override;
117
118protected:
119 void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
120 unsigned Indent, DIDumpOptions DumpOpts,
121 const DWARFObject &Obj) const override;
122};
123
125public:
127 : DWARFLocationTable(std::move(Data)), Version(Version) {}
128
131 function_ref<bool(const DWARFLocationEntry &)> Callback) const override;
132
133 /// Dump all location lists within the given range.
134 void dumpRange(uint64_t StartOffset, uint64_t Size, raw_ostream &OS,
135 const DWARFObject &Obj, DIDumpOptions DumpOpts);
136
137protected:
138 void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
139 unsigned Indent, DIDumpOptions DumpOpts,
140 const DWARFObject &Obj) const override;
141
142private:
143 uint16_t Version;
144};
145
146class ResolverError : public ErrorInfo<ResolverError> {
147public:
148 static char ID;
149
151
152 void log(raw_ostream &OS) const override;
153 std::error_code convertToErrorCode() const override {
155 }
156
157private:
160};
161
162} // end namespace llvm
163
164#endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H
uint64_t Size
This file defines the SmallVector class.
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, const DWARFObject &Obj) const override
void dump(raw_ostream &OS, const DWARFObject &Obj, DIDumpOptions DumpOpts, std::optional< uint64_t > Offset) const
Print the location lists found within the debug_loc section.
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...
DWARFDebugLoc(DWARFDataExtractor Data)
void dumpRange(uint64_t StartOffset, uint64_t Size, raw_ostream &OS, const DWARFObject &Obj, DIDumpOptions DumpOpts)
Dump all location lists within the given range.
DWARFDebugLoclists(DWARFDataExtractor Data, uint16_t Version)
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...
void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, const DWARFObject &Obj) const override
An abstract base class for various kinds of location tables (.debug_loc, .debug_loclists,...
Definition: DWARFDebugLoc.h:49
virtual void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts, const DWARFObject &Obj) const =0
DWARFLocationTable(DWARFDataExtractor Data)
Definition: DWARFDebugLoc.h:51
DWARFDataExtractor Data
Definition: DWARFDebugLoc.h:81
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...
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
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()
Definition: DWARFDebugLoc.h:78
virtual ~DWARFLocationTable()=default
Base class for user error types.
Definition: Error.h:348
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
Tagged union holding either a T or a Error.
Definition: Error.h:470
void log(raw_ostream &OS) const override
Print an error message to an output stream.
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.
Definition: SmallVector.h:1200
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:52
LoclistEntries
DWARF v5 loc list entry encoding values.
Definition: Dwarf.h:494
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:406
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:1862
Definition: BitVector.h:851
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:189
A list of locations that contain one variable.
Definition: DWARFDebugLoc.h:91
uint64_t Offset
The beginning offset where this location list is stored in the debug_loc section.
Definition: DWARFDebugLoc.h:94
SmallVector< DWARFLocationEntry, 2 > Entries
All the locations in which the variable is stored.
Definition: DWARFDebugLoc.h:96
A single location within a location list.
Definition: DWARFDebugLoc.h:30
SmallVector< uint8_t, 4 > Loc
The location expression itself (if applicable).
Definition: DWARFDebugLoc.h:44
uint8_t Kind
The entry kind (DW_LLE_***).
Definition: DWARFDebugLoc.h:32
uint64_t Value1
The second value of the location entry (if applicable).
Definition: DWARFDebugLoc.h:38
uint64_t SectionIndex
The index of the section this entry is relative to (if applicable).
Definition: DWARFDebugLoc.h:41
uint64_t Value0
The first value of the location entry (if applicable).
Definition: DWARFDebugLoc.h:35