mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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
This commit is contained in:
@@ -270,6 +270,9 @@ class IRGenOptions {
|
|||||||
public:
|
public:
|
||||||
std::string ModuleName;
|
std::string ModuleName;
|
||||||
|
|
||||||
|
/// The path to the main binary swiftmodule for the debug info.
|
||||||
|
std::string DebugModulePath;
|
||||||
|
|
||||||
/// The compilation directory for the debug info.
|
/// The compilation directory for the debug info.
|
||||||
std::string DebugCompilationDir;
|
std::string DebugCompilationDir;
|
||||||
|
|
||||||
|
|||||||
@@ -643,6 +643,12 @@ def project_name : Separate<["-"], "project-name">,
|
|||||||
def module_name_EQ : Joined<["-"], "module-name=">, Flags<[FrontendOption]>,
|
def module_name_EQ : Joined<["-"], "module-name=">, Flags<[FrontendOption]>,
|
||||||
Alias<module_name>;
|
Alias<module_name>;
|
||||||
|
|
||||||
|
def debug_module_path : Separate<["-"], "debug-module-path">,
|
||||||
|
Flags<[FrontendOption]>,
|
||||||
|
HelpText<"Path to this module's binary swiftmodule artifact (required by debug info)">;
|
||||||
|
def debug_module_path_EQ : Joined<["-"], "debug-module-path=">, Flags<[FrontendOption]>,
|
||||||
|
Alias<debug_module_path>;
|
||||||
|
|
||||||
def module_alias : Separate<["-"], "module-alias">,
|
def module_alias : Separate<["-"], "module-alias">,
|
||||||
Flags<[FrontendOption, ModuleInterfaceOption]>,
|
Flags<[FrontendOption, ModuleInterfaceOption]>,
|
||||||
MetaVarName<"<alias_name=real_name>">,
|
MetaVarName<"<alias_name=real_name>">,
|
||||||
|
|||||||
@@ -3460,6 +3460,9 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
|
|||||||
A->getAsString(Args), A->getValue());
|
A->getAsString(Args), A->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (const Arg *A = Args.getLastArg(options::OPT_debug_module_path))
|
||||||
|
Opts.DebugModulePath = A->getValue();
|
||||||
|
|
||||||
for (auto A : Args.getAllArgValues(options::OPT_file_prefix_map)) {
|
for (auto A : Args.getAllArgValues(options::OPT_file_prefix_map)) {
|
||||||
auto SplitMap = StringRef(A).split('=');
|
auto SplitMap = StringRef(A).split('=');
|
||||||
Opts.FilePrefixMap.addMapping(SplitMap.first, SplitMap.second);
|
Opts.FilePrefixMap.addMapping(SplitMap.first, SplitMap.second);
|
||||||
|
|||||||
@@ -864,7 +864,7 @@ private:
|
|||||||
llvm::DIModule *getOrCreateModule(const void *Key, llvm::DIScope *Parent,
|
llvm::DIModule *getOrCreateModule(const void *Key, llvm::DIScope *Parent,
|
||||||
StringRef Name, StringRef IncludePath,
|
StringRef Name, StringRef IncludePath,
|
||||||
uint64_t Signature = ~1ULL,
|
uint64_t Signature = ~1ULL,
|
||||||
StringRef ASTFile = StringRef()) {
|
StringRef ASTFile = {}) {
|
||||||
// Look in the cache first.
|
// Look in the cache first.
|
||||||
auto Val = DIModuleCache.find(Key);
|
auto Val = DIModuleCache.find(Key);
|
||||||
if (Val != DIModuleCache.end())
|
if (Val != DIModuleCache.end())
|
||||||
@@ -2823,8 +2823,12 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
|
|||||||
|
|
||||||
// Create a module for the current compile unit.
|
// Create a module for the current compile unit.
|
||||||
auto *MDecl = IGM.getSwiftModule();
|
auto *MDecl = IGM.getSwiftModule();
|
||||||
llvm::sys::path::remove_filename(SourcePath);
|
StringRef Path = Opts.DebugModulePath;
|
||||||
MainModule = getOrCreateModule(MDecl, TheCU, Opts.ModuleName, SourcePath);
|
if (Path.empty()) {
|
||||||
|
llvm::sys::path::remove_filename(SourcePath);
|
||||||
|
Path = SourcePath;
|
||||||
|
}
|
||||||
|
MainModule = getOrCreateModule(MDecl, TheCU, Opts.ModuleName, Path);
|
||||||
DBuilder.createImportedModule(MainFile, MainModule, MainFile, 0);
|
DBuilder.createImportedModule(MainFile, MainModule, MainFile, 0);
|
||||||
|
|
||||||
// Macro definitions that were defined by the user with "-Xcc -D" on the
|
// Macro definitions that were defined by the user with "-Xcc -D" on the
|
||||||
|
|||||||
4
test/DebugInfo/ebm_module_path.swift
Normal file
4
test/DebugInfo/ebm_module_path.swift
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// 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
|
||||||
|
|
||||||
|
// CHECK: DIModule(scope: null, name: "A", includePath: "{{.*}}MY_MODULE_PATH.swiftmodule")
|
||||||
|
|
||||||
Reference in New Issue
Block a user