teemperor created this revision. teemperor added reviewers: aprantl, shafik. teemperor added a project: C++ modules in LLDB. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
The ClangModulesDeclVendor is currently interpreting all injected `@import` statements in our expression wrapper as modules that the user has explicitly requested to be persistently loaded. As we inject `@import` statements with our std module prototype, the ClangModulesDeclVendor will start compiling and loading unrelated C++ modules because it thinks the user has requested that it should load them. As the ClangModulesDeclVendor is lacking the setup to compile these modules (e.g. it lacks the include paths), it will then actually just fail to compile them and cause the whole expression evaluation to fail. This causes these tests to fail on systems that enable the ClangModulesDeclVendor (such as macOS). This patch fixes this by preventing the ClangModulesDeclVendor from interpreting `@import` statements in the wrapper source code. This is done by defining a macro directly before the actual user expression and letting the preprocessor callbacks ignore import statements until we hit that macro. This patch also enables most of the `import-std-module/` tests to make sure this patch is working as intended. I didn't enable the sysroot test here as it still fails (due to another issue which will be a separate patch). Repository: rLLDB LLDB https://reviews.llvm.org/D61565 Files: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/TestImportStdModule.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/TestStdModuleWithConflicts.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-basic/TestBasicDeque.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-dbg-info-content/TestDbgInfoContentDeque.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-basic/TestBasicForwardList.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardList.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/list-basic/TestBasicList.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/list-dbg-info-content/TestDbgInfoContentList.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/TestMissingStdModule.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/queue/TestQueue.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr-dbg-info-content/TestSharedPtrDbgInfoContent.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr/TestSharedPtr.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/stack/TestStack.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr/TestUniquePtr.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-basic/TestBasicVector.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-bool/TestBoolVector.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-dbg-info-content/TestDbgInfoContentVector.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-of-vectors/TestVectorOfVectors.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtr.py lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr/TestWeakPtr.py lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h =================================================================== --- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h +++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h @@ -60,6 +60,11 @@ lldb::LanguageType wrapping_language, size_t &start_loc, size_t &end_loc); + /// Returns the name of the macro that we placed directly before the + /// user expression in the source code. Used to signal the parser that it + /// is has started to parse the actual user expression. + static const char *GetExprStartMacroName() { return "__LLDB_EXPR_START"; } + protected: ClangExpressionSourceCode(const char *name, const char *prefix, const char *body, bool wrap) : Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp =================================================================== --- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp +++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp @@ -363,10 +363,12 @@ "void \n" "%s(void *$__lldb_arg) \n" "{ \n" + "#define %s \n" " %s; \n" "%s" "} \n", module_imports.c_str(), m_name.c_str(), + GetExprStartMacroName(), lldb_local_var_decls.GetData(), tagged_body.c_str()); break; case lldb::eLanguageTypeC_plus_plus: @@ -374,10 +376,12 @@ "void \n" "$__lldb_class::%s(void *$__lldb_arg) \n" "{ \n" + "#define %s \n" " %s; \n" "%s" "} \n", module_imports.c_str(), m_name.c_str(), + GetExprStartMacroName(), lldb_local_var_decls.GetData(), tagged_body.c_str()); break; case lldb::eLanguageTypeObjC: @@ -390,12 +394,14 @@ "@implementation $__lldb_objc_class ($__lldb_category) \n" "+(void)%s:(void *)$__lldb_arg \n" "{ \n" + "#define %s \n" " %s; \n" "%s" "} \n" "@end \n", module_imports.c_str(), m_name.c_str(), m_name.c_str(), - lldb_local_var_decls.GetData(), tagged_body.c_str()); + GetExprStartMacroName(), lldb_local_var_decls.GetData(), + tagged_body.c_str()); } else { wrap_stream.Printf( "%s" @@ -405,12 +411,14 @@ "@implementation $__lldb_objc_class ($__lldb_category) \n" "-(void)%s:(void *)$__lldb_arg \n" "{ \n" + "#define %s \n" " %s; \n" "%s" "} \n" "@end \n", module_imports.c_str(), m_name.c_str(), m_name.c_str(), - lldb_local_var_decls.GetData(), tagged_body.c_str()); + GetExprStartMacroName(), lldb_local_var_decls.GetData(), + tagged_body.c_str()); } break; } Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp =================================================================== --- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp +++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp @@ -51,6 +51,7 @@ #include "ClangDiagnostic.h" #include "ClangExpressionParser.h" +#include "ClangExpressionSourceCode.h" #include "ClangUserExpression.h" #include "ASTUtils.h" @@ -106,14 +107,41 @@ ClangPersistentVariables &m_persistent_vars; StreamString m_error_stream; bool m_has_errors = false; + // True iff the parser has entered or passed the actual user expression. + // False means the parser is still parsing the wrapper code generated by LLDB. + bool m_entered_expr = false; public: LLDBPreprocessorCallbacks(ClangModulesDeclVendor &decl_vendor, ClangPersistentVariables &persistent_vars) : m_decl_vendor(decl_vendor), m_persistent_vars(persistent_vars) {} + virtual void MacroDefined(const Token &MacroNameTok, + const MacroDirective *MD) override { + // We track the macro in the source code that is directly before the user + // expression. If that macro is defined, then we have entered the + // user expression. + + if (!MacroNameTok.is(tok::TokenKind::identifier)) + return; + + auto *II = MacroNameTok.getIdentifierInfo(); + if (!II) + return; + + if (II->getName() == ClangExpressionSourceCode::GetExprStartMacroName()) + m_entered_expr = true; + } + void moduleImport(SourceLocation import_location, clang::ModuleIdPath path, const clang::Module * /*null*/) override { + // If we imported a module before we have started parsing the user + // expression, then the import was generated by LLDB and is not actually + // loaded by the user. We can stop here as we only care about user-loaded + // modules. + if (!m_entered_expr) + return; + SourceModule module; for (const std::pair<IdentifierInfo *, SourceLocation> &component : path) Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr/TestWeakPtr.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr/TestWeakPtr.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr/TestWeakPtr.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtr.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtr.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtr.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-of-vectors/TestVectorOfVectors.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-of-vectors/TestVectorOfVectors.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-of-vectors/TestVectorOfVectors.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-dbg-info-content/TestDbgInfoContentVector.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-dbg-info-content/TestDbgInfoContentVector.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-dbg-info-content/TestDbgInfoContentVector.py @@ -15,7 +15,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-bool/TestBoolVector.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-bool/TestBoolVector.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-bool/TestBoolVector.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-basic/TestBasicVector.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-basic/TestBasicVector.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/vector-basic/TestBasicVector.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr/TestUniquePtr.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr/TestUniquePtr.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr/TestUniquePtr.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/stack/TestStack.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/stack/TestStack.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/stack/TestStack.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr/TestSharedPtr.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr/TestSharedPtr.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr/TestSharedPtr.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr-dbg-info-content/TestSharedPtrDbgInfoContent.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr-dbg-info-content/TestSharedPtrDbgInfoContent.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/shared_ptr-dbg-info-content/TestSharedPtrDbgInfoContent.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/queue/TestQueue.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/queue/TestQueue.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/queue/TestQueue.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/TestMissingStdModule.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/TestMissingStdModule.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/TestMissingStdModule.py @@ -21,7 +21,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/list-dbg-info-content/TestDbgInfoContentList.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/list-dbg-info-content/TestDbgInfoContentList.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/list-dbg-info-content/TestDbgInfoContentList.py @@ -15,7 +15,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/list-basic/TestBasicList.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/list-basic/TestBasicList.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/list-basic/TestBasicList.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardList.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardList.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardList.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-basic/TestBasicForwardList.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-basic/TestBasicForwardList.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/forward_list-basic/TestBasicForwardList.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-dbg-info-content/TestDbgInfoContentDeque.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-dbg-info-content/TestDbgInfoContentDeque.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-dbg-info-content/TestDbgInfoContentDeque.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-basic/TestBasicDeque.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-basic/TestBasicDeque.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/deque-basic/TestBasicDeque.py @@ -14,7 +14,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/TestStdModuleWithConflicts.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/TestStdModuleWithConflicts.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/TestStdModuleWithConflicts.py @@ -20,7 +20,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() Index: lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/TestImportStdModule.py =================================================================== --- lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/TestImportStdModule.py +++ lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/TestImportStdModule.py @@ -15,7 +15,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test(self): self.build() @@ -38,7 +38,7 @@ # skipIf's in the future. @add_test_categories(["libc++"]) @skipIf(compiler=no_match("clang")) - @skipIf(oslist=no_match(["linux"])) + @skipIf(oslist=no_match(["linux", "macosx"])) @skipIf(debug_info=no_match(["dwarf"])) def test_non_cpp_language(self): self.build()
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits