[Lldb-commits] [lldb] [lldb][SBAPI] Fix crash when calling SBProgress constructor. (PR #224176)
Ebuka Ezike via lldb-commits
lldb-commits at lists.llvm.org
Wed Sep 16 19:32:25 PDT 2026
https://github.com/da-viper updated https://github.com/llvm/llvm-project/pull/224176
>From 037dfe05a4bd6e33b4bea8e8d6bd4754f64f1ff4 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Thu, 17 Sep 2026 02:23:22 +0100
Subject: [PATCH 1/3] [lldb][SBAPI] Fix crash when calling SBProgress
constructor.
Fix crash when calling SBProgress constructor with nullptr.
---
lldb/source/API/SBProgress.cpp | 6 +++--
lldb/source/Core/Progress.cpp | 3 ++-
lldb/unittests/API/CMakeLists.txt | 1 +
lldb/unittests/API/SBProgressTest.cpp | 37 +++++++++++++++++++++++++++
4 files changed, 44 insertions(+), 3 deletions(-)
create mode 100644 lldb/unittests/API/SBProgressTest.cpp
diff --git a/lldb/source/API/SBProgress.cpp b/lldb/source/API/SBProgress.cpp
index e3318624c5fd1..dd9982f036704 100644
--- a/lldb/source/API/SBProgress.cpp
+++ b/lldb/source/API/SBProgress.cpp
@@ -17,7 +17,8 @@ SBProgress::SBProgress(const char *title, const char *details,
LLDB_INSTRUMENT_VA(this, title, details, debugger);
m_opaque_up = std::make_unique<lldb_private::Progress>(
- title, details, /*total=*/std::nullopt, debugger.get(),
+ llvm::StringRef(title).str(), llvm::StringRef(details).str(),
+ /*total=*/std::nullopt, debugger.get(),
/*minimum_report_time=*/std::nullopt,
lldb_private::Progress::Origin::eExternal);
}
@@ -27,7 +28,8 @@ SBProgress::SBProgress(const char *title, const char *details,
LLDB_INSTRUMENT_VA(this, title, details, total_units, debugger);
m_opaque_up = std::make_unique<lldb_private::Progress>(
- title, details, total_units, debugger.get(),
+ llvm::StringRef(title).str(), llvm::StringRef(details).str(), total_units,
+ debugger.get(),
/*minimum_report_time=*/std::nullopt,
lldb_private::Progress::Origin::eExternal);
}
diff --git a/lldb/source/Core/Progress.cpp b/lldb/source/Core/Progress.cpp
index d29dce0a688c0..ff55feda5ac23 100644
--- a/lldb/source/Core/Progress.cpp
+++ b/lldb/source/Core/Progress.cpp
@@ -16,6 +16,7 @@
#include <cstdint>
#include <mutex>
#include <optional>
+#include <utility>
using namespace lldb;
using namespace lldb_private;
@@ -31,7 +32,7 @@ Progress::Progress(std::string title, std::string details,
Timeout<std::nano> minimum_report_time,
Progress::Origin origin)
: m_total(total.value_or(Progress::kNonDeterministicTotal)),
- m_minimum_report_time(minimum_report_time), m_title(title),
+ m_minimum_report_time(minimum_report_time), m_title(std::move(title)),
m_progress_id(++g_id),
m_debugger_id(debugger ? std::optional<user_id_t>(debugger->GetID())
: std::nullopt),
diff --git a/lldb/unittests/API/CMakeLists.txt b/lldb/unittests/API/CMakeLists.txt
index 3ea6fe872b39d..ac7061c96bfd3 100644
--- a/lldb/unittests/API/CMakeLists.txt
+++ b/lldb/unittests/API/CMakeLists.txt
@@ -5,6 +5,7 @@ add_lldb_unittest(APITests
SBMutexTest.cpp
SBBreakpointClearConditionTest.cpp
SBProtocolServerTest.cpp
+ SBProgressTest.cpp
SBAPITEST
diff --git a/lldb/unittests/API/SBProgressTest.cpp b/lldb/unittests/API/SBProgressTest.cpp
new file mode 100644
index 0000000000000..c713ef334e2dd
--- /dev/null
+++ b/lldb/unittests/API/SBProgressTest.cpp
@@ -0,0 +1,37 @@
+//===-- SBProgressTest.cpp -------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===/
+
+#include "gtest/gtest.h"
+
+#include "TestingSupport/SubsystemRAII.h"
+#include "lldb/API/LLDB.h"
+
+using namespace lldb_private;
+using namespace lldb;
+
+class SBProgressTest : public testing::Test {
+protected:
+ void SetUp() override {
+ debugger = SBDebugger::Create(/*source_init_files=*/false);
+ }
+
+ void TearDown() override { SBDebugger::Destroy(debugger); }
+
+ SubsystemRAII<SBDebugger> subsystems;
+ SBDebugger debugger;
+};
+
+TEST_F(SBProgressTest, Constructor) {
+ // Calling the constructor with null values does not crash.
+ SBProgress progress(nullptr, nullptr, debugger);
+ SBProgress progress2(nullptr, nullptr, /*total_units=*/10, debugger);
+
+ progress.Increment(2, nullptr);
+ progress.Increment(2, "Other");
+ progress.Finalize();
+}
>From 20bbe6ba87a183469c30cbfd7738f0a30893202b Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Thu, 17 Sep 2026 02:30:15 +0100
Subject: [PATCH 2/3] remove file name in comment
---
lldb/unittests/API/SBProgressTest.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lldb/unittests/API/SBProgressTest.cpp b/lldb/unittests/API/SBProgressTest.cpp
index c713ef334e2dd..318a4a4725533 100644
--- a/lldb/unittests/API/SBProgressTest.cpp
+++ b/lldb/unittests/API/SBProgressTest.cpp
@@ -1,4 +1,4 @@
-//===-- SBProgressTest.cpp -------------------------------------===//
+//===---------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
>From c000d8607ec24529e225b7c1231dff1417bdb1f8 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Thu, 17 Sep 2026 03:31:58 +0100
Subject: [PATCH 3/3] Get the data from the progress
---
lldb/unittests/API/SBProgressTest.cpp | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/lldb/unittests/API/SBProgressTest.cpp b/lldb/unittests/API/SBProgressTest.cpp
index 318a4a4725533..8edb7d7865ac6 100644
--- a/lldb/unittests/API/SBProgressTest.cpp
+++ b/lldb/unittests/API/SBProgressTest.cpp
@@ -10,6 +10,8 @@
#include "TestingSupport/SubsystemRAII.h"
#include "lldb/API/LLDB.h"
+#include "lldb/lldb-enumerations.h"
+#include "llvm/Testing/Support/Error.h"
using namespace lldb_private;
using namespace lldb;
@@ -18,6 +20,7 @@ class SBProgressTest : public testing::Test {
protected:
void SetUp() override {
debugger = SBDebugger::Create(/*source_init_files=*/false);
+ debugger.SetAsync(false);
}
void TearDown() override { SBDebugger::Destroy(debugger); }
@@ -31,7 +34,31 @@ TEST_F(SBProgressTest, Constructor) {
SBProgress progress(nullptr, nullptr, debugger);
SBProgress progress2(nullptr, nullptr, /*total_units=*/10, debugger);
+ SBListener listener("Test Listener");
+ SBBroadcaster broadcaster = debugger.GetBroadcaster();
+ broadcaster.AddListener(listener, lldb::eBroadcastBitExternalProgress);
+
progress.Increment(2, nullptr);
progress.Increment(2, "Other");
progress.Finalize();
+
+ SBEvent event;
+ EXPECT_TRUE(listener.GetNextEvent(event));
+
+ const SBStructuredData sdata = SBDebugger::GetProgressDataFromEvent(event);
+ SBStream stream;
+ sdata.GetAsJSON(stream);
+ llvm::StringRef data(stream.GetData(), stream.GetSize());
+ llvm::Expected<llvm::json::Value> progress_data = llvm::json::parse(data);
+
+ ASSERT_THAT_EXPECTED(progress_data, llvm::Succeeded());
+ auto *proj_json = progress_data->getAsObject();
+ ASSERT_NE(proj_json, nullptr);
+ for (llvm::StringRef field : {"message", "title", "details"}) {
+ auto field_val = proj_json->getString(field);
+ ASSERT_TRUE(field_val.has_value());
+ EXPECT_EQ(field_val.value(), llvm::StringRef(""));
+ }
+
+ EXPECT_TRUE(event.GetDescription(stream));
}
More information about the lldb-commits
mailing list