[Lldb-commits] [lldb] (lldb) (minor) Correctly fix a usage of `PATH_MAX` (PR #104502)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 15 15:19:16 PDT 2024
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 <royshi at meta.com>
Date: Thu, 15 Aug 2024 13:34:53 -0700
Subject: [PATCH 1/2] (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 <royshi at meta.com>
Date: Thu, 15 Aug 2024 15:18:58 -0700
Subject: [PATCH 2/2] 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);
}
More information about the lldb-commits
mailing list