mirror-llvm-project/lldb
Med Ismail Bennani 1ac9b999f8
[lldb] Reimplement PythonCallable::GetArgInfo without executing Python code (#213378)
`b05a5d0a` added an arity-trimming step to the shared
`ScriptedPythonInterface::Dispatch`: extensions are now allowed to
define methods with trailing parameters as optional
(`num_children(self)` vs. `num_children(self, max_count)`), so before
calling into a method, `Dispatch` needs to know how many positional
arguments it actually accepts and drop any trailing ones we'd otherwise
pass.

That check calls `PythonCallable::GetArgInfo`, which ran a whole
embedded Python script through `inspect.signature` on every call, since
every scripted-extension dispatch goes through it.

For the common case `GetArgInfo()` actually needs to handle fast (plain
Python functions/methods, classes used as constructors, and callable
instances defining `__call__`, i.e. everything `Dispatch<T>()` and
`CreatePluginObject()` ever pass it), the answer is available as plain
data attributes, with no Python bytecode execution required:
`__func__`/`__self__` to unwrap bound methods, and `__code__`'s
`co_argcount`/`co_flags` for the actual positional-argument count and
varargs bit. For a class, that means `__init__` -- except a class may
customize `__new__` instead and leave `__init__` untouched, in which
case `object.__init__` becomes lenient about extra arguments.

Anything else still lacking `__code__` can fall back to the original
`inspect.signature()`-based implementation, now exposed as
`PythonCallable::GetArgInfoFromInspectSignature()` so it can be used
separately.

rdar://183776556

---------

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2026-08-01 16:23:21 -07:00
..
bindings [lldb/Interpreter] Surface Python exceptions from scripted extensions (#198153) 2026-07-31 17:51:12 -07:00
cmake [lldb] Make missing DWO diagnostics customizable (#212338) 2026-07-30 10:51:49 -07:00
docs [lldb] Introduce the require decorator (#212753) 2026-08-01 18:03:29 +02:00
examples [lldb/script] Migrate synthetic children providers onto ScriptedPythonInterface (#210845) 2026-07-30 13:39:36 -07:00
include [lldb/Interpreter] Surface Python exceptions from scripted extensions (#198153) 2026-07-31 17:51:12 -07:00
packages/Python/lldbsuite [lldb] Introduce the require decorator (#212753) 2026-08-01 18:03:29 +02:00
resources
scripts [lldb][docs] Generate the Python API enums page from headers (#202780) 2026-06-10 16:14:46 -07:00
source [lldb] Reimplement PythonCallable::GetArgInfo without executing Python code (#213378) 2026-08-01 16:23:21 -07:00
test [lldb] Reimplement PythonCallable::GetArgInfo without executing Python code (#213378) 2026-08-01 16:23:21 -07:00
tools [lldb] Make missing DWO diagnostics customizable (#212338) 2026-07-30 10:51:49 -07:00
unittests [lldb] Reimplement PythonCallable::GetArgInfo without executing Python code (#213378) 2026-08-01 16:23:21 -07:00
utils [lldb-server] Add accelerator plugin infrastructure for debugging hardware accelerators like gpus (#198907) 2026-05-29 17:33:55 -05:00
.clang-format
.clang-tidy [lldb] Configure llvm-formatv-string clang-tidy options (#197242) 2026-05-13 08:22:43 -07:00
.gitignore
CMakeLists.txt [lldb][Windows] Use (lib)python3.dll when linking with limited API (#206585) 2026-06-30 10:32:31 +02:00
LICENSE.TXT
Maintainers.md [lldb] Nominate myself for FreeBSD maintainer (#180053) 2026-03-13 18:14:47 -07:00
use_lldb_suite_root.py