1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
//===-- ClangPersistentVariables.h ------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H
#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H
#include "llvm/ADT/DenseMap.h"
#include "ClangExpressionVariable.h"
#include "ClangModulesDeclVendor.h"
#include "lldb/Expression/ExpressionVariable.h"
#include <optional>
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringRef.h"
#include <set>
#include <string>
#include <unordered_map>
namespace clang {
class TypeDecl;
}
namespace lldb_private {
class ClangASTImporter;
class ClangModulesDeclVendor;
class Target;
class TypeSystemClang;
/// \class ClangPersistentVariables ClangPersistentVariables.h
/// "lldb/Expression/ClangPersistentVariables.h" Manages persistent values
/// that need to be preserved between expression invocations.
///
/// A list of variables that can be accessed and updated by any expression. See
/// ClangPersistentVariable for more discussion. Also provides an increasing,
/// 0-based counter for naming result variables.
class ClangPersistentVariables
: public llvm::RTTIExtends<ClangPersistentVariables,
PersistentExpressionState> {
public:
// LLVM RTTI support
static char ID;
ClangPersistentVariables(std::shared_ptr<Target> target_sp);
~ClangPersistentVariables() override = default;
std::shared_ptr<ClangASTImporter> GetClangASTImporter();
std::shared_ptr<ClangModulesDeclVendor> GetClangModulesDeclVendor();
lldb::ExpressionVariableSP
CreatePersistentVariable(const lldb::ValueObjectSP &valobj_sp) override;
lldb::ExpressionVariableSP CreatePersistentVariable(
ExecutionContextScope *exe_scope, ConstString name,
const CompilerType &compiler_type, lldb::ByteOrder byte_order,
uint32_t addr_byte_size) override;
void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
ConstString GetNextPersistentVariableName(bool is_error = false) override;
// This just adds this module to the list of hand-loaded modules, it doesn't
// actually load it.
void AddHandLoadedModule(ConstString module_name) {
m_hand_loaded_modules.insert(module_name);
}
using HandLoadedModuleCallback = std::function<bool(const ConstString)>;
bool RunOverHandLoadedModules(HandLoadedModuleCallback callback) {
for (ConstString name : m_hand_loaded_modules) {
if (!callback(name))
return false;
}
return true;
}
/// Returns the next file name that should be used for user expressions.
std::string GetNextExprFileName() {
std::string name;
name.append("<user expression ");
name.append(std::to_string(m_next_user_file_id++));
name.append(">");
return name;
}
std::optional<CompilerType>
GetCompilerTypeFromPersistentDecl(ConstString type_name) override;
void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl,
std::shared_ptr<TypeSystemClang> ctx);
clang::NamedDecl *GetPersistentDecl(ConstString name);
void AddHandLoadedClangModule(ClangModulesDeclVendor::ModuleID module) {
m_hand_loaded_clang_modules.push_back(module);
}
const ClangModulesDeclVendor::ModuleVector &GetHandLoadedClangModules() {
return m_hand_loaded_clang_modules;
}
protected:
llvm::StringRef
GetPersistentVariablePrefix(bool is_error = false) const override {
return "$";
}
private:
/// The counter used by GetNextExprFileName.
uint32_t m_next_user_file_id = 0;
// The counter used by GetNextPersistentVariableName
uint32_t m_next_persistent_variable_id = 0;
typedef llvm::DenseMap<const char *, clang::TypeDecl *>
ClangPersistentTypeMap;
ClangPersistentTypeMap
m_clang_persistent_types; ///< The persistent types declared by the user.
typedef std::set<lldb::IRExecutionUnitSP> ExecutionUnitSet;
ExecutionUnitSet
m_execution_units; ///< The execution units that contain valuable symbols.
typedef std::set<lldb_private::ConstString> HandLoadedModuleSet;
HandLoadedModuleSet m_hand_loaded_modules; ///< These are the names of modules
///that we have loaded by
///< hand into the Contexts we make for parsing.
typedef llvm::DenseMap<const char *, lldb::addr_t> SymbolMap;
SymbolMap
m_symbol_map; ///< The addresses of the symbols in m_execution_units.
struct PersistentDecl {
/// The persistent decl.
clang::NamedDecl *m_decl = nullptr;
/// The TypeSystemClang for the ASTContext of m_decl.
lldb::TypeSystemWP m_context;
};
typedef llvm::DenseMap<const char *, PersistentDecl> PersistentDeclMap;
PersistentDeclMap
m_persistent_decls; ///< Persistent entities declared by the user.
ClangModulesDeclVendor::ModuleVector
m_hand_loaded_clang_modules; ///< These are Clang modules we hand-loaded;
///these are the highest-
///< priority source for macros.
std::shared_ptr<ClangASTImporter> m_ast_importer_sp;
std::shared_ptr<ClangModulesDeclVendor> m_modules_decl_vendor_sp;
std::shared_ptr<Target> m_target_sp;
};
} // namespace lldb_private
#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGPERSISTENTVARIABLES_H
|