https://github.com/charles-zablit updated 
https://github.com/llvm/llvm-project/pull/181160

>From 442c48f4f3c75d17b2c41795df01d335e5bcd403 Mon Sep 17 00:00:00 2001
From: Charles Zablit <[email protected]>
Date: Thu, 12 Feb 2026 14:57:05 +0000
Subject: [PATCH 1/5] [lldb][windows] print an error if Python fails to
 initialize

---
 .../Python/ScriptInterpreterPython.cpp        | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 35a772c1454df..9af480c4113d9 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -120,14 +120,30 @@ struct InitializePythonRAII {
       return spec.GetPath();
     }();
     if (!g_python_home.empty()) {
-      PyConfig_SetBytesString(&config, &config.home, g_python_home.c_str());
+      PyStatus py_status =
+          PyConfig_SetBytesString(&config, &config.home, 
g_python_home.c_str());
+      if (py_status._type == PyStatus::_PyStatus_TYPE_ERROR) {
+        PyConfig_Clear(&config);
+        llvm::WithColor::error() << "Failed to set the Python config: '"
+                                 << py_status.err_msg << "'.\n";
+        return;
+      }
     }
 
     config.install_signal_handlers = 0;
-    Py_InitializeFromConfig(&config);
+    PyStatus py_status = Py_InitializeFromConfig(&config);
     PyConfig_Clear(&config);
+    if (py_status._type == PyStatus::_PyStatus_TYPE_ERROR) {
+      llvm::WithColor::error()
+          << "Python failed to initialize: '" << py_status.err_msg << "'.\n";
+      return;
+    }
 #else
     Py_InitializeEx(/*install_sigs=*/0);
+    if (!Py_IsInitialized()) {
+      llvm::WithColor::error() << "Python failed to initialize.\n";
+      return;
+    }
 #endif
 
     // The only case we should go further and acquire the GIL: it is unlocked.

>From 8ace7e584c325e90e0648b1dfdf10800d7f1492e Mon Sep 17 00:00:00 2001
From: Charles Zablit <[email protected]>
Date: Fri, 13 Feb 2026 12:22:44 +0100
Subject: [PATCH 2/5] remove private API usage

---
 .../Python/ScriptInterpreterPython.cpp             | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 9af480c4113d9..c954f167a22b8 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -120,22 +120,22 @@ struct InitializePythonRAII {
       return spec.GetPath();
     }();
     if (!g_python_home.empty()) {
-      PyStatus py_status =
+      PyStatus status =
           PyConfig_SetBytesString(&config, &config.home, 
g_python_home.c_str());
-      if (py_status._type == PyStatus::_PyStatus_TYPE_ERROR) {
+      if (PyStatus_Exception(status)) {
         PyConfig_Clear(&config);
-        llvm::WithColor::error() << "Failed to set the Python config: '"
-                                 << py_status.err_msg << "'.\n";
+        llvm::WithColor::error()
+            << "Failed to set the Python config: '" << status.err_msg << 
"'.\n";
         return;
       }
     }
 
     config.install_signal_handlers = 0;
-    PyStatus py_status = Py_InitializeFromConfig(&config);
+    PyStatus status = Py_InitializeFromConfig(&config);
     PyConfig_Clear(&config);
-    if (py_status._type == PyStatus::_PyStatus_TYPE_ERROR) {
+    if (PyStatus_Exception(status)) {
       llvm::WithColor::error()
-          << "Python failed to initialize: '" << py_status.err_msg << "'.\n";
+          << "Python failed to initialize: '" << status.err_msg << "'.\n";
       return;
     }
 #else

>From 83418baf076ecc100a5e5d41f7dc7eb86b91a721 Mon Sep 17 00:00:00 2001
From: Charles Zablit <[email protected]>
Date: Mon, 16 Feb 2026 16:38:27 +0100
Subject: [PATCH 3/5] create standalone method instead of initializing in
 constructor

---
 .../ScriptInterpreter/Python/ScriptInterpreterPython.cpp       | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index c954f167a22b8..bd2ffa4cb0349 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -91,7 +91,7 @@ namespace {
 // save off initial state at the beginning, and restore it at the end
 struct InitializePythonRAII {
 public:
-  InitializePythonRAII() {
+  void DoInitialize() {
     // The table of built-in modules can only be extended before Python is
     // initialized.
     if (!Py_IsInitialized()) {
@@ -3039,6 +3039,7 @@ void ScriptInterpreterPythonImpl::Initialize() {
   // restoring various other pieces of state that can get mucked with during
   // initialization.
   InitializePythonRAII initialize_guard;
+  initialize_guard.DoInitialize();
 
   LLDBSwigPyInit();
 

>From 86631a7cb1850563c351090657200f3846991c26 Mon Sep 17 00:00:00 2001
From: Charles Zablit <[email protected]>
Date: Mon, 16 Feb 2026 16:49:03 +0100
Subject: [PATCH 4/5] switch to llvm::report_fatal_error

---
 .../Python/ScriptInterpreterPython.cpp        | 21 ++++++-------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index bd2ffa4cb0349..016b4f5c600f9 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -122,28 +122,19 @@ struct InitializePythonRAII {
     if (!g_python_home.empty()) {
       PyStatus status =
           PyConfig_SetBytesString(&config, &config.home, 
g_python_home.c_str());
-      if (PyStatus_Exception(status)) {
-        PyConfig_Clear(&config);
-        llvm::WithColor::error()
-            << "Failed to set the Python config: '" << status.err_msg << 
"'.\n";
-        return;
-      }
+      if (PyStatus_Exception(status))
+        llvm::report_fatal_error(llvm::Twine("Failed to set the Python config: 
'") + status.err_msg + "'.");
     }
 
     config.install_signal_handlers = 0;
     PyStatus status = Py_InitializeFromConfig(&config);
     PyConfig_Clear(&config);
-    if (PyStatus_Exception(status)) {
-      llvm::WithColor::error()
-          << "Python failed to initialize: '" << status.err_msg << "'.\n";
-      return;
-    }
+    if (PyStatus_Exception(status))
+      llvm::report_fatal_error(llvm::Twine("Python failed to initialize: '") + 
status.err_msg + "'.");
 #else
     Py_InitializeEx(/*install_sigs=*/0);
-    if (!Py_IsInitialized()) {
-      llvm::WithColor::error() << "Python failed to initialize.\n";
-      return;
-    }
+    if (!Py_IsInitialized())
+      llvm::report_fatal_error("Python failed to initialize.");
 #endif
 
     // The only case we should go further and acquire the GIL: it is unlocked.

>From 1bf62ae724637f5b986178a388351d62084abb21 Mon Sep 17 00:00:00 2001
From: Charles Zablit <[email protected]>
Date: Mon, 16 Feb 2026 19:16:25 +0100
Subject: [PATCH 5/5] Update
 lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Co-authored-by: Jonas Devlieghere <[email protected]>
---
 .../ScriptInterpreter/Python/ScriptInterpreterPython.cpp        | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 016b4f5c600f9..464fa6c499cdc 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -123,7 +123,7 @@ struct InitializePythonRAII {
       PyStatus status =
           PyConfig_SetBytesString(&config, &config.home, 
g_python_home.c_str());
       if (PyStatus_Exception(status))
-        llvm::report_fatal_error(llvm::Twine("Failed to set the Python config: 
'") + status.err_msg + "'.");
+        llvm::report_fatal_error(llvm::Twine("failed to set the Python config: 
'") + status.err_msg + "'");
     }
 
     config.install_signal_handlers = 0;

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

Reply via email to