From 26ddf274d79e33d4440e1983aa2ceffd3addbc84 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 11 Jul 2018 12:30:35 +0000 Subject: Use debug-prefix-map for AT_NAME AT_NAME was being emitted before the directory paths were remapped. This ensures that all paths are remapped before anything is emitted. An additional test case has been added. Note that this only works if the replacement string is an absolute path. If not, then AT_decl_file believes the new path is a relative path, and joins that path with the compilation directory. I do not know of a good way to resolve this. Patch by: Siddhartha Bagaria (starsid) Differential revision: https://reviews.llvm.org/D49169 llvm-svn: 336793 --- llvm/lib/MC/MCContext.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'llvm/lib/MC/MCContext.cpp') diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index b601ab24434..606da252689 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -540,19 +540,26 @@ void MCContext::addDebugPrefixMapEntry(const std::string &From, DebugPrefixMap.insert(std::make_pair(From, To)); } -void MCContext::RemapDebugPath(std::string *Path) { - for (const auto &Entry : DebugPrefixMap) - if (StringRef(*Path).startswith(Entry.first)) { - std::string RemappedPath = - (Twine(Entry.second) + Path->substr(Entry.first.size())).str(); - Path->swap(RemappedPath); - } -} - -void MCContext::RemapCompilationDir() { +void MCContext::RemapDebugPaths() { + const auto &DebugPrefixMap = this->DebugPrefixMap; + const auto RemapDebugPath = [&DebugPrefixMap](std::string &Path) { + for (const auto &Entry : DebugPrefixMap) + if (StringRef(Path).startswith(Entry.first)) { + std::string RemappedPath = + (Twine(Entry.second) + Path.substr(Entry.first.size())).str(); + Path.swap(RemappedPath); + } + }; + + // Remap compilation directory. std::string CompDir = CompilationDir.str(); - RemapDebugPath(&CompDir); + RemapDebugPath(CompDir); CompilationDir = CompDir; + + // Remap MCDwarfDirs in all compilation units. + for (auto &CUIDTablePair : MCDwarfLineTablesCUMap) + for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs()) + RemapDebugPath(Dir); } //===----------------------------------------------------------------------===// -- cgit v1.2.3