[PATCH] D73383: Allow retrieving source files relative to the compilation directory.

Sterling Augustine via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 24 15:05:16 PST 2020


saugustine created this revision.
Herald added subscribers: llvm-commits, hiraditya, aprantl.
Herald added a project: LLVM.
saugustine added reviewers: labath, rupprecht, jhenderson.
saugustine added a comment.
saugustine added a reviewer: MaskRay.

This revision also moves the absolute path logic out of the dwarf-4 only side of the conditional. I believe that was a mistake in an earlier patch, because there is nothing special about dwarf-4 vs dwarf-5 in this regard. Although there are some changes in where it is stored, they aren't relevant to whether it should be appended.


Dwarf stores source-file names the three parts:
<compilation_directory><include_directory><filename>

Prior to this change, the code only allowed retrieving either all
three as the absolute path, or just the filename.  But many
compile-command lines--especially those in hermetic build systems
don't specify an absolute path, nor just the filename, but rather the
path relative to the compilation directory. This features allows
retrieving them in that style.

Not sure of the best place for a test for this. Neither of the
other options are tested explicitly. The unittests are all very
low level (Can we read .debug_info properly? And a symbolizer
test would require adding a new flag to the symbolizer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73383

Files:
  llvm/include/llvm/DebugInfo/DIContext.h
  llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp


Index: llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1056,7 +1056,7 @@
   if (!Name)
     return false;
   StringRef FileName = *Name;
-  if (Kind != FileLineInfoKind::AbsoluteFilePath ||
+  if (Kind == FileLineInfoKind::None || Kind == FileLineInfoKind::Default ||
       isPathAbsoluteOnWindowsOrPosix(FileName)) {
     Result = FileName;
     return true;
@@ -1072,13 +1072,17 @@
     if (0 < Entry.DirIdx && Entry.DirIdx <= IncludeDirectories.size())
       IncludeDir =
           IncludeDirectories[Entry.DirIdx - 1].getAsCString().getValue();
-
-    // We may still need to append compilation directory of compile unit.
-    // We know that FileName is not absolute, the only way to have an
-    // absolute path at this point would be if IncludeDir is absolute.
-    if (!CompDir.empty() && !isPathAbsoluteOnWindowsOrPosix(IncludeDir))
-      sys::path::append(FilePath, Style, CompDir);
   }
+  // For absolute paths only, include the compilation directory of compile unit.
+  // We know that FileName is not absolute, the only way to have an absolute
+  // path at this point would be if IncludeDir is absolute.
+  if (Kind == FileLineInfoKind::AbsoluteFilePath && !CompDir.empty() &&
+      !isPathAbsoluteOnWindowsOrPosix(IncludeDir))
+    sys::path::append(FilePath, Style, CompDir);
+
+  assert((Kind == FileLineInfoKind::AbsoluteFilePath ||
+          Kind == FileLineInfoKind::RelativeFilePath) &&
+         "invalid FileLineInfo Kind");
 
   // sys::path::append skips empty strings.
   sys::path::append(FilePath, Style, IncludeDir, FileName);
Index: llvm/include/llvm/DebugInfo/DIContext.h
===================================================================
--- llvm/include/llvm/DebugInfo/DIContext.h
+++ llvm/include/llvm/DebugInfo/DIContext.h
@@ -133,7 +133,12 @@
 /// Controls which fields of DILineInfo container should be filled
 /// with data.
 struct DILineInfoSpecifier {
-  enum class FileLineInfoKind { None, Default, AbsoluteFilePath };
+  enum class FileLineInfoKind {
+    None,
+    Default,
+    RelativeFilePath,
+    AbsoluteFilePath
+  };
   using FunctionNameKind = DINameKind;
 
   FileLineInfoKind FLIKind;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73383.240301.patch
Type: text/x-patch
Size: 2314 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200124/c4c64b1e/attachment.bin>


More information about the llvm-commits mailing list