LLDB  mainline
ClangPersistentVariables.h
Go to the documentation of this file.
1 //===-- ClangPersistentVariables.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_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H
10 #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H
11 
12 #include "llvm/ADT/DenseMap.h"
13 
15 #include "ClangModulesDeclVendor.h"
16 
18 
19 namespace lldb_private {
20 
21 class ClangASTImporter;
22 class ClangModulesDeclVendor;
23 class Target;
24 class TypeSystemClang;
25 
26 /// \class ClangPersistentVariables ClangPersistentVariables.h
27 /// "lldb/Expression/ClangPersistentVariables.h" Manages persistent values
28 /// that need to be preserved between expression invocations.
29 ///
30 /// A list of variables that can be accessed and updated by any expression. See
31 /// ClangPersistentVariable for more discussion. Also provides an increasing,
32 /// 0-based counter for naming result variables.
34 public:
35  ClangPersistentVariables(std::shared_ptr<Target> target_sp);
36 
37  ~ClangPersistentVariables() override = default;
38 
39  // llvm casting support
40  static bool classof(const PersistentExpressionState *pv) {
42  }
43 
44  std::shared_ptr<ClangASTImporter> GetClangASTImporter();
45  std::shared_ptr<ClangModulesDeclVendor> GetClangModulesDeclVendor();
46 
47  lldb::ExpressionVariableSP
48  CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override;
49 
50  lldb::ExpressionVariableSP CreatePersistentVariable(
51  ExecutionContextScope *exe_scope, ConstString name,
52  const CompilerType &compiler_type, lldb::ByteOrder byte_order,
53  uint32_t addr_byte_size) override;
54 
55  void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
56 
57  ConstString GetNextPersistentVariableName(bool is_error = false) override;
58 
59  /// Returns the next file name that should be used for user expressions.
61  std::string name;
62  name.append("<user expression ");
63  name.append(std::to_string(m_next_user_file_id++));
64  name.append(">");
65  return name;
66  }
67 
68  llvm::Optional<CompilerType>
70 
71  void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl,
72  TypeSystemClang *ctx);
73 
74  clang::NamedDecl *GetPersistentDecl(ConstString name);
75 
77  m_hand_loaded_clang_modules.push_back(module);
78  }
79 
82  }
83 
84 protected:
85  llvm::StringRef
86  GetPersistentVariablePrefix(bool is_error = false) const override {
87  return "$";
88  }
89 
90 private:
91  /// The counter used by GetNextExprFileName.
93  // The counter used by GetNextPersistentVariableName
95 
96  struct PersistentDecl {
97  /// The persistent decl.
98  clang::NamedDecl *m_decl = nullptr;
99  /// The TypeSystemClang for the ASTContext of m_decl.
101  };
102 
103  typedef llvm::DenseMap<const char *, PersistentDecl> PersistentDeclMap;
105  m_persistent_decls; ///< Persistent entities declared by the user.
106 
108  m_hand_loaded_clang_modules; ///< These are Clang modules we hand-loaded;
109  ///these are the highest-
110  ///< priority source for macros.
111  std::shared_ptr<ClangASTImporter> m_ast_importer_sp;
112  std::shared_ptr<ClangModulesDeclVendor> m_modules_decl_vendor_sp;
113  std::shared_ptr<Target> m_target_sp;
114 };
115 
116 } // namespace lldb_private
117 
118 #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H
ExpressionVariable.h
lldb_private::ClangPersistentVariables::GetPersistentDecl
clang::NamedDecl * GetPersistentDecl(ConstString name)
Definition: ClangPersistentVariables.cpp:103
lldb_private::ClangPersistentVariables
Definition: ClangPersistentVariables.h:33
ClangModulesDeclVendor.h
lldb_private::ClangPersistentVariables::PersistentDecl
Definition: ClangPersistentVariables.h:96
lldb_private::ClangPersistentVariables::m_hand_loaded_clang_modules
ClangModulesDeclVendor::ModuleVector m_hand_loaded_clang_modules
These are Clang modules we hand-loaded; these are the highest- priority source for macros.
Definition: ClangPersistentVariables.h:108
lldb_private::ClangPersistentVariables::PersistentDecl::m_decl
clang::NamedDecl * m_decl
The persistent decl.
Definition: ClangPersistentVariables.h:98
lldb_private::ClangPersistentVariables::GetClangASTImporter
std::shared_ptr< ClangASTImporter > GetClangASTImporter()
Definition: ClangPersistentVariables.cpp:108
lldb_private::PersistentExpressionState::getKind
LLVMCastKind getKind() const
Definition: ExpressionVariable.h:208
lldb_private::ExecutionContextScope
Definition: ExecutionContextScope.h:32
lldb_private::ClangModulesDeclVendor::ModuleVector
std::vector< ModuleID > ModuleVector
Definition: ClangModulesDeclVendor.h:37
lldb_private::PersistentExpressionState::eKindClang
@ eKindClang
Definition: ExpressionVariable.h:206
lldb_private::ClangPersistentVariables::GetCompilerTypeFromPersistentDecl
llvm::Optional< CompilerType > GetCompilerTypeFromPersistentDecl(ConstString type_name) override
Definition: ClangPersistentVariables.cpp:72
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::ClangPersistentVariables::AddHandLoadedClangModule
void AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module)
Definition: ClangPersistentVariables.h:76
lldb_private::ClangPersistentVariables::GetClangModulesDeclVendor
std::shared_ptr< ClangModulesDeclVendor > GetClangModulesDeclVendor()
Definition: ClangPersistentVariables.cpp:116
lldb_private::ClangModulesDeclVendor::ModuleID
uintptr_t ModuleID
Definition: ClangModulesDeclVendor.h:36
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::ClangPersistentVariables::m_next_user_file_id
uint32_t m_next_user_file_id
The counter used by GetNextExprFileName.
Definition: ClangPersistentVariables.h:92
lldb_private::ClangPersistentVariables::~ClangPersistentVariables
~ClangPersistentVariables() override=default
lldb_private::ClangPersistentVariables::GetHandLoadedClangModules
const ClangModulesDeclVendor::ModuleVector & GetHandLoadedClangModules()
Definition: ClangPersistentVariables.h:80
uint32_t
lldb_private::ClangPersistentVariables::classof
static bool classof(const PersistentExpressionState *pv)
Definition: ClangPersistentVariables.h:40
lldb_private::ClangPersistentVariables::m_target_sp
std::shared_ptr< Target > m_target_sp
Definition: ClangPersistentVariables.h:113
lldb_private::ClangPersistentVariables::PersistentDecl::m_context
TypeSystemClang * m_context
The TypeSystemClang for the ASTContext of m_decl.
Definition: ClangPersistentVariables.h:100
lldb_private::ClangPersistentVariables::GetNextPersistentVariableName
ConstString GetNextPersistentVariableName(bool is_error=false) override
Return a new persistent variable name with the specified prefix.
Definition: ClangPersistentVariables.cpp:125
lldb_private::ClangPersistentVariables::RegisterPersistentDecl
void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl, TypeSystemClang *ctx)
Definition: ClangPersistentVariables.cpp:87
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private::ClangPersistentVariables::PersistentDeclMap
llvm::DenseMap< const char *, PersistentDecl > PersistentDeclMap
Definition: ClangPersistentVariables.h:103
lldb_private::ClangPersistentVariables::m_next_persistent_variable_id
uint32_t m_next_persistent_variable_id
Definition: ClangPersistentVariables.h:94
lldb_private::PersistentExpressionState
Definition: ExpressionVariable.h:203
lldb_private::ClangPersistentVariables::CreatePersistentVariable
lldb::ExpressionVariableSP CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override
Definition: ClangPersistentVariables.cpp:32
lldb_private::ClangPersistentVariables::m_modules_decl_vendor_sp
std::shared_ptr< ClangModulesDeclVendor > m_modules_decl_vendor_sp
Definition: ClangPersistentVariables.h:112
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::TypeSystemClang
A TypeSystem implementation based on Clang.
Definition: TypeSystemClang.h:106
ClangExpressionVariable.h
lldb_private::ClangPersistentVariables::GetNextExprFileName
std::string GetNextExprFileName()
Returns the next file name that should be used for user expressions.
Definition: ClangPersistentVariables.h:60
lldb_private::ClangPersistentVariables::m_persistent_decls
PersistentDeclMap m_persistent_decls
Persistent entities declared by the user.
Definition: ClangPersistentVariables.h:105
lldb_private::ClangPersistentVariables::m_ast_importer_sp
std::shared_ptr< ClangASTImporter > m_ast_importer_sp
Definition: ClangPersistentVariables.h:111
lldb_private::ClangPersistentVariables::GetPersistentVariablePrefix
llvm::StringRef GetPersistentVariablePrefix(bool is_error=false) const override
Definition: ClangPersistentVariables.h:86
lldb_private::ClangPersistentVariables::ClangPersistentVariables
ClangPersistentVariables(std::shared_ptr< Target > target_sp)
Definition: ClangPersistentVariables.cpp:27
lldb_private::ClangPersistentVariables::RemovePersistentVariable
void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override
Definition: ClangPersistentVariables.cpp:45
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:138