diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp index 9a5d49a7ea363..d1feda1f0b629 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp @@ -379,12 +379,12 @@ static void SetupDeclVendor(ExecutionContext &exe_ctx, Target *target, if (!err) return; - // FIXME: should we be dumping these to the error log instead of as - // diagnostics? They are non-fatal and are usually quite noisy. - llvm::handleAllErrors( - std::move(err), [&diagnostic_manager](const llvm::StringError &e) { - diagnostic_manager.PutString(lldb::eSeverityInfo, e.getMessage()); - }); + // Module load errors aren't fatal to the expression evaluator. Printing + // them as diagnostics to the console would be too noisy and misleading + // Hence just print them to the expression log. + llvm::handleAllErrors(std::move(err), [](const llvm::StringError &e) { + LLDB_LOG(GetLog(LLDBLog::Expressions), "{0}", e.getMessage()); + }); } ClangExpressionSourceCode::WrapKind ClangUserExpression::GetWrapKind() const { diff --git a/lldb/test/API/lang/objc/modules-compile-error/Makefile b/lldb/test/API/lang/objc/modules-compile-error/Makefile deleted file mode 100644 index e031aa0bbbb8d..0000000000000 --- a/lldb/test/API/lang/objc/modules-compile-error/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -OBJC_SOURCES := main.m - -CFLAGS_EXTRAS = $(MANDATORY_MODULE_BUILD_CFLAGS) -I$(BUILDDIR) -DONLY_CLANG=1 - -include Makefile.rules diff --git a/lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py b/lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py deleted file mode 100644 index 36e302be2525b..0000000000000 --- a/lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py +++ /dev/null @@ -1,28 +0,0 @@ -import lldb -from lldbsuite.test.decorators import * -from lldbsuite.test.lldbtest import * -from lldbsuite.test import lldbutil - - -class TestCase(TestBase): - @skipIf(compiler="clang", compiler_version=["<", "11.0"]) - def test(self): - self.build() - lldbutil.run_to_source_breakpoint( - self, "// break here", lldb.SBFileSpec("main.m") - ) - - # Try importing our custom module. This will fail as LLDB won't define - # the CLANG_ONLY define when it compiles the module for the expression - # evaluator. - # Check that the error message shows file/line/column, prints the relevant - # line from the source code and mentions the module that failed to build. - self.expect( - "expr @import LLDBTestModule", - error=True, - substrs=[ - "module.h:4:1: error: use of undeclared identifier 'syntax_error_for_lldb_to_find'", - "syntax_error_for_lldb_to_find // comment that tests source printing", - "could not build module 'LLDBTestModule'", - ], - ) diff --git a/lldb/test/API/lang/objc/modules-compile-error/main.m b/lldb/test/API/lang/objc/modules-compile-error/main.m deleted file mode 100644 index 35259dd287b01..0000000000000 --- a/lldb/test/API/lang/objc/modules-compile-error/main.m +++ /dev/null @@ -1,5 +0,0 @@ -@import LLDBTestModule; - -int main() { - return foo(); // break here -} diff --git a/lldb/test/API/lang/objc/modules-compile-error/module.h b/lldb/test/API/lang/objc/modules-compile-error/module.h deleted file mode 100644 index 2edd13b0832db..0000000000000 --- a/lldb/test/API/lang/objc/modules-compile-error/module.h +++ /dev/null @@ -1,5 +0,0 @@ -int foo() { return 123; } - -#ifndef ONLY_CLANG -syntax_error_for_lldb_to_find // comment that tests source printing -#endif diff --git a/lldb/test/API/lang/objc/modules-compile-error/module.modulemap b/lldb/test/API/lang/objc/modules-compile-error/module.modulemap deleted file mode 100644 index 3d44faf3e9080..0000000000000 --- a/lldb/test/API/lang/objc/modules-compile-error/module.modulemap +++ /dev/null @@ -1 +0,0 @@ -module LLDBTestModule { header "module.h" export * } diff --git a/lldb/test/Shell/Expr/TestClangModuleLoadError_CompileFailure.test b/lldb/test/Shell/Expr/TestClangModuleLoadError_CompileFailure.test new file mode 100644 index 0000000000000..49ee2778ea18b --- /dev/null +++ b/lldb/test/Shell/Expr/TestClangModuleLoadError_CompileFailure.test @@ -0,0 +1,46 @@ +## Tests the case where module compilation fails. +# +# REQUIRES: system-darwin +# +# RUN: split-file %s %t/sources +# RUN: %clang_host -g %t/sources/main.m -fmodules -fcxx-modules \ +# RUN: -DSHOULD_COMPILE=1 \ +# RUN: -fmodule-map-file=%t/sources/module.modulemap \ +# RUN: -fmodules-cache-path=%t/ModuleCache -o %t.out +# +# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \ +# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s + +#--- main.m +@import foo; + +int main() { __builtin_debugtrap(); } + +#--- foo.h +struct foo {}; + +#ifndef SHOULD_COMPILE +#error "Compilation failure." +#endif + +#--- module.modulemap +module foo { + header "foo.h" + export * +} + +#--- commands.input +log enable lldb expr +run +## Make sure expression fails so the 'note' diagnostics get printed. +expr blah + +# CHECK: Finished building Clang module foo +# CHECK: couldn't load top-level module foo: +# CHECK: While building module 'foo' imported from LLDBModulesMemoryBuffer +# CHEKC: {{.*}}sources/foo.h{{.*}}: error: "Compilation failure." +# CHECK: LLDBModulesMemoryBuffer:1:1: fatal error: could not build module 'foo' + +# CHECK: Error while loading hand-imported modules: +# CHECK: couldn't load top-level module foo: +# CHECK-NOT: Compilation failure diff --git a/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidNestedSubmodule.test b/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidNestedSubmodule.test index a5822ae4a75e7..1e8075dd20fad 100644 --- a/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidNestedSubmodule.test +++ b/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidNestedSubmodule.test @@ -10,7 +10,10 @@ # RUN: sed -i '' -e 's/module qux/module quz/' %t/sources/module.modulemap # # RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \ -# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s +# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=NO_LOG +# +# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \ +# RUN: -s %t/sources/commands-with-log.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=LOG #--- main.m @import foo.baz.qux; @@ -56,4 +59,12 @@ run ## Make sure expression fails so the 'note' diagnostics get printed. expr blah -# CHECK: note: couldn't load submodule 'qux' of module 'foo.baz' +# NO_LOG-NOT: couldn't load submodule 'qux' of module 'foo.baz' + +#--- commands-with-log.input +log enable lldb expr +run +## Make sure expression fails so the 'note' diagnostics get printed. +expr blah + +# LOG: couldn't load submodule 'qux' of module 'foo.baz' diff --git a/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidSearchPath.test b/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidSearchPath.test index e5a6334d2ee22..35ba5802d2add 100644 --- a/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidSearchPath.test +++ b/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidSearchPath.test @@ -9,10 +9,14 @@ # RUN: -fmodules-cache-path=%t/ModuleCache -o %t.out # # RUN: cp %t/sources/commands.input %t/commands.input +# RUN: cp %t/sources/commands-with-log.input %t/commands-with-log.input # RUN: rm -r %t/sources # # RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \ -# RUN: -s %t/commands.input %t.out -o exit 2>&1 | FileCheck %s +# RUN: -s %t/commands.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=NO_LOG +# +# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \ +# RUN: -s %t/commands-with-log.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=LOG #--- main.m @import foo; @@ -42,5 +46,14 @@ run ## Make sure expression fails so the 'note' diagnostics get printed. expr blah -# CHECK: note: couldn't find module search path directory {{.*}}sources -# CHECK: note: couldn't find module search path directory {{.*}}sources +# NO_LOG-NOT: couldn't find module search path directory {{.*}}sources +# NO_LOG-NOT: couldn't find module search path directory {{.*}}sources + +#--- commands-with-log.input +log enable lldb expr +run +## Make sure expression fails so the 'note' diagnostics get printed. +expr blah + +# LOG: couldn't find module search path directory {{.*}}sources +# LOG: couldn't find module search path directory {{.*}}sources diff --git a/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidSubmodule.test b/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidSubmodule.test index 2552cdb4b61db..1bfbbcf32ecae 100644 --- a/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidSubmodule.test +++ b/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidSubmodule.test @@ -10,7 +10,10 @@ # RUN: sed -i '' -e 's/module baz/module qux/' %t/sources/module.modulemap # # RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \ -# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s +# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=NO_LOG +# +# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \ +# RUN: -s %t/sources/commands-with-log.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=LOG #--- main.m @import foo.baz; @@ -48,4 +51,12 @@ run ## Make sure expression fails so the 'note' diagnostics get printed. expr blah -# CHECK: note: couldn't load submodule 'baz' of module 'foo' +# NO_LOG-NOT: couldn't load submodule 'baz' of module 'foo' + +#--- commands-with-log.input +log enable lldb expr +run +## Make sure expression fails so the 'note' diagnostics get printed. +expr blah + +# LOG: couldn't load submodule 'baz' of module 'foo' diff --git a/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidTopLevelModule.test b/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidTopLevelModule.test index 189a3c0fcdf26..ad181ee7e15e6 100644 --- a/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidTopLevelModule.test +++ b/lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidTopLevelModule.test @@ -11,7 +11,10 @@ # RUN: sed -i '' -e 's/bar\.h/qux\.h/' %t/sources/module.modulemap # # RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \ -# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s +# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=NO_LOG +# +# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \ +# RUN: -s %t/sources/commands-with-log.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=LOG #--- main.m @import foo; @@ -41,9 +44,16 @@ run ## Make sure expression fails so the 'note' diagnostics get printed. expr blah -# CHECK: note: couldn't load top-level module foo -## FIXME: clang error diagnostic shouldn't be dumped to the console. -# CHECK: error: -# CHECK: note: couldn't load top-level module bar -## FIXME: clang error diagnostic shouldn't be dumped to the console. -# CHECK: error: +# NO_LOG-NOT: couldn't load top-level module foo +# NO_LOG-NOT: error: header + +#--- commands-with-log.input +log enable lldb expr +run +## Make sure expression fails so the 'note' diagnostics get printed. +expr blah + +# LOG: couldn't load top-level module foo +# LOG: error: header 'baz.h' +# LOG: couldn't load top-level module bar +# LOG: error: header 'qux.h' diff --git a/lldb/test/Shell/Expr/TestClangModuleLoadError_ModulemapParsing.test b/lldb/test/Shell/Expr/TestClangModuleLoadError_ModulemapParsing.test index 53efffffe435c..6d8e665102b17 100644 --- a/lldb/test/Shell/Expr/TestClangModuleLoadError_ModulemapParsing.test +++ b/lldb/test/Shell/Expr/TestClangModuleLoadError_ModulemapParsing.test @@ -11,7 +11,10 @@ # RUN: sed -i '' -e 's/module foo/module bar/' %t/sources/module.modulemap # # RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \ -# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s +# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=NO_LOG +# +# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \ +# RUN: -s %t/sources/commands-with-log.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=LOG #--- main.m @import foo; @@ -41,5 +44,14 @@ run ## Make sure expression fails so the 'note' diagnostics get printed. expr blah -# CHECK: note: failed to parse and load modulemap file in {{.*}}sources -# CHECK: note: failed to parse and load modulemap file in {{.*}}sources +# NO_LOG-NOT: failed to parse and load +# NO_LOG-NOT: failed to parse and load + +#--- commands-with-log.input +log enable lldb expr +run +## Make sure expression fails so the 'note' diagnostics get printed. +expr blah + +# LOG: failed to parse and load modulemap file in {{.*}}sources +# LOG: failed to parse and load modulemap file in {{.*}}sources diff --git a/lldb/test/Shell/Expr/TestClangModuleLoadError_NoModule.test b/lldb/test/Shell/Expr/TestClangModuleLoadError_NoModule.test index 2962614086931..bcb8a7d2c5594 100644 --- a/lldb/test/Shell/Expr/TestClangModuleLoadError_NoModule.test +++ b/lldb/test/Shell/Expr/TestClangModuleLoadError_NoModule.test @@ -12,7 +12,10 @@ # RUN: sed -i '' -e 's/module bar/module qux/' %t/sources/module.modulemap # # RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \ -# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s +# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=NO_LOG +# +# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \ +# RUN: -s %t/sources/commands-with-log.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=LOG #--- main.m @import foo; @@ -42,5 +45,14 @@ run ## Make sure expression fails so the 'note' diagnostics get printed. expr blah -# CHECK: note: header search couldn't locate module 'foo' -# CHECK: note: header search couldn't locate module 'bar' +# NO_LOG-NOT: header search couldn't locate module 'foo' +# NO_LOG-NOT: header search couldn't locate module 'bar' + +#--- commands-with-log.input +log enable lldb expr +run +## Make sure expression fails so the 'note' diagnostics get printed. +expr blah + +# LOG: header search couldn't locate module 'foo' +# LOG: header search couldn't locate module 'bar' diff --git a/lldb/test/Shell/Expr/TestClangModuleLoadError_NoModuleMap.test b/lldb/test/Shell/Expr/TestClangModuleLoadError_NoModuleMap.test index 917facb05fd47..57f7f16cc84dd 100644 --- a/lldb/test/Shell/Expr/TestClangModuleLoadError_NoModuleMap.test +++ b/lldb/test/Shell/Expr/TestClangModuleLoadError_NoModuleMap.test @@ -7,7 +7,10 @@ # RUN: rm %t/sources/module.modulemap # # RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \ -# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s +# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=NO_LOG +# +# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \ +# RUN: -s %t/sources/commands-with-log.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=LOG #--- main.m @import foo; @@ -37,5 +40,14 @@ run ## Make sure expression fails so the 'note' diagnostics get printed. expr blah -# CHECK: note: couldn't find modulemap file in {{.*}}sources -# CHECK: note: couldn't find modulemap file in {{.*}}sources +# NO_LOG-NOT: couldn't find modulemap +# NO_LOG-NOT: couldn't find modulemap + +#--- commands-with-log.input +log enable lldb expr +run +## Make sure expression fails so the 'note' diagnostics get printed. +expr blah + +# LOG: couldn't find modulemap file in {{.*}}sources +# LOG: couldn't find modulemap file in {{.*}}sources