[Lldb-commits] [PATCH] D47495: Support relative paths with less than two components in DBGSourcePathRemapping

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue May 29 13:46:23 PDT 2018


JDevlieghere created this revision.
JDevlieghere added reviewers: jasonmolenda, clayborg, labath.

When reading DBGSourcePathRemapping from a dSYM, we remove the last two path components to make the source lookup more general. However, when dealing with a relative path that has less than 2 components, we ended up with an invalid (empty) FileSpec. The problem is the result of a combination of two thins:

1. How the relative path `.` or `./` is stored: both are considered to be an empty directory and just the dot as filename.
2. How removeLastPathComponent works: it makes sense that `/foo.bar` -> `/` and  `foo.bar` -> ``.

Because outside this context it doesn't really make sense to change either, I've added a flag to `removeLastPathComponent` to obtain the desired behavior.


https://reviews.llvm.org/D47495

Files:
  include/lldb/Utility/FileSpec.h
  source/Host/macosx/Symbols.cpp
  source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
  source/Utility/FileSpec.cpp


Index: source/Utility/FileSpec.cpp
===================================================================
--- source/Utility/FileSpec.cpp
+++ source/Utility/FileSpec.cpp
@@ -785,14 +785,16 @@
   return AppendPathComponent(new_path.GetPath(false));
 }
 
-void FileSpec::RemoveLastPathComponent() {
+void FileSpec::RemoveLastPathComponent(bool keep_dot) {
   // CLEANUP: Use StringRef for string handling.
 
   const bool resolve = false;
   if (m_filename.IsEmpty() && m_directory.IsEmpty()) {
     SetFile("", resolve);
     return;
   }
+  if (keep_dot && *this == FileSpec(".", false))
+    return;
   if (m_directory.IsEmpty()) {
     SetFile("", resolve);
     return;
@@ -816,6 +818,7 @@
   } else
     SetFile(m_directory.GetCString(), resolve);
 }
+
 //------------------------------------------------------------------
 /// Returns true if the filespec represents an implementation source
 /// file (files with a ".c", ".cpp", ".m", ".mm" (many more)
Index: source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
===================================================================
--- source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
+++ source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
@@ -260,10 +260,10 @@
                                 if (do_truncate_remapping_names) {
                                   FileSpec build_path(key.AsCString(), false);
                                   FileSpec source_path(DBGSourcePath.c_str(), false);
-                                  build_path.RemoveLastPathComponent();
-                                  build_path.RemoveLastPathComponent();
-                                  source_path.RemoveLastPathComponent();
-                                  source_path.RemoveLastPathComponent();
+                                  build_path.RemoveLastPathComponent(true);
+                                  build_path.RemoveLastPathComponent(true);
+                                  source_path.RemoveLastPathComponent(true);
+                                  source_path.RemoveLastPathComponent(true);
                                   module_sp->GetSourceMappingList().Append(
                                       ConstString(build_path.GetPath().c_str()),
                                       ConstString(source_path.GetPath().c_str()), true);
Index: source/Host/macosx/Symbols.cpp
===================================================================
--- source/Host/macosx/Symbols.cpp
+++ source/Host/macosx/Symbols.cpp
@@ -409,10 +409,10 @@
             if (do_truncate_remapping_names) {
               FileSpec build_path(DBGBuildSourcePath.c_str(), false);
               FileSpec source_path(DBGSourcePath.c_str(), false);
-              build_path.RemoveLastPathComponent();
-              build_path.RemoveLastPathComponent();
-              source_path.RemoveLastPathComponent();
-              source_path.RemoveLastPathComponent();
+              build_path.RemoveLastPathComponent(true);
+              build_path.RemoveLastPathComponent(true);
+              source_path.RemoveLastPathComponent(true);
+              source_path.RemoveLastPathComponent(true);
               module_spec.GetSourceMappingList().Append(
                 ConstString(build_path.GetPath().c_str()),
                 ConstString(source_path.GetPath().c_str()), true);
Index: include/lldb/Utility/FileSpec.h
===================================================================
--- include/lldb/Utility/FileSpec.h
+++ include/lldb/Utility/FileSpec.h
@@ -532,7 +532,7 @@
   void AppendPathComponent(llvm::StringRef component);
   void AppendPathComponent(const FileSpec &new_path);
 
-  void RemoveLastPathComponent();
+  void RemoveLastPathComponent(bool keep_dot = false);
 
   ConstString GetLastPathComponent() const;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47495.148976.patch
Type: text/x-patch
Size: 3789 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180529/32da93b5/attachment.bin>


More information about the lldb-commits mailing list