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/Utility/RangeMap.h"
14 #include "lldb/lldb-private.h"
15 
16 class DWARFUnit;
17 
18 namespace 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.
24 public:
25  DWARFExpressionList() = default;
26 
27  DWARFExpressionList(lldb::ModuleSP module_sp, const DWARFUnit *dwarf_cu,
28  lldb::addr_t func_file_addr)
29  : m_module_wp(module_sp), m_dwarf_cu(dwarf_cu),
30  m_func_file_addr(func_file_addr) {}
31 
32  DWARFExpressionList(lldb::ModuleSP module_sp, DWARFExpression expr,
33  const DWARFUnit *dwarf_cu)
34  : m_module_wp(module_sp), m_dwarf_cu(dwarf_cu) {
36  }
37 
38  /// Return true if the location expression contains data
39  bool IsValid() const { return !m_exprs.IsEmpty(); }
40 
41  void Clear() { m_exprs.Clear(); }
42 
43  // Return true if the location expression is always valid.
44  bool IsAlwaysValidSingleExpr() const;
45 
47 
48  /// Get the expression data at the file address.
50  lldb::addr_t func_load_addr = LLDB_INVALID_ADDRESS,
51  lldb::addr_t file_addr = 0) const;
52 
53  /// Sort m_expressions.
54  void Sort() { m_exprs.Sort(); }
55 
56  void SetFuncFileAddress(lldb::addr_t func_file_addr) {
57  m_func_file_addr = func_file_addr;
58  }
59 
61 
63  lldb::addr_t load_addr) const;
64 
65  const DWARFExpression *GetAlwaysValidExpr() const;
66 
68  lldb::addr_t func_load_addr = LLDB_INVALID_ADDRESS,
69  lldb::addr_t load_addr = 0);
70 
71  size_t GetSize() const { return m_exprs.GetSize(); }
72 
73  bool ContainsThreadLocalStorage() const;
74 
76  lldb::ModuleSP new_module_sp,
77  std::function<lldb::addr_t(lldb::addr_t file_addr)> const
78  &link_address_callback);
79 
80  bool MatchesOperand(StackFrame &frame,
81  const Instruction::Operand &operand) const;
82 
83  /// Dump locations that contains file_addr if it's valid. Otherwise. dump all
84  /// locations.
86  lldb::addr_t func_load_addr, lldb::addr_t file_addr,
87  ABI *abi) const;
88 
89  /// Dump all locaitons with each seperated by new line.
90  void GetDescription(Stream *s, lldb::DescriptionLevel level, ABI *abi) const;
91 
92  /// Search for a load address in the dwarf location list
93  ///
94  /// \param[in] func_load_addr
95  /// The actual address of the function containing this location list.
96  ///
97  /// \param[in] addr
98  /// The address to resolve.
99  ///
100  /// \return
101  /// True if IsLocationList() is true and the address was found;
102  /// false otherwise.
103  // bool
104  // LocationListContainsLoadAddress (Process* process, const Address &addr)
105  // const;
106  //
107  bool ContainsAddress(lldb::addr_t func_load_addr, lldb::addr_t addr) const;
108 
109  void SetModule(const lldb::ModuleSP &module) { m_module_wp = module; }
110 
111  bool Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
112  lldb::addr_t func_load_addr, const Value *initial_value_ptr,
113  const Value *object_address_ptr, Value &result,
114  Status *error_ptr) const;
115 
116 private:
117  // RangeDataVector requires a comparator for DWARFExpression, but it doesn't
118  // make sense to do so.
120  public:
121  bool operator()(const DWARFExpression &lhs,
122  const DWARFExpression &rhs) const {
123  return false;
124  }
125  };
129 
130  // File address range mapping to single dwarf expression.
132 
133  /// Module which defined this expression.
134  lldb::ModuleWP m_module_wp;
135 
136  /// The DWARF compile unit this expression belongs to. It is used to evaluate
137  /// values indexing into the .debug_addr section (e.g. DW_OP_GNU_addr_index,
138  /// DW_OP_GNU_const_index)
139  const DWARFUnit *m_dwarf_cu = nullptr;
140 
141  // Function base file address.
143 
145  const_iterator begin() const { return m_exprs.begin(); }
146  const_iterator end() const { return m_exprs.end(); }
147 };
148 } // namespace lldb_private
149 
150 #endif // LLDB_EXPRESSION_DWARFEXPRESSIONLIST_H
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::DWARFExpressionList::Clear
void Clear()
Definition: DWARFExpressionList.h:41
lldb_private::DWARFExpressionList::Sort
void Sort()
Sort m_expressions.
Definition: DWARFExpressionList.h:54
lldb_private::DWARFExpressionList::DWARFExpressionCompare::operator()
bool operator()(const DWARFExpression &lhs, const DWARFExpression &rhs) const
Definition: DWARFExpressionList.h:121
lldb_private::ABI
Definition: ABI.h:27
lldb_private::Value
Definition: Value.h:38
lldb_private::DWARFExpressionList::LinkThreadLocalStorage
bool LinkThreadLocalStorage(lldb::ModuleSP new_module_sp, std::function< lldb::addr_t(lldb::addr_t file_addr)> const &link_address_callback)
Definition: DWARFExpressionList.cpp:96
lldb_private::DWARFExpressionList::DWARFExpressionList
DWARFExpressionList(lldb::ModuleSP module_sp, DWARFExpression expr, const DWARFUnit *dwarf_cu)
Definition: DWARFExpressionList.h:32
lldb_private::DWARFExpressionList::MatchesOperand
bool MatchesOperand(StackFrame &frame, const Instruction::Operand &operand) const
Definition: DWARFExpressionList.cpp:115
lldb_private::DWARFExpressionList::IsAlwaysValidSingleExpr
bool IsAlwaysValidSingleExpr() const
Definition: DWARFExpressionList.cpp:20
lldb_private::RangeDataVector::Sort
void Sort()
Definition: RangeMap.h:460
lldb_private::RangeDataVector::Clear
void Clear()
Definition: RangeMap.h:522
lldb_private::DWARFExpressionList::ExprVec
RangeDataVector< lldb::addr_t, lldb::addr_t, DWARFExpression, 0, DWARFExpressionCompare > ExprVec
Definition: DWARFExpressionList.h:127
lldb_private::DWARFExpressionList::const_iterator
ExprVec::Collection::const_iterator const_iterator
Definition: DWARFExpressionList.h:144
lldb_private::Stream
Definition: Stream.h:28
lldb_private::RangeData
Definition: RangeMap.h:415
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
RangeMap.h
lldb_private::DWARFExpressionList::m_func_file_addr
lldb::addr_t m_func_file_addr
Definition: DWARFExpressionList.h:142
lldb_private::RangeDataVector< lldb::addr_t, lldb::addr_t, DWARFExpression, 0, DWARFExpressionCompare >::Entry
RangeData< lldb::addr_t, lldb::addr_t, DWARFExpression > Entry
Definition: RangeMap.h:443
lldb_private::DWARFExpressionList::AddExpression
bool AddExpression(lldb::addr_t base, lldb::addr_t end, DWARFExpression expr)
Definition: DWARFExpressionList.cpp:33
DWARFUnit
Definition: DWARFUnit.h:84
lldb_private::DWARFExpressionList::DWARFExpressionList
DWARFExpressionList()=default
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::DWARFExpressionList::begin
const_iterator begin() const
Definition: DWARFExpressionList.h:145
lldb_private::DWARFExpressionList::ContainsThreadLocalStorage
bool ContainsThreadLocalStorage() const
Definition: DWARFExpressionList.cpp:85
lldb_private::RangeDataVector< lldb::addr_t, lldb::addr_t, DWARFExpression, 0, DWARFExpressionCompare >::const_iterator
typename Collection::const_iterator const_iterator
Definition: RangeMap.h:652
lldb_private::DWARFExpression
Definition: DWARFExpression.h:36
lldb_private::DWARFExpressionList::DWARFExpressionCompare
Definition: DWARFExpressionList.h:119
lldb_private::DWARFExpressionList::GetFuncFileAddress
lldb::addr_t GetFuncFileAddress()
Definition: DWARFExpressionList.h:60
lldb_private::Instruction::Operand
Definition: Disassembler.h:198
lldb_private::DWARFExpressionList::IsValid
bool IsValid() const
Return true if the location expression contains data.
Definition: DWARFExpressionList.h:39
lldb_private::DWARFExpressionList::m_module_wp
lldb::ModuleWP m_module_wp
Module which defined this expression.
Definition: DWARFExpressionList.h:134
lldb_private::RegisterContext
Definition: RegisterContext.h:17
lldb_private::DWARFExpressionList::Evaluate
bool Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::addr_t func_load_addr, const Value *initial_value_ptr, const Value *object_address_ptr, Value &result, Status *error_ptr) const
Definition: DWARFExpressionList.cpp:201
lldb-private.h
lldb_private::DWARFExpressionList::SetFuncFileAddress
void SetFuncFileAddress(lldb::addr_t func_file_addr)
Definition: DWARFExpressionList.h:56
lldb_private::DWARFExpressionList::GetDescription
void GetDescription(Stream *s, lldb::DescriptionLevel level, ABI *abi) const
Dump all locaitons with each seperated by new line.
Definition: DWARFExpressionList.cpp:176
lldb_private::DWARFExpressionList::GetSize
size_t GetSize() const
Definition: DWARFExpressionList.h:71
lldb_private::Status
Definition: Status.h:44
lldb_private::DWARFExpressionList::GetExpressionAtAddress
const DWARFExpression * GetExpressionAtAddress(lldb::addr_t func_load_addr, lldb::addr_t load_addr) const
Definition: DWARFExpressionList.cpp:58
lldb_private::RangeDataVector::GetSize
size_t GetSize() const
Definition: RangeMap.h:526
lldb_private::RangeDataVector
Definition: RangeMap.h:440
lldb_private::RangeDataVector::IsEmpty
bool IsEmpty() const
Definition: RangeMap.h:524
lldb_private::DWARFExpressionList::end
const_iterator end() const
Definition: DWARFExpressionList.h:146
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
lldb_private::DWARFExpressionList::DWARFExpressionList
DWARFExpressionList(lldb::ModuleSP module_sp, const DWARFUnit *dwarf_cu, lldb::addr_t func_file_addr)
Definition: DWARFExpressionList.h:27
DWARFExpression.h
lldb_private::RangeDataVector::end
const_iterator end() const
Definition: RangeMap.h:654
lldb_private::DWARFExpressionList::m_exprs
ExprVec m_exprs
Definition: DWARFExpressionList.h:131
lldb_private::RangeDataVector::begin
const_iterator begin() const
Definition: RangeMap.h:653
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::DWARFExpressionList::ContainsAddress
bool ContainsAddress(lldb::addr_t func_load_addr, lldb::addr_t addr) const
Search for a load address in the dwarf location list.
Definition: DWARFExpressionList.cpp:50
lldb_private::DWARFExpressionList::m_dwarf_cu
const DWARFUnit * m_dwarf_cu
The DWARF compile unit this expression belongs to.
Definition: DWARFExpressionList.h:139
lldb_private::DWARFExpressionList::DumpLocations
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.
Definition: DWARFExpressionList.cpp:142
lldb_private::DWARFExpressionList::GetExpressionData
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.
Definition: DWARFExpressionList.cpp:41
lldb_private::DWARFExpressionList
Definition: DWARFExpressionList.h:23
lldb_private::DWARFExpressionList::GetAlwaysValidExpr
const DWARFExpression * GetAlwaysValidExpr() const
Definition: DWARFExpressionList.cpp:24
lldb_private::StackFrame
Definition: StackFrame.h:40
lldb_private::DWARFExpressionList::SetModule
void SetModule(const lldb::ModuleSP &module)
Definition: DWARFExpressionList.h:109
lldb_private::DWARFExpressionList::GetMutableExpressionAtAddress
DWARFExpression * GetMutableExpressionAtAddress(lldb::addr_t func_load_addr=LLDB_INVALID_ADDRESS, lldb::addr_t load_addr=0)
Definition: DWARFExpressionList.cpp:72
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:208