https://github.com/Jlalond updated https://github.com/llvm/llvm-project/pull/128971
>From ac90ec73ccfb02923ff0343189d2efaeb6108fa3 Mon Sep 17 00:00:00 2001 From: Jacob Lalonde <jalalo...@fb.com> Date: Wed, 26 Feb 2025 15:48:14 -0800 Subject: [PATCH 1/3] Fix bad optional access in sbprogress --- lldb/source/API/SBProgress.cpp | 5 ++++- .../test/API/python_api/sbprogress/TestSBProgress.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lldb/source/API/SBProgress.cpp b/lldb/source/API/SBProgress.cpp index e67e289a60eff..d40e11da973d4 100644 --- a/lldb/source/API/SBProgress.cpp +++ b/lldb/source/API/SBProgress.cpp @@ -40,7 +40,10 @@ SBProgress::~SBProgress() = default; void SBProgress::Increment(uint64_t amount, const char *description) { LLDB_INSTRUMENT_VA(amount, description); - m_opaque_up->Increment(amount, description); + std::optional<std::string> description_opt; + if (description && description[0]) + description_opt = description; + m_opaque_up->Increment(amount, description_opt); } 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..5f7820a5bd81e 100644 --- a/lldb/test/API/python_api/sbprogress/TestSBProgress.py +++ b/lldb/test/API/python_api/sbprogress/TestSBProgress.py @@ -33,3 +33,15 @@ 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_with_external_bit_set(self): + """Test SBProgress can handle null events.""" + + progress = lldb.SBProgress("Test SBProgress", "Test progress", self.dbg) + listener = lldb.SBListener("Test listener") + broadcaster = self.dbg.GetBroadcaster() + broadcaster.AddListener(listener, lldb.eBroadcastBitExternalProgress) + event = lldb.SBEvent() + + progress.Increment(1, None) + self.assertTrue(listener.PeekAtNextEvent(event)) >From 4f1aaa6a2cf81da53db634a69155ef1e8aa29c6c Mon Sep 17 00:00:00 2001 From: Jacob Lalonde <jalalo...@fb.com> Date: Wed, 26 Feb 2025 16:18:11 -0800 Subject: [PATCH 2/3] Expand test case based on Dave's feedback --- lldb/test/API/python_api/sbprogress/TestSBProgress.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lldb/test/API/python_api/sbprogress/TestSBProgress.py b/lldb/test/API/python_api/sbprogress/TestSBProgress.py index 5f7820a5bd81e..eab5e5bb18cf0 100644 --- a/lldb/test/API/python_api/sbprogress/TestSBProgress.py +++ b/lldb/test/API/python_api/sbprogress/TestSBProgress.py @@ -37,11 +37,18 @@ def test_without_external_bit_set(self): def test_with_external_bit_set(self): """Test SBProgress can handle null events.""" - progress = lldb.SBProgress("Test SBProgress", "Test progress", self.dbg) + progress = lldb.SBProgress("Test SBProgress", "Test progress", 3, self.dbg) listener = lldb.SBListener("Test listener") broadcaster = self.dbg.GetBroadcaster() broadcaster.AddListener(listener, lldb.eBroadcastBitExternalProgress) event = lldb.SBEvent() progress.Increment(1, None) - self.assertTrue(listener.PeekAtNextEvent(event)) + self.assertTrue(listener.GetNextEvent(event)) + progress.Increment(1, "") + self.assertTrue(listener.GetNextEvent(event)) + progress.Increment(1, "Step 3") + self.assertTrue(listener.GetNextEvent(event)) + stream = lldb.SBStream() + event.GetDescription(stream) + self.assertIn("Step 3", stream.GetData()) >From 6e9ce7e7e55924e93231799e03c4ea3cc45c1810 Mon Sep 17 00:00:00 2001 From: Jacob Lalonde <jalalo...@fb.com> Date: Wed, 26 Feb 2025 16:35:55 -0800 Subject: [PATCH 3/3] Further asserts based on Greg's feedback --- .../API/python_api/sbprogress/TestSBProgress.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lldb/test/API/python_api/sbprogress/TestSBProgress.py b/lldb/test/API/python_api/sbprogress/TestSBProgress.py index eab5e5bb18cf0..1b8f01d3e8bb1 100644 --- a/lldb/test/API/python_api/sbprogress/TestSBProgress.py +++ b/lldb/test/API/python_api/sbprogress/TestSBProgress.py @@ -42,11 +42,24 @@ def test_with_external_bit_set(self): broadcaster = self.dbg.GetBroadcaster() broadcaster.AddListener(listener, lldb.eBroadcastBitExternalProgress) event = lldb.SBEvent() - + # Sample JSON we're expecting: + # { id = 2, title = "Test SBProgress", details = "Test progress", type = update, progress = 1 of 3} + # details remains the same as specified in the constructor of the progress + # until we update it in the increment function, so we check for the Null and empty string case + # that details hasn't changed, but progress x of 3 has. progress.Increment(1, None) self.assertTrue(listener.GetNextEvent(event)) + stream = lldb.SBStream() + event.GetDescription(stream) + self.assertIn("Test progress", stream.GetData()) + self.assertIn("1 of 3", stream.GetData()) + progress.Increment(1, "") self.assertTrue(listener.GetNextEvent(event)) + event.GetDescription(stream) + self.assertIn("Test progress", stream.GetData()) + self.assertIn("2 of 3", stream.GetData()) + progress.Increment(1, "Step 3") self.assertTrue(listener.GetNextEvent(event)) stream = lldb.SBStream() _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits