mirror-llvm-project/lldb/source
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
..
API [lldb/script] Add class-based summary providers via ScriptedStringSummaryInterface (#210469) 2026-07-29 18:44:26 -07:00
Breakpoint [lldb/Interpreter] Surface Python exceptions from scripted extensions (#198153) 2026-07-31 17:51:12 -07:00
Commands [lldb] Ask the reporter what happened in a bug report (#213173) 2026-07-30 17:59:44 -07:00
Core [lldb] Only preload a Module's symbols once (#213094) 2026-07-31 11:49:30 +02:00
DataFormatters [lldb/script] Migrate synthetic children providers onto ScriptedPythonInterface (#210845) 2026-07-30 13:39:36 -07:00
Expression Reapply "Make result variables obey their dynamic values in subsequent expressions" (#211321) (#213308) 2026-07-31 11:13:06 -07:00
Host [ADT] Remove deprecated llvm::make_scope_exit (#212987) 2026-07-30 14:58:46 +02:00
Initialization [lldb] Move Diagnostics from Utility to Core (NFC) (#206152) 2026-06-26 20:08:23 +00:00
Interpreter [lldb/script] Migrate synthetic children providers onto ScriptedPythonInterface (#210845) 2026-07-30 13:39:36 -07:00
Plugins [lldb] Reimplement PythonCallable::GetArgInfo without executing Python code (#213378) 2026-08-01 16:23:21 -07:00
Protocol [lldb] Reply to malformed requests and use JSON-RPC error codes (#212678) 2026-07-29 11:12:30 -07:00
Symbol [lldb] Treat synthetic variables as always in scope (#204177) 2026-07-31 15:08:03 +02:00
Target [lldb/Interpreter] Surface Python exceptions from scripted extensions (#198153) 2026-07-31 17:51:12 -07:00
Utility [lldb] Convert generic register names in a case insensitive way (#213001) 2026-07-31 10:28:36 +01:00
ValueObject [lldb] Avoid returning a stale AddressOf (#212915) 2026-07-31 14:19:53 -07:00
Version Re-land [lldb][NFC] Mark ValueObject library with NO_PLUGIN_DEPENDENCIES (#167933) 2025-11-14 11:17:04 -08:00
CMakeLists.txt [lldb] Move MCP protocol into its own library (NFC) (#152059) 2025-08-05 09:48:26 -07:00