LLDB mainline
DWARFExpressionList.h
Go to the documentation of this file.
1//===-- DWARFExpressionList.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 LLDB_EXPRESSION_DWARFEXPRESSIONLIST_H
10#define LLDB_EXPRESSION_DWARFEXPRESSIONLIST_H
11
13#include "lldb/Core/Value.h"
16#include "lldb/lldb-private.h"
17
18namespace lldb_private {
19
20/// \class DWARFExpressionList DWARFExpressionList.h
21/// "lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file
22/// address range to a single DWARF location expression.
24public:
26
28 const DWARFExpression::Delegate *dwarf_cu,
29 lldb::addr_t func_file_addr)
30 : m_module_wp(module_sp), m_dwarf_cu(dwarf_cu),
31 m_func_file_addr(func_file_addr) {}
32
34 const DWARFExpression::Delegate *dwarf_cu)
35 : m_module_wp(module_sp), m_dwarf_cu(dwarf_cu) {
37 }
38
39 /// Return true if the location expression contains data
40 bool IsValid() const { return !m_exprs.IsEmpty(); }
41
42 void Clear() { m_exprs.Clear(); }
43
44 // Return true if the location expression is always valid.
45 bool IsAlwaysValidSingleExpr() const;
46
48
49 /// Get the expression data at the file address.
51 lldb::addr_t func_load_addr = LLDB_INVALID_ADDRESS,
52 lldb::addr_t file_addr = 0) const;
53
54 /// Sort m_expressions.
55 void Sort() { m_exprs.Sort(); }
56
57 void SetFuncFileAddress(lldb::addr_t func_file_addr) {
58 m_func_file_addr = func_file_addr;
59 }
60
62
63 /// Represents an entry in the DWARFExpressionList with all needed metadata.
65 /// Represents a DWARF location range in the DWARF unit’s file‐address space
66 std::optional<AddressRange> file_range; ///< None = always-valid single expr
68 };
69
70 /// Returns a DWARFExpressionEntry whose file_range contains the given
71 /// load‐address. `func_load_addr` is the load‐address of the function
72 /// start; `load_addr` is the full runtime PC. On success, `expr` is
73 /// non-null.
74 std::optional<DWARFExpressionEntry>
76 lldb::addr_t load_addr) const;
77
79 lldb::addr_t load_addr) const;
80
82
84 lldb::addr_t func_load_addr = LLDB_INVALID_ADDRESS,
85 lldb::addr_t load_addr = 0);
86
87 size_t GetSize() const { return m_exprs.GetSize(); }
88
89 bool ContainsThreadLocalStorage() const;
90
92 lldb::ModuleSP new_module_sp,
93 std::function<lldb::addr_t(lldb::addr_t file_addr)> const
94 &link_address_callback);
95
96 bool MatchesOperand(StackFrame &frame,
97 const Instruction::Operand &operand) const;
98
99 /// Dump locations that contains file_addr if it's valid. Otherwise. dump all
100 /// locations.
102 lldb::addr_t func_load_addr, lldb::addr_t file_addr,
103 ABI *abi) const;
104
105 /// Dump all locaitons with each separated by new line.
106 void GetDescription(Stream *s, lldb::DescriptionLevel level, ABI *abi) const;
107
108 /// Search for a load address in the dwarf location list
109 ///
110 /// \param[in] func_load_addr
111 /// The actual address of the function containing this location list.
112 ///
113 /// \param[in] addr
114 /// The address to resolve.
115 ///
116 /// \return
117 /// True if IsLocationList() is true and the address was found;
118 /// false otherwise.
119 bool ContainsAddress(lldb::addr_t func_load_addr, lldb::addr_t addr) const;
120
121 void SetModule(const lldb::ModuleSP &module) { m_module_wp = module; }
122
123 llvm::Expected<Value> Evaluate(ExecutionContext *exe_ctx,
124 RegisterContext *reg_ctx,
125 lldb::addr_t func_load_addr,
126 const Value *initial_value_ptr,
127 const Value *object_address_ptr) const;
128
129private:
130 // RangeDataVector requires a comparator for DWARFExpression, but it doesn't
131 // make sense to do so.
133 public:
135 const DWARFExpression &rhs) const {
136 return false;
137 }
138 };
142
143 // File address range mapping to single dwarf expression.
145
146 /// Module which defined this expression.
148
149 /// The DWARF compile unit this expression belongs to. It is used to evaluate
150 /// values indexing into the .debug_addr section (e.g. DW_OP_GNU_addr_index,
151 /// DW_OP_GNU_const_index)
153
154 // Function base file address.
156
158 const_iterator begin() const { return m_exprs.begin(); }
159 const_iterator end() const { return m_exprs.end(); }
160};
161} // namespace lldb_private
162
163#endif // LLDB_EXPRESSION_DWARFEXPRESSIONLIST_H
bool AddExpression(lldb::addr_t base, lldb::addr_t end, DWARFExpression expr)
const DWARFExpression * GetExpressionAtAddress(lldb::addr_t func_load_addr, lldb::addr_t load_addr) const
const DWARFExpression::Delegate * m_dwarf_cu
The DWARF compile unit this expression belongs to.
void GetDescription(Stream *s, lldb::DescriptionLevel level, ABI *abi) const
Dump all locaitons with each separated by new line.
bool MatchesOperand(StackFrame &frame, const Instruction::Operand &operand) const
llvm::Expected< Value > Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::addr_t func_load_addr, const Value *initial_value_ptr, const Value *object_address_ptr) const
DWARFExpressionList(lldb::ModuleSP module_sp, DWARFExpression expr, const DWARFExpression::Delegate *dwarf_cu)
const DWARFExpression * GetAlwaysValidExpr() const
lldb::ModuleWP m_module_wp
Module which defined this expression.
bool GetExpressionData(DataExtractor &data, lldb::addr_t func_load_addr=LLDB_INVALID_ADDRESS, lldb::addr_t file_addr=0) const
Get the expression data at the file address.
std::optional< DWARFExpressionEntry > GetExpressionEntryAtAddress(lldb::addr_t func_load_addr, lldb::addr_t load_addr) const
Returns a DWARFExpressionEntry whose file_range contains the given load‐address.
void SetModule(const lldb::ModuleSP &module)
bool IsValid() const
Return true if the location expression contains data.
void SetFuncFileAddress(lldb::addr_t func_file_addr)
DWARFExpressionList(lldb::ModuleSP module_sp, const DWARFExpression::Delegate *dwarf_cu, lldb::addr_t func_file_addr)
bool DumpLocations(Stream *s, lldb::DescriptionLevel level, lldb::addr_t func_load_addr, lldb::addr_t file_addr, ABI *abi) const
Dump locations that contains file_addr if it's valid.
bool LinkThreadLocalStorage(lldb::ModuleSP new_module_sp, std::function< lldb::addr_t(lldb::addr_t file_addr)> const &link_address_callback)
bool ContainsAddress(lldb::addr_t func_load_addr, lldb::addr_t addr) const
Search for a load address in the dwarf location list.
DWARFExpression * GetMutableExpressionAtAddress(lldb::addr_t func_load_addr=LLDB_INVALID_ADDRESS, lldb::addr_t load_addr=0)
ExprVec::Collection::const_iterator const_iterator
RangeDataVector< lldb::addr_t, lldb::addr_t, DWARFExpression, 0, DWARFExpressionCompare > ExprVec
"lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location expression and interprets it.
An data extractor class.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
This base class provides an interface to stack frames.
Definition StackFrame.h:44
A stream class that can stream formatted output to a file.
Definition Stream.h:28
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
std::weak_ptr< lldb_private::Module > ModuleWP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
bool operator()(const DWARFExpression &lhs, const DWARFExpression &rhs) const
Represents an entry in the DWARFExpressionList with all needed metadata.
std::optional< AddressRange > file_range
Represents a DWARF location range in the DWARF unit’s file‐address space.