LLDB mainline
DWARFExpression.h
Go to the documentation of this file.
1//===-- DWARFExpression.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_DWARFEXPRESSION_H
10#define LLDB_EXPRESSION_DWARFEXPRESSION_H
11
12#include "lldb/Core/Address.h"
15#include "lldb/Utility/Scalar.h"
16#include "lldb/Utility/Status.h"
17#include "lldb/lldb-private.h"
18#include "llvm/DebugInfo/DWARF/DWARFLocationExpression.h"
19#include "llvm/Support/Error.h"
20#include <functional>
21
22namespace lldb_private {
23
24namespace plugin {
25namespace dwarf {
26class DWARFUnit;
27} // namespace dwarf
28} // namespace plugin
29
30/// \class DWARFExpression DWARFExpression.h
31/// "lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location
32/// expression and interprets it.
33///
34/// DWARF location expressions are used in two ways by LLDB. The first
35/// use is to find entities specified in the debug information, since their
36/// locations are specified in precisely this language. The second is to
37/// interpret expressions without having to run the target in cases where the
38/// overhead from copying JIT-compiled code into the target is too high or
39/// where the target cannot be run. This class encapsulates a single DWARF
40/// location expression or a location list and interprets it.
42public:
44
45 /// Constructor
46 ///
47 /// \param[in] data
48 /// A data extractor configured to read the DWARF location expression's
49 /// bytecode.
50 DWARFExpression(const DataExtractor &data);
51
52 /// Destructor
54
55 /// Return true if the location expression contains data
56 bool IsValid() const;
57
58 /// Return the address specified by the first
59 /// DW_OP_{addr, addrx, GNU_addr_index} in the operation stream.
60 ///
61 /// \param[in] dwarf_cu
62 /// The dwarf unit this expression belongs to. Only required to resolve
63 /// DW_OP{addrx, GNU_addr_index}.
64 ///
65 /// \return
66 /// The address specified by the operation, if the operation exists, or
67 /// an llvm::Error otherwise.
68 llvm::Expected<lldb::addr_t>
70
72 lldb::addr_t file_addr);
73
74 void UpdateValue(uint64_t const_value, lldb::offset_t const_value_byte_size,
75 uint8_t addr_byte_size);
76
77 bool
79
81 const plugin::dwarf::DWARFUnit *dwarf_cu,
82 std::function<lldb::addr_t(lldb::addr_t file_addr)> const
83 &link_address_callback);
84
85 /// Return the call-frame-info style register kind
87
88 /// Set the call-frame-info style register kind
89 ///
90 /// \param[in] reg_kind
91 /// The register kind.
93
94 /// Evaluate a DWARF location expression in a particular context
95 ///
96 /// \param[in] exe_ctx
97 /// The execution context in which to evaluate the location
98 /// expression. The location expression may access the target's
99 /// memory, especially if it comes from the expression parser.
100 ///
101 /// \param[in] opcode_ctx
102 /// The module which defined the expression.
103 ///
104 /// \param[in] opcodes
105 /// This is a static method so the opcodes need to be provided
106 /// explicitly.
107 ///
108 /// \param[in] reg_ctx
109 /// An optional parameter which provides a RegisterContext for use
110 /// when evaluating the expression (i.e. for fetching register values).
111 /// Normally this will come from the ExecutionContext's StackFrame but
112 /// in the case where an expression needs to be evaluated while building
113 /// the stack frame list, this short-cut is available.
114 ///
115 /// \param[in] reg_set
116 /// The call-frame-info style register kind.
117 ///
118 /// \param[in] initial_value_ptr
119 /// A value to put on top of the interpreter stack before evaluating
120 /// the expression, if the expression is parametrized. Can be NULL.
121 ///
122 /// \param[in] result
123 /// A value into which the result of evaluating the expression is
124 /// to be placed.
125 ///
126 /// \param[in] error_ptr
127 /// If non-NULL, used to report errors in expression evaluation.
128 ///
129 /// \return
130 /// True on success; false otherwise. If error_ptr is non-NULL,
131 /// details of the failure are provided through it.
132 static llvm::Expected<Value>
133 Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
134 lldb::ModuleSP module_sp, const DataExtractor &opcodes,
135 const plugin::dwarf::DWARFUnit *dwarf_cu,
136 const lldb::RegisterKind reg_set, const Value *initial_value_ptr,
137 const Value *object_address_ptr);
138
139 static bool ParseDWARFLocationList(const plugin::dwarf::DWARFUnit *dwarf_cu,
140 const DataExtractor &data,
141 DWARFExpressionList *loc_list);
142
144 data = m_data;
145 return data.GetByteSize() > 0;
146 }
147
148 void DumpLocation(Stream *s, lldb::DescriptionLevel level, ABI *abi) const;
149
150 bool MatchesOperand(StackFrame &frame, const Instruction::Operand &op) const;
151
152private:
153 /// A data extractor capable of reading opcode bytes
155
156 /// One of the defines that starts with LLDB_REGKIND_
158};
159
160} // namespace lldb_private
161
162#endif // LLDB_EXPRESSION_DWARFEXPRESSION_H
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
"lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location expression and interprets it.
static llvm::Expected< Value > Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::ModuleSP module_sp, const DataExtractor &opcodes, const plugin::dwarf::DWARFUnit *dwarf_cu, const lldb::RegisterKind reg_set, const Value *initial_value_ptr, const Value *object_address_ptr)
Evaluate a DWARF location expression in a particular context.
DataExtractor m_data
A data extractor capable of reading opcode bytes.
bool LinkThreadLocalStorage(const plugin::dwarf::DWARFUnit *dwarf_cu, std::function< lldb::addr_t(lldb::addr_t file_addr)> const &link_address_callback)
bool GetExpressionData(DataExtractor &data) const
void DumpLocation(Stream *s, lldb::DescriptionLevel level, ABI *abi) const
bool Update_DW_OP_addr(const plugin::dwarf::DWARFUnit *dwarf_cu, lldb::addr_t file_addr)
void UpdateValue(uint64_t const_value, lldb::offset_t const_value_byte_size, uint8_t addr_byte_size)
static bool ParseDWARFLocationList(const plugin::dwarf::DWARFUnit *dwarf_cu, const DataExtractor &data, DWARFExpressionList *loc_list)
bool ContainsThreadLocalStorage(const plugin::dwarf::DWARFUnit *dwarf_cu) const
lldb::RegisterKind m_reg_kind
One of the defines that starts with LLDB_REGKIND_.
void SetRegisterKind(lldb::RegisterKind reg_kind)
Set the call-frame-info style register kind.
llvm::Expected< lldb::addr_t > GetLocation_DW_OP_addr(const plugin::dwarf::DWARFUnit *dwarf_cu) const
Return the address specified by the first DW_OP_{addr, addrx, GNU_addr_index} in the operation stream...
bool MatchesOperand(StackFrame &frame, const Instruction::Operand &op) const
lldb::RegisterKind GetRegisterKind() const
Return the call-frame-info style register kind.
bool IsValid() const
Return true if the location expression contains data.
An data extractor class.
Definition: DataExtractor.h:48
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
"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
A class that represents a running process on the host machine.
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
uint64_t offset_t
Definition: lldb-types.h:85
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:373
RegisterKind
Register numbering types.
@ eRegisterKindDWARF
the register numbers seen DWARF