[Lldb-commits] [lldb] r279533 - Change the PathMappingList::FindFile to use FileSpec API's
Jim Ingham via lldb-commits
lldb-commits at lists.llvm.org
Tue Aug 23 10:13:34 PDT 2016
Author: jingham
Date: Tue Aug 23 12:13:33 2016
New Revision: 279533
URL: http://llvm.org/viewvc/llvm-project?rev=279533&view=rev
Log:
Change the PathMappingList::FindFile to use FileSpec API's
Also, when appending path components, collapse multiple "/" into one at the join.
Modified:
lldb/trunk/source/Host/common/FileSpec.cpp
lldb/trunk/source/Target/PathMappingList.cpp
lldb/trunk/unittests/Host/FileSpecTest.cpp
Modified: lldb/trunk/source/Host/common/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSpec.cpp?rev=279533&r1=279532&r2=279533&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/FileSpec.cpp (original)
+++ lldb/trunk/source/Host/common/FileSpec.cpp Tue Aug 23 12:13:33 2016
@@ -1552,6 +1552,9 @@ FileSpec::AppendPathComponent(const char
stream.PutChar(GetPrefferedPathSeparator(m_syntax));
}
+ while (IsPathSeparator(new_path[0], m_syntax))
+ new_path++;
+
stream.PutCString(new_path);
const bool resolve = false;
Modified: lldb/trunk/source/Target/PathMappingList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/PathMappingList.cpp?rev=279533&r1=279532&r2=279533&view=diff
==============================================================================
--- lldb/trunk/source/Target/PathMappingList.cpp (original)
+++ lldb/trunk/source/Target/PathMappingList.cpp Tue Aug 23 12:13:33 2016
@@ -224,6 +224,7 @@ PathMappingList::ReverseRemapPath (const
for (const auto& it : m_pairs)
{
+ // FIXME: This should be using FileSpec API's to do the path appending.
const size_t prefixLen = it.second.GetLength();
if (::strncmp (it.second.GetCString(), path_cstr, prefixLen) == 0)
{
@@ -242,7 +243,6 @@ PathMappingList::FindFile (const FileSpe
if (!m_pairs.empty())
{
char orig_path[PATH_MAX];
- char new_path[PATH_MAX];
const size_t orig_path_len = orig_spec.GetPath (orig_path, sizeof(orig_path));
if (orig_path_len > 0)
{
@@ -255,13 +255,10 @@ PathMappingList::FindFile (const FileSpe
{
if (::strncmp (pos->first.GetCString(), orig_path, prefix_len) == 0)
{
- const size_t new_path_len = snprintf(new_path, sizeof(new_path), "%s/%s", pos->second.GetCString(), orig_path + prefix_len);
- if (new_path_len < sizeof(new_path))
- {
- new_spec.SetFile (new_path, true);
- if (new_spec.Exists())
- return true;
- }
+ new_spec.SetFile(pos->second.GetCString(), false);
+ new_spec.AppendPathComponent(orig_path+prefix_len);
+ if (new_spec.Exists())
+ return true;
}
}
}
Modified: lldb/trunk/unittests/Host/FileSpecTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/FileSpecTest.cpp?rev=279533&r1=279532&r2=279533&view=diff
==============================================================================
--- lldb/trunk/unittests/Host/FileSpecTest.cpp (original)
+++ lldb/trunk/unittests/Host/FileSpecTest.cpp Tue Aug 23 12:13:33 2016
@@ -69,6 +69,12 @@ TEST(FileSpecTest, AppendPathComponent)
EXPECT_STREQ("/foo", fs_posix.GetDirectory().GetCString());
EXPECT_STREQ("bar", fs_posix.GetFilename().GetCString());
+ FileSpec fs_posix_2("/foo", false, FileSpec::ePathSyntaxPosix);
+ fs_posix_2.AppendPathComponent("//bar/baz");
+ EXPECT_STREQ("/foo/bar/baz", fs_posix_2.GetCString());
+ EXPECT_STREQ("/foo/bar", fs_posix_2.GetDirectory().GetCString());
+ EXPECT_STREQ("baz", fs_posix_2.GetFilename().GetCString());
+
FileSpec fs_windows("F:\\bar", false, FileSpec::ePathSyntaxWindows);
fs_windows.AppendPathComponent("baz");
EXPECT_STREQ("F:\\bar\\baz", fs_windows.GetCString());
More information about the lldb-commits
mailing list