From 68ed93d2528f28e04c8b96dde59225d4cc87ff3a Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Tue, 27 Nov 2018 22:11:02 +0000 Subject: [Reproducers] Improve reproducer API and add unit tests. When I landed the initial reproducer framework I knew there were some things that needed improvement. Rather than bundling it with a patch that adds more functionality I split it off into this patch. I also think the API is stable enough to add unit testing, which is included in this patch as well. Other improvements include: - Refactor how we initialize the loader and generator. - Improve naming consistency: capture and replay seems the least ambiguous. - Index providers by name and make sure there's only one of each. - Add convenience methods for creating and accessing providers. Differential revision: https://reviews.llvm.org/D54616 llvm-svn: 347716 --- .../Plugins/Process/gdb-remote/ProcessGDBRemote.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp') diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index e1be28e2ca8..7225a39d0e3 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -157,7 +157,8 @@ static const ProcessKDPPropertiesSP &GetGlobalPluginProperties() { return g_settings_sp; } -class ProcessGDBRemoteProvider : public repro::Provider { +class ProcessGDBRemoteProvider + : public repro::Provider { public: ProcessGDBRemoteProvider(const FileSpec &directory) : Provider(directory) { m_info.name = "gdb-remote"; @@ -166,7 +167,7 @@ public: raw_ostream *GetHistoryStream() { FileSpec history_file = - GetDirectory().CopyByAppendingPathComponent("gdb-remote.yaml"); + GetRoot().CopyByAppendingPathComponent("gdb-remote.yaml"); std::error_code EC; m_stream_up = llvm::make_unique(history_file.GetPath(), EC, @@ -182,11 +183,15 @@ public: void Discard() override { m_callback(); } + static char ID; + private: std::function m_callback; std::unique_ptr m_stream_up; }; +char ProcessGDBRemoteProvider::ID = 0; + } // namespace // TODO Randomly assigning a port is unsafe. We should get an unused @@ -297,10 +302,9 @@ ProcessGDBRemote::ProcessGDBRemote(lldb::TargetSP target_sp, m_async_broadcaster.SetEventName(eBroadcastBitAsyncThreadDidExit, "async thread did exit"); - repro::Generator *generator = repro::Reproducer::Instance().GetGenerator(); - if (generator) { + if (repro::Generator *g = repro::Reproducer::Instance().GetGenerator()) { ProcessGDBRemoteProvider &provider = - generator->CreateProvider(); + g->GetOrCreate(); // Set the history stream to the stream owned by the provider. m_gdb_comm.SetHistoryStream(provider.GetHistoryStream()); // Make sure to clear the stream again when we're finished. @@ -3436,8 +3440,8 @@ Status ProcessGDBRemote::ConnectToReplayServer(repro::Loader *loader) { return Status("Provider for gdb-remote contains no files."); // Construct replay history path. - FileSpec history_file(loader->GetDirectory()); - history_file.AppendPathComponent(provider_info->files.front()); + FileSpec history_file = loader->GetRoot().CopyByAppendingPathComponent( + provider_info->files.front()); // Enable replay mode. m_replay_mode = true; -- cgit v1.2.3