[Lldb-commits] [lldb] r282277 - Change Module::RemapPath to use StringRef.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 23 11:42:38 PDT 2016


Author: zturner
Date: Fri Sep 23 13:42:38 2016
New Revision: 282277

URL: http://llvm.org/viewvc/llvm-project?rev=282277&view=rev
Log:
Change Module::RemapPath to use StringRef.

Modified:
    lldb/trunk/include/lldb/Core/Module.h
    lldb/trunk/include/lldb/Target/PathMappingList.h
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugLine.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Target/PathMappingList.cpp

Modified: lldb/trunk/include/lldb/Core/Module.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=282277&r1=282276&r2=282277&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Module.h (original)
+++ lldb/trunk/include/lldb/Core/Module.h Fri Sep 23 13:42:38 2016
@@ -27,7 +27,9 @@
 #include "lldb/Symbol/TypeSystem.h"
 #include "lldb/Target/PathMappingList.h"
 #include "lldb/lldb-forward.h"
+
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/StringRef.h"
 
 namespace lldb_private {
 
@@ -953,7 +955,8 @@ public:
   ///     /b true if \a path was successfully located and \a new_path
   ///     is filled in with a new source path, \b false otherwise.
   //------------------------------------------------------------------
-  bool RemapSourceFile(const char *path, std::string &new_path) const;
+  bool RemapSourceFile(llvm::StringRef path, std::string &new_path) const;
+  bool RemapSourceFile(const char *, std::string &) const = delete;
 
   //----------------------------------------------------------------------
   /// @class LookupInfo Module.h "lldb/Core/Module.h"

Modified: lldb/trunk/include/lldb/Target/PathMappingList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/PathMappingList.h?rev=282277&r1=282276&r2=282277&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/PathMappingList.h (original)
+++ lldb/trunk/include/lldb/Target/PathMappingList.h Fri Sep 23 13:42:38 2016
@@ -87,7 +87,8 @@ public:
   ///     /b true if \a path was successfully located and \a new_path
   ///     is filled in with a new source path, \b false otherwise.
   //------------------------------------------------------------------
-  bool RemapPath(const char *path, std::string &new_path) const;
+  bool RemapPath(llvm::StringRef path, std::string &new_path) const;
+  bool RemapPath(const char *, std::string &) const = delete;
 
   bool ReverseRemapPath(const ConstString &path, ConstString &new_path) const;
 

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=282277&r1=282276&r2=282277&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Fri Sep 23 13:42:38 2016
@@ -1635,7 +1635,8 @@ bool Module::FindSourceFile(const FileSp
   return m_source_mappings.FindFile(orig_spec, new_spec);
 }
 
-bool Module::RemapSourceFile(const char *path, std::string &new_path) const {
+bool Module::RemapSourceFile(llvm::StringRef path,
+                             std::string &new_path) const {
   std::lock_guard<std::recursive_mutex> guard(m_mutex);
   return m_source_mappings.RemapPath(path, new_path);
 }

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugLine.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugLine.cpp?rev=282277&r1=282276&r2=282277&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugLine.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugLine.cpp Fri Sep 23 13:42:38 2016
@@ -462,7 +462,7 @@ bool DWARFDebugLine::ParseSupportFiles(
 
   for (uint32_t file_idx = 1;
        prologue.GetFile(file_idx, cu_comp_dir, file_spec); ++file_idx) {
-    if (module_sp->RemapSourceFile(file_spec.GetCString(), remapped_file))
+    if (module_sp->RemapSourceFile(file_spec.GetPath(), remapped_file))
       file_spec.SetFile(remapped_file, false);
     support_files.Append(file_spec);
   }

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=282277&r1=282276&r2=282277&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Fri Sep 23 13:42:38 2016
@@ -746,7 +746,7 @@ lldb::CompUnitSP SymbolFileDWARF::ParseC
               }
 
               std::string remapped_file;
-              if (module_sp->RemapSourceFile(cu_file_spec.GetCString(),
+              if (module_sp->RemapSourceFile(cu_file_spec.GetPath(),
                                              remapped_file))
                 cu_file_spec.SetFile(remapped_file, false);
             }

Modified: lldb/trunk/source/Target/PathMappingList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/PathMappingList.cpp?rev=282277&r1=282276&r2=282277&view=diff
==============================================================================
--- lldb/trunk/source/Target/PathMappingList.cpp (original)
+++ lldb/trunk/source/Target/PathMappingList.cpp Fri Sep 23 13:42:38 2016
@@ -136,7 +136,8 @@ void PathMappingList::Clear(bool notify)
 bool PathMappingList::RemapPath(const ConstString &path,
                                 ConstString &new_path) const {
   const char *path_cstr = path.GetCString();
-
+  // CLEANUP: Convert this function to use StringRefs internally instead
+  // of raw c-strings.
   if (!path_cstr)
     return false;
 
@@ -154,19 +155,19 @@ bool PathMappingList::RemapPath(const Co
   return false;
 }
 
-bool PathMappingList::RemapPath(const char *path, std::string &new_path) const {
-  if (m_pairs.empty() || path == nullptr || path[0] == '\0')
+bool PathMappingList::RemapPath(llvm::StringRef path,
+                                std::string &new_path) const {
+  if (m_pairs.empty() || path.empty())
     return false;
 
   const_iterator pos, end = m_pairs.end();
   for (pos = m_pairs.begin(); pos != end; ++pos) {
-    const size_t prefix_len = pos->first.GetLength();
+    if (!path.consume_front(pos->first.GetStringRef()))
+      continue;
 
-    if (::strncmp(pos->first.GetCString(), path, prefix_len) == 0) {
-      new_path = pos->second.GetCString();
-      new_path.append(path + prefix_len);
-      return true;
-    }
+    new_path = pos->second.GetStringRef();
+    new_path.append(path);
+    return true;
   }
   return false;
 }




More information about the lldb-commits mailing list