Skip to content

Commit cb4efa0

Browse files
committed
Add a -debug-module-path frontend option
This new option allows the Driver to pass the path to a compilation job's own binary swiftmodule artifact to the frontend. The compiler then stores this path in the debug info, to allow clients like LLDB to unambiguously know which binary Swift module belongs to which compile unit. rdar://163302154
1 parent be3009d commit cb4efa0

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
@@ -270,6 +270,9 @@ class IRGenOptions {
270270
public:
271271
std::string ModuleName;
272272

273+
/// The path to the main binary swiftmodule for the debug info.
274+
std::string DebugModulePath;
275+
273276
/// The compilation directory for the debug info.
274277
std::string DebugCompilationDir;
275278

include/swift/Option/Options.td

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

646+
def debug_module_path : Separate<["-"], "debug-module-path">,
647+
Flags<[FrontendOption]>,
648+
HelpText<"Path to this module's binary swiftmodule artifact (required by debug info)">;
649+
def debug_module_path_EQ : Joined<["-"], "debug-module-path=">, Flags<[FrontendOption]>,
650+
Alias<debug_module_path>;
651+
646652
def module_alias : Separate<["-"], "module-alias">,
647653
Flags<[FrontendOption, ModuleInterfaceOption]>,
648654
MetaVarName<"<alias_name=real_name>">,

lib/Frontend/CompilerInvocation.cpp

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

3463+
if (const Arg *A = Args.getLastArg(options::OPT_debug_module_path))
3464+
Opts.DebugModulePath = A->getValue();
3465+
34633466
for (auto A : Args.getAllArgValues(options::OPT_file_prefix_map)) {
34643467
auto SplitMap = StringRef(A).split('=');
34653468
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)