Skip to content

Commit 10a9dca

Browse files
authored
[LLDB][SBProgress] Fix bad optional in sbprogress (#128971)
This fixes the obvious, but untested case of sending None/Null to SBProgress.
1 parent 440ea3e commit 10a9dca

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lldb/source/API/SBProgress.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ 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+
std::optional<std::string> description_opt;
44+
if (description && description[0])
45+
description_opt = description;
46+
m_opaque_up->Increment(amount, std::move(description_opt));
4447
}
4548

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

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,35 @@ 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_with_external_bit_set(self):
38+
"""Test SBProgress can handle null events."""
39+
40+
progress = lldb.SBProgress("Test SBProgress", "Test progress", 3, self.dbg)
41+
listener = lldb.SBListener("Test listener")
42+
broadcaster = self.dbg.GetBroadcaster()
43+
broadcaster.AddListener(listener, lldb.eBroadcastBitExternalProgress)
44+
event = lldb.SBEvent()
45+
# Sample JSON we're expecting:
46+
# { id = 2, title = "Test SBProgress", details = "Test progress", type = update, progress = 1 of 3}
47+
# details remains the same as specified in the constructor of the progress
48+
# until we update it in the increment function, so we check for the Null and empty string case
49+
# that details hasn't changed, but progress x of 3 has.
50+
progress.Increment(1, None)
51+
self.assertTrue(listener.GetNextEvent(event))
52+
stream = lldb.SBStream()
53+
event.GetDescription(stream)
54+
self.assertIn("Test progress", stream.GetData())
55+
self.assertIn("1 of 3", stream.GetData())
56+
57+
progress.Increment(1, "")
58+
self.assertTrue(listener.GetNextEvent(event))
59+
event.GetDescription(stream)
60+
self.assertIn("Test progress", stream.GetData())
61+
self.assertIn("2 of 3", stream.GetData())
62+
63+
progress.Increment(1, "Step 3")
64+
self.assertTrue(listener.GetNextEvent(event))
65+
stream = lldb.SBStream()
66+
event.GetDescription(stream)
67+
self.assertIn("Step 3", stream.GetData())

0 commit comments

Comments
 (0)