[Reproducer] Discard reproducer directory if not generated.
authorJonas Devlieghere <jonas@devlieghere.com>
Wed, 13 Nov 2019 04:16:33 +0000 (20:16 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Wed, 13 Nov 2019 04:16:33 +0000 (20:16 -0800)
If lldb was run in capture mode, but no reproducer was generated, make
sure we clean up the reproducer directory.

lldb/include/lldb/Utility/Reproducer.h
lldb/source/Utility/Reproducer.cpp
lldb/test/Shell/Reproducer/Inputs/Discard.in [new file with mode: 0644]
lldb/test/Shell/Reproducer/TestDiscard.test [new file with mode: 0644]

index 3db98a7..ddb1f45 100644 (file)
@@ -288,7 +288,7 @@ private:
   FileSpec m_root;
 
   /// Flag to ensure that we never call both keep and discard.
-  bool m_done;
+  bool m_done = false;
 };
 
 class Loader final {
index 4777d75..e0806f5 100644 (file)
@@ -143,12 +143,14 @@ static FileSpec MakeAbsolute(FileSpec file_spec) {
   return FileSpec(path, file_spec.GetPathStyle());
 }
 
-Generator::Generator(FileSpec root)
-    : m_root(MakeAbsolute(std::move(root))), m_done(false) {
+Generator::Generator(FileSpec root) : m_root(MakeAbsolute(std::move(root))) {
   GetOrCreate<repro::WorkingDirectoryProvider>();
 }
 
-Generator::~Generator() {}
+Generator::~Generator() {
+  if (!m_done)
+    Discard();
+}
 
 ProviderBase *Generator::Register(std::unique_ptr<ProviderBase> provider) {
   std::lock_guard<std::mutex> lock(m_providers_mutex);
diff --git a/lldb/test/Shell/Reproducer/Inputs/Discard.in b/lldb/test/Shell/Reproducer/Inputs/Discard.in
new file mode 100644 (file)
index 0000000..a2c4e48
--- /dev/null
@@ -0,0 +1,5 @@
+breakpoint set -f simple.c -l 12
+run
+bt
+cont
+reproducer status
diff --git a/lldb/test/Shell/Reproducer/TestDiscard.test b/lldb/test/Shell/Reproducer/TestDiscard.test
new file mode 100644 (file)
index 0000000..db9614a
--- /dev/null
@@ -0,0 +1,13 @@
+# UNSUPPORTED: system-windows
+# This ensures that the reproducer properly cleans up after itself.
+
+# Build the inferior.
+# RUN: mkdir -p %t
+# RUN: rm -rf %t.repro
+# RUN: %clang_host %S/Inputs/simple.c -g -o %t/reproducer.out
+
+# Capture but don't generate the reproducer.
+# RUN: %lldb -x -b -s %S/Inputs/Discard.in --capture --capture-path %t.repro %t/reproducer.out
+
+# Make sure the directory doesn't exist.
+# RUN: mkdir %t.repro