https://github.com/DavidSpickett created 
https://github.com/llvm/llvm-project/pull/170156

Fixes #169788

When this function fails to initialise the debugger, it sets the SBError using 
the returned error from the initialise function. This results in Success being 
false and isVaid being true. This is expected behaviour.

When it does not fail to initialise, it was returning the default constructed 
SBError which has Success() == true but IsValid == false. IsValid should be 
true, to show that the success can be trusted.

To fix this, construct the SBError using a default constructed Status, which 
results in Success and IsValid being true.

>From 7652ad3829c431361fdb86c00924fdde0642086b Mon Sep 17 00:00:00 2001
From: David Spickett <[email protected]>
Date: Mon, 1 Dec 2025 15:48:48 +0000
Subject: [PATCH] [lldb] Make sure SBError is valid when
 SBDebugger::InitializeWithErrorHandling succeeds

Fixes #169788

When this function fails to initialise the debugger, it sets the SBError
using the returned error from the initialise function. This results
in Success being false and isVaid being true. This is expected behaviour.

When it does not fail to initialise, it was returning the default
constructed SBError which has Success() == true but IsValid == false.
IsValid should be true, to show that the success can be trusted.

To fix this, construct the SBError using a default constructed Status,
which results in Success and IsValid being true.
---
 lldb/source/API/SBDebugger.cpp  | 2 +-
 lldb/unittests/DAP/TestBase.cpp | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 7a4bebfdf998e..f939955ba57c8 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -179,7 +179,7 @@ void SBDebugger::Initialize() {
 lldb::SBError SBDebugger::InitializeWithErrorHandling() {
   LLDB_INSTRUMENT();
 
-  SBError error;
+  SBError error((Status()));
   if (auto e = g_debugger_lifetime->Initialize(
           std::make_unique<SystemInitializerFull>())) {
     error.SetError(Status::FromError(std::move(e)));
diff --git a/lldb/unittests/DAP/TestBase.cpp b/lldb/unittests/DAP/TestBase.cpp
index 8cb459964f7d8..f4dde9559e9d3 100644
--- a/lldb/unittests/DAP/TestBase.cpp
+++ b/lldb/unittests/DAP/TestBase.cpp
@@ -72,6 +72,7 @@ void DAPTestBase::TearDown() {
 
 void DAPTestBase::SetUpTestSuite() {
   lldb::SBError error = SBDebugger::InitializeWithErrorHandling();
+  EXPECT_TRUE(error.IsValid());
   EXPECT_TRUE(error.Success());
 }
 void DAPTestBase::TeatUpTestSuite() { SBDebugger::Terminate(); }

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to