]> granicus.if.org Git - llvm/commitdiff
Use debug-prefix-map for AT_NAME
authorJonas Devlieghere <jonas@devlieghere.com>
Wed, 11 Jul 2018 12:30:35 +0000 (12:30 +0000)
committerJonas Devlieghere <jonas@devlieghere.com>
Wed, 11 Jul 2018 12:30:35 +0000 (12:30 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336793 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCContext.h
include/llvm/MC/MCDwarf.h
lib/MC/MCContext.cpp
lib/MC/MCDwarf.cpp
lib/MC/MCObjectStreamer.cpp
test/MC/ELF/debug-prefix-map.s

index 6fa36d096e71aa8aa9ccb6bf85736c367dc92514..a712e2d95cbc57608af24528929c5b60b2e34729 100644 (file)
@@ -502,11 +502,8 @@ namespace llvm {
     /// Add an entry to the debug prefix map.
     void addDebugPrefixMapEntry(const std::string &From, const std::string &To);
 
-    // Remaps the given path in-place as per the debug prefix map.
-    void RemapDebugPath(std::string *Path);
-
-    // Remaps the compilation dir as per the debug prefix map.
-    void RemapCompilationDir();
+    // Remaps all debug directory paths in-place as per the debug prefix map.
+    void RemapDebugPaths();
 
     /// Get the main file name for use in error messages and debug
     /// info. This can be set to ensure we've got the correct file name
index e091452e28cd1736c80b84ee2dc53ce1f6564248..785f42d2f9d73e941085c303e548146f3dbc1394 100644 (file)
@@ -301,8 +301,6 @@ public:
                                FileNumber));
   }
 
-  void RemapDwarfDirs(MCContext &Context);
-
   void setRootFile(StringRef Directory, StringRef FileName,
                    MD5::MD5Result *Checksum, Optional<StringRef> Source) {
     Header.CompilationDir = Directory;
index b601ab2443420dc2c21b1fdbc2fcb3bc47d8ded2..606da2526890ba128c627cde698dcaa74c966533 100644 (file)
@@ -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);
 }
 
 //===----------------------------------------------------------------------===//
index 1d33d9947bed3a91d0040084efbff505f1542bb0..6131fcd658b2e84fce639dfec9776c4c94e31edf 100644 (file)
@@ -251,9 +251,7 @@ void MCDwarfLineTable::Emit(MCObjectStreamer *MCOS,
 
   // Handle the rest of the Compile Units.
   for (const auto &CUIDTablePair : LineTables) {
-    auto &LineTable = context.getMCDwarfLineTable(CUIDTablePair.first);
-    LineTable.RemapDwarfDirs(MCOS->getContext());
-    LineTable.EmitCU(MCOS, Params, LineStr);
+    CUIDTablePair.second.EmitCU(MCOS, Params, LineStr);
   }
 
   if (LineStr)
@@ -634,11 +632,6 @@ MCDwarfLineTableHeader::tryGetFile(StringRef &Directory,
   return FileNumber;
 }
 
-void MCDwarfLineTable::RemapDwarfDirs(MCContext &Context) {
-  for (auto &Dir : Header.MCDwarfDirs)
-    Context.RemapDebugPath(&Dir);
-}
-
 /// Utility function to emit the encoding to a streamer.
 void MCDwarfLineAddr::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
                            int64_t LineDelta, uint64_t AddrDelta) {
index 9fab8d835f8096664af60f86bf77f2a5fd611e5a..9d536883b98be74ad2dc13bba7bae8292c1419b3 100644 (file)
@@ -661,8 +661,7 @@ void MCObjectStreamer::EmitFileDirective(StringRef Filename) {
 }
 
 void MCObjectStreamer::FinishImpl() {
-  // Remap the compilation directory before emitting.
-  getContext().RemapCompilationDir();
+  getContext().RemapDebugPaths();
 
   // If we are generating dwarf for assembly source files dump out the sections.
   if (getContext().getGenDwarfForAssembly())
index f81730418b0beb6c7ab3e0c3c2e939bf193232e6..06990b88eaef7b6c4f3333830164588f1922d1c0 100644 (file)
@@ -4,9 +4,13 @@
 
 // RUN: llvm-mc -triple=x86_64-linux-unknown -g src.s -filetype=obj -o out.o
 // RUN: llvm-dwarfdump -v -debug-info out.o | FileCheck --check-prefix=NO_MAP %s
+
 // RUN: llvm-mc -triple=x86_64-linux-unknown -g src.s -filetype=obj -o out.o -fdebug-prefix-map=%t.foo=src_root
 // RUN: llvm-dwarfdump -v -debug-info out.o | FileCheck --check-prefix=MAP --implicit-check-not ".foo" %s
 
+// RUN: llvm-mc -triple=x86_64-linux-unknown -g %t.foo/src.s -filetype=obj -o out.o -fdebug-prefix-map=%t.foo=/src_root
+// RUN: llvm-dwarfdump -v -debug-info out.o | FileCheck --check-prefix=MAP_ABS --implicit-check-not ".foo" %s
+
 f:
   nop
 
@@ -15,3 +19,7 @@ f:
 // MAP: DW_AT_name [DW_FORM_string] ("src.s")
 // MAP: DW_AT_comp_dir [DW_FORM_string] ("src_root")
 // MAP: DW_AT_decl_file [DW_FORM_data4] ("src_root{{(/|\\)}}src.s")
+
+// MAP_ABS: DW_AT_name [DW_FORM_string] ("{{/|\\}}src_root{{(/|\\)}}src.s")
+// MAP_ABS: DW_AT_comp_dir [DW_FORM_string] ("{{/|\\}}src_root")
+// MAP_ABS: DW_AT_decl_file [DW_FORM_data4] ("{{/|\\}}src_root{{(/|\\)}}src.s")