Skip to content

Commit d5b62fa

Browse files
authored
[lldb][ClangModulesDeclVendor] Print Clang module loading errors to expression log instead of console (#166964)
Depends on: * #166917 * #166940 While these errors can contribute to an expression failing, they are never *the* reason the expression failed. I.e., they are always just 'note:' diagnostics that we hand-emit. Because they are quite noisy (and we potentially have many of them if we auto-load all modules in a CU), this patch logs the errors to the `expr` log, instead of the console. Previously these errors would only get omitted when the expression itself failed. Meaning if the expression failed, we'd dump these 'note' module load errors in next to the actual expression error, obscuring the output. Moreover, if the expression succeeded, any module load errors would be dropped. Now we always log all module loading errors to the expression log, regardless of whether the expression fails or not.
1 parent 8552a8f commit d5b62fa

14 files changed

+156
-73
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,12 @@ static void SetupDeclVendor(ExecutionContext &exe_ctx, Target *target,
379379
if (!err)
380380
return;
381381

382-
// FIXME: should we be dumping these to the error log instead of as
383-
// diagnostics? They are non-fatal and are usually quite noisy.
384-
llvm::handleAllErrors(
385-
std::move(err), [&diagnostic_manager](const llvm::StringError &e) {
386-
diagnostic_manager.PutString(lldb::eSeverityInfo, e.getMessage());
387-
});
382+
// Module load errors aren't fatal to the expression evaluator. Printing
383+
// them as diagnostics to the console would be too noisy and misleading
384+
// Hence just print them to the expression log.
385+
llvm::handleAllErrors(std::move(err), [](const llvm::StringError &e) {
386+
LLDB_LOG(GetLog(LLDBLog::Expressions), "{0}", e.getMessage());
387+
});
388388
}
389389

390390
ClangExpressionSourceCode::WrapKind ClangUserExpression::GetWrapKind() const {

lldb/test/API/lang/objc/modules-compile-error/Makefile

Lines changed: 0 additions & 5 deletions
This file was deleted.

lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

lldb/test/API/lang/objc/modules-compile-error/main.m

Lines changed: 0 additions & 5 deletions
This file was deleted.

lldb/test/API/lang/objc/modules-compile-error/module.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

lldb/test/API/lang/objc/modules-compile-error/module.modulemap

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## Tests the case where module compilation fails.
2+
#
3+
# REQUIRES: system-darwin
4+
#
5+
# RUN: split-file %s %t/sources
6+
# RUN: %clang_host -g %t/sources/main.m -fmodules -fcxx-modules \
7+
# RUN: -DSHOULD_COMPILE=1 \
8+
# RUN: -fmodule-map-file=%t/sources/module.modulemap \
9+
# RUN: -fmodules-cache-path=%t/ModuleCache -o %t.out
10+
#
11+
# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \
12+
# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s
13+
14+
#--- main.m
15+
@import foo;
16+
17+
int main() { __builtin_debugtrap(); }
18+
19+
#--- foo.h
20+
struct foo {};
21+
22+
#ifndef SHOULD_COMPILE
23+
#error "Compilation failure."
24+
#endif
25+
26+
#--- module.modulemap
27+
module foo {
28+
header "foo.h"
29+
export *
30+
}
31+
32+
#--- commands.input
33+
log enable lldb expr
34+
run
35+
## Make sure expression fails so the 'note' diagnostics get printed.
36+
expr blah
37+
38+
# CHECK: Finished building Clang module foo
39+
# CHECK: couldn't load top-level module foo:
40+
# CHECK: While building module 'foo' imported from LLDBModulesMemoryBuffer
41+
# CHEKC: {{.*}}sources/foo.h{{.*}}: error: "Compilation failure."
42+
# CHECK: LLDBModulesMemoryBuffer:1:1: fatal error: could not build module 'foo'
43+
44+
# CHECK: Error while loading hand-imported modules:
45+
# CHECK: couldn't load top-level module foo:
46+
# CHECK-NOT: Compilation failure

lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidNestedSubmodule.test

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
# RUN: sed -i '' -e 's/module qux/module quz/' %t/sources/module.modulemap
1111
#
1212
# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \
13-
# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s
13+
# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=NO_LOG
14+
#
15+
# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \
16+
# RUN: -s %t/sources/commands-with-log.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=LOG
1417

1518
#--- main.m
1619
@import foo.baz.qux;
@@ -56,4 +59,12 @@ run
5659
## Make sure expression fails so the 'note' diagnostics get printed.
5760
expr blah
5861

59-
# CHECK: note: couldn't load submodule 'qux' of module 'foo.baz'
62+
# NO_LOG-NOT: couldn't load submodule 'qux' of module 'foo.baz'
63+
64+
#--- commands-with-log.input
65+
log enable lldb expr
66+
run
67+
## Make sure expression fails so the 'note' diagnostics get printed.
68+
expr blah
69+
70+
# LOG: couldn't load submodule 'qux' of module 'foo.baz'

lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidSearchPath.test

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
# RUN: -fmodules-cache-path=%t/ModuleCache -o %t.out
1010
#
1111
# RUN: cp %t/sources/commands.input %t/commands.input
12+
# RUN: cp %t/sources/commands-with-log.input %t/commands-with-log.input
1213
# RUN: rm -r %t/sources
1314
#
1415
# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \
15-
# RUN: -s %t/commands.input %t.out -o exit 2>&1 | FileCheck %s
16+
# RUN: -s %t/commands.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=NO_LOG
17+
#
18+
# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \
19+
# RUN: -s %t/commands-with-log.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=LOG
1620

1721
#--- main.m
1822
@import foo;
@@ -42,5 +46,14 @@ run
4246
## Make sure expression fails so the 'note' diagnostics get printed.
4347
expr blah
4448

45-
# CHECK: note: couldn't find module search path directory {{.*}}sources
46-
# CHECK: note: couldn't find module search path directory {{.*}}sources
49+
# NO_LOG-NOT: couldn't find module search path directory {{.*}}sources
50+
# NO_LOG-NOT: couldn't find module search path directory {{.*}}sources
51+
52+
#--- commands-with-log.input
53+
log enable lldb expr
54+
run
55+
## Make sure expression fails so the 'note' diagnostics get printed.
56+
expr blah
57+
58+
# LOG: couldn't find module search path directory {{.*}}sources
59+
# LOG: couldn't find module search path directory {{.*}}sources

lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidSubmodule.test

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
# RUN: sed -i '' -e 's/module baz/module qux/' %t/sources/module.modulemap
1111
#
1212
# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \
13-
# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s
13+
# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=NO_LOG
14+
#
15+
# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \
16+
# RUN: -s %t/sources/commands-with-log.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=LOG
1417

1518
#--- main.m
1619
@import foo.baz;
@@ -48,4 +51,12 @@ run
4851
## Make sure expression fails so the 'note' diagnostics get printed.
4952
expr blah
5053

51-
# CHECK: note: couldn't load submodule 'baz' of module 'foo'
54+
# NO_LOG-NOT: couldn't load submodule 'baz' of module 'foo'
55+
56+
#--- commands-with-log.input
57+
log enable lldb expr
58+
run
59+
## Make sure expression fails so the 'note' diagnostics get printed.
60+
expr blah
61+
62+
# LOG: couldn't load submodule 'baz' of module 'foo'

0 commit comments

Comments
 (0)