Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===-- DWARFExpression.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_DWARFEXPRESSION_H
0010 #define LLDB_EXPRESSION_DWARFEXPRESSION_H
0011 
0012 #include "lldb/Core/Address.h"
0013 #include "lldb/Core/Disassembler.h"
0014 #include "lldb/Utility/DataExtractor.h"
0015 #include "lldb/Utility/Scalar.h"
0016 #include "lldb/Utility/Status.h"
0017 #include "lldb/lldb-private.h"
0018 #include "llvm/DebugInfo/DWARF/DWARFLocationExpression.h"
0019 #include "llvm/Support/Error.h"
0020 #include <functional>
0021 
0022 namespace lldb_private {
0023 
0024 namespace plugin {
0025 namespace dwarf {
0026 class DWARFUnit;
0027 } // namespace dwarf
0028 } // namespace plugin
0029 
0030 /// \class DWARFExpression DWARFExpression.h
0031 /// "lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location
0032 /// expression and interprets it.
0033 ///
0034 /// DWARF location expressions are used in two ways by LLDB.  The first
0035 /// use is to find entities specified in the debug information, since their
0036 /// locations are specified in precisely this language.  The second is to
0037 /// interpret expressions without having to run the target in cases where the
0038 /// overhead from copying JIT-compiled code into the target is too high or
0039 /// where the target cannot be run.  This class encapsulates a single DWARF
0040 /// location expression or a location list and interprets it.
0041 class DWARFExpression {
0042 public:
0043   DWARFExpression();
0044 
0045   /// Constructor
0046   ///
0047   /// \param[in] data
0048   ///     A data extractor configured to read the DWARF location expression's
0049   ///     bytecode.
0050   DWARFExpression(const DataExtractor &data);
0051 
0052   /// Destructor
0053   ~DWARFExpression();
0054 
0055   /// Return true if the location expression contains data
0056   bool IsValid() const;
0057 
0058   /// Return the address specified by the first
0059   /// DW_OP_{addr, addrx, GNU_addr_index} in the operation stream.
0060   ///
0061   /// \param[in] dwarf_cu
0062   ///     The dwarf unit this expression belongs to. Only required to resolve
0063   ///     DW_OP{addrx, GNU_addr_index}.
0064   ///
0065   /// \return
0066   ///     The address specified by the operation, if the operation exists, or
0067   ///     an llvm::Error otherwise.
0068   llvm::Expected<lldb::addr_t>
0069   GetLocation_DW_OP_addr(const plugin::dwarf::DWARFUnit *dwarf_cu) const;
0070 
0071   bool Update_DW_OP_addr(const plugin::dwarf::DWARFUnit *dwarf_cu,
0072                          lldb::addr_t file_addr);
0073 
0074   void UpdateValue(uint64_t const_value, lldb::offset_t const_value_byte_size,
0075                    uint8_t addr_byte_size);
0076 
0077   bool
0078   ContainsThreadLocalStorage(const plugin::dwarf::DWARFUnit *dwarf_cu) const;
0079 
0080   bool LinkThreadLocalStorage(
0081       const plugin::dwarf::DWARFUnit *dwarf_cu,
0082       std::function<lldb::addr_t(lldb::addr_t file_addr)> const
0083           &link_address_callback);
0084 
0085   /// Return the call-frame-info style register kind
0086   lldb::RegisterKind GetRegisterKind() const;
0087 
0088   /// Set the call-frame-info style register kind
0089   ///
0090   /// \param[in] reg_kind
0091   ///     The register kind.
0092   void SetRegisterKind(lldb::RegisterKind reg_kind);
0093 
0094   /// Evaluate a DWARF location expression in a particular context
0095   ///
0096   /// \param[in] exe_ctx
0097   ///     The execution context in which to evaluate the location
0098   ///     expression.  The location expression may access the target's
0099   ///     memory, especially if it comes from the expression parser.
0100   ///
0101   /// \param[in] opcode_ctx
0102   ///     The module which defined the expression.
0103   ///
0104   /// \param[in] opcodes
0105   ///     This is a static method so the opcodes need to be provided
0106   ///     explicitly.
0107   ///
0108   ///  \param[in] reg_ctx
0109   ///     An optional parameter which provides a RegisterContext for use
0110   ///     when evaluating the expression (i.e. for fetching register values).
0111   ///     Normally this will come from the ExecutionContext's StackFrame but
0112   ///     in the case where an expression needs to be evaluated while building
0113   ///     the stack frame list, this short-cut is available.
0114   ///
0115   /// \param[in] reg_set
0116   ///     The call-frame-info style register kind.
0117   ///
0118   /// \param[in] initial_value_ptr
0119   ///     A value to put on top of the interpreter stack before evaluating
0120   ///     the expression, if the expression is parametrized.  Can be NULL.
0121   ///
0122   /// \param[in] result
0123   ///     A value into which the result of evaluating the expression is
0124   ///     to be placed.
0125   ///
0126   /// \param[in] error_ptr
0127   ///     If non-NULL, used to report errors in expression evaluation.
0128   ///
0129   /// \return
0130   ///     True on success; false otherwise.  If error_ptr is non-NULL,
0131   ///     details of the failure are provided through it.
0132   static llvm::Expected<Value>
0133   Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
0134            lldb::ModuleSP module_sp, const DataExtractor &opcodes,
0135            const plugin::dwarf::DWARFUnit *dwarf_cu,
0136            const lldb::RegisterKind reg_set, const Value *initial_value_ptr,
0137            const Value *object_address_ptr);
0138 
0139   static bool ParseDWARFLocationList(const plugin::dwarf::DWARFUnit *dwarf_cu,
0140                                      const DataExtractor &data,
0141                                      DWARFExpressionList *loc_list);
0142 
0143   bool GetExpressionData(DataExtractor &data) const {
0144     data = m_data;
0145     return data.GetByteSize() > 0;
0146   }
0147 
0148   void DumpLocation(Stream *s, lldb::DescriptionLevel level, ABI *abi) const;
0149 
0150   bool MatchesOperand(StackFrame &frame, const Instruction::Operand &op) const;
0151 
0152 private:
0153   /// A data extractor capable of reading opcode bytes
0154   DataExtractor m_data;
0155 
0156   /// One of the defines that starts with LLDB_REGKIND_
0157   lldb::RegisterKind m_reg_kind = lldb::eRegisterKindDWARF;
0158 };
0159 
0160 } // namespace lldb_private
0161 
0162 #endif // LLDB_EXPRESSION_DWARFEXPRESSION_H