[Lldb-commits] [lldb] [lldb][NFC] Defer python init until ScriptInterpreter is created (PR #105757)

2024-08-22 Thread Daniel Xu via lldb-commits

https://github.com/danobi created 
https://github.com/llvm/llvm-project/pull/105757

Previously python was initialized during static registration of the plugin. 
This causes the python interpreter to run even if python support is explicitly 
disabled thru:

SBDebugger::SetScriptLanguage(ScriptLanguage::eScriptLanguageNone)

This commit defers python initialization until a ScriptInterpreterPython 
instance is created.

>From 049c89e9e8e92cb1564020335d6f69d89d8adf43 Mon Sep 17 00:00:00 2001
From: Daniel Xu 
Date: Thu, 22 Aug 2024 17:32:22 -0700
Subject: [PATCH] [lldb][NFC] Defer python init until ScriptInterpreter is
 created

Previously python was initialized during static registration of the
plugin. This causes the python interpreter to run even if python support
is explicitly disabled thru:

SBDebugger::SetScriptLanguage(ScriptLanguage::eScriptLanguageNone)

This commit defers python initialization until a ScriptInterpreterPython
instance is created.
---
 .../ScriptInterpreter/Python/ScriptInterpreterPython.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 335c482f8495ad..bc4e7485067048 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -352,7 +352,6 @@ void ScriptInterpreterPython::Initialize() {
   GetPluginDescriptionStatic(),
   lldb::eScriptLanguagePython,
   ScriptInterpreterPythonImpl::CreateInstance);
-ScriptInterpreterPythonImpl::Initialize();
   });
 }
 
@@ -429,6 +428,10 @@ 
ScriptInterpreterPythonImpl::ScriptInterpreterPythonImpl(Debugger &debugger)
   m_active_io_handler(eIOHandlerNone), m_session_is_active(false),
   m_pty_secondary_is_open(false), m_valid_session(true), m_lock_count(0),
   m_command_thread_state(nullptr) {
+  static llvm::once_flag g_once_flag;
+  llvm::call_once(g_once_flag, []() {
+ScriptInterpreterPythonImpl::Initialize();
+  });
 
   m_dictionary_name.append("_dict");
   StreamString run_string;

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][NFC] Defer python init until ScriptInterpreter is created (PR #105757)

2024-08-22 Thread Daniel Xu via lldb-commits

danobi wrote:

Also see: https://github.com/bpftrace/bpftrace/pull/3359

https://github.com/llvm/llvm-project/pull/105757
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][NFC] Defer python init until ScriptInterpreter is created (PR #105757)

2024-08-22 Thread Daniel Xu via lldb-commits

https://github.com/danobi ready_for_review 
https://github.com/llvm/llvm-project/pull/105757
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][NFC] Defer python init until ScriptInterpreter is created (PR #105757)

2024-08-22 Thread Daniel Xu via lldb-commits

danobi wrote:

Test failure looks unrelated. I see it in other PRs as well.

https://github.com/llvm/llvm-project/pull/105757
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][NFC] Defer python init until ScriptInterpreter is created (PR #105757)

2024-08-23 Thread Daniel Xu via lldb-commits

danobi wrote:

 Hi @JDevlieghere , thanks for taking a look at this.

I'm not very familiar with lldb in general so I can't comment much on 
alternatives. Lazy loading does some fairly reasonable to me but I don't know 
what kind of code changes that'd require.

The motivation behind this change starts with 
https://github.com/bpftrace/bpftrace/issues/3329. Basically we got a bug report 
from a user saying they're getting python errors when running bpftrace. 
bpftrace does not use python at runtime anywhere, so it was quite surprising. 
It turns out that lldb was running python standard library code. And the 
environment bpftrace was running in (appimage) does not have any python 
support, so no standard library available.

For context, bpftrace uses liblldb to parse DWARF. We used to directly use 
libdw but it was kinda hard to work with. liblldb has very nice high level API 
that we found useful for velocity. We never have (and probably never will) use 
python bindings to lldb.
The reason we can't just compile out python bindings is b/c we need to build 
with whatever distros give us. And my understanding is that distros are more or 
less forced to build with bindings on so that lldb (the cli tool) will function.

You're right that this patch only addresses a subset of the real goal - the 
real goal being we want to disable all plugins at runtime. It'd probably help 
with performance for other liblldb users as well.

Hopefully this essay makes the goal more clear. Please lemme know how we should 
proceed. I'd be happy to help out if it's not too complicated.


https://github.com/llvm/llvm-project/pull/105757
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][NFC] Defer python init until ScriptInterpreter is created (PR #105757)

2025-02-07 Thread Daniel Xu via lldb-commits

https://github.com/danobi closed 
https://github.com/llvm/llvm-project/pull/105757
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][NFC] Defer python init until ScriptInterpreter is created (PR #105757)

2025-02-07 Thread Daniel Xu via lldb-commits

danobi wrote:

Hi @labath, sorry for late reply, I must've missed a notification :(

That makes sense to me - perhaps LLDB is not the right dependency for us to 
take.

https://github.com/llvm/llvm-project/pull/105757
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][NFC] Defer python init until ScriptInterpreter is created (PR #105757)

2024-12-17 Thread Daniel Xu via lldb-commits

danobi wrote:

Hi @JDevlieghere, we hit this issue again recently. We're wondering if we have 
a path forward for landing this fix.

https://github.com/llvm/llvm-project/pull/105757
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits