Skip to content

Commit 3157cbe

Browse files
committed
[lldb][ClangModulesDeclVendor] Print Clang module loading errors to expression log instead of console
Depends on: * llvm#166917 * llvm#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 150188c commit 3157cbe

8 files changed

+106
-27
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,9 @@ 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.
384382
llvm::handleAllErrors(
385-
std::move(err), [&diagnostic_manager](const llvm::StringError &e) {
386-
diagnostic_manager.PutString(lldb::eSeverityInfo, e.getMessage());
383+
std::move(err), [](const llvm::StringError &e) {
384+
LLDB_LOG(GetLog(LLDBLog::Expressions), "{0}", e.getMessage());
387385
});
388386
}
389387

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'

lldb/test/Shell/Expr/TestClangModuleLoadError_InvalidTopLevelModule.test

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

1619
#--- main.m
1720
@import foo;
@@ -41,9 +44,16 @@ run
4144
## Make sure expression fails so the 'note' diagnostics get printed.
4245
expr blah
4346

44-
# CHECK: note: couldn't load top-level module foo
45-
## FIXME: clang error diagnostic shouldn't be dumped to the console.
46-
# CHECK: error:
47-
# CHECK: note: couldn't load top-level module bar
48-
## FIXME: clang error diagnostic shouldn't be dumped to the console.
49-
# CHECK: error:
47+
# NO_LOG-NOT: couldn't load top-level module foo
48+
# NO_LOG-NOT: error: header
49+
50+
#--- commands-with-log.input
51+
log enable lldb expr
52+
run
53+
## Make sure expression fails so the 'note' diagnostics get printed.
54+
expr blah
55+
56+
# LOG: couldn't load top-level module foo
57+
# LOG: error: header 'baz.h'
58+
# LOG: couldn't load top-level module bar
59+
# LOG: error: header 'qux.h'

lldb/test/Shell/Expr/TestClangModuleLoadError_ModulemapParsing.test

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

1619
#--- main.m
1720
@import foo;
@@ -41,5 +44,14 @@ run
4144
## Make sure expression fails so the 'note' diagnostics get printed.
4245
expr blah
4346

44-
# CHECK: note: failed to parse and load modulemap file in {{.*}}sources
45-
# CHECK: note: failed to parse and load modulemap file in {{.*}}sources
47+
# NO_LOG-NOT: failed to parse and load
48+
# NO_LOG-NOT: failed to parse and load
49+
50+
#--- commands-with-log.input
51+
log enable lldb expr
52+
run
53+
## Make sure expression fails so the 'note' diagnostics get printed.
54+
expr blah
55+
56+
# LOG: failed to parse and load modulemap file in {{.*}}sources
57+
# LOG: failed to parse and load modulemap file in {{.*}}sources

lldb/test/Shell/Expr/TestClangModuleLoadError_NoModule.test

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

1720
#--- main.m
1821
@import foo;
@@ -42,5 +45,14 @@ run
4245
## Make sure expression fails so the 'note' diagnostics get printed.
4346
expr blah
4447

45-
# CHECK: note: header search couldn't locate module 'foo'
46-
# CHECK: note: header search couldn't locate module 'bar'
48+
# NO_LOG-NOT: header search couldn't locate module 'foo'
49+
# NO_LOG-NOT: header search couldn't locate module 'bar'
50+
51+
#--- commands-with-log.input
52+
log enable lldb expr
53+
run
54+
## Make sure expression fails so the 'note' diagnostics get printed.
55+
expr blah
56+
57+
# LOG: header search couldn't locate module 'foo'
58+
# LOG: header search couldn't locate module 'bar'

lldb/test/Shell/Expr/TestClangModuleLoadError_NoModuleMap.test

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
# RUN: rm %t/sources/module.modulemap
88
#
99
# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \
10-
# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s
10+
# RUN: -s %t/sources/commands.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=NO_LOG
11+
#
12+
# RUN: %lldb -x -o "settings set interpreter.stop-command-source-on-error false" \
13+
# RUN: -s %t/sources/commands-with-log.input %t.out -o exit 2>&1 | FileCheck %s --check-prefix=LOG
1114

1215
#--- main.m
1316
@import foo;
@@ -37,5 +40,14 @@ run
3740
## Make sure expression fails so the 'note' diagnostics get printed.
3841
expr blah
3942

40-
# CHECK: note: couldn't find modulemap file in {{.*}}sources
41-
# CHECK: note: couldn't find modulemap file in {{.*}}sources
43+
# NO_LOG-NOT: couldn't find modulemap
44+
# NO_LOG-NOT: couldn't find modulemap
45+
46+
#--- commands-with-log.input
47+
log enable lldb expr
48+
run
49+
## Make sure expression fails so the 'note' diagnostics get printed.
50+
expr blah
51+
52+
# LOG: couldn't find modulemap file in {{.*}}sources
53+
# LOG: couldn't find modulemap file in {{.*}}sources

0 commit comments

Comments
 (0)