[Lldb-commits] [lldb] r371689 - [Reproducer] Move the command loader into the reproducer (NFC)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed Sep 11 16:27:12 PDT 2019
Author: jdevlieghere
Date: Wed Sep 11 16:27:12 2019
New Revision: 371689
URL: http://llvm.org/viewvc/llvm-project?rev=371689&view=rev
Log:
[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.
Modified:
lldb/trunk/include/lldb/Utility/Reproducer.h
lldb/trunk/source/API/SBDebugger.cpp
lldb/trunk/source/Utility/Reproducer.cpp
Modified: lldb/trunk/include/lldb/Utility/Reproducer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/Reproducer.h?rev=371689&r1=371688&r2=371689&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/Reproducer.h (original)
+++ lldb/trunk/include/lldb/Utility/Reproducer.h Wed Sep 11 16:27:12 2019
@@ -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
Modified: lldb/trunk/source/API/SBDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=371689&r1=371688&r2=371689&view=diff
==============================================================================
--- lldb/trunk/source/API/SBDebugger.cpp (original)
+++ lldb/trunk/source/API/SBDebugger.cpp Wed Sep 11 16:27:12 2019
@@ -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
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);
}
Modified: lldb/trunk/source/Utility/Reproducer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/Reproducer.cpp?rev=371689&r1=371688&r2=371689&view=diff
==============================================================================
--- lldb/trunk/source/Utility/Reproducer.cpp (original)
+++ lldb/trunk/source/Utility/Reproducer.cpp Wed Sep 11 16:27:12 2019
@@ -281,6 +281,40 @@ llvm::raw_ostream *ProcessGDBRemoteProvi
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;
More information about the lldb-commits
mailing list