Skip to content

Commit 16dd318

Browse files
authored
Merge pull request #2040 from apple/revert-2033-🍒/bastille/73811d32c72d
Revert "[lldb] Move copying of files into reproducer out of process"
2 parents ef50e3e + 18827c0 commit 16dd318

File tree

16 files changed

+84
-266
lines changed

16 files changed

+84
-266
lines changed

lldb/include/lldb/API/SBReproducer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class LLDB_API SBReproducer {
4848
static const char *Replay(const char *path, bool skip_version_check);
4949
static const char *Replay(const char *path, const SBReplayOptions &options);
5050
static const char *PassiveReplay(const char *path);
51-
static const char *Finalize(const char *path);
5251
static const char *GetPath();
5352
static bool SetAutoGenerate(bool b);
5453
static bool Generate();

lldb/include/lldb/Host/FileSystem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class FileSystem {
3434
FileSystem()
3535
: m_fs(llvm::vfs::getRealFileSystem()), m_collector(nullptr),
3636
m_home_directory(), m_mapped(false) {}
37-
FileSystem(std::shared_ptr<llvm::FileCollectorBase> collector)
37+
FileSystem(std::shared_ptr<llvm::FileCollector> collector)
3838
: m_fs(llvm::vfs::getRealFileSystem()), m_collector(std::move(collector)),
3939
m_home_directory(), m_mapped(false) {}
4040
FileSystem(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
@@ -48,7 +48,7 @@ class FileSystem {
4848
static FileSystem &Instance();
4949

5050
static void Initialize();
51-
static void Initialize(std::shared_ptr<llvm::FileCollectorBase> collector);
51+
static void Initialize(std::shared_ptr<llvm::FileCollector> collector);
5252
static llvm::Error Initialize(const FileSpec &mapping);
5353
static void Initialize(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs);
5454
static void Terminate();
@@ -199,7 +199,7 @@ class FileSystem {
199199
private:
200200
static llvm::Optional<FileSystem> &InstanceImpl();
201201
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> m_fs;
202-
std::shared_ptr<llvm::FileCollectorBase> m_collector;
202+
std::shared_ptr<llvm::FileCollector> m_collector;
203203
std::string m_home_directory;
204204
bool m_mapped;
205205
};

lldb/include/lldb/Utility/Reproducer.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,6 @@ struct ReplayOptions {
243243
bool check_version = true;
244244
};
245245

246-
llvm::Error Finalize(Loader *loader);
247-
llvm::Error Finalize(const FileSpec &root);
248-
249246
} // namespace repro
250247
} // namespace lldb_private
251248

lldb/include/lldb/Utility/ReproducerProvider.h

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,50 +90,38 @@ class YamlRecorder : public AbstractRecorder {
9090
}
9191
};
9292

93-
class FlushingFileCollector : public llvm::FileCollectorBase {
94-
public:
95-
FlushingFileCollector(llvm::StringRef files_path, llvm::StringRef dirs_path,
96-
std::error_code &ec);
97-
98-
protected:
99-
void addFileImpl(llvm::StringRef file) override;
100-
101-
llvm::vfs::directory_iterator
102-
addDirectoryImpl(const llvm::Twine &dir,
103-
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs,
104-
std::error_code &dir_ec) override;
105-
106-
llvm::Optional<llvm::raw_fd_ostream> m_files_os;
107-
llvm::Optional<llvm::raw_fd_ostream> m_dirs_os;
108-
};
109-
11093
class FileProvider : public Provider<FileProvider> {
11194
public:
11295
struct Info {
11396
static const char *name;
11497
static const char *file;
11598
};
11699

117-
FileProvider(const FileSpec &directory) : Provider(directory) {
118-
std::error_code ec;
119-
m_collector = std::make_shared<FlushingFileCollector>(
120-
directory.CopyByAppendingPathComponent("files.txt").GetPath(),
121-
directory.CopyByAppendingPathComponent("dirs.txt").GetPath(), ec);
122-
if (ec)
123-
m_collector.reset();
124-
}
100+
FileProvider(const FileSpec &directory)
101+
: Provider(directory),
102+
m_collector(std::make_shared<llvm::FileCollector>(
103+
directory.CopyByAppendingPathComponent("root").GetPath(),
104+
directory.GetPath())) {}
125105

126-
std::shared_ptr<llvm::FileCollectorBase> GetFileCollector() {
106+
std::shared_ptr<llvm::FileCollector> GetFileCollector() {
127107
return m_collector;
128108
}
129109

130110
void RecordInterestingDirectory(const llvm::Twine &dir);
131111
void RecordInterestingDirectoryRecursive(const llvm::Twine &dir);
132112

113+
void Keep() override {
114+
auto mapping = GetRoot().CopyByAppendingPathComponent(Info::file);
115+
// Temporary files that are removed during execution can cause copy errors.
116+
if (auto ec = m_collector->copyFiles(/*stop_on_error=*/false))
117+
return;
118+
m_collector->writeMapping(mapping.GetPath());
119+
}
120+
133121
static char ID;
134122

135123
private:
136-
std::shared_ptr<FlushingFileCollector> m_collector;
124+
std::shared_ptr<llvm::FileCollector> m_collector;
137125
};
138126

139127
/// Provider for the LLDB version number.

lldb/source/API/SBReproducer.cpp

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "SBReproducerPrivate.h"
1010

11+
#include "SBReproducerPrivate.h"
1112
#include "lldb/API/LLDB.h"
1213
#include "lldb/API/SBAddress.h"
1314
#include "lldb/API/SBAttachInfo.h"
@@ -265,27 +266,6 @@ const char *SBReproducer::Replay(const char *path,
265266
return nullptr;
266267
}
267268

268-
const char *SBReproducer::Finalize(const char *path) {
269-
static std::string error;
270-
if (auto e = Reproducer::Initialize(ReproducerMode::Replay, FileSpec(path))) {
271-
error = llvm::toString(std::move(e));
272-
return error.c_str();
273-
}
274-
275-
repro::Loader *loader = repro::Reproducer::Instance().GetLoader();
276-
if (!loader) {
277-
error = "unable to get replay loader.";
278-
return error.c_str();
279-
}
280-
281-
if (auto e = repro::Finalize(loader)) {
282-
error = llvm::toString(std::move(e));
283-
return error.c_str();
284-
}
285-
286-
return nullptr;
287-
}
288-
289269
bool SBReproducer::Generate() {
290270
auto &r = Reproducer::Instance();
291271
if (auto generator = r.GetGenerator()) {
@@ -305,11 +285,10 @@ bool SBReproducer::SetAutoGenerate(bool b) {
305285
}
306286

307287
const char *SBReproducer::GetPath() {
308-
ConstString path;
288+
static std::string path;
309289
auto &r = Reproducer::Instance();
310-
if (FileSpec reproducer_path = Reproducer::Instance().GetReproducerPath())
311-
path = ConstString(r.GetReproducerPath().GetCString());
312-
return path.GetCString();
290+
path = r.GetReproducerPath().GetCString();
291+
return path.c_str();
313292
}
314293

315294
void SBReproducer::SetWorkingDirectory(const char *path) {

lldb/source/Commands/CommandObjectReproducer.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ class CommandObjectReproducerGenerate : public CommandObjectParsed {
192192
auto &r = Reproducer::Instance();
193193
if (auto generator = r.GetGenerator()) {
194194
generator->Keep();
195-
if (llvm::Error e = repro::Finalize(r.GetReproducerPath())) {
196-
SetError(result, std::move(e));
197-
return result.Succeeded();
198-
}
199195
} else if (r.IsReplaying()) {
200196
// Make this operation a NO-OP in replay mode.
201197
result.SetStatus(eReturnStatusSuccessFinishNoResult);

lldb/source/Host/common/FileSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void FileSystem::Initialize() {
4949
InstanceImpl().emplace();
5050
}
5151

52-
void FileSystem::Initialize(std::shared_ptr<FileCollectorBase> collector) {
52+
void FileSystem::Initialize(std::shared_ptr<FileCollector> collector) {
5353
lldbassert(!InstanceImpl() && "Already initialized.");
5454
InstanceImpl().emplace(collector);
5555
}

lldb/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ModuleDependencyCollectorAdaptor
1818
: public clang::ModuleDependencyCollector {
1919
public:
2020
ModuleDependencyCollectorAdaptor(
21-
std::shared_ptr<llvm::FileCollectorBase> file_collector)
21+
std::shared_ptr<llvm::FileCollector> file_collector)
2222
: clang::ModuleDependencyCollector(""), m_file_collector(file_collector) {
2323
}
2424

@@ -33,7 +33,7 @@ class ModuleDependencyCollectorAdaptor
3333
void writeFileMap() override {}
3434

3535
private:
36-
std::shared_ptr<llvm::FileCollectorBase> m_file_collector;
36+
std::shared_ptr<llvm::FileCollector> m_file_collector;
3737
};
3838
} // namespace lldb_private
3939

lldb/source/Utility/Reproducer.cpp

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,10 @@ Generator::Generator(FileSpec root) : m_root(MakeAbsolute(std::move(root))) {
176176

177177
Generator::~Generator() {
178178
if (!m_done) {
179-
if (m_auto_generate) {
179+
if (m_auto_generate)
180180
Keep();
181-
llvm::cantFail(Finalize(GetRoot()));
182-
} else {
181+
else
183182
Discard();
184-
}
185183
}
186184
}
187185

@@ -361,58 +359,3 @@ void Verifier::Verify(
361359
}
362360
}
363361
}
364-
365-
static llvm::Error addPaths(StringRef path,
366-
function_ref<void(StringRef)> callback) {
367-
auto buffer = llvm::MemoryBuffer::getFile(path);
368-
if (!buffer)
369-
return errorCodeToError(buffer.getError());
370-
371-
SmallVector<StringRef, 0> paths;
372-
(*buffer)->getBuffer().split(paths, '\0');
373-
for (StringRef p : paths) {
374-
if (!p.empty())
375-
callback(p);
376-
}
377-
378-
return errorCodeToError(llvm::sys::fs::remove(path));
379-
}
380-
381-
llvm::Error repro::Finalize(Loader *loader) {
382-
if (!loader)
383-
return make_error<StringError>("invalid loader",
384-
llvm::inconvertibleErrorCode());
385-
386-
FileSpec reproducer_root = loader->GetRoot();
387-
std::string files_path =
388-
reproducer_root.CopyByAppendingPathComponent("files.txt").GetPath();
389-
std::string dirs_path =
390-
reproducer_root.CopyByAppendingPathComponent("dirs.txt").GetPath();
391-
392-
FileCollector collector(
393-
reproducer_root.CopyByAppendingPathComponent("root").GetPath(),
394-
reproducer_root.GetPath());
395-
396-
if (Error e =
397-
addPaths(files_path, [&](StringRef p) { collector.addFile(p); }))
398-
return e;
399-
400-
if (Error e =
401-
addPaths(dirs_path, [&](StringRef p) { collector.addDirectory(p); }))
402-
return e;
403-
404-
FileSpec mapping =
405-
reproducer_root.CopyByAppendingPathComponent(FileProvider::Info::file);
406-
if (auto ec = collector.copyFiles(/*stop_on_error=*/false))
407-
return errorCodeToError(ec);
408-
collector.writeMapping(mapping.GetPath());
409-
410-
return llvm::Error::success();
411-
}
412-
413-
llvm::Error repro::Finalize(const FileSpec &root) {
414-
Loader loader(root);
415-
if (Error e = loader.LoadIndex())
416-
return e;
417-
return Finalize(&loader);
418-
}

lldb/source/Utility/ReproducerProvider.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "lldb/Utility/ReproducerProvider.h"
1010
#include "lldb/Utility/ProcessInfo.h"
11-
#include "llvm/ADT/ScopeExit.h"
1211
#include "llvm/Support/FileSystem.h"
1312
#include "llvm/Support/WithColor.h"
1413
#include "llvm/Support/raw_ostream.h"
@@ -45,40 +44,6 @@ void VersionProvider::Keep() {
4544
os << m_version << "\n";
4645
}
4746

48-
FlushingFileCollector::FlushingFileCollector(llvm::StringRef files_path,
49-
llvm::StringRef dirs_path,
50-
std::error_code &ec) {
51-
auto clear = llvm::make_scope_exit([this]() {
52-
m_files_os.reset();
53-
m_dirs_os.reset();
54-
});
55-
m_files_os.emplace(files_path, ec, llvm::sys::fs::OF_Append);
56-
if (ec)
57-
return;
58-
m_dirs_os.emplace(dirs_path, ec, llvm::sys::fs::OF_Append);
59-
if (ec)
60-
return;
61-
clear.release();
62-
}
63-
64-
void FlushingFileCollector::addFileImpl(StringRef file) {
65-
if (m_files_os) {
66-
*m_files_os << file << '\0';
67-
m_files_os->flush();
68-
}
69-
}
70-
71-
llvm::vfs::directory_iterator
72-
FlushingFileCollector::addDirectoryImpl(const Twine &dir,
73-
IntrusiveRefCntPtr<vfs::FileSystem> vfs,
74-
std::error_code &dir_ec) {
75-
if (m_dirs_os) {
76-
*m_dirs_os << dir << '\0';
77-
m_dirs_os->flush();
78-
}
79-
return vfs->dir_begin(dir, dir_ec);
80-
}
81-
8247
void FileProvider::RecordInterestingDirectory(const llvm::Twine &dir) {
8348
if (m_collector)
8449
m_collector->addFile(dir);

lldb/test/Shell/Reproducer/TestCaptureEnvOverride.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
# RUN: LLDB_CAPTURE_REPRODUCER=0 %lldb -b -o 'reproducer status' --capture --capture-path %t.repro | FileCheck %s --check-prefix OFF
1111
# RUN: LLDB_CAPTURE_REPRODUCER=0 %lldb -b -o 'reproducer status' --capture | FileCheck %s --check-prefix OFF
12+
# RUN: LLDB_CAPTURE_REPRODUCER=OFF %lldb -b -o 'reproducer status' --capture --capture-path %t.repro | FileCheck %s --check-prefix OFF
13+
# RUN: LLDB_CAPTURE_REPRODUCER=off %lldb -b -o 'reproducer status' --capture | FileCheck %s --check-prefix OFF
1214

1315
# RUN: LLDB_CAPTURE_REPRODUCER=bogus %lldb -b -o 'reproducer status' --capture | FileCheck %s --check-prefix CAPTURE
1416
# RUN: LLDB_CAPTURE_REPRODUCER=bogus %lldb -b -o 'reproducer status' | FileCheck %s --check-prefix OFF

lldb/test/Shell/Reproducer/TestFinalize.test

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)