|
@@ -47,6 +47,8 @@ CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
|
|
: CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
|
|
: CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
|
|
DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
|
|
DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
|
|
DBuilder(CGM.getModule()) {
|
|
DBuilder(CGM.getModule()) {
|
|
|
|
+ for (const auto &KV : CGM.getCodeGenOpts().DebugPrefixMap)
|
|
|
|
+ DebugPrefixMap[KV.first] = KV.second;
|
|
CreateCompileUnit();
|
|
CreateCompileUnit();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -255,14 +257,16 @@ StringRef CGDebugInfo::getClassName(const RecordDecl *RD) {
|
|
llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
|
|
llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
|
|
if (!Loc.isValid())
|
|
if (!Loc.isValid())
|
|
// If Location is not valid then use main input file.
|
|
// If Location is not valid then use main input file.
|
|
- return DBuilder.createFile(TheCU->getFilename(), TheCU->getDirectory());
|
|
|
|
|
|
+ return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
|
|
|
|
+ remapDIPath(TheCU->getDirectory()));
|
|
|
|
|
|
SourceManager &SM = CGM.getContext().getSourceManager();
|
|
SourceManager &SM = CGM.getContext().getSourceManager();
|
|
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
|
|
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
|
|
|
|
|
|
if (PLoc.isInvalid() || StringRef(PLoc.getFilename()).empty())
|
|
if (PLoc.isInvalid() || StringRef(PLoc.getFilename()).empty())
|
|
// If the location is not valid then use main input file.
|
|
// If the location is not valid then use main input file.
|
|
- return DBuilder.createFile(TheCU->getFilename(), TheCU->getDirectory());
|
|
|
|
|
|
+ return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
|
|
|
|
+ remapDIPath(TheCU->getDirectory()));
|
|
|
|
|
|
// Cache the results.
|
|
// Cache the results.
|
|
const char *fname = PLoc.getFilename();
|
|
const char *fname = PLoc.getFilename();
|
|
@@ -274,15 +278,23 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
|
|
return cast<llvm::DIFile>(V);
|
|
return cast<llvm::DIFile>(V);
|
|
}
|
|
}
|
|
|
|
|
|
- llvm::DIFile *F =
|
|
|
|
- DBuilder.createFile(PLoc.getFilename(), getCurrentDirname());
|
|
|
|
|
|
+ llvm::DIFile *F = DBuilder.createFile(remapDIPath(PLoc.getFilename()),
|
|
|
|
+ remapDIPath(getCurrentDirname()));
|
|
|
|
|
|
DIFileCache[fname].reset(F);
|
|
DIFileCache[fname].reset(F);
|
|
return F;
|
|
return F;
|
|
}
|
|
}
|
|
|
|
|
|
llvm::DIFile *CGDebugInfo::getOrCreateMainFile() {
|
|
llvm::DIFile *CGDebugInfo::getOrCreateMainFile() {
|
|
- return DBuilder.createFile(TheCU->getFilename(), TheCU->getDirectory());
|
|
|
|
|
|
+ return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
|
|
|
|
+ remapDIPath(TheCU->getDirectory()));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+std::string CGDebugInfo::remapDIPath(StringRef Path) const {
|
|
|
|
+ for (const auto &Entry : DebugPrefixMap)
|
|
|
|
+ if (Path.startswith(Entry.first))
|
|
|
|
+ return (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
|
|
|
|
+ return Path.str();
|
|
}
|
|
}
|
|
|
|
|
|
unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) {
|
|
unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) {
|
|
@@ -338,7 +350,7 @@ void CGDebugInfo::CreateCompileUnit() {
|
|
// file to determine the real absolute path for the file.
|
|
// file to determine the real absolute path for the file.
|
|
std::string MainFileDir;
|
|
std::string MainFileDir;
|
|
if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
|
|
if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
|
|
- MainFileDir = MainFile->getDir()->getName();
|
|
|
|
|
|
+ MainFileDir = remapDIPath(MainFile->getDir()->getName());
|
|
if (MainFileDir != ".") {
|
|
if (MainFileDir != ".") {
|
|
llvm::SmallString<1024> MainFileDirSS(MainFileDir);
|
|
llvm::SmallString<1024> MainFileDirSS(MainFileDir);
|
|
llvm::sys::path::append(MainFileDirSS, MainFileName);
|
|
llvm::sys::path::append(MainFileDirSS, MainFileName);
|
|
@@ -371,8 +383,8 @@ void CGDebugInfo::CreateCompileUnit() {
|
|
// Create new compile unit.
|
|
// Create new compile unit.
|
|
// FIXME - Eliminate TheCU.
|
|
// FIXME - Eliminate TheCU.
|
|
TheCU = DBuilder.createCompileUnit(
|
|
TheCU = DBuilder.createCompileUnit(
|
|
- LangTag, MainFileName, getCurrentDirname(), Producer, LO.Optimize,
|
|
|
|
- CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers,
|
|
|
|
|
|
+ LangTag, remapDIPath(MainFileName), remapDIPath(getCurrentDirname()),
|
|
|
|
+ Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers,
|
|
CGM.getCodeGenOpts().SplitDwarfFile,
|
|
CGM.getCodeGenOpts().SplitDwarfFile,
|
|
DebugKind <= CodeGenOptions::DebugLineTablesOnly
|
|
DebugKind <= CodeGenOptions::DebugLineTablesOnly
|
|
? llvm::DIBuilder::LineTablesOnly
|
|
? llvm::DIBuilder::LineTablesOnly
|