Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:47

0001 //===-- DWARFExpressionList.h -----------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_EXPRESSION_DWARFEXPRESSIONLIST_H
0010 #define LLDB_EXPRESSION_DWARFEXPRESSIONLIST_H
0011 
0012 #include "lldb/Core/Value.h"
0013 #include "lldb/Expression/DWARFExpression.h"
0014 #include "lldb/Utility/RangeMap.h"
0015 #include "lldb/lldb-private.h"
0016 
0017 namespace lldb_private {
0018 
0019 namespace plugin {
0020 namespace dwarf {
0021 class DWARFUnit;
0022 } // namespace dwarf
0023 } // namespace plugin
0024 
0025 /// \class DWARFExpressionList DWARFExpressionList.h
0026 /// "lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file
0027 /// address range to a single DWARF location expression.
0028 class DWARFExpressionList {
0029 public:
0030   DWARFExpressionList() = default;
0031 
0032   DWARFExpressionList(lldb::ModuleSP module_sp,
0033                       const plugin::dwarf::DWARFUnit *dwarf_cu,
0034                       lldb::addr_t func_file_addr)
0035       : m_module_wp(module_sp), m_dwarf_cu(dwarf_cu),
0036         m_func_file_addr(func_file_addr) {}
0037 
0038   DWARFExpressionList(lldb::ModuleSP module_sp, DWARFExpression expr,
0039                       const plugin::dwarf::DWARFUnit *dwarf_cu)
0040       : m_module_wp(module_sp), m_dwarf_cu(dwarf_cu) {
0041     AddExpression(0, LLDB_INVALID_ADDRESS, expr);
0042   }
0043 
0044   /// Return true if the location expression contains data
0045   bool IsValid() const { return !m_exprs.IsEmpty(); }
0046 
0047   void Clear() { m_exprs.Clear(); }
0048 
0049   // Return true if the location expression is always valid.
0050   bool IsAlwaysValidSingleExpr() const;
0051 
0052   bool AddExpression(lldb::addr_t base, lldb::addr_t end, DWARFExpression expr);
0053 
0054   /// Get the expression data at the file address.
0055   bool GetExpressionData(DataExtractor &data,
0056                          lldb::addr_t func_load_addr = LLDB_INVALID_ADDRESS,
0057                          lldb::addr_t file_addr = 0) const;
0058 
0059   /// Sort m_expressions.
0060   void Sort() { m_exprs.Sort(); }
0061 
0062   void SetFuncFileAddress(lldb::addr_t func_file_addr) {
0063     m_func_file_addr = func_file_addr;
0064   }
0065 
0066   lldb::addr_t GetFuncFileAddress() { return m_func_file_addr; }
0067 
0068   const DWARFExpression *GetExpressionAtAddress(lldb::addr_t func_load_addr,
0069                                                 lldb::addr_t load_addr) const;
0070 
0071   const DWARFExpression *GetAlwaysValidExpr() const;
0072 
0073   DWARFExpression *GetMutableExpressionAtAddress(
0074       lldb::addr_t func_load_addr = LLDB_INVALID_ADDRESS,
0075       lldb::addr_t load_addr = 0);
0076 
0077   size_t GetSize() const { return m_exprs.GetSize(); }
0078 
0079   bool ContainsThreadLocalStorage() const;
0080 
0081   bool LinkThreadLocalStorage(
0082       lldb::ModuleSP new_module_sp,
0083       std::function<lldb::addr_t(lldb::addr_t file_addr)> const
0084           &link_address_callback);
0085 
0086   bool MatchesOperand(StackFrame &frame,
0087                       const Instruction::Operand &operand) const;
0088 
0089   /// Dump locations that contains file_addr if it's valid. Otherwise. dump all
0090   /// locations.
0091   bool DumpLocations(Stream *s, lldb::DescriptionLevel level,
0092                      lldb::addr_t func_load_addr, lldb::addr_t file_addr,
0093                      ABI *abi) const;
0094 
0095   /// Dump all locaitons with each separated by new line.
0096   void GetDescription(Stream *s, lldb::DescriptionLevel level, ABI *abi) const;
0097 
0098   /// Search for a load address in the dwarf location list
0099   ///
0100   /// \param[in] func_load_addr
0101   ///     The actual address of the function containing this location list.
0102   ///
0103   /// \param[in] addr
0104   ///     The address to resolve.
0105   ///
0106   /// \return
0107   ///     True if IsLocationList() is true and the address was found;
0108   ///     false otherwise.
0109   //    bool
0110   //    LocationListContainsLoadAddress (Process* process, const Address &addr)
0111   //    const;
0112   //
0113   bool ContainsAddress(lldb::addr_t func_load_addr, lldb::addr_t addr) const;
0114 
0115   void SetModule(const lldb::ModuleSP &module) { m_module_wp = module; }
0116 
0117   llvm::Expected<Value> Evaluate(ExecutionContext *exe_ctx,
0118                                  RegisterContext *reg_ctx,
0119                                  lldb::addr_t func_load_addr,
0120                                  const Value *initial_value_ptr,
0121                                  const Value *object_address_ptr) const;
0122 
0123 private:
0124   // RangeDataVector requires a comparator for DWARFExpression, but it doesn't
0125   // make sense to do so.
0126   struct DWARFExpressionCompare {
0127   public:
0128     bool operator()(const DWARFExpression &lhs,
0129                     const DWARFExpression &rhs) const {
0130       return false;
0131     }
0132   };
0133   using ExprVec = RangeDataVector<lldb::addr_t, lldb::addr_t, DWARFExpression,
0134                                   0, DWARFExpressionCompare>;
0135   using Entry = ExprVec::Entry;
0136 
0137   // File address range mapping to single dwarf expression.
0138   ExprVec m_exprs;
0139 
0140   /// Module which defined this expression.
0141   lldb::ModuleWP m_module_wp;
0142 
0143   /// The DWARF compile unit this expression belongs to. It is used to evaluate
0144   /// values indexing into the .debug_addr section (e.g. DW_OP_GNU_addr_index,
0145   /// DW_OP_GNU_const_index)
0146   const plugin::dwarf::DWARFUnit *m_dwarf_cu = nullptr;
0147 
0148   // Function base file address.
0149   lldb::addr_t m_func_file_addr = LLDB_INVALID_ADDRESS;
0150 
0151   using const_iterator = ExprVec::Collection::const_iterator;
0152   const_iterator begin() const { return m_exprs.begin(); }
0153   const_iterator end() const { return m_exprs.end(); }
0154 };
0155 } // namespace lldb_private
0156 
0157 #endif // LLDB_EXPRESSION_DWARFEXPRESSIONLIST_H