From 738af7a6241c98164625b9cd1ba9f8af4e36f197 Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Fri, 25 Oct 2019 14:05:07 -0700 Subject: Add the ability to pass extra args to a Python breakpoint callback. For example, it is pretty easy to write a breakpoint command that implements "stop when my caller is Foo", and it is pretty easy to write a breakpoint command that implements "stop when my caller is Bar". But there's no way to write a generic "stop when my caller is..." function, and then specify the caller when you add the command to a breakpoint. With this patch, you can pass this data in a SBStructuredData dictionary. That will get stored in the PythonCommandBaton for the breakpoint, and passed to the implementation function (if it has the right signature) when the breakpoint is hit. Then in lldb, you can say: (lldb) break com add -F caller_is -k caller_name -v Foo More generally this will allow us to write reusable Python breakpoint commands. Differential Revision: https://reviews.llvm.org/D68671 --- .../Python/ScriptInterpreterPythonImpl.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h') diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h index 929567e579d..e480bc3af99 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h @@ -179,8 +179,10 @@ public: Status GenerateFunction(const char *signature, const StringList &input) override; - Status GenerateBreakpointCommandCallbackData(StringList &input, - std::string &output) override; + Status GenerateBreakpointCommandCallbackData( + StringList &input, + std::string &output, + bool has_extra_args) override; bool GenerateWatchpointCommandCallbackData(StringList &input, std::string &output) override; @@ -244,14 +246,22 @@ public: Status SetBreakpointCommandCallback(BreakpointOptions *bp_options, const char *callback_body) override; - void SetBreakpointCommandCallbackFunction(BreakpointOptions *bp_options, - const char *function_name) override; + Status SetBreakpointCommandCallbackFunction( + BreakpointOptions *bp_options, + const char *function_name, + StructuredData::ObjectSP extra_args_sp) override; /// This one is for deserialization: Status SetBreakpointCommandCallback( BreakpointOptions *bp_options, std::unique_ptr &data_up) override; + Status SetBreakpointCommandCallback( + BreakpointOptions *bp_options, + const char *command_body_text, + StructuredData::ObjectSP extra_args_sp, + bool uses_extra_args); + /// Set a one-liner as the callback for the watchpoint. void SetWatchpointCommandCallback(WatchpointOptions *wp_options, const char *oneliner) override; @@ -368,6 +378,10 @@ public: python::PythonDictionary &GetSessionDictionary(); python::PythonDictionary &GetSysModuleDictionary(); + + llvm::Expected + GetNumFixedArgumentsForCallable(const llvm::StringRef &callable_name) + override; bool GetEmbeddedInterpreterModuleObjects(); -- cgit v1.2.3