Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===-- Variable.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_SYMBOL_VARIABLE_H
0010 #define LLDB_SYMBOL_VARIABLE_H
0011 
0012 #include "lldb/Core/Declaration.h"
0013 #include "lldb/Core/Mangled.h"
0014 #include "lldb/Expression/DWARFExpressionList.h"
0015 #include "lldb/Utility/CompletionRequest.h"
0016 #include "lldb/Utility/RangeMap.h"
0017 #include "lldb/Utility/UserID.h"
0018 #include "lldb/lldb-enumerations.h"
0019 #include "lldb/lldb-private.h"
0020 #include <memory>
0021 #include <vector>
0022 
0023 namespace lldb_private {
0024 
0025 class Variable : public UserID, public std::enable_shared_from_this<Variable> {
0026 public:
0027   typedef RangeVector<lldb::addr_t, lldb::addr_t> RangeList;
0028 
0029   /// Constructors and Destructors.
0030   ///
0031   /// \param mangled The mangled or fully qualified name of the variable.
0032   Variable(lldb::user_id_t uid, const char *name, const char *mangled,
0033            const lldb::SymbolFileTypeSP &symfile_type_sp, lldb::ValueType scope,
0034            SymbolContextScope *owner_scope, const RangeList &scope_range,
0035            Declaration *decl, const DWARFExpressionList &location,
0036            bool external, bool artificial, bool location_is_constant_data,
0037            bool static_member = false);
0038 
0039   virtual ~Variable();
0040 
0041   void Dump(Stream *s, bool show_context) const;
0042 
0043   bool DumpDeclaration(Stream *s, bool show_fullpaths, bool show_module);
0044 
0045   const Declaration &GetDeclaration() const { return m_declaration; }
0046 
0047   ConstString GetName() const;
0048 
0049   ConstString GetUnqualifiedName() const;
0050 
0051   SymbolContextScope *GetSymbolContextScope() const { return m_owner_scope; }
0052 
0053   /// Since a variable can have a basename "i" and also a mangled named
0054   /// "_ZN12_GLOBAL__N_11iE" and a demangled mangled name "(anonymous
0055   /// namespace)::i", this function will allow a generic match function that can
0056   /// be called by commands and expression parsers to make sure we match
0057   /// anything we come across.
0058   bool NameMatches(ConstString name) const;
0059 
0060   bool NameMatches(const RegularExpression &regex) const;
0061 
0062   Type *GetType();
0063 
0064   lldb::LanguageType GetLanguage() const;
0065 
0066   lldb::ValueType GetScope() const { return m_scope; }
0067 
0068   const RangeList &GetScopeRange() const { return m_scope_range; }
0069 
0070   bool IsExternal() const { return m_external; }
0071 
0072   bool IsArtificial() const { return m_artificial; }
0073 
0074   bool IsStaticMember() const { return m_static_member; }
0075 
0076   DWARFExpressionList &LocationExpressionList() { return m_location_list; }
0077 
0078   const DWARFExpressionList &LocationExpressionList() const {
0079     return m_location_list;
0080   }
0081 
0082   // When given invalid address, it dumps all locations. Otherwise it only dumps
0083   // the location that contains this address.
0084   bool DumpLocations(Stream *s, const Address &address);
0085 
0086   size_t MemorySize() const;
0087 
0088   void CalculateSymbolContext(SymbolContext *sc);
0089 
0090   bool IsInScope(StackFrame *frame);
0091 
0092   bool LocationIsValidForFrame(StackFrame *frame);
0093 
0094   bool LocationIsValidForAddress(const Address &address);
0095 
0096   bool GetLocationIsConstantValueData() const { return m_loc_is_const_data; }
0097 
0098   void SetLocationIsConstantValueData(bool b) { m_loc_is_const_data = b; }
0099 
0100   typedef size_t (*GetVariableCallback)(void *baton, const char *name,
0101                                         VariableList &var_list);
0102 
0103   static Status GetValuesForVariableExpressionPath(
0104       llvm::StringRef variable_expr_path, ExecutionContextScope *scope,
0105       GetVariableCallback callback, void *baton, VariableList &variable_list,
0106       ValueObjectList &valobj_list);
0107 
0108   static void AutoComplete(const ExecutionContext &exe_ctx,
0109                            CompletionRequest &request);
0110 
0111   CompilerDeclContext GetDeclContext();
0112 
0113   CompilerDecl GetDecl();
0114 
0115 protected:
0116   /// The basename of the variable (no namespaces).
0117   ConstString m_name;
0118   /// The mangled name of the variable.
0119   Mangled m_mangled;
0120   /// The type pointer of the variable (int, struct, class, etc)
0121   /// global, parameter, local.
0122   lldb::SymbolFileTypeSP m_symfile_type_sp;
0123   lldb::ValueType m_scope;
0124   /// The symbol file scope that this variable was defined in
0125   SymbolContextScope *m_owner_scope;
0126   /// The list of ranges inside the owner's scope where this variable
0127   /// is valid.
0128   RangeList m_scope_range;
0129   /// Declaration location for this item.
0130   Declaration m_declaration;
0131   /// The location of this variable that can be fed to
0132   /// DWARFExpression::Evaluate().
0133   DWARFExpressionList m_location_list;
0134   /// Visible outside the containing compile unit?
0135   unsigned m_external : 1;
0136   /// Non-zero if the variable is not explicitly declared in source.
0137   unsigned m_artificial : 1;
0138   /// The m_location expression contains the constant variable value
0139   /// data, not a DWARF location.
0140   unsigned m_loc_is_const_data : 1;
0141   /// Non-zero if variable is static member of a class or struct.
0142   unsigned m_static_member : 1;
0143 
0144 private:
0145   Variable(const Variable &rhs) = delete;
0146   Variable &operator=(const Variable &rhs) = delete;
0147 };
0148 
0149 } // namespace lldb_private
0150 
0151 #endif // LLDB_SYMBOL_VARIABLE_H