From 9dbd966e73512270f68b35f24bfe5da607843801 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Thu, 22 Mar 2018 10:47:24 -0700 Subject: [PATCH] [lldb-moduleimport] Add the logic for testing getDeclBySymbolName(). Adrian already found and reported a bug, which I'm going to fix in a later commit. Eventually this will go away, but in the meanwhile, we should add test for this codepath. --- test/DebugInfo/DumpDeclFromMangledName.swift | 25 +++++++++++++++++++ test/DebugInfo/Inputs/decl-reconstr-names.txt | 2 ++ .../lldb-moduleimport-test.cpp | 25 ++++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 test/DebugInfo/DumpDeclFromMangledName.swift create mode 100644 test/DebugInfo/Inputs/decl-reconstr-names.txt diff --git a/test/DebugInfo/DumpDeclFromMangledName.swift b/test/DebugInfo/DumpDeclFromMangledName.swift new file mode 100644 index 00000000000..154afd3290f --- /dev/null +++ b/test/DebugInfo/DumpDeclFromMangledName.swift @@ -0,0 +1,25 @@ +// RUN: %empty-directory(%t) + +// %t.input: "A ---> B" ==> "A" +// RUN: sed -ne '/--->/s/ *--->.*$//p' < %S/Inputs/decl-reconstr-names.txt > %t.input + +// %t.check: "A ---> B" ==> "B" +// RUN: sed -ne '/--->/s/^.*---> *//p' < %S/Inputs/decl-reconstr-names.txt > %t.check + +// RUN: %target-build-swift -emit-executable %s -g -o %t/DeclReconstr -emit-module +// RUN: %lldb-moduleimport-test %t/DeclReconstr \ +// RUN: -decl-from-mangled=%t.input > %t.output 2>&1 +// RUN: diff %t.check %t.output + +// REQUIRES: executable_test +struct S { + init() { + } +} + +func patatino() -> Int { + let s = S() + return 0 +} + +patatino() diff --git a/test/DebugInfo/Inputs/decl-reconstr-names.txt b/test/DebugInfo/Inputs/decl-reconstr-names.txt new file mode 100644 index 00000000000..03dabbc5b38 --- /dev/null +++ b/test/DebugInfo/Inputs/decl-reconstr-names.txt @@ -0,0 +1,2 @@ +$S12DeclReconstr8patatinoSiyF ---> func patatino() -> Int +$S12DeclReconstr1SVACycfC ---> Can't resolve decl of $S12DeclReconstr1SVACycfC diff --git a/tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp b/tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp index fb5539ed376..ce740116f58 100644 --- a/tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp +++ b/tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp @@ -62,6 +62,21 @@ static void printValidationInfo(llvm::StringRef data) { } } +static void resolveDeclFromMangledNameList( + swift::ASTContext &Ctx, llvm::ArrayRef MangledNames) { + std::string Error; + for (auto &Mangled : MangledNames) { + swift::Decl *ResolvedDecl = + swift::ide::getDeclFromMangledSymbolName(Ctx, Mangled, Error); + if (!ResolvedDecl) { + llvm::errs() << "Can't resolve decl of " << Mangled << "\n"; + } else { + ResolvedDecl->print(llvm::errs()); + llvm::errs() << "\n"; + } + } +} + static void resolveTypeFromMangledNameList( swift::ASTContext &Ctx, llvm::ArrayRef MangledNames) { std::string Error; @@ -117,8 +132,11 @@ int main(int argc, char **argv) { llvm::cl::list FrameworkPaths( "F", llvm::cl::desc("add a directory to the framework search path")); + llvm::cl::opt DumpDeclFromMangled( + "decl-from-mangled", llvm::cl::desc("dump decl from mangled names list")); + llvm::cl::opt DumpTypeFromMangled( - "type-from-mangled", llvm::cl::desc("dump type from mangled name")); + "type-from-mangled", llvm::cl::desc("dump type from mangled names list")); llvm::cl::ParseCommandLineOptions(argc, argv); // Unregister our options so they don't interfere with the command line @@ -269,6 +287,11 @@ int main(int argc, char **argv) { collectMangledNames(DumpTypeFromMangled, MangledNames); resolveTypeFromMangledNameList(CI.getASTContext(), MangledNames); } + if (!DumpDeclFromMangled.empty()) { + llvm::SmallVector MangledNames; + collectMangledNames(DumpDeclFromMangled, MangledNames); + resolveDeclFromMangledNameList(CI.getASTContext(), MangledNames); + } } return 0; }