LLVM 24.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 raw_ostream;
21class DWARFObject;
22struct DIDumpOptions;
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_***).
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).
67 LLVM_ABI bool
69 std::optional<object::SectionedAddress> BaseAddr,
70 const DWARFObject &Obj, DWARFUnit *U, DIDumpOptions DumpOpts,
71 unsigned Indent) const;
72
74 uint64_t Offset, std::optional<object::SectionedAddress> BaseAddr,
75 std::function<std::optional<object::SectionedAddress>(uint32_t)>
76 LookupAddr,
78
79 const DWARFDataExtractor &getData() { return Data; }
80
81protected:
83
84 virtual void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
85 unsigned Indent, DIDumpOptions DumpOpts,
86 const DWARFObject &Obj) const = 0;
87};
88
90public:
93
94 /// Print the location lists found within the debug_loc section.
95 void dump(raw_ostream &OS, const DWARFObject &Obj, DIDumpOptions DumpOpts,
96 std::optional<uint64_t> Offset) const;
97
98 Error visitLocationList(
100 function_ref<bool(const DWARFLocationEntry &)> Callback) const override;
101
102protected:
103 void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
104 unsigned Indent, DIDumpOptions DumpOpts,
105 const DWARFObject &Obj) const override;
106};
107
109public:
112
113 Error visitLocationList(
115 function_ref<bool(const DWARFLocationEntry &)> Callback) const override;
116
117 /// Dump all location lists within the given range.
118 void dumpRange(uint64_t StartOffset, uint64_t Size, raw_ostream &OS,
119 const DWARFObject &Obj, DIDumpOptions DumpOpts);
120
121protected:
122 void dumpRawEntry(const DWARFLocationEntry &Entry, raw_ostream &OS,
123 unsigned Indent, DIDumpOptions DumpOpts,
124 const DWARFObject &Obj) const override;
125
126private:
128};
129
130class LLVM_ABI ResolverError : public ErrorInfo<ResolverError> {
131public:
132 static char ID;
133
134 ResolverError(uint32_t Index, dwarf::LoclistEntries Kind) : Index(Index), Kind(Kind) {}
135
136 void log(raw_ostream &OS) const override;
137 std::error_code convertToErrorCode() const override {
139 }
140
141private:
142 uint32_t Index;
144};
145
146} // end namespace llvm
147
148#endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H
uint64_t uint64_t
#define LLVM_ABI
Definition Compiler.h:211
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
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:950
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
@ Offset
Definition DWP.cpp:577
@ invalid_argument
Definition Errc.h:56
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:1933
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
Container for dump options that control which debug information will be dumped.
Definition DIContext.h:197
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.