[Reproducers] Stop recording instead of deallocating
authorJonas Devlieghere <jonas@devlieghere.com>
Tue, 12 Mar 2019 17:10:28 +0000 (17:10 +0000)
committerJonas Devlieghere <jonas@devlieghere.com>
Tue, 12 Mar 2019 17:10:28 +0000 (17:10 +0000)
The command interpreter holds a pointer to a DataRecorder. After
generating the reproducer, we deallocated all the DataRecorders, causing
the command interpreter to hold a non-null reference to an invalid
object.

This patch changes the behavior of the command provider to stop the
DataRecorders when a reproducer is generated, rather than deallocating
them.

llvm-svn: 355940

lldb/include/lldb/Utility/Reproducer.h
lldb/source/Utility/Reproducer.cpp

index cf7887a..4cad298 100644 (file)
@@ -115,7 +115,7 @@ class DataRecorder {
 public:
   DataRecorder(FileSpec filename, std::error_code &ec)
       : m_filename(std::move(filename)),
-        m_os(m_filename.GetPath(), ec, llvm::sys::fs::F_Text) {}
+        m_os(m_filename.GetPath(), ec, llvm::sys::fs::F_Text), m_record(true) {}
 
   static llvm::Expected<std::unique_ptr<DataRecorder>>
   Create(FileSpec filename);
@@ -128,9 +128,15 @@ public:
 
   const FileSpec &GetFilename() { return m_filename; }
 
+  void Stop() {
+    assert(m_record);
+    m_record = false;
+  }
+
 private:
   FileSpec m_filename;
   llvm::raw_fd_ostream m_os;
+  bool m_record;
 };
 
 struct CommandInfo {
index 3e2ffcd..20d255e 100644 (file)
@@ -247,8 +247,10 @@ DataRecorder *CommandProvider::GetNewDataRecorder() {
 
 void CommandProvider::Keep() {
   std::vector<std::string> files;
-  for (auto &recorder : m_data_recorders)
+  for (auto &recorder : m_data_recorders) {
+    recorder->Stop();
     files.push_back(recorder->GetFilename().GetPath());
+  }
 
   FileSpec file = GetRoot().CopyByAppendingPathComponent(info::file);
   std::error_code ec;