diff options
author | Raphael Isemann <teemperor@gmail.com> | 2019-07-21 10:31:13 +0000 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2019-07-21 10:31:13 +0000 |
commit | ca9dfdfaecaa13fc075858a2965fd2f43e7bc8e1 (patch) | |
tree | e383985c1218ba0a4a898c1fb4e452e98608e92b | |
parent | 8a431874e995b3ff3c4c99a23cfed0429cc9f117 (diff) | |
download | bcm5719-llvm-ca9dfdfaecaa13fc075858a2965fd2f43e7bc8e1.tar.gz bcm5719-llvm-ca9dfdfaecaa13fc075858a2965fd2f43e7bc8e1.zip |
[lldb] Fix crash when looking up type coming from the ClangModuleDeclVendor
Summary:
We assume in LLDB that every type comes from an ASTContext with an associated ClangASTContext.
However the types inside the ClangModuleDeclVendor don't have a ClangASTContext so we end up
crashing whenever we create a CompilerType for one of these types.
Simplest way to trigger this bug is to just look up NSObject from a module:
(lldb) expr @import Foundation
(lldb) type lookup NSObject
Assertion failed: (m_type_system != nullptr), function CompilerType, file /Users/teemperor/llvm1/llvm-project/lldb/source/Symbol/CompilerType.cpp, line 39.
This patch just creates a ClangASTContext for the ASTContext used by ClangModuleDeclVendor.
Reviewers: davide, shafik
Reviewed By: davide
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D64989
llvm-svn: 366653
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/lang/objc/modules/TestObjCModules.py | 4 | ||||
-rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp | 12 |
2 files changed, 15 insertions, 1 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lang/objc/modules/TestObjCModules.py b/lldb/packages/Python/lldbsuite/test/lang/objc/modules/TestObjCModules.py index 8f5c407000c..4e40c58effa 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/objc/modules/TestObjCModules.py +++ b/lldb/packages/Python/lldbsuite/test/lang/objc/modules/TestObjCModules.py @@ -60,6 +60,10 @@ class ObjCModulesTestCase(TestBase): "int", "4"]) + # Type lookup should still work and print something reasonable + # for types from the module. + self.expect("type lookup NSObject", substrs=["instanceMethod"]) + self.expect("expr string.length", VARIABLES_DISPLAYED_CORRECTLY, substrs=["NSUInteger", "5"]) diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp index 4a220790e50..deecb66a24f 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp @@ -27,6 +27,7 @@ #include "lldb/Core/ModuleList.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" +#include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/SourceModule.h" #include "lldb/Target/Target.h" @@ -110,6 +111,9 @@ private: ImportedModuleMap m_imported_modules; ImportedModuleSet m_user_imported_modules; const clang::ExternalASTMerger::OriginMap m_origin_map; + // We assume that every ASTContext has an ClangASTContext, so we also store + // a custom ClangASTContext for our internal ASTContext. + std::unique_ptr<ClangASTContext> m_ast_context; }; } // anonymous namespace @@ -155,7 +159,13 @@ ClangModulesDeclVendorImpl::ClangModulesDeclVendorImpl( : m_diagnostics_engine(std::move(diagnostics_engine)), m_compiler_invocation(std::move(compiler_invocation)), m_compiler_instance(std::move(compiler_instance)), - m_parser(std::move(parser)), m_origin_map() {} + m_parser(std::move(parser)), m_origin_map() { + + // Initialize our ClangASTContext. + auto target_opts = m_compiler_invocation->getTargetOpts(); + m_ast_context.reset(new ClangASTContext(target_opts.Triple.c_str())); + m_ast_context->setASTContext(&m_compiler_instance->getASTContext()); +} void ClangModulesDeclVendorImpl::ReportModuleExportsHelper( std::set<ClangModulesDeclVendor::ModuleID> &exports, |