Allow remapping Clang module include paths

in the debug info with -fdebug-prefix-map.

rdar://problem/55685132

This reapplies an earlier attempt to commit this without
modifications.

Differential Revision: https://reviews.llvm.org/D76385
This commit is contained in:
Adrian Prantl 2020-03-18 15:30:20 -07:00
parent 5be9b8cbe2
commit 22d5bd0e3b
2 changed files with 21 additions and 11 deletions

View File

@ -2483,6 +2483,17 @@ llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
assert(StringRef(M->Name).startswith(CGM.getLangOpts().ModuleName) &&
"clang module without ASTFile must be specified by -fmodule-name");
// Return a StringRef to the remapped Path.
auto RemapPath = [this](StringRef Path) -> std::string {
std::string Remapped = remapDIPath(Path);
StringRef Relative(Remapped);
StringRef CompDir = TheCU->getDirectory();
if (Relative.consume_front(CompDir))
Relative.consume_front(llvm::sys::path::get_separator());
return Relative.str();
};
if (CreateSkeletonCU && IsRootModule && !Mod.getASTFile().empty()) {
// PCH files don't have a signature field in the control block,
// but LLVM detects skeleton CUs by looking for a non-zero DWO id.
@ -2496,16 +2507,12 @@ llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
if (!llvm::sys::path::is_absolute(Mod.getASTFile()))
PCM = Mod.getPath();
llvm::sys::path::append(PCM, Mod.getASTFile());
std::string RemappedPCM = remapDIPath(PCM);
StringRef RelativePCM(RemappedPCM);
StringRef CompDir = TheCU->getDirectory();
if (RelativePCM.consume_front(CompDir))
RelativePCM.consume_front(llvm::sys::path::get_separator());
DIB.createCompileUnit(TheCU->getSourceLanguage(),
// TODO: Support "Source" from external AST providers?
DIB.createFile(Mod.getModuleName(), CompDir),
TheCU->getProducer(), false, StringRef(), 0, RelativePCM,
llvm::DICompileUnit::FullDebug, Signature);
DIB.createCompileUnit(
TheCU->getSourceLanguage(),
// TODO: Support "Source" from external AST providers?
DIB.createFile(Mod.getModuleName(), TheCU->getDirectory()),
TheCU->getProducer(), false, StringRef(), 0, RemapPath(PCM),
llvm::DICompileUnit::FullDebug, Signature);
DIB.finalize();
}
@ -2513,9 +2520,10 @@ llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
IsRootModule ? nullptr
: getOrCreateModuleRef(ASTSourceDescriptor(*M->Parent),
CreateSkeletonCU);
std::string IncludePath = Mod.getPath().str();
llvm::DIModule *DIMod =
DBuilder.createModule(Parent, Mod.getModuleName(), ConfigMacros,
Mod.getPath());
RemapPath(IncludePath));
ModuleCache[M].reset(DIMod);
return DIMod;
}

View File

@ -34,9 +34,11 @@
// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
// RUN: -fmodules-cache-path=%t -fdebug-prefix-map=%t=/MODULE-CACHE \
// RUN: -fdebug-prefix-map=%S=/SRCDIR \
// RUN: -fmodule-format=obj -dwarf-ext-refs \
// RUN: %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
// RUN: | FileCheck %s --check-prefix=SKEL-CHECK
// SKEL-CHECK: includePath: "/SRCDIR/Inputs"
// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]]
// SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[DWOFILE:[0-9]+]]{{.*}}splitDebugFilename: "/MODULE-CACHE{{.*}}dwoId