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"
13 #include "lldb/Core/Disassembler.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 <functional>
20 
21 class DWARFUnit;
22 
23 namespace lldb_private {
24 
25 /// \class DWARFExpression DWARFExpression.h
26 /// "lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location
27 /// expression and interprets it.
28 ///
29 /// DWARF location expressions are used in two ways by LLDB. The first
30 /// use is to find entities specified in the debug information, since their
31 /// locations are specified in precisely this language. The second is to
32 /// interpret expressions without having to run the target in cases where the
33 /// overhead from copying JIT-compiled code into the target is too high or
34 /// where the target cannot be run. This class encapsulates a single DWARF
35 /// location expression or a location list and interprets it.
37 public:
39 
40  /// Constructor
41  ///
42  /// \param[in] data
43  /// A data extractor configured to read the DWARF location expression's
44  /// bytecode.
45  DWARFExpression(const DataExtractor &data);
46 
47  /// Destructor
48  virtual ~DWARFExpression();
49 
50  /// Return true if the location expression contains data
51  bool IsValid() const;
52 
53  /// If a location is not a location list, return true if the location
54  /// contains a DW_OP_addr () opcode in the stream that matches \a file_addr.
55  /// If file_addr is LLDB_INVALID_ADDRESS, the this function will return true
56  /// if the variable there is any DW_OP_addr in a location that (yet still is
57  /// NOT a location list). This helps us detect if a variable is a global or
58  /// static variable since there is no other indication from DWARF debug
59  /// info.
60  ///
61  /// \param[in] dwarf_cu
62  /// The dwarf unit this expression belongs to.
63  ///
64  /// \param[in] op_addr_idx
65  /// The DW_OP_addr index to retrieve in case there is more than
66  /// one DW_OP_addr opcode in the location byte stream.
67  ///
68  /// \param[out] error
69  /// If the location stream contains unknown DW_OP opcodes or the
70  /// data is missing, \a error will be set to \b true.
71  ///
72  /// \return
73  /// LLDB_INVALID_ADDRESS if the location doesn't contain a
74  /// DW_OP_addr for \a op_addr_idx, otherwise a valid file address
76  uint32_t op_addr_idx, bool &error) const;
77 
78  bool Update_DW_OP_addr(const DWARFUnit *dwarf_cu, lldb::addr_t file_addr);
79 
80  void UpdateValue(uint64_t const_value, lldb::offset_t const_value_byte_size,
81  uint8_t addr_byte_size);
82 
83  bool ContainsThreadLocalStorage(const DWARFUnit *dwarf_cu) const;
84 
86  const DWARFUnit *dwarf_cu,
87  std::function<lldb::addr_t(lldb::addr_t file_addr)> const
88  &link_address_callback);
89 
90  /// Return the call-frame-info style register kind
92 
93  /// Set the call-frame-info style register kind
94  ///
95  /// \param[in] reg_kind
96  /// The register kind.
97  void SetRegisterKind(lldb::RegisterKind reg_kind);
98 
99  /// Evaluate a DWARF location expression in a particular context
100  ///
101  /// \param[in] exe_ctx
102  /// The execution context in which to evaluate the location
103  /// expression. The location expression may access the target's
104  /// memory, especially if it comes from the expression parser.
105  ///
106  /// \param[in] opcode_ctx
107  /// The module which defined the expression.
108  ///
109  /// \param[in] opcodes
110  /// This is a static method so the opcodes need to be provided
111  /// explicitly.
112  ///
113  /// \param[in] reg_ctx
114  /// An optional parameter which provides a RegisterContext for use
115  /// when evaluating the expression (i.e. for fetching register values).
116  /// Normally this will come from the ExecutionContext's StackFrame but
117  /// in the case where an expression needs to be evaluated while building
118  /// the stack frame list, this short-cut is available.
119  ///
120  /// \param[in] reg_set
121  /// The call-frame-info style register kind.
122  ///
123  /// \param[in] initial_value_ptr
124  /// A value to put on top of the interpreter stack before evaluating
125  /// the expression, if the expression is parametrized. Can be NULL.
126  ///
127  /// \param[in] result
128  /// A value into which the result of evaluating the expression is
129  /// to be placed.
130  ///
131  /// \param[in] error_ptr
132  /// If non-NULL, used to report errors in expression evaluation.
133  ///
134  /// \return
135  /// True on success; false otherwise. If error_ptr is non-NULL,
136  /// details of the failure are provided through it.
137  static bool Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
138  lldb::ModuleSP module_sp, const DataExtractor &opcodes,
139  const DWARFUnit *dwarf_cu,
140  const lldb::RegisterKind reg_set,
141  const Value *initial_value_ptr,
142  const Value *object_address_ptr, Value &result,
143  Status *error_ptr);
144 
145  static bool ParseDWARFLocationList(const DWARFUnit *dwarf_cu,
146  const DataExtractor &data,
147  DWARFExpressionList *loc_list);
148 
149  bool GetExpressionData(DataExtractor &data) const {
150  data = m_data;
151  return data.GetByteSize() > 0;
152  }
153 
154  void DumpLocation(Stream *s, lldb::DescriptionLevel level, ABI *abi) const;
155 
156  bool MatchesOperand(StackFrame &frame, const Instruction::Operand &op) const;
157 
158 private:
159  /// A data extractor capable of reading opcode bytes
161 
162  /// One of the defines that starts with LLDB_REGKIND_
164 };
165 
166 } // namespace lldb_private
167 
168 #endif // LLDB_EXPRESSION_DWARFEXPRESSION_H
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
Scalar.h
lldb_private::ABI
Definition: ABI.h:27
lldb::eRegisterKindDWARF
@ eRegisterKindDWARF
the register numbers seen DWARF
Definition: lldb-enumerations.h:230
lldb_private::DWARFExpression::~DWARFExpression
virtual ~DWARFExpression()
Destructor.
lldb_private::Value
Definition: Value.h:38
lldb_private::DWARFExpression::m_data
DataExtractor m_data
A data extractor capable of reading opcode bytes.
Definition: DWARFExpression.h:160
lldb_private::DWARFExpression::ParseDWARFLocationList
static bool ParseDWARFLocationList(const DWARFUnit *dwarf_cu, const DataExtractor &data, DWARFExpressionList *loc_list)
Definition: DWARFExpression.cpp:2608
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
Disassembler.h
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::DWARFExpression::ContainsThreadLocalStorage
bool ContainsThreadLocalStorage(const DWARFUnit *dwarf_cu) const
Definition: DWARFExpression.cpp:420
lldb_private::DWARFExpression::LinkThreadLocalStorage
bool LinkThreadLocalStorage(const DWARFUnit *dwarf_cu, std::function< lldb::addr_t(lldb::addr_t file_addr)> const &link_address_callback)
Definition: DWARFExpression.cpp:436
lldb_private::DWARFExpression::m_reg_kind
lldb::RegisterKind m_reg_kind
One of the defines that starts with LLDB_REGKIND_.
Definition: DWARFExpression.h:163
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::DWARFExpression::SetRegisterKind
void SetRegisterKind(lldb::RegisterKind reg_kind)
Set the call-frame-info style register kind.
Definition: DWARFExpression.cpp:79
DWARFUnit
Definition: DWARFUnit.h:83
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::DWARFExpression::Update_DW_OP_addr
bool Update_DW_OP_addr(const DWARFUnit *dwarf_cu, lldb::addr_t file_addr)
Definition: DWARFExpression.cpp:382
lldb_private::DWARFExpression::DumpLocation
void DumpLocation(Stream *s, lldb::DescriptionLevel level, ABI *abi) const
Definition: DWARFExpression.cpp:70
lldb_private::DWARFExpression
Definition: DWARFExpression.h:36
lldb_private::DWARFExpression::GetRegisterKind
lldb::RegisterKind GetRegisterKind() const
Return the call-frame-info style register kind.
Definition: DWARFExpression.cpp:77
lldb_private::DWARFExpression::GetLocation_DW_OP_addr
lldb::addr_t GetLocation_DW_OP_addr(const DWARFUnit *dwarf_cu, uint32_t op_addr_idx, bool &error) const
If a location is not a location list, return true if the location contains a DW_OP_addr () opcode in ...
Definition: DWARFExpression.cpp:344
lldb_private::Instruction::Operand
Definition: Disassembler.h:198
Address.h
lldb_private::RegisterContext
Definition: RegisterContext.h:17
lldb_private::DWARFExpression::GetExpressionData
bool GetExpressionData(DataExtractor &data) const
Definition: DWARFExpression.h:149
lldb_private::DWARFExpression::UpdateValue
void UpdateValue(uint64_t const_value, lldb::offset_t const_value_byte_size, uint8_t addr_byte_size)
Definition: DWARFExpression.cpp:58
lldb::RegisterKind
RegisterKind
Register numbering types.
Definition: lldb-enumerations.h:228
lldb-private.h
lldb_private::DWARFExpression::MatchesOperand
bool MatchesOperand(StackFrame &frame, const Instruction::Operand &op) const
Definition: DWARFExpression.cpp:2645
lldb_private::DWARFExpression::DWARFExpression
DWARFExpression()
Definition: DWARFExpression.cpp:49
lldb_private::Status
Definition: Status.h:44
uint32_t
lldb_private::DWARFExpression::Evaluate
static bool Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::ModuleSP module_sp, const DataExtractor &opcodes, const DWARFUnit *dwarf_cu, const lldb::RegisterKind reg_set, const Value *initial_value_ptr, const Value *object_address_ptr, Value &result, Status *error_ptr)
Evaluate a DWARF location expression in a particular context.
Definition: DWARFExpression.cpp:843
DataExtractor.h
Status.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::DWARFExpressionList
Definition: DWARFExpressionList.h:24
lldb_private::DataExtractor::GetByteSize
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
Definition: DataExtractor.h:270
lldb_private::StackFrame
Definition: StackFrame.h:40
lldb_private::DWARFExpression::IsValid
bool IsValid() const
Return true if the location expression contains data.
Definition: DWARFExpression.cpp:56
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:208