Skip to content

Commit eeac130

Browse files
author
Davide Italiano
committed
[lldb-moduleimport-test] Get informations from the module.
This now mirrors what lldb does, and allows us to test this codepath outside of the debugger. <rdar://problem/38867076>
1 parent 1c6d19a commit eeac130

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

test/DebugInfo/DumpDeclFromMangledName.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// RUN: sed -ne '/--->/s/^.*---> *//p' < %S/Inputs/decl-reconstr-names.txt > %t.check
88

99
// RUN: %target-build-swift -emit-executable %s -g -o %t/DeclReconstr -emit-module
10-
// RUN: %lldb-moduleimport-test %t/DeclReconstr -target-triple %target-triple \
10+
// RUN: %lldb-moduleimport-test %t/DeclReconstr \
1111
// RUN: -decl-from-mangled=%t.input > %t.output 2>&1
1212
// RUN: diff %t.check %t.output
1313

tools/lldb-moduleimport-test/lldb-moduleimport-test.cpp

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ void anchorForGetMainExecutable() {}
4242

4343
using namespace llvm::MachO;
4444

45-
static bool validateModule(llvm::StringRef data, bool Verbose) {
46-
swift::serialization::ExtendedValidationInfo extendedInfo;
47-
swift::serialization::ValidationInfo info =
48-
swift::serialization::validateSerializedAST(data, &extendedInfo);
45+
static bool validateModule(llvm::StringRef data, bool Verbose,
46+
swift::serialization::ValidationInfo &info,
47+
swift::serialization::ExtendedValidationInfo &extendedInfo) {
48+
info = swift::serialization::validateSerializedAST(data, &extendedInfo);
4949
if (info.status != swift::serialization::Status::Valid)
5050
return false;
5151

@@ -175,9 +175,6 @@ int main(int argc, char **argv) {
175175
llvm::cl::Positional, llvm::cl::desc("compiled_swift_file1.o ..."),
176176
llvm::cl::OneOrMore);
177177

178-
llvm::cl::opt<std::string> SDK(
179-
"sdk", llvm::cl::desc("path to the SDK to build against"));
180-
181178
llvm::cl::opt<bool> DumpModule(
182179
"dump-module", llvm::cl::desc(
183180
"Dump the imported module after checking it imports just fine"));
@@ -194,40 +191,33 @@ int main(int argc, char **argv) {
194191
llvm::cl::opt<std::string> DumpTypeFromMangled(
195192
"type-from-mangled", llvm::cl::desc("dump type from mangled names list"));
196193

197-
// FIXME: we should infer this from the module.
198-
llvm::cl::opt<std::string> TargetTriple(
199-
"target-triple", llvm::cl::desc("specify target triple"));
200-
201194
llvm::cl::ParseCommandLineOptions(argc, argv);
202195
// Unregister our options so they don't interfere with the command line
203196
// parsing in CodeGen/BackendUtil.cpp.
204197
ModuleCachePath.removeArgument();
205198
DumpModule.removeArgument();
206199
DumpTypeFromMangled.removeArgument();
207-
SDK.removeArgument();
208200
InputNames.removeArgument();
209-
TargetTriple.removeArgument();
210201

211202
// Fetch the serialized module bitstreams from the Mach-O files and
212203
// register them with the module loader.
213204
llvm::SmallVector<std::pair<char *, uint64_t>, 8> Modules;
214205
if (!collectASTModules(InputNames, Modules))
215206
return 1;
216207

208+
if (Modules.empty())
209+
return 0;
210+
211+
swift::serialization::ValidationInfo info;
212+
swift::serialization::ExtendedValidationInfo extendedInfo;
217213
for (auto &Module : Modules) {
218-
if (!validateModule(StringRef(Module.first, Module.second), Verbose)) {
214+
if (!validateModule(StringRef(Module.first, Module.second), Verbose, info,
215+
extendedInfo)) {
219216
llvm::errs() << "Malformed module!\n";
220217
return 1;
221218
}
222219
}
223220

224-
// If no SDK was specified via -sdk, check environment variable SDKROOT.
225-
if (SDK.getNumOccurrences() == 0) {
226-
const char *SDKROOT = getenv("SDKROOT");
227-
if (SDKROOT)
228-
SDK = SDKROOT;
229-
}
230-
231221
// Create a Swift compiler.
232222
llvm::SmallVector<std::string, 4> modules;
233223
swift::CompilerInstance CI;
@@ -237,13 +227,9 @@ int main(int argc, char **argv) {
237227
llvm::sys::fs::getMainExecutable(argv[0],
238228
reinterpret_cast<void *>(&anchorForGetMainExecutable)));
239229

240-
Invocation.setSDKPath(SDK);
241-
242-
// FIXME: we should infer this from the module.
243-
if (!TargetTriple.empty())
244-
Invocation.setTargetTriple(TargetTriple);
245-
else
246-
Invocation.setTargetTriple(llvm::sys::getDefaultTargetTriple());
230+
// Infer SDK and Target triple from the module.
231+
Invocation.setSDKPath(extendedInfo.getSDKPath());
232+
Invocation.setTargetTriple(info.targetTriple);
247233

248234
Invocation.setModuleName("lldbtest");
249235
Invocation.getClangImporterOptions().ModuleCachePath = ModuleCachePath;

0 commit comments

Comments
 (0)