[Reproducer] Move the command loader into the reproducer (NFC)

This just moves the CommandLoader utility into the reproducer namespace
and makes it accessible outside the API layer. This is setting things up
for a bigger change.

llvm-svn: 371689
This commit is contained in:
Jonas Devlieghere 2019-09-11 23:27:12 +00:00
parent d9aec34b97
commit 4a491ec491
3 changed files with 53 additions and 48 deletions

View File

@ -327,6 +327,19 @@ private:
mutable std::mutex m_mutex;
};
/// Helper class for replaying commands through the reproducer.
class CommandLoader {
public:
CommandLoader(std::vector<std::string> files) : m_files(files) {}
static std::unique_ptr<CommandLoader> Create(Loader *loader);
llvm::Optional<std::string> GetNextFile();
private:
std::vector<std::string> m_files;
unsigned m_index = 0;
};
} // namespace repro
} // namespace lldb_private

View File

@ -57,51 +57,6 @@
using namespace lldb;
using namespace lldb_private;
/// Helper class for replaying commands through the reproducer.
class CommandLoader {
public:
CommandLoader(std::vector<std::string> files) : m_files(files) {}
static std::unique_ptr<CommandLoader> Create() {
repro::Loader *loader = repro::Reproducer::Instance().GetLoader();
if (!loader)
return {};
FileSpec file = loader->GetFile<repro::CommandProvider::Info>();
if (!file)
return {};
auto error_or_file = llvm::MemoryBuffer::getFile(file.GetPath());
if (auto err = error_or_file.getError())
return {};
std::vector<std::string> files;
llvm::yaml::Input yin((*error_or_file)->getBuffer());
yin >> files;
if (auto err = yin.error())
return {};
for (auto &file : files) {
FileSpec absolute_path =
loader->GetRoot().CopyByAppendingPathComponent(file);
file = absolute_path.GetPath();
}
return std::make_unique<CommandLoader>(std::move(files));
}
FILE *GetNextFile() {
if (m_index >= m_files.size())
return nullptr;
return FileSystem::Instance().Fopen(m_files[m_index++].c_str(), "r");
}
private:
std::vector<std::string> m_files;
unsigned m_index = 0;
};
static llvm::sys::DynamicLibrary LoadPlugin(const lldb::DebuggerSP &debugger_sp,
const FileSpec &spec,
Status &error) {
@ -344,9 +299,12 @@ void SBDebugger::SetInputFileHandle(FILE *fh, bool transfer_ownership) {
if (repro::Generator *g = repro::Reproducer::Instance().GetGenerator())
recorder = g->GetOrCreate<repro::CommandProvider>().GetNewDataRecorder();
static std::unique_ptr<CommandLoader> loader = CommandLoader::Create();
if (loader)
fh = loader->GetNextFile();
static std::unique_ptr<repro::CommandLoader> loader =
repro::CommandLoader::Create(repro::Reproducer::Instance().GetLoader());
if (loader) {
llvm::Optional<std::string> file = loader->GetNextFile();
fh = file ? FileSystem::Instance().Fopen(file->c_str(), "r") : nullptr;
}
m_opaque_sp->SetInputFileHandle(fh, transfer_ownership, recorder);
}

View File

@ -281,6 +281,40 @@ llvm::raw_ostream *ProcessGDBRemoteProvider::GetHistoryStream() {
return m_stream_up.get();
}
std::unique_ptr<CommandLoader> CommandLoader::Create(Loader *loader) {
if (!loader)
return {};
FileSpec file = loader->GetFile<repro::CommandProvider::Info>();
if (!file)
return {};
auto error_or_file = llvm::MemoryBuffer::getFile(file.GetPath());
if (auto err = error_or_file.getError())
return {};
std::vector<std::string> files;
llvm::yaml::Input yin((*error_or_file)->getBuffer());
yin >> files;
if (auto err = yin.error())
return {};
for (auto &file : files) {
FileSpec absolute_path =
loader->GetRoot().CopyByAppendingPathComponent(file);
file = absolute_path.GetPath();
}
return std::make_unique<CommandLoader>(std::move(files));
}
llvm::Optional<std::string> CommandLoader::GetNextFile() {
if (m_index >= m_files.size())
return {};
return m_files[m_index++];
}
void ProviderBase::anchor() {}
char CommandProvider::ID = 0;
char FileProvider::ID = 0;