xiaobai created this revision. xiaobai added reviewers: compnerd, davide, labath, JDevlieghere, aprantl, jingham. Herald added a subscriber: mgorny.
PersistentStateExpressions (e.g. ClangPersistentVariables) have the ability to define types using expressions that persist throughout the debugging session. SetCompilerTypeFromPersistentDecl is a useful operation to have if you need to use any of those persistently declared types, like in CommandObjectMemory. This decouples clang from CommandObjectMemory and decouples Plugins from Commands in general. https://reviews.llvm.org/D62797 Files: include/lldb/Expression/ExpressionVariable.h source/Commands/CMakeLists.txt source/Commands/CommandObjectMemory.cpp source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h
Index: source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h =================================================================== --- source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h +++ source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h @@ -50,6 +50,9 @@ return "$"; } + bool SetCompilerTypeFromPersistentDecl(ConstString type_name, + CompilerType &compiler_type) override; + void RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl); clang::NamedDecl *GetPersistentDecl(ConstString name); Index: source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp =================================================================== --- source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp +++ source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp @@ -9,6 +9,7 @@ #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" @@ -52,6 +53,19 @@ m_next_persistent_variable_id--; } +bool ClangPersistentVariables::SetCompilerTypeFromPersistentDecl( + ConstString type_name, CompilerType &compiler_type) { + if (clang::TypeDecl *tdecl = llvm::dyn_cast_or_null<clang::TypeDecl>( + GetPersistentDecl(type_name))) { + compiler_type.SetCompilerType( + ClangASTContext::GetASTContext(&tdecl->getASTContext()), + reinterpret_cast<lldb::opaque_compiler_type_t>( + const_cast<clang::Type *>(tdecl->getTypeForDecl()))); + return true; + } + return false; +} + void ClangPersistentVariables::RegisterPersistentDecl(ConstString name, clang::NamedDecl *decl) { m_persistent_decls.insert( Index: source/Commands/CommandObjectMemory.cpp =================================================================== --- source/Commands/CommandObjectMemory.cpp +++ source/Commands/CommandObjectMemory.cpp @@ -6,16 +6,14 @@ // //===----------------------------------------------------------------------===// -#include "clang/AST/Decl.h" - #include "CommandObjectMemory.h" -#include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/DumpDataExtractor.h" #include "lldb/Core/Module.h" #include "lldb/Core/Section.h" #include "lldb/Core/ValueObjectMemory.h" #include "lldb/DataFormatters/ValueObjectPrinter.h" +#include "lldb/Expression/ExpressionVariable.h" #include "lldb/Host/OptionParser.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" @@ -25,13 +23,14 @@ #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" #include "lldb/Interpreter/OptionValueString.h" #include "lldb/Interpreter/Options.h" -#include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/SymbolFile.h" #include "lldb/Symbol/TypeList.h" +#include "lldb/Target/Language.h" #include "lldb/Target/MemoryHistory.h" #include "lldb/Target/MemoryRegionInfo.h" #include "lldb/Target/Process.h" #include "lldb/Target/StackFrame.h" +#include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Utility/Args.h" #include "lldb/Utility/DataBufferHeap.h" @@ -472,21 +471,13 @@ exact_match, 1, searched_symbol_files, type_list); - if (type_list.GetSize() == 0 && lookup_type_name.GetCString() && - *lookup_type_name.GetCString() == '$') { - if (ClangPersistentVariables *persistent_vars = - llvm::dyn_cast_or_null<ClangPersistentVariables>( - target->GetPersistentExpressionStateForLanguage( - lldb::eLanguageTypeC))) { - clang::TypeDecl *tdecl = llvm::dyn_cast_or_null<clang::TypeDecl>( - persistent_vars->GetPersistentDecl( - ConstString(lookup_type_name))); - - if (tdecl) { - clang_ast_type.SetCompilerType( - ClangASTContext::GetASTContext(&tdecl->getASTContext()), - reinterpret_cast<lldb::opaque_compiler_type_t>( - const_cast<clang::Type *>(tdecl->getTypeForDecl()))); + if (type_list.GetSize() == 0 && lookup_type_name.GetCString()) { + for (auto lang : Language::GetSupportedLanguages()) { + if (PersistentExpressionState *persistent_vars = + target->GetPersistentExpressionStateForLanguage(lang)) { + if (persistent_vars->SetCompilerTypeFromPersistentDecl( + lookup_type_name, clang_ast_type)) + break; } } } Index: source/Commands/CMakeLists.txt =================================================================== --- source/Commands/CMakeLists.txt +++ source/Commands/CMakeLists.txt @@ -41,7 +41,6 @@ lldbSymbol lldbTarget lldbUtility - lldbPluginExpressionParserClang LINK_COMPONENTS Support Index: include/lldb/Expression/ExpressionVariable.h =================================================================== --- include/lldb/Expression/ExpressionVariable.h +++ include/lldb/Expression/ExpressionVariable.h @@ -232,6 +232,9 @@ virtual void RemovePersistentVariable(lldb::ExpressionVariableSP variable) = 0; + virtual bool SetCompilerTypeFromPersistentDecl(ConstString type_name, + CompilerType &compiler_type) = 0; + virtual lldb::addr_t LookupSymbol(ConstString name); void RegisterExecutionUnit(lldb::IRExecutionUnitSP &execution_unit_sp);
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits