Skip to content

Commit 3c4b333

Browse files
committed
Add a finalize method to the sbprogress, with an associated doc string and a test
1 parent f6703a4 commit 3c4b333

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

lldb/bindings/interface/SBProgressDocstrings.i

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ and will always send an initial progress update, updates when
1212
Progress::Increment() is called, and also will make sure that a progress
1313
completed update is reported even if the user doesn't explicitly cause one
1414
to be sent.") lldb::SBProgress;
15+
16+
%feature("docstring",
17+
"Explicitly end an SBProgress, this is a utility to send the progressEnd event
18+
without waiting for your language or language implementations non-deterministic destruction
19+
of the SBProgress object.
20+
21+
Note once finalized, no further increments will be processed.") lldb::SBProgress::Finalize;

lldb/include/lldb/API/SBProgress.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class LLDB_API SBProgress {
5959

6060
void Increment(uint64_t amount, const char *description = nullptr);
6161

62+
/// Explicitly finalize an SBProgress, this can be used to terminate a
63+
/// progress on command instead of waiting for a garbage collection or other
64+
/// finalizer.
65+
void Finalize();
66+
6267
protected:
6368
lldb_private::Progress &ref() const;
6469

lldb/source/API/SBProgress.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,20 @@ SBProgress::~SBProgress() = default;
4040
void SBProgress::Increment(uint64_t amount, const char *description) {
4141
LLDB_INSTRUMENT_VA(amount, description);
4242

43-
m_opaque_up->Increment(amount, description);
43+
if (!m_opaque_up)
44+
return;
45+
46+
std::optional<std::string> description_opt;
47+
if (description && description[0])
48+
description_opt = description;
49+
m_opaque_up->Increment(amount, description_opt);
50+
}
51+
52+
void SBProgress::Finalize() {
53+
if (!m_opaque_up)
54+
return;
55+
56+
m_opaque_up.reset();
4457
}
4558

4659
lldb_private::Progress &SBProgress::ref() const { return *m_opaque_up; }

lldb/test/API/python_api/sbprogress/TestSBProgress.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,17 @@ def test_without_external_bit_set(self):
3333
expected_string = "Test progress first increment"
3434
progress.Increment(1, expected_string)
3535
self.assertFalse(listener.PeekAtNextEvent(event))
36+
37+
def test_progress_finalize(self):
38+
"""Test SBProgress finalize sends the progressEnd event"""
39+
40+
progress = lldb.SBProgress("Test SBProgress", "Test finalize", self.dbg)
41+
listener = lldb.SBListener("Test listener")
42+
broadcaster = self.dbg.GetBroadcaster()
43+
broadcaster.AddListener(listener, lldb.eBroadcastBitExternalProgressCategory)
44+
event = lldb.SBEvent()
45+
progress.Finalize()
46+
self.assertTrue(listener.WaitForEvent(5, event))
47+
stream = lldb.SBStream()
48+
event.GetDescription(stream)
49+
self.assertIn("type = end", stream.GetData())

0 commit comments

Comments
 (0)