Author: Michael Buch Date: 2025-06-03T12:10:15+01:00 New Revision: 9c52b177ea27778e904908c974e8113ed637dd69
URL: https://github.com/llvm/llvm-project/commit/9c52b177ea27778e904908c974e8113ed637dd69 DIFF: https://github.com/llvm/llvm-project/commit/9c52b177ea27778e904908c974e8113ed637dd69.diff LOG: [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`. Added: lldb/test/Shell/Expr/TestClangModulesDeclLookup.test Modified: Removed: ################################################################################ diff --git a/lldb/test/Shell/Expr/TestClangModulesDeclLookup.test b/lldb/test/Shell/Expr/TestClangModulesDeclLookup.test new file mode 100644 index 0000000000000..d4f2b3259772e --- /dev/null +++ b/lldb/test/Shell/Expr/TestClangModulesDeclLookup.test @@ -0,0 +1,60 @@ +# XFAIL: target-windows + +# Test that we can successfully locate decls in Clang modules for C++. + +# RUN: split-file %s %t +# RUN: %clang_host -g -gdwarf %t/main.cpp -fmodules -fcxx-modules -o %t.out +# RUN: %lldb -o "settings set interpreter.stop-command-source-on-error false" \ +# RUN: -x -b -s %t/commands.input %t.out 2>&1 \ +# RUN: | FileCheck %s + +#--- main.cpp + +#include "Module.h" + +int main() { + foo(10); + return 0; +} + +#--- module.modulemap + +module Module { + header "Module.h" + export * +} + +#--- Module.h + +// We use nodebug here ensures that LLDB tries to pick the decl out of the module. +// If debug-info is available, it would use that to construct the decl instead. +[[gnu::nodebug]] int foo(int x) { return x; } + +int bar(int x, int y) { return x + y; } + +#--- commands.input + +breakpoint set -n foo +run + +expression foo(5) + +# FIXME: when we're stopped in a frame without debug-info, the ClangModulesDeclVendor +# is initialized properly and none of the modules in the CU are compiled (and lookup +# in the DeclVendor is not enabled). +# CHECK: expression foo(5) +# CHECK: error: 'foo' has unknown return type; cast the call to its declared return type + +breakpoint set -p return -X main +continue +expression foo(50) + +# However, once we're back in a frame with debug-info, the ClangModulesDeclVendor infrastructure +# is back on track. + +# CHECK: expression foo(50) +# CHECK-NEXT: (int) $0 = 5 + +target modules dump ast --filter foo +# CHECK: (lldb) target modules dump ast --filter foo +# CHECK-NOT: foo _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits