Skip to content

Commit 9c52b17

Browse files
committed
[lldb][test] Add test for looking up decls in Clang modules for C++
Adds coverage for the code-path where `ClangExpressionDeclMap::FindExternalVisibleDecls` finds a decl inside of a Clang module (without explicitly having to import the module on the LLDB CLI). AFAICT, we had not tests for this. `LookupFunction` will try to find a `FunctionDecl` in debug-info. But if no debug-info exists, it will ask the `ClangModulesDeclVendor` to search for the function with the specified name in any of the Clang modules that got added to it in `SetupDeclVendor`.
1 parent 9a2d4d1 commit 9c52b17

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# XFAIL: target-windows
2+
3+
# Test that we can successfully locate decls in Clang modules for C++.
4+
5+
# RUN: split-file %s %t
6+
# RUN: %clang_host -g -gdwarf %t/main.cpp -fmodules -fcxx-modules -o %t.out
7+
# RUN: %lldb -o "settings set interpreter.stop-command-source-on-error false" \
8+
# RUN: -x -b -s %t/commands.input %t.out 2>&1 \
9+
# RUN: | FileCheck %s
10+
11+
#--- main.cpp
12+
13+
#include "Module.h"
14+
15+
int main() {
16+
foo(10);
17+
return 0;
18+
}
19+
20+
#--- module.modulemap
21+
22+
module Module {
23+
header "Module.h"
24+
export *
25+
}
26+
27+
#--- Module.h
28+
29+
// We use nodebug here ensures that LLDB tries to pick the decl out of the module.
30+
// If debug-info is available, it would use that to construct the decl instead.
31+
[[gnu::nodebug]] int foo(int x) { return x; }
32+
33+
int bar(int x, int y) { return x + y; }
34+
35+
#--- commands.input
36+
37+
breakpoint set -n foo
38+
run
39+
40+
expression foo(5)
41+
42+
# FIXME: when we're stopped in a frame without debug-info, the ClangModulesDeclVendor
43+
# is initialized properly and none of the modules in the CU are compiled (and lookup
44+
# in the DeclVendor is not enabled).
45+
# CHECK: expression foo(5)
46+
# CHECK: error: 'foo' has unknown return type; cast the call to its declared return type
47+
48+
breakpoint set -p return -X main
49+
continue
50+
expression foo(50)
51+
52+
# However, once we're back in a frame with debug-info, the ClangModulesDeclVendor infrastructure
53+
# is back on track.
54+
55+
# CHECK: expression foo(50)
56+
# CHECK-NEXT: (int) $0 = 5
57+
58+
target modules dump ast --filter foo
59+
# CHECK: (lldb) target modules dump ast --filter foo
60+
# CHECK-NOT: foo

0 commit comments

Comments
 (0)