Skip to content

Commit 457a2d3

Browse files
Merge pull request #85100 from adrian-prantl/163302154
Add a -debug-module-path frontend option
2 parents 6dbe0cb + cb4efa0 commit 457a2d3

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ class IRGenOptions {
278278
public:
279279
std::string ModuleName;
280280

281+
/// The path to the main binary swiftmodule for the debug info.
282+
std::string DebugModulePath;
283+
281284
/// The compilation directory for the debug info.
282285
std::string DebugCompilationDir;
283286

include/swift/Option/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,12 @@ def project_name : Separate<["-"], "project-name">,
653653
def module_name_EQ : Joined<["-"], "module-name=">, Flags<[FrontendOption]>,
654654
Alias<module_name>;
655655

656+
def debug_module_path : Separate<["-"], "debug-module-path">,
657+
Flags<[FrontendOption]>,
658+
HelpText<"Path to this module's binary swiftmodule artifact (required by debug info)">;
659+
def debug_module_path_EQ : Joined<["-"], "debug-module-path=">, Flags<[FrontendOption]>,
660+
Alias<debug_module_path>;
661+
656662
def module_alias : Separate<["-"], "module-alias">,
657663
Flags<[FrontendOption, ModuleInterfaceOption]>,
658664
MetaVarName<"<alias_name=real_name>">,

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3462,6 +3462,9 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
34623462
A->getAsString(Args), A->getValue());
34633463
}
34643464

3465+
if (const Arg *A = Args.getLastArg(options::OPT_debug_module_path))
3466+
Opts.DebugModulePath = A->getValue();
3467+
34653468
for (auto A : Args.getAllArgValues(options::OPT_file_prefix_map)) {
34663469
auto SplitMap = StringRef(A).split('=');
34673470
Opts.FilePrefixMap.addMapping(SplitMap.first, SplitMap.second);

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
864864
llvm::DIModule *getOrCreateModule(const void *Key, llvm::DIScope *Parent,
865865
StringRef Name, StringRef IncludePath,
866866
uint64_t Signature = ~1ULL,
867-
StringRef ASTFile = StringRef()) {
867+
StringRef ASTFile = {}) {
868868
// Look in the cache first.
869869
auto Val = DIModuleCache.find(Key);
870870
if (Val != DIModuleCache.end())
@@ -2823,8 +2823,12 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
28232823

28242824
// Create a module for the current compile unit.
28252825
auto *MDecl = IGM.getSwiftModule();
2826-
llvm::sys::path::remove_filename(SourcePath);
2827-
MainModule = getOrCreateModule(MDecl, TheCU, Opts.ModuleName, SourcePath);
2826+
StringRef Path = Opts.DebugModulePath;
2827+
if (Path.empty()) {
2828+
llvm::sys::path::remove_filename(SourcePath);
2829+
Path = SourcePath;
2830+
}
2831+
MainModule = getOrCreateModule(MDecl, TheCU, Opts.ModuleName, Path);
28282832
DBuilder.createImportedModule(MainFile, MainModule, MainFile, 0);
28292833

28302834
// Macro definitions that were defined by the user with "-Xcc -D" on the
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %target-swift-frontend -primary-file %s -emit-ir -g -module-name=A -debug-module-path %t/MY_MODULE_PATH.swiftmodule -emit-ir -o - | %FileCheck %s
2+
3+
// CHECK: DIModule(scope: null, name: "A", includePath: "{{.*}}MY_MODULE_PATH.swiftmodule")
4+

0 commit comments

Comments
 (0)