[Lldb-commits] [lldb] [LLDB][SBProgress] Add a finalize method (PR #128966)
Jacob Lalonde via lldb-commits
lldb-commits at lists.llvm.org
Wed Feb 26 15:55:06 PST 2025
https://github.com/Jlalond updated https://github.com/llvm/llvm-project/pull/128966
>From 3c4b333869c17005deb8d4e9307babc94d0dc9b5 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Wed, 26 Feb 2025 15:38:24 -0800
Subject: [PATCH 1/2] Add a finalize method to the sbprogress, with an
associated doc string and a test
---
lldb/bindings/interface/SBProgressDocstrings.i | 7 +++++++
lldb/include/lldb/API/SBProgress.h | 5 +++++
lldb/source/API/SBProgress.cpp | 15 ++++++++++++++-
.../API/python_api/sbprogress/TestSBProgress.py | 14 ++++++++++++++
4 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/lldb/bindings/interface/SBProgressDocstrings.i b/lldb/bindings/interface/SBProgressDocstrings.i
index 2997fe619fcc7..50648b62411f8 100644
--- a/lldb/bindings/interface/SBProgressDocstrings.i
+++ b/lldb/bindings/interface/SBProgressDocstrings.i
@@ -12,3 +12,10 @@ and will always send an initial progress update, updates when
Progress::Increment() is called, and also will make sure that a progress
completed update is reported even if the user doesn't explicitly cause one
to be sent.") lldb::SBProgress;
+
+%feature("docstring",
+"Explicitly end an SBProgress, this is a utility to send the progressEnd event
+without waiting for your language or language implementations non-deterministic destruction
+of the SBProgress object.
+
+Note once finalized, no further increments will be processed.") lldb::SBProgress::Finalize;
diff --git a/lldb/include/lldb/API/SBProgress.h b/lldb/include/lldb/API/SBProgress.h
index d574d1d2982b9..1558cdc08e080 100644
--- a/lldb/include/lldb/API/SBProgress.h
+++ b/lldb/include/lldb/API/SBProgress.h
@@ -59,6 +59,11 @@ class LLDB_API SBProgress {
void Increment(uint64_t amount, const char *description = nullptr);
+ /// Explicitly finalize an SBProgress, this can be used to terminate a
+ /// progress on command instead of waiting for a garbage collection or other
+ /// finalizer.
+ void Finalize();
+
protected:
lldb_private::Progress &ref() const;
diff --git a/lldb/source/API/SBProgress.cpp b/lldb/source/API/SBProgress.cpp
index e67e289a60eff..4991d55ad0248 100644
--- a/lldb/source/API/SBProgress.cpp
+++ b/lldb/source/API/SBProgress.cpp
@@ -40,7 +40,20 @@ SBProgress::~SBProgress() = default;
void SBProgress::Increment(uint64_t amount, const char *description) {
LLDB_INSTRUMENT_VA(amount, description);
- m_opaque_up->Increment(amount, description);
+ if (!m_opaque_up)
+ return;
+
+ std::optional<std::string> description_opt;
+ if (description && description[0])
+ description_opt = description;
+ m_opaque_up->Increment(amount, description_opt);
+}
+
+void SBProgress::Finalize() {
+ if (!m_opaque_up)
+ return;
+
+ m_opaque_up.reset();
}
lldb_private::Progress &SBProgress::ref() const { return *m_opaque_up; }
diff --git a/lldb/test/API/python_api/sbprogress/TestSBProgress.py b/lldb/test/API/python_api/sbprogress/TestSBProgress.py
index c456247da80c6..dd7e4b6f2ac5c 100644
--- a/lldb/test/API/python_api/sbprogress/TestSBProgress.py
+++ b/lldb/test/API/python_api/sbprogress/TestSBProgress.py
@@ -33,3 +33,17 @@ def test_without_external_bit_set(self):
expected_string = "Test progress first increment"
progress.Increment(1, expected_string)
self.assertFalse(listener.PeekAtNextEvent(event))
+
+ def test_progress_finalize(self):
+ """Test SBProgress finalize sends the progressEnd event"""
+
+ progress = lldb.SBProgress("Test SBProgress", "Test finalize", self.dbg)
+ listener = lldb.SBListener("Test listener")
+ broadcaster = self.dbg.GetBroadcaster()
+ broadcaster.AddListener(listener, lldb.eBroadcastBitExternalProgressCategory)
+ event = lldb.SBEvent()
+ progress.Finalize()
+ self.assertTrue(listener.WaitForEvent(5, event))
+ stream = lldb.SBStream()
+ event.GetDescription(stream)
+ self.assertIn("type = end", stream.GetData())
>From c461be577af8d13b889bab5a54b429610d9c969c Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Wed, 26 Feb 2025 15:54:52 -0800
Subject: [PATCH 2/2] Drop the bug fix now that I opened 128971
---
lldb/source/API/SBProgress.cpp | 3 ---
1 file changed, 3 deletions(-)
diff --git a/lldb/source/API/SBProgress.cpp b/lldb/source/API/SBProgress.cpp
index 4991d55ad0248..656c86ac953dc 100644
--- a/lldb/source/API/SBProgress.cpp
+++ b/lldb/source/API/SBProgress.cpp
@@ -43,9 +43,6 @@ void SBProgress::Increment(uint64_t amount, const char *description) {
if (!m_opaque_up)
return;
- std::optional<std::string> description_opt;
- if (description && description[0])
- description_opt = description;
m_opaque_up->Increment(amount, description_opt);
}
More information about the lldb-commits
mailing list