diff --git a/lldb/include/lldb/Utility/Reproducer.h b/lldb/include/lldb/Utility/Reproducer.h index 3db98a781d4cec..ddb1f45a7219e8 100644 --- a/lldb/include/lldb/Utility/Reproducer.h +++ b/lldb/include/lldb/Utility/Reproducer.h @@ -288,7 +288,7 @@ class Generator final { FileSpec m_root; /// Flag to ensure that we never call both keep and discard. - bool m_done; + bool m_done = false; }; class Loader final { diff --git a/lldb/source/Utility/Reproducer.cpp b/lldb/source/Utility/Reproducer.cpp index 4777d7576a321e..e0806f5f5981dd 100644 --- a/lldb/source/Utility/Reproducer.cpp +++ b/lldb/source/Utility/Reproducer.cpp @@ -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(); } -Generator::~Generator() {} +Generator::~Generator() { + if (!m_done) + Discard(); +} ProviderBase *Generator::Register(std::unique_ptr provider) { std::lock_guard 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 index 00000000000000..a2c4e48d1f46c6 --- /dev/null +++ b/lldb/test/Shell/Reproducer/Inputs/Discard.in @@ -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 index 00000000000000..db9614aabb8414 --- /dev/null +++ b/lldb/test/Shell/Reproducer/TestDiscard.test @@ -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