diff options
author | 2020-08-03 14:33:06 +0000 | |
---|---|---|
committer | 2020-08-03 14:33:06 +0000 | |
commit | 061da546b983eb767bad15e67af1174fb0bcf31c (patch) | |
tree | 83c78b820819d70aa40c36d90447978b300078c5 /gnu/llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp | |
parent | Import LLVM 10.0.0 release including clang, lld and lldb. (diff) | |
download | wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.tar.xz wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.zip |
Import LLVM 10.0.0 release including clang, lld and lldb.
ok hackroom
tested by plenty
Diffstat (limited to 'gnu/llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp')
-rw-r--r-- | gnu/llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp b/gnu/llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp new file mode 100644 index 00000000000..41d62a462ab --- /dev/null +++ b/gnu/llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp @@ -0,0 +1,101 @@ +//===-- ClangPersistentVariables.cpp ----------------------------*- 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 +// +//===----------------------------------------------------------------------===// + +#include "ClangPersistentVariables.h" + +#include "lldb/Core/Value.h" +#include "lldb/Symbol/ClangASTContext.h" +#include "lldb/Target/Target.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/StreamString.h" + +#include "clang/AST/Decl.h" + +#include "llvm/ADT/StringMap.h" + +using namespace lldb; +using namespace lldb_private; + +ClangPersistentVariables::ClangPersistentVariables() + : lldb_private::PersistentExpressionState(LLVMCastKind::eKindClang) {} + +ExpressionVariableSP ClangPersistentVariables::CreatePersistentVariable( + const lldb::ValueObjectSP &valobj_sp) { + return AddNewlyConstructedVariable(new ClangExpressionVariable(valobj_sp)); +} + +ExpressionVariableSP ClangPersistentVariables::CreatePersistentVariable( + ExecutionContextScope *exe_scope, ConstString name, + const CompilerType &compiler_type, lldb::ByteOrder byte_order, + uint32_t addr_byte_size) { + return AddNewlyConstructedVariable(new ClangExpressionVariable( + exe_scope, name, compiler_type, byte_order, addr_byte_size)); +} + +void ClangPersistentVariables::RemovePersistentVariable( + lldb::ExpressionVariableSP variable) { + RemoveVariable(variable); + + // Check if the removed variable was the last one that was created. If yes, + // reuse the variable id for the next variable. + + // Nothing to do if we have not assigned a variable id so far. + if (m_next_persistent_variable_id == 0) + return; + + llvm::StringRef name = variable->GetName().GetStringRef(); + // Remove the prefix from the variable that only the indes is left. + if (!name.consume_front(GetPersistentVariablePrefix(false))) + return; + + // Check if the variable contained a variable id. + uint32_t variable_id; + if (name.getAsInteger(10, variable_id)) + return; + // If it's the most recent variable id that was assigned, make sure that this + // variable id will be used for the next persistent variable. + if (variable_id == m_next_persistent_variable_id - 1) + m_next_persistent_variable_id--; +} + +llvm::Optional<CompilerType> +ClangPersistentVariables::GetCompilerTypeFromPersistentDecl( + ConstString type_name) { + PersistentDecl p = m_persistent_decls.lookup(type_name.GetCString()); + + if (p.m_decl == nullptr) + return llvm::None; + + if (clang::TypeDecl *tdecl = llvm::dyn_cast<clang::TypeDecl>(p.m_decl)) { + opaque_compiler_type_t t = static_cast<opaque_compiler_type_t>( + const_cast<clang::Type *>(tdecl->getTypeForDecl())); + return CompilerType(p.m_context, t); + } + return llvm::None; +} + +void ClangPersistentVariables::RegisterPersistentDecl(ConstString name, + clang::NamedDecl *decl, + ClangASTContext *ctx) { + PersistentDecl p = {decl, ctx}; + m_persistent_decls.insert(std::make_pair(name.GetCString(), p)); + + if (clang::EnumDecl *enum_decl = llvm::dyn_cast<clang::EnumDecl>(decl)) { + for (clang::EnumConstantDecl *enumerator_decl : enum_decl->enumerators()) { + p = {enumerator_decl, ctx}; + m_persistent_decls.insert(std::make_pair( + ConstString(enumerator_decl->getNameAsString()).GetCString(), p)); + } + } +} + +clang::NamedDecl * +ClangPersistentVariables::GetPersistentDecl(ConstString name) { + return m_persistent_decls.lookup(name.GetCString()).m_decl; +} |