https://github.com/royitaqi updated https://github.com/llvm/llvm-project/pull/104502
>From 1e0e766530acffc29fef0b0b2cd909a943a92599 Mon Sep 17 00:00:00 2001 From: Roy Shi <roy...@meta.com> Date: Thu, 15 Aug 2024 13:34:53 -0700 Subject: [PATCH 1/6] (lldb) (minor) Correctly fix a usage of PATH_MAX --- lldb/source/Utility/RealpathPrefixes.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lldb/source/Utility/RealpathPrefixes.cpp b/lldb/source/Utility/RealpathPrefixes.cpp index ee1c404c89967..78ba6ee655864 100644 --- a/lldb/source/Utility/RealpathPrefixes.cpp +++ b/lldb/source/Utility/RealpathPrefixes.cpp @@ -8,7 +8,6 @@ #include "lldb/Utility/RealpathPrefixes.h" -#include "lldb/Host/PosixApi.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/FileSpecList.h" #include "lldb/Utility/LLDBLog.h" @@ -54,7 +53,7 @@ RealpathPrefixes::ResolveSymlinks(const FileSpec &file_spec) { LLDB_LOGF(log, "Realpath'ing support file %s", file_spec_path.c_str()); // One prefix matched. Try to realpath. - llvm::SmallString<PATH_MAX> buff; + llvm::SmallString<1024> buff; std::error_code ec = m_fs->getRealPath(file_spec_path, buff); if (ec) return std::nullopt; >From 3813cf592c64f5ed3202fb76032c7f2d1ac91b83 Mon Sep 17 00:00:00 2001 From: Roy Shi <roy...@meta.com> Date: Thu, 15 Aug 2024 15:18:58 -0700 Subject: [PATCH 2/6] Fix unit tests for Windows --- lldb/unittests/Utility/FileSpecListTest.cpp | 64 +++++++++--------- .../Utility/RealpathPrefixesTest.cpp | 65 +++++++++++-------- 2 files changed, 69 insertions(+), 60 deletions(-) diff --git a/lldb/unittests/Utility/FileSpecListTest.cpp b/lldb/unittests/Utility/FileSpecListTest.cpp index 4c04f43426130..d18445365999c 100644 --- a/lldb/unittests/Utility/FileSpecListTest.cpp +++ b/lldb/unittests/Utility/FileSpecListTest.cpp @@ -133,20 +133,20 @@ TEST(SupportFileListTest, RelativePathMatchesWindows) { TEST(SupportFileListTest, SymlinkedAbsolutePaths) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - FileSpec("/symlink_dir/foo.h"), FileSpec("/real_dir/foo.h"))); + PosixSpec("/symlink_dir/foo.h"), PosixSpec("/real_dir/foo.h"))); // Prepare RealpathPrefixes FileSpecList file_spec_list; - file_spec_list.EmplaceBack("/symlink_dir"); + file_spec_list.Append(PosixSpec("/symlink_dir")); RealpathPrefixes prefixes(file_spec_list, fs); // Prepare support file list SupportFileList support_file_list; - support_file_list.EmplaceBack(FileSpec("/symlink_dir/foo.h")); + support_file_list.Append(PosixSpec("/symlink_dir/foo.h")); // Test size_t ret = support_file_list.FindCompatibleIndex( - 0, FileSpec("/real_dir/foo.h"), &prefixes); + 0, PosixSpec("/real_dir/foo.h"), &prefixes); EXPECT_EQ(ret, (size_t)0); } @@ -157,20 +157,20 @@ TEST(SupportFileListTest, SymlinkedAbsolutePaths) { TEST(SupportFileListTest, RootDirectory) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - FileSpec("/symlink_dir/foo.h"), FileSpec("/real_dir/foo.h"))); + PosixSpec("/symlink_dir/foo.h"), PosixSpec("/real_dir/foo.h"))); // Prepare RealpathPrefixes FileSpecList file_spec_list; - file_spec_list.EmplaceBack("/"); + file_spec_list.Append(PosixSpec("/")); RealpathPrefixes prefixes(file_spec_list, fs); // Prepare support file list SupportFileList support_file_list; - support_file_list.EmplaceBack(FileSpec("/symlink_dir/foo.h")); + support_file_list.Append(PosixSpec("/symlink_dir/foo.h")); // Test size_t ret = support_file_list.FindCompatibleIndex( - 0, FileSpec("/real_dir/foo.h"), &prefixes); + 0, PosixSpec("/real_dir/foo.h"), &prefixes); EXPECT_EQ(ret, (size_t)0); } @@ -181,20 +181,20 @@ TEST(SupportFileListTest, RootDirectory) { TEST(SupportFileListTest, SymlinkedRelativePaths) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - FileSpec("symlink_dir/foo.h"), FileSpec("real_dir/foo.h"))); + PosixSpec("symlink_dir/foo.h"), PosixSpec("real_dir/foo.h"))); // Prepare RealpathPrefixes FileSpecList file_spec_list; - file_spec_list.EmplaceBack("symlink_dir"); + file_spec_list.Append(PosixSpec("symlink_dir")); RealpathPrefixes prefixes(file_spec_list, fs); // Prepare support file list SupportFileList support_file_list; - support_file_list.EmplaceBack(FileSpec("symlink_dir/foo.h")); + support_file_list.Append(PosixSpec("symlink_dir/foo.h")); // Test size_t ret = support_file_list.FindCompatibleIndex( - 0, FileSpec("real_dir/foo.h"), &prefixes); + 0, PosixSpec("real_dir/foo.h"), &prefixes); EXPECT_EQ(ret, (size_t)0); } @@ -205,20 +205,20 @@ TEST(SupportFileListTest, SymlinkedRelativePaths) { TEST(SupportFileListTest, RealpathOnlyMatchFileName) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - FileSpec("symlink_dir/foo.h"), FileSpec("real_dir/foo.h"))); + PosixSpec("symlink_dir/foo.h"), PosixSpec("real_dir/foo.h"))); // Prepare RealpathPrefixes FileSpecList file_spec_list; - file_spec_list.EmplaceBack("symlink_dir"); + file_spec_list.Append(PosixSpec("symlink_dir")); RealpathPrefixes prefixes(file_spec_list, fs); // Prepare support file list SupportFileList support_file_list; - support_file_list.EmplaceBack(FileSpec("symlink_dir/foo.h")); + support_file_list.Append(PosixSpec("symlink_dir/foo.h")); // Test size_t ret = support_file_list.FindCompatibleIndex( - 0, FileSpec("some_other_dir/foo.h"), &prefixes); + 0, PosixSpec("some_other_dir/foo.h"), &prefixes); EXPECT_EQ(ret, UINT32_MAX); } @@ -228,21 +228,21 @@ TEST(SupportFileListTest, RealpathOnlyMatchFileName) { TEST(SupportFileListTest, DirectoryMatchStringPrefixButNotWholeDirectoryName) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - FileSpec("symlink_dir/foo.h"), FileSpec("real_dir/foo.h"))); + PosixSpec("symlink_dir/foo.h"), PosixSpec("real_dir/foo.h"))); // Prepare RealpathPrefixes FileSpecList file_spec_list; - file_spec_list.EmplaceBack("symlink"); // This is a string prefix of the + file_spec_list.Append(PosixSpec("symlink")); // This is a string prefix of the // symlink but not a path prefix. RealpathPrefixes prefixes(file_spec_list, fs); // Prepare support file list SupportFileList support_file_list; - support_file_list.EmplaceBack(FileSpec("symlink_dir/foo.h")); + support_file_list.Append(PosixSpec("symlink_dir/foo.h")); // Test size_t ret = support_file_list.FindCompatibleIndex( - 0, FileSpec("real_dir/foo.h"), &prefixes); + 0, PosixSpec("real_dir/foo.h"), &prefixes); EXPECT_EQ(ret, UINT32_MAX); } @@ -253,20 +253,20 @@ TEST(SupportFileListTest, DirectoryMatchStringPrefixButNotWholeDirectoryName) { TEST(SupportFileListTest, PartialBreakpointPath) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - FileSpec("symlink_dir/foo.h"), FileSpec("/real_dir/foo.h"))); + PosixSpec("symlink_dir/foo.h"), PosixSpec("/real_dir/foo.h"))); // Prepare RealpathPrefixes FileSpecList file_spec_list; - file_spec_list.EmplaceBack("symlink_dir"); + file_spec_list.Append(PosixSpec("symlink_dir")); RealpathPrefixes prefixes(file_spec_list, fs); // Prepare support file list SupportFileList support_file_list; - support_file_list.EmplaceBack(FileSpec("symlink_dir/foo.h")); + support_file_list.Append(PosixSpec("symlink_dir/foo.h")); // Test size_t ret = support_file_list.FindCompatibleIndex( - 0, FileSpec("real_dir/foo.h"), &prefixes); + 0, PosixSpec("real_dir/foo.h"), &prefixes); EXPECT_EQ(ret, (size_t)0); } @@ -277,20 +277,20 @@ TEST(SupportFileListTest, PartialBreakpointPath) { TEST(SupportFileListTest, DifferentBasename) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - FileSpec("/symlink_dir/foo.h"), FileSpec("/real_dir/bar.h"))); + PosixSpec("/symlink_dir/foo.h"), PosixSpec("/real_dir/bar.h"))); // Prepare RealpathPrefixes FileSpecList file_spec_list; - file_spec_list.EmplaceBack("/symlink_dir"); + file_spec_list.Append(PosixSpec("/symlink_dir")); RealpathPrefixes prefixes(file_spec_list, fs); // Prepare support file list SupportFileList support_file_list; - support_file_list.EmplaceBack(FileSpec("/symlink_dir/foo.h")); + support_file_list.Append(PosixSpec("/symlink_dir/foo.h")); // Test size_t ret = support_file_list.FindCompatibleIndex( - 0, FileSpec("real_dir/bar.h"), &prefixes); + 0, PosixSpec("real_dir/bar.h"), &prefixes); EXPECT_EQ(ret, UINT32_MAX); } @@ -300,11 +300,11 @@ TEST(SupportFileListTest, DifferentBasename) { TEST(SupportFileListTest, NoPrefixes) { // Prepare support file list SupportFileList support_file_list; - support_file_list.EmplaceBack(FileSpec("/real_dir/bar.h")); + support_file_list.Append(PosixSpec("/real_dir/bar.h")); // Test size_t ret = support_file_list.FindCompatibleIndex( - 0, FileSpec("/real_dir/foo.h"), nullptr); + 0, PosixSpec("/real_dir/foo.h"), nullptr); EXPECT_EQ(ret, UINT32_MAX); } @@ -314,10 +314,10 @@ TEST(SupportFileListTest, NoPrefixes) { TEST(SupportFileListTest, SameFile) { // Prepare support file list SupportFileList support_file_list; - support_file_list.EmplaceBack(FileSpec("/real_dir/foo.h")); + support_file_list.Append(PosixSpec("/real_dir/foo.h")); // Test size_t ret = support_file_list.FindCompatibleIndex( - 0, FileSpec("/real_dir/foo.h"), nullptr); + 0, PosixSpec("/real_dir/foo.h"), nullptr); EXPECT_EQ(ret, (size_t)0); } diff --git a/lldb/unittests/Utility/RealpathPrefixesTest.cpp b/lldb/unittests/Utility/RealpathPrefixesTest.cpp index 872ddf1fd223a..52387067596d7 100644 --- a/lldb/unittests/Utility/RealpathPrefixesTest.cpp +++ b/lldb/unittests/Utility/RealpathPrefixesTest.cpp @@ -15,57 +15,66 @@ using namespace lldb_private; +static FileSpec PosixSpec(llvm::StringRef path) { + return FileSpec(path, FileSpec::Style::posix); +} + +static FileSpec WindowsSpec(llvm::StringRef path) { + return FileSpec(path, FileSpec::Style::windows); +} + + // Should resolve a symlink which match an absolute prefix TEST(RealpathPrefixesTest, MatchingAbsolutePrefix) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - FileSpec("/dir1/link.h"), FileSpec("/dir2/real.h"))); + PosixSpec("/dir1/link.h"), PosixSpec("/dir2/real.h"))); // Prepare RealpathPrefixes FileSpecList file_spec_list; - file_spec_list.EmplaceBack("/dir1"); + file_spec_list.Append(PosixSpec("/dir1")); RealpathPrefixes prefixes(file_spec_list, fs); // Test std::optional<FileSpec> ret = - prefixes.ResolveSymlinks(FileSpec("/dir1/link.h")); - EXPECT_EQ(ret, FileSpec("/dir2/real.h")); + prefixes.ResolveSymlinks(PosixSpec("/dir1/link.h")); + EXPECT_EQ(ret, PosixSpec("/dir2/real.h")); } // Should resolve a symlink which match a relative prefix TEST(RealpathPrefixesTest, MatchingRelativePrefix) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - FileSpec("dir1/link.h"), FileSpec("dir2/real.h"))); + PosixSpec("dir1/link.h"), PosixSpec("dir2/real.h"))); // Prepare RealpathPrefixes FileSpecList file_spec_list; - file_spec_list.EmplaceBack("dir1"); + file_spec_list.Append(PosixSpec("dir1")); RealpathPrefixes prefixes(file_spec_list, fs); // Test std::optional<FileSpec> ret = - prefixes.ResolveSymlinks(FileSpec("dir1/link.h")); - EXPECT_EQ(ret, FileSpec("dir2/real.h")); + prefixes.ResolveSymlinks(PosixSpec("dir1/link.h")); + EXPECT_EQ(ret, PosixSpec("dir2/real.h")); } // Should resolve in Windows and/or with a case-insensitive support file TEST(RealpathPrefixesTest, WindowsAndCaseInsensitive) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - FileSpec("f:\\dir1\\link.h", FileSpec::Style::windows), - FileSpec("f:\\dir2\\real.h", FileSpec::Style::windows), + WindowsSpec("f:\\dir1\\link.h"), + WindowsSpec("f:\\dir2\\real.h"), FileSpec::Style::windows)); // Prepare RealpathPrefixes FileSpecList file_spec_list; - file_spec_list.EmplaceBack(FileSpec("f:\\dir1", FileSpec::Style::windows)); + file_spec_list.Append(WindowsSpec("f:\\dir1")); RealpathPrefixes prefixes(file_spec_list, fs); // Test std::optional<FileSpec> ret = prefixes.ResolveSymlinks( - FileSpec("F:\\DIR1\\LINK.H", FileSpec::Style::windows)); - EXPECT_EQ(ret, FileSpec("f:\\dir2\\real.h", FileSpec::Style::windows)); + WindowsSpec("F:\\DIR1\\LINK.H")); + EXPECT_EQ(ret, WindowsSpec("f:\\dir2\\real.h")); } // Should resolve a symlink when there is mixture of matching and mismatching @@ -73,52 +82,52 @@ TEST(RealpathPrefixesTest, WindowsAndCaseInsensitive) { TEST(RealpathPrefixesTest, MatchingAndMismatchingPrefix) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - FileSpec("/dir1/link.h"), FileSpec("/dir2/real.h"))); + PosixSpec("/dir1/link.h"), PosixSpec("/dir2/real.h"))); // Prepare RealpathPrefixes FileSpecList file_spec_list; - file_spec_list.EmplaceBack("/fake/path1"); - file_spec_list.EmplaceBack("/dir1"); // Matching prefix - file_spec_list.EmplaceBack("/fake/path2"); + file_spec_list.Append(PosixSpec("/fake/path1")); + file_spec_list.Append(PosixSpec("/dir1")); // Matching prefix + file_spec_list.Append(PosixSpec("/fake/path2")); RealpathPrefixes prefixes(file_spec_list, fs); // Test std::optional<FileSpec> ret = - prefixes.ResolveSymlinks(FileSpec("/dir1/link.h")); - EXPECT_EQ(ret, FileSpec("/dir2/real.h")); + prefixes.ResolveSymlinks(PosixSpec("/dir1/link.h")); + EXPECT_EQ(ret, PosixSpec("/dir2/real.h")); } // Should resolve a symlink when the prefixes matches after normalization TEST(RealpathPrefixesTest, ComplexPrefixes) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - FileSpec("dir1/link.h"), FileSpec("dir2/real.h"))); + PosixSpec("dir1/link.h"), PosixSpec("dir2/real.h"))); // Prepare RealpathPrefixes FileSpecList file_spec_list; - file_spec_list.EmplaceBack("./dir1/foo/../bar/.."); // Equivalent to "/dir1" + file_spec_list.Append(PosixSpec("./dir1/foo/../bar/..")); // Equivalent to "/dir1" RealpathPrefixes prefixes(file_spec_list, fs); // Test std::optional<FileSpec> ret = - prefixes.ResolveSymlinks(FileSpec("dir1/link.h")); - EXPECT_EQ(ret, FileSpec("dir2/real.h")); + prefixes.ResolveSymlinks(PosixSpec("dir1/link.h")); + EXPECT_EQ(ret, PosixSpec("dir2/real.h")); } // Should not resolve a symlink which doesn't match any prefixes TEST(RealpathPrefixesTest, MismatchingPrefixes) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - FileSpec("/dir1/link.h"), FileSpec("/dir2/real.h"))); + PosixSpec("/dir1/link.h"), PosixSpec("/dir2/real.h"))); // Prepare RealpathPrefixes FileSpecList file_spec_list; - file_spec_list.EmplaceBack("/dir3"); + file_spec_list.Append(PosixSpec("/dir3")); RealpathPrefixes prefixes(file_spec_list, fs); // Test std::optional<FileSpec> ret = - prefixes.ResolveSymlinks(FileSpec("/dir1/link.h")); + prefixes.ResolveSymlinks(PosixSpec("/dir1/link.h")); EXPECT_EQ(ret, std::nullopt); } @@ -130,11 +139,11 @@ TEST(RealpathPrefixesTest, Realpath) { // Prepare RealpathPrefixes FileSpecList file_spec_list; - file_spec_list.EmplaceBack("/symlink_dir"); + file_spec_list.Append(PosixSpec("/symlink_dir")); RealpathPrefixes prefixes(file_spec_list, fs); // Test std::optional<FileSpec> ret = - prefixes.ResolveSymlinks(FileSpec("/dir/real.h")); + prefixes.ResolveSymlinks(PosixSpec("/dir/real.h")); EXPECT_EQ(ret, std::nullopt); } >From a8c968c4f4b37b6aaee3cfab800a15eaa80b8452 Mon Sep 17 00:00:00 2001 From: Roy Shi <roy...@meta.com> Date: Thu, 15 Aug 2024 15:29:07 -0700 Subject: [PATCH 3/6] Typedef PathSmallString in lldb_private --- lldb/include/lldb/lldb-private-types.h | 3 +++ lldb/source/Utility/RealpathPrefixes.cpp | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lldb/include/lldb/lldb-private-types.h b/lldb/include/lldb/lldb-private-types.h index 055eea9f6456d..755183f91e8ec 100644 --- a/lldb/include/lldb/lldb-private-types.h +++ b/lldb/include/lldb/lldb-private-types.h @@ -12,6 +12,7 @@ #include "lldb/lldb-private.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallString.h" #include <type_traits> @@ -26,6 +27,8 @@ class Platform; class ExecutionContext; class RegisterFlags; +typedef llvm::SmallString<128> PathSmallString; + typedef llvm::sys::DynamicLibrary (*LoadPluginCallbackType)( const lldb::DebuggerSP &debugger_sp, const FileSpec &spec, Status &error); diff --git a/lldb/source/Utility/RealpathPrefixes.cpp b/lldb/source/Utility/RealpathPrefixes.cpp index 78ba6ee655864..3ebe5aed44ba3 100644 --- a/lldb/source/Utility/RealpathPrefixes.cpp +++ b/lldb/source/Utility/RealpathPrefixes.cpp @@ -8,6 +8,7 @@ #include "lldb/Utility/RealpathPrefixes.h" +#include "lldb/lldb-private-types.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/FileSpecList.h" #include "lldb/Utility/LLDBLog.h" @@ -53,7 +54,7 @@ RealpathPrefixes::ResolveSymlinks(const FileSpec &file_spec) { LLDB_LOGF(log, "Realpath'ing support file %s", file_spec_path.c_str()); // One prefix matched. Try to realpath. - llvm::SmallString<1024> buff; + PathSmallString buff; std::error_code ec = m_fs->getRealPath(file_spec_path, buff); if (ec) return std::nullopt; >From 15b855a292f74144b7c06e875d85c73113ac3ae9 Mon Sep 17 00:00:00 2001 From: Roy Shi <roy...@meta.com> Date: Thu, 15 Aug 2024 15:30:16 -0700 Subject: [PATCH 4/6] Fix format --- lldb/source/Utility/RealpathPrefixes.cpp | 2 +- lldb/unittests/Utility/FileSpecListTest.cpp | 2 +- lldb/unittests/Utility/RealpathPrefixesTest.cpp | 11 +++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lldb/source/Utility/RealpathPrefixes.cpp b/lldb/source/Utility/RealpathPrefixes.cpp index 3ebe5aed44ba3..f6e1d17e30c69 100644 --- a/lldb/source/Utility/RealpathPrefixes.cpp +++ b/lldb/source/Utility/RealpathPrefixes.cpp @@ -8,11 +8,11 @@ #include "lldb/Utility/RealpathPrefixes.h" -#include "lldb/lldb-private-types.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/FileSpecList.h" #include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Log.h" +#include "lldb/lldb-private-types.h" using namespace lldb_private; diff --git a/lldb/unittests/Utility/FileSpecListTest.cpp b/lldb/unittests/Utility/FileSpecListTest.cpp index d18445365999c..b13d8fc2aa5dc 100644 --- a/lldb/unittests/Utility/FileSpecListTest.cpp +++ b/lldb/unittests/Utility/FileSpecListTest.cpp @@ -233,7 +233,7 @@ TEST(SupportFileListTest, DirectoryMatchStringPrefixButNotWholeDirectoryName) { // Prepare RealpathPrefixes FileSpecList file_spec_list; file_spec_list.Append(PosixSpec("symlink")); // This is a string prefix of the - // symlink but not a path prefix. + // symlink but not a path prefix. RealpathPrefixes prefixes(file_spec_list, fs); // Prepare support file list diff --git a/lldb/unittests/Utility/RealpathPrefixesTest.cpp b/lldb/unittests/Utility/RealpathPrefixesTest.cpp index 52387067596d7..731ee7811d988 100644 --- a/lldb/unittests/Utility/RealpathPrefixesTest.cpp +++ b/lldb/unittests/Utility/RealpathPrefixesTest.cpp @@ -23,7 +23,6 @@ static FileSpec WindowsSpec(llvm::StringRef path) { return FileSpec(path, FileSpec::Style::windows); } - // Should resolve a symlink which match an absolute prefix TEST(RealpathPrefixesTest, MatchingAbsolutePrefix) { // Prepare FS @@ -62,8 +61,7 @@ TEST(RealpathPrefixesTest, MatchingRelativePrefix) { TEST(RealpathPrefixesTest, WindowsAndCaseInsensitive) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - WindowsSpec("f:\\dir1\\link.h"), - WindowsSpec("f:\\dir2\\real.h"), + WindowsSpec("f:\\dir1\\link.h"), WindowsSpec("f:\\dir2\\real.h"), FileSpec::Style::windows)); // Prepare RealpathPrefixes @@ -72,8 +70,8 @@ TEST(RealpathPrefixesTest, WindowsAndCaseInsensitive) { RealpathPrefixes prefixes(file_spec_list, fs); // Test - std::optional<FileSpec> ret = prefixes.ResolveSymlinks( - WindowsSpec("F:\\DIR1\\LINK.H")); + std::optional<FileSpec> ret = + prefixes.ResolveSymlinks(WindowsSpec("F:\\DIR1\\LINK.H")); EXPECT_EQ(ret, WindowsSpec("f:\\dir2\\real.h")); } @@ -105,7 +103,8 @@ TEST(RealpathPrefixesTest, ComplexPrefixes) { // Prepare RealpathPrefixes FileSpecList file_spec_list; - file_spec_list.Append(PosixSpec("./dir1/foo/../bar/..")); // Equivalent to "/dir1" + file_spec_list.Append( + PosixSpec("./dir1/foo/../bar/..")); // Equivalent to "/dir1" RealpathPrefixes prefixes(file_spec_list, fs); // Test >From 85a2061305a61f46dc871b1078dc43ce91f7bdfd Mon Sep 17 00:00:00 2001 From: Roy Shi <roy...@meta.com> Date: Thu, 15 Aug 2024 15:38:19 -0700 Subject: [PATCH 5/6] Change initial size to 256 --- lldb/include/lldb/lldb-private-types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/include/lldb/lldb-private-types.h b/lldb/include/lldb/lldb-private-types.h index 755183f91e8ec..b82a2b8aa0574 100644 --- a/lldb/include/lldb/lldb-private-types.h +++ b/lldb/include/lldb/lldb-private-types.h @@ -27,7 +27,7 @@ class Platform; class ExecutionContext; class RegisterFlags; -typedef llvm::SmallString<128> PathSmallString; +typedef llvm::SmallString<256> PathSmallString; typedef llvm::sys::DynamicLibrary (*LoadPluginCallbackType)( const lldb::DebuggerSP &debugger_sp, const FileSpec &spec, Status &error); >From c8036db3776d9de015cea9ba532497acde7a1fbb Mon Sep 17 00:00:00 2001 From: Roy Shi <roy...@meta.com> Date: Thu, 15 Aug 2024 15:54:38 -0700 Subject: [PATCH 6/6] Specify explicit posix-vs.-windows style when creating MockSymlinkFileSystem in unit tests --- lldb/unittests/Utility/FileSpecListTest.cpp | 21 ++++++++++++------- .../Utility/RealpathPrefixesTest.cpp | 15 ++++++++----- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lldb/unittests/Utility/FileSpecListTest.cpp b/lldb/unittests/Utility/FileSpecListTest.cpp index b13d8fc2aa5dc..d3f89ad0dfcb3 100644 --- a/lldb/unittests/Utility/FileSpecListTest.cpp +++ b/lldb/unittests/Utility/FileSpecListTest.cpp @@ -133,7 +133,8 @@ TEST(SupportFileListTest, RelativePathMatchesWindows) { TEST(SupportFileListTest, SymlinkedAbsolutePaths) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - PosixSpec("/symlink_dir/foo.h"), PosixSpec("/real_dir/foo.h"))); + PosixSpec("/symlink_dir/foo.h"), PosixSpec("/real_dir/foo.h"), + FileSpec::Style::posix)); // Prepare RealpathPrefixes FileSpecList file_spec_list; @@ -157,7 +158,8 @@ TEST(SupportFileListTest, SymlinkedAbsolutePaths) { TEST(SupportFileListTest, RootDirectory) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - PosixSpec("/symlink_dir/foo.h"), PosixSpec("/real_dir/foo.h"))); + PosixSpec("/symlink_dir/foo.h"), PosixSpec("/real_dir/foo.h"), + FileSpec::Style::posix)); // Prepare RealpathPrefixes FileSpecList file_spec_list; @@ -181,7 +183,8 @@ TEST(SupportFileListTest, RootDirectory) { TEST(SupportFileListTest, SymlinkedRelativePaths) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - PosixSpec("symlink_dir/foo.h"), PosixSpec("real_dir/foo.h"))); + PosixSpec("symlink_dir/foo.h"), PosixSpec("real_dir/foo.h"), + FileSpec::Style::posix)); // Prepare RealpathPrefixes FileSpecList file_spec_list; @@ -205,7 +208,8 @@ TEST(SupportFileListTest, SymlinkedRelativePaths) { TEST(SupportFileListTest, RealpathOnlyMatchFileName) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - PosixSpec("symlink_dir/foo.h"), PosixSpec("real_dir/foo.h"))); + PosixSpec("symlink_dir/foo.h"), PosixSpec("real_dir/foo.h"), + FileSpec::Style::posix)); // Prepare RealpathPrefixes FileSpecList file_spec_list; @@ -228,7 +232,8 @@ TEST(SupportFileListTest, RealpathOnlyMatchFileName) { TEST(SupportFileListTest, DirectoryMatchStringPrefixButNotWholeDirectoryName) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - PosixSpec("symlink_dir/foo.h"), PosixSpec("real_dir/foo.h"))); + PosixSpec("symlink_dir/foo.h"), PosixSpec("real_dir/foo.h"), + FileSpec::Style::posix)); // Prepare RealpathPrefixes FileSpecList file_spec_list; @@ -253,7 +258,8 @@ TEST(SupportFileListTest, DirectoryMatchStringPrefixButNotWholeDirectoryName) { TEST(SupportFileListTest, PartialBreakpointPath) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - PosixSpec("symlink_dir/foo.h"), PosixSpec("/real_dir/foo.h"))); + PosixSpec("symlink_dir/foo.h"), PosixSpec("/real_dir/foo.h"), + FileSpec::Style::posix)); // Prepare RealpathPrefixes FileSpecList file_spec_list; @@ -277,7 +283,8 @@ TEST(SupportFileListTest, PartialBreakpointPath) { TEST(SupportFileListTest, DifferentBasename) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - PosixSpec("/symlink_dir/foo.h"), PosixSpec("/real_dir/bar.h"))); + PosixSpec("/symlink_dir/foo.h"), PosixSpec("/real_dir/bar.h"), + FileSpec::Style::posix)); // Prepare RealpathPrefixes FileSpecList file_spec_list; diff --git a/lldb/unittests/Utility/RealpathPrefixesTest.cpp b/lldb/unittests/Utility/RealpathPrefixesTest.cpp index 731ee7811d988..a4dc7d6dd9822 100644 --- a/lldb/unittests/Utility/RealpathPrefixesTest.cpp +++ b/lldb/unittests/Utility/RealpathPrefixesTest.cpp @@ -27,7 +27,8 @@ static FileSpec WindowsSpec(llvm::StringRef path) { TEST(RealpathPrefixesTest, MatchingAbsolutePrefix) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - PosixSpec("/dir1/link.h"), PosixSpec("/dir2/real.h"))); + PosixSpec("/dir1/link.h"), PosixSpec("/dir2/real.h"), + FileSpec::Style::posix)); // Prepare RealpathPrefixes FileSpecList file_spec_list; @@ -44,7 +45,8 @@ TEST(RealpathPrefixesTest, MatchingAbsolutePrefix) { TEST(RealpathPrefixesTest, MatchingRelativePrefix) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - PosixSpec("dir1/link.h"), PosixSpec("dir2/real.h"))); + PosixSpec("dir1/link.h"), PosixSpec("dir2/real.h"), + FileSpec::Style::posix)); // Prepare RealpathPrefixes FileSpecList file_spec_list; @@ -80,7 +82,8 @@ TEST(RealpathPrefixesTest, WindowsAndCaseInsensitive) { TEST(RealpathPrefixesTest, MatchingAndMismatchingPrefix) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - PosixSpec("/dir1/link.h"), PosixSpec("/dir2/real.h"))); + PosixSpec("/dir1/link.h"), PosixSpec("/dir2/real.h"), + FileSpec::Style::posix)); // Prepare RealpathPrefixes FileSpecList file_spec_list; @@ -99,7 +102,8 @@ TEST(RealpathPrefixesTest, MatchingAndMismatchingPrefix) { TEST(RealpathPrefixesTest, ComplexPrefixes) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - PosixSpec("dir1/link.h"), PosixSpec("dir2/real.h"))); + PosixSpec("dir1/link.h"), PosixSpec("dir2/real.h"), + FileSpec::Style::posix)); // Prepare RealpathPrefixes FileSpecList file_spec_list; @@ -117,7 +121,8 @@ TEST(RealpathPrefixesTest, ComplexPrefixes) { TEST(RealpathPrefixesTest, MismatchingPrefixes) { // Prepare FS llvm::IntrusiveRefCntPtr<MockSymlinkFileSystem> fs(new MockSymlinkFileSystem( - PosixSpec("/dir1/link.h"), PosixSpec("/dir2/real.h"))); + PosixSpec("/dir1/link.h"), PosixSpec("/dir2/real.h"), + FileSpec::Style::posix)); // Prepare RealpathPrefixes FileSpecList file_spec_list; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits