Skip to content

Commit 59eb705

Browse files
committed
[lldb] Remove FileSystem::Initialize from VFS mapping
This patch removes the ability to instantiate the LLDB FileSystem class based on a VFS overlay. This also removes the "hack" where we cast the VFS to a RedirectingFileSystem to obtain the external path. You can still instantiate a FileSystem with a VFS, but with the caveat that operations that rely on the external path won't work. Differential revision: https://reviews.llvm.org/D120923
1 parent f769899 commit 59eb705

File tree

4 files changed

+11
-96
lines changed

4 files changed

+11
-96
lines changed

lldb/include/lldb/Host/FileSystem.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ class FileSystem {
3333

3434
FileSystem() : m_fs(llvm::vfs::getRealFileSystem()), m_collector(nullptr) {}
3535
FileSystem(std::shared_ptr<llvm::FileCollectorBase> collector)
36-
: m_fs(llvm::vfs::getRealFileSystem()), m_collector(std::move(collector)),
37-
m_mapped(false) {}
38-
FileSystem(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
39-
bool mapped = false)
40-
: m_fs(std::move(fs)), m_collector(nullptr), m_mapped(mapped) {}
36+
: m_fs(llvm::vfs::getRealFileSystem()),
37+
m_collector(std::move(collector)) {}
38+
FileSystem(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs)
39+
: m_fs(std::move(fs)), m_collector(nullptr) {}
4140

4241
FileSystem(const FileSystem &fs) = delete;
4342
FileSystem &operator=(const FileSystem &fs) = delete;
@@ -46,7 +45,6 @@ class FileSystem {
4645

4746
static void Initialize();
4847
static void Initialize(std::shared_ptr<llvm::FileCollectorBase> collector);
49-
static llvm::Error Initialize(const FileSpec &mapping);
5048
static void Initialize(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs);
5149
static void Terminate();
5250

@@ -189,9 +187,6 @@ class FileSystem {
189187
std::error_code GetRealPath(const llvm::Twine &path,
190188
llvm::SmallVectorImpl<char> &output) const;
191189

192-
llvm::ErrorOr<std::string> GetExternalPath(const llvm::Twine &path);
193-
llvm::ErrorOr<std::string> GetExternalPath(const FileSpec &file_spec);
194-
195190
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> GetVirtualFileSystem() {
196191
return m_fs;
197192
}
@@ -206,7 +201,6 @@ class FileSystem {
206201
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> m_fs;
207202
std::shared_ptr<llvm::FileCollectorBase> m_collector;
208203
std::string m_home_directory;
209-
bool m_mapped = false;
210204
};
211205
} // namespace lldb_private
212206

lldb/source/Host/common/FileSystem.cpp

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,6 @@ void FileSystem::Initialize(std::shared_ptr<FileCollectorBase> collector) {
5454
InstanceImpl().emplace(collector);
5555
}
5656

57-
llvm::Error FileSystem::Initialize(const FileSpec &mapping) {
58-
lldbassert(!InstanceImpl() && "Already initialized.");
59-
60-
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
61-
llvm::vfs::getRealFileSystem()->getBufferForFile(mapping.GetPath());
62-
63-
if (!buffer)
64-
return llvm::errorCodeToError(buffer.getError());
65-
66-
InstanceImpl().emplace(llvm::vfs::getVFSFromYAML(std::move(buffer.get()),
67-
nullptr, mapping.GetPath()),
68-
true);
69-
70-
return llvm::Error::success();
71-
}
72-
7357
void FileSystem::Initialize(IntrusiveRefCntPtr<vfs::FileSystem> fs) {
7458
lldbassert(!InstanceImpl() && "Already initialized.");
7559
InstanceImpl().emplace(fs);
@@ -300,21 +284,16 @@ FileSystem::CreateDataBuffer(const llvm::Twine &path, uint64_t size,
300284
Collect(path);
301285

302286
const bool is_volatile = !IsLocal(path);
303-
const ErrorOr<std::string> external_path = GetExternalPath(path);
304-
305-
if (!external_path)
306-
return nullptr;
307-
308287
std::unique_ptr<llvm::WritableMemoryBuffer> buffer;
309288
if (size == 0) {
310289
auto buffer_or_error =
311-
llvm::WritableMemoryBuffer::getFile(*external_path, is_volatile);
290+
llvm::WritableMemoryBuffer::getFile(path, is_volatile);
312291
if (!buffer_or_error)
313292
return nullptr;
314293
buffer = std::move(*buffer_or_error);
315294
} else {
316295
auto buffer_or_error = llvm::WritableMemoryBuffer::getFileSlice(
317-
*external_path, size, offset, is_volatile);
296+
path, size, offset, is_volatile);
318297
if (!buffer_or_error)
319298
return nullptr;
320299
buffer = std::move(*buffer_or_error);
@@ -457,12 +436,10 @@ Expected<FileUP> FileSystem::Open(const FileSpec &file_spec,
457436
const mode_t open_mode =
458437
(open_flags & O_CREAT) ? GetOpenMode(permissions) : 0;
459438

460-
auto path = GetExternalPath(file_spec);
461-
if (!path)
462-
return errorCodeToError(path.getError());
439+
auto path = file_spec.GetPath();
463440

464441
int descriptor = llvm::sys::RetryAfterSignal(
465-
-1, OpenWithFS, *this, path->c_str(), open_flags, open_mode);
442+
-1, OpenWithFS, *this, path.c_str(), open_flags, open_mode);
466443

467444
if (!File::DescriptorIsValid(descriptor))
468445
return llvm::errorCodeToError(
@@ -474,29 +451,6 @@ Expected<FileUP> FileSystem::Open(const FileSpec &file_spec,
474451
return std::move(file);
475452
}
476453

477-
ErrorOr<std::string> FileSystem::GetExternalPath(const llvm::Twine &path) {
478-
if (!m_mapped)
479-
return path.str();
480-
481-
// If VFS mapped we know the underlying FS is a RedirectingFileSystem.
482-
ErrorOr<vfs::RedirectingFileSystem::LookupResult> Result =
483-
static_cast<vfs::RedirectingFileSystem &>(*m_fs).lookupPath(path.str());
484-
if (!Result) {
485-
if (Result.getError() == llvm::errc::no_such_file_or_directory) {
486-
return path.str();
487-
}
488-
return Result.getError();
489-
}
490-
491-
if (Optional<StringRef> ExtRedirect = Result->getExternalRedirect())
492-
return std::string(*ExtRedirect);
493-
return make_error_code(llvm::errc::not_supported);
494-
}
495-
496-
ErrorOr<std::string> FileSystem::GetExternalPath(const FileSpec &file_spec) {
497-
return GetExternalPath(file_spec.GetPath());
498-
}
499-
500454
void FileSystem::Collect(const FileSpec &file_spec) {
501455
Collect(file_spec.GetPath());
502456
}

lldb/source/Host/macosx/objcxx/Host.mm

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,15 +1305,12 @@ static bool ShouldLaunchUsingXPC(ProcessLaunchInfo &launch_info) {
13051305

13061306
lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
13071307

1308-
// From now on we'll deal with the external (devirtualized) path.
1309-
auto exe_path = fs.GetExternalPath(exe_spec);
1310-
if (!exe_path)
1311-
return Status(exe_path.getError());
1308+
auto exe_path = exe_spec.GetPath();
13121309

13131310
if (ShouldLaunchUsingXPC(launch_info))
1314-
error = LaunchProcessXPC(exe_path->c_str(), launch_info, pid);
1311+
error = LaunchProcessXPC(exe_path.c_str(), launch_info, pid);
13151312
else
1316-
error = LaunchProcessPosixSpawn(exe_path->c_str(), launch_info, pid);
1313+
error = LaunchProcessPosixSpawn(exe_path.c_str(), launch_info, pid);
13171314

13181315
if (pid != LLDB_INVALID_PROCESS_ID) {
13191316
// If all went well, then set the process ID into the launch info

lldb/source/Initialization/SystemInitializerCommon.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,6 @@ SystemInitializerCommon::~SystemInitializerCommon() = default;
4343
/// Initialize the FileSystem based on the current reproducer mode.
4444
static llvm::Error InitializeFileSystem() {
4545
auto &r = repro::Reproducer::Instance();
46-
if (repro::Loader *loader = r.GetLoader()) {
47-
FileSpec vfs_mapping = loader->GetFile<FileProvider::Info>();
48-
if (vfs_mapping) {
49-
if (llvm::Error e = FileSystem::Initialize(vfs_mapping))
50-
return e;
51-
} else {
52-
FileSystem::Initialize();
53-
}
54-
55-
// Set the current working directory form the reproducer.
56-
llvm::Expected<std::string> working_dir =
57-
repro::GetDirectoryFrom<WorkingDirectoryProvider>(loader);
58-
if (!working_dir)
59-
return working_dir.takeError();
60-
if (std::error_code ec = FileSystem::Instance()
61-
.GetVirtualFileSystem()
62-
->setCurrentWorkingDirectory(*working_dir)) {
63-
return llvm::errorCodeToError(ec);
64-
}
65-
66-
// Set the home directory from the reproducer.
67-
llvm::Expected<std::string> home_dir =
68-
repro::GetDirectoryFrom<HomeDirectoryProvider>(loader);
69-
if (!home_dir)
70-
return home_dir.takeError();
71-
FileSystem::Instance().SetHomeDirectory(*home_dir);
72-
73-
return llvm::Error::success();
74-
}
75-
7646
if (repro::Generator *g = r.GetGenerator()) {
7747
repro::VersionProvider &vp = g->GetOrCreate<repro::VersionProvider>();
7848
vp.SetVersion(lldb_private::GetVersion());

0 commit comments

Comments
 (0)