kwk created this revision.
kwk added a reviewer: labath.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

PLEASE DO NOT REVIEW YET. This is for brainstorming an idea with @labath


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74650

Files:
  lldb/include/lldb/Utility/FileSpec.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Utility/FileSpec.cpp

Index: lldb/source/Utility/FileSpec.cpp
===================================================================
--- lldb/source/Utility/FileSpec.cpp
+++ lldb/source/Utility/FileSpec.cpp
@@ -68,8 +68,9 @@
 FileSpec::FileSpec() : m_style(GetNativeStyle()) {}
 
 // Default constructor that can take an optional full path to a file on disk.
-FileSpec::FileSpec(llvm::StringRef path, Style style) : m_style(style) {
-  SetFile(path, style);
+FileSpec::FileSpec(llvm::StringRef path, Style style, bool normalize)
+    : m_style(style) {
+  SetFile(path, style, normalize);
 }
 
 FileSpec::FileSpec(llvm::StringRef path, const llvm::Triple &triple)
@@ -171,7 +172,7 @@
 // Update the contents of this object with a new path. The path will be split
 // up into a directory and filename and stored as uniqued string values for
 // quick comparison and efficient memory usage.
-void FileSpec::SetFile(llvm::StringRef pathname, Style style) {
+void FileSpec::SetFile(llvm::StringRef pathname, Style style, bool normalize) {
   m_filename.Clear();
   m_directory.Clear();
   m_is_resolved = false;
@@ -183,11 +184,11 @@
   llvm::SmallString<128> resolved(pathname);
 
   // Normalize the path by removing ".", ".." and other redundant components.
-  if (needsNormalization(resolved))
+  if (normalize && needsNormalization(resolved))
     llvm::sys::path::remove_dots(resolved, true, m_style);
 
   // Normalize back slashes to forward slashes
-  if (m_style == Style::windows)
+  if (normalize && m_style == Style::windows)
     std::replace(resolved.begin(), resolved.end(), '\\', '/');
 
   if (resolved.empty()) {
@@ -213,6 +214,10 @@
   return SetFile(path, triple.isOSWindows() ? Style::windows : Style::posix);
 }
 
+bool FileSpec::IsNormalized() const {
+  return *this == FileSpec(GetPath(), m_style, true);
+}
+
 // Convert to pointer operator. This allows code to check any FileSpec objects
 // to see if they contain anything valid using code such as:
 //
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -213,7 +213,7 @@
         remapped_file = std::move(*file_path);
 
     // Unconditionally add an entry, so the indices match up.
-    support_files.EmplaceBack(remapped_file, style);
+    support_files.EmplaceBack(remapped_file, style, false);
   }
 
   return support_files;
Index: lldb/include/lldb/Utility/FileSpec.h
===================================================================
--- lldb/include/lldb/Utility/FileSpec.h
+++ lldb/include/lldb/Utility/FileSpec.h
@@ -70,8 +70,12 @@
   /// \param[in] style
   ///     The style of the path
   ///
+  /// \param[in] normalize
+  ///     Whether or not to cleanup the filepath or not.
+  ///
   /// \see FileSpec::SetFile (const char *path)
-  explicit FileSpec(llvm::StringRef path, Style style = Style::native);
+  explicit FileSpec(llvm::StringRef path, Style style = Style::native,
+                    bool normalize = true);
 
   explicit FileSpec(llvm::StringRef path, const llvm::Triple &triple);
 
@@ -348,7 +352,10 @@
   ///
   /// \param[in] style
   ///     The style for the given path.
-  void SetFile(llvm::StringRef path, Style style);
+  ///
+  /// \param[in] normalize
+  ///     Whether or not to cleanup the filepath or not.
+  void SetFile(llvm::StringRef path, Style style, bool normalize = true);
 
   /// Change the file specified with a new path.
   ///
@@ -363,6 +370,10 @@
   ///     The triple which is used to set the Path style.
   void SetFile(llvm::StringRef path, const llvm::Triple &triple);
 
+  /// \returns \c true if the normalized FileSpec is the same as this; otherwise
+  /// \c false is returned.
+  bool IsNormalized() const;
+
   bool IsResolved() const { return m_is_resolved; }
 
   /// Set if the file path has been resolved or not.
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PAT... Konrad Wilhelm Kleine via Phabricator via lldb-commits

Reply via email to