Skip to content

[lldb-moduleimport] Add the logic for testing getDeclBySymbolName(). #15431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions test/DebugInfo/DumpDeclFromMangledName.swift
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions test/DebugInfo/Inputs/decl-reconstr-names.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$S12DeclReconstr8patatinoSiyF ---> func patatino() -> Int
$S12DeclReconstr1SVACycfC ---> Can't resolve decl of $S12DeclReconstr1SVACycfC
31 changes: 27 additions & 4 deletions tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,23 @@ static void printValidationInfo(llvm::StringRef data) {
}
}

static void resolveDeclFromMangledNameList(
swift::ASTContext &Ctx, llvm::ArrayRef<std::string> 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::SmallVector<std::string, 8> &MangledNames) {
swift::ASTContext &Ctx, llvm::ArrayRef<std::string> MangledNames) {
std::string Error;
for (auto &Mangled : MangledNames) {
swift::Type ResolvedType =
Expand All @@ -78,8 +93,8 @@ static void resolveTypeFromMangledNameList(
}

static void
collectMangledNames(std::string &FilePath,
llvm::SmallVector<std::string, 8> &MangledNames) {
collectMangledNames(const std::string &FilePath,
llvm::SmallVectorImpl<std::string> &MangledNames) {
std::string Name;
std::ifstream InputStream(FilePath);
while (std::getline(InputStream, Name)) {
Expand Down Expand Up @@ -117,8 +132,11 @@ int main(int argc, char **argv) {
llvm::cl::list<std::string> FrameworkPaths(
"F", llvm::cl::desc("add a directory to the framework search path"));

llvm::cl::opt<std::string> DumpDeclFromMangled(
"decl-from-mangled", llvm::cl::desc("dump decl from mangled names list"));

llvm::cl::opt<std::string> 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
Expand Down Expand Up @@ -269,6 +287,11 @@ int main(int argc, char **argv) {
collectMangledNames(DumpTypeFromMangled, MangledNames);
resolveTypeFromMangledNameList(CI.getASTContext(), MangledNames);
}
if (!DumpDeclFromMangled.empty()) {
llvm::SmallVector<std::string, 8> MangledNames;
collectMangledNames(DumpDeclFromMangled, MangledNames);
resolveDeclFromMangledNameList(CI.getASTContext(), MangledNames);
}
}
return 0;
}