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
This commit is contained in:
Jim Ingham
2019-10-25 14:05:07 -07:00
parent a6b0219fc4
commit 738af7a624
26 changed files with 465 additions and 135 deletions

View File

@@ -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<BreakpointOptions::CommandData> &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<size_t>
GetNumFixedArgumentsForCallable(const llvm::StringRef &callable_name)
override;
bool GetEmbeddedInterpreterModuleObjects();