summaryrefslogtreecommitdiffstats
path: root/lldb/source/API
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2019-10-25 14:05:07 -0700
committerJim Ingham <jingham@apple.com>2019-10-25 14:05:07 -0700
commit738af7a6241c98164625b9cd1ba9f8af4e36f197 (patch)
tree35ecaeb5e79f0fe728c25e82157831b26c3f7158 /lldb/source/API
parenta6b0219fc4a78e96ff268d101b911466dedbbf2c (diff)
downloadbcm5719-llvm-738af7a6241c98164625b9cd1ba9f8af4e36f197.tar.gz
bcm5719-llvm-738af7a6241c98164625b9cd1ba9f8af4e36f197.zip
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
Diffstat (limited to 'lldb/source/API')
-rw-r--r--lldb/source/API/SBBreakpoint.cpp34
-rw-r--r--lldb/source/API/SBBreakpointLocation.cpp31
-rw-r--r--lldb/source/API/SBBreakpointName.cpp37
3 files changed, 81 insertions, 21 deletions
diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp
index 45eaea6b618..8159b851d58 100644
--- a/lldb/source/API/SBBreakpoint.cpp
+++ b/lldb/source/API/SBBreakpoint.cpp
@@ -14,6 +14,7 @@
#include "lldb/API/SBProcess.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBStringList.h"
+#include "lldb/API/SBStructuredData.h"
#include "lldb/API/SBThread.h"
#include "lldb/Breakpoint/Breakpoint.h"
@@ -25,6 +26,7 @@
#include "lldb/Core/Address.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/StreamFile.h"
+#include "lldb/Core/StructuredDataImpl.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Target/Process.h"
@@ -590,22 +592,38 @@ void SBBreakpoint ::SetCallback(SBBreakpointHitCallback callback, void *baton) {
}
void SBBreakpoint::SetScriptCallbackFunction(
- const char *callback_function_name) {
- LLDB_RECORD_METHOD(void, SBBreakpoint, SetScriptCallbackFunction,
- (const char *), callback_function_name);
-
+ const char *callback_function_name) {
+LLDB_RECORD_METHOD(void, SBBreakpoint, SetScriptCallbackFunction,
+ (const char *), callback_function_name);
+ SBStructuredData empty_args;
+ SetScriptCallbackFunction(callback_function_name, empty_args);
+}
+
+SBError SBBreakpoint::SetScriptCallbackFunction(
+ const char *callback_function_name,
+ SBStructuredData &extra_args) {
+ LLDB_RECORD_METHOD(SBError, SBBreakpoint, SetScriptCallbackFunction,
+ (const char *, SBStructuredData &), callback_function_name, extra_args);
+ SBError sb_error;
BreakpointSP bkpt_sp = GetSP();
if (bkpt_sp) {
+ Status error;
std::lock_guard<std::recursive_mutex> guard(
bkpt_sp->GetTarget().GetAPIMutex());
BreakpointOptions *bp_options = bkpt_sp->GetOptions();
- bkpt_sp->GetTarget()
+ error = bkpt_sp->GetTarget()
.GetDebugger()
.GetScriptInterpreter()
->SetBreakpointCommandCallbackFunction(bp_options,
- callback_function_name);
- }
+ callback_function_name,
+ extra_args.m_impl_up
+ ->GetObjectSP());
+ sb_error.SetError(error);
+ } else
+ sb_error.SetErrorString("invalid breakpoint");
+
+ return LLDB_RECORD_RESULT(sb_error);
}
SBError SBBreakpoint::SetScriptCallbackBody(const char *callback_body_text) {
@@ -992,6 +1010,8 @@ void RegisterMethods<SBBreakpoint>(Registry &R) {
(lldb::SBAddress &));
LLDB_REGISTER_METHOD(void, SBBreakpoint, SetScriptCallbackFunction,
(const char *));
+ LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpoint, SetScriptCallbackFunction,
+ (const char *, SBStructuredData &));
LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpoint, SetScriptCallbackBody,
(const char *));
LLDB_REGISTER_METHOD(bool, SBBreakpoint, AddName, (const char *));
diff --git a/lldb/source/API/SBBreakpointLocation.cpp b/lldb/source/API/SBBreakpointLocation.cpp
index 640545f55ef..2b62a69a21e 100644
--- a/lldb/source/API/SBBreakpointLocation.cpp
+++ b/lldb/source/API/SBBreakpointLocation.cpp
@@ -12,12 +12,14 @@
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBDefines.h"
#include "lldb/API/SBStream.h"
+#include "lldb/API/SBStructuredData.h"
#include "lldb/API/SBStringList.h"
#include "lldb/Breakpoint/Breakpoint.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/StreamFile.h"
+#include "lldb/Core/StructuredDataImpl.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Target/Target.h"
@@ -207,23 +209,38 @@ bool SBBreakpointLocation::GetAutoContinue() {
}
void SBBreakpointLocation::SetScriptCallbackFunction(
- const char *callback_function_name) {
- LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetScriptCallbackFunction,
- (const char *), callback_function_name);
+ const char *callback_function_name) {
+LLDB_RECORD_METHOD(void, SBBreakpointLocation, SetScriptCallbackFunction,
+ (const char *), callback_function_name);
+}
+SBError SBBreakpointLocation::SetScriptCallbackFunction(
+ const char *callback_function_name,
+ SBStructuredData &extra_args) {
+ LLDB_RECORD_METHOD(SBError, SBBreakpointLocation, SetScriptCallbackFunction,
+ (const char *, SBStructuredData &),
+ callback_function_name, extra_args);
+ SBError sb_error;
BreakpointLocationSP loc_sp = GetSP();
if (loc_sp) {
+ Status error;
std::lock_guard<std::recursive_mutex> guard(
loc_sp->GetTarget().GetAPIMutex());
BreakpointOptions *bp_options = loc_sp->GetLocationOptions();
- loc_sp->GetBreakpoint()
+ error = loc_sp->GetBreakpoint()
.GetTarget()
.GetDebugger()
.GetScriptInterpreter()
->SetBreakpointCommandCallbackFunction(bp_options,
- callback_function_name);
- }
+ callback_function_name,
+ extra_args.m_impl_up
+ ->GetObjectSP());
+ sb_error.SetError(error);
+ } else
+ sb_error.SetErrorString("invalid breakpoint");
+
+ return LLDB_RECORD_RESULT(sb_error);
}
SBError
@@ -482,6 +499,8 @@ void RegisterMethods<SBBreakpointLocation>(Registry &R) {
LLDB_REGISTER_METHOD(bool, SBBreakpointLocation, GetAutoContinue, ());
LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetScriptCallbackFunction,
(const char *));
+ LLDB_REGISTER_METHOD(SBError, SBBreakpointLocation, SetScriptCallbackFunction,
+ (const char *, SBStructuredData &));
LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpointLocation,
SetScriptCallbackBody, (const char *));
LLDB_REGISTER_METHOD(void, SBBreakpointLocation, SetCommandLineCommands,
diff --git a/lldb/source/API/SBBreakpointName.cpp b/lldb/source/API/SBBreakpointName.cpp
index 1c794fca8ca..5bd7732ebb6 100644
--- a/lldb/source/API/SBBreakpointName.cpp
+++ b/lldb/source/API/SBBreakpointName.cpp
@@ -12,11 +12,13 @@
#include "lldb/API/SBError.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBStringList.h"
+#include "lldb/API/SBStructuredData.h"
#include "lldb/API/SBTarget.h"
#include "lldb/Breakpoint/BreakpointName.h"
#include "lldb/Breakpoint/StoppointCallbackContext.h"
#include "lldb/Core/Debugger.h"
+#include "lldb/Core/StructuredDataImpl.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Target/Target.h"
@@ -565,24 +567,41 @@ void SBBreakpointName::SetCallback(SBBreakpointHitCallback callback,
}
void SBBreakpointName::SetScriptCallbackFunction(
- const char *callback_function_name) {
- LLDB_RECORD_METHOD(void, SBBreakpointName, SetScriptCallbackFunction,
- (const char *), callback_function_name);
-
+ const char *callback_function_name) {
+LLDB_RECORD_METHOD(void, SBBreakpointName, SetScriptCallbackFunction,
+ (const char *), callback_function_name);
+ SBStructuredData empty_args;
+ SetScriptCallbackFunction(callback_function_name, empty_args);
+}
+
+SBError SBBreakpointName::SetScriptCallbackFunction(
+ const char *callback_function_name,
+ SBStructuredData &extra_args) {
+ LLDB_RECORD_METHOD(SBError, SBBreakpointName, SetScriptCallbackFunction,
+ (const char *, SBStructuredData &),
+ callback_function_name, extra_args);
+ SBError sb_error;
BreakpointName *bp_name = GetBreakpointName();
- if (!bp_name)
- return;
+ if (!bp_name) {
+ sb_error.SetErrorString("unrecognized breakpoint name");
+ return LLDB_RECORD_RESULT(sb_error);
+ }
std::lock_guard<std::recursive_mutex> guard(
m_impl_up->GetTarget()->GetAPIMutex());
BreakpointOptions &bp_options = bp_name->GetOptions();
- m_impl_up->GetTarget()
+ Status error;
+ error = m_impl_up->GetTarget()
->GetDebugger()
.GetScriptInterpreter()
->SetBreakpointCommandCallbackFunction(&bp_options,
- callback_function_name);
+ callback_function_name,
+ extra_args.m_impl_up
+ ->GetObjectSP());
+ sb_error.SetError(error);
UpdateName(*bp_name);
+ return LLDB_RECORD_RESULT(sb_error);
}
SBError
@@ -728,6 +747,8 @@ void RegisterMethods<SBBreakpointName>(Registry &R) {
(lldb::SBStream &));
LLDB_REGISTER_METHOD(void, SBBreakpointName, SetScriptCallbackFunction,
(const char *));
+ LLDB_REGISTER_METHOD(SBError, SBBreakpointName, SetScriptCallbackFunction,
+ (const char *, SBStructuredData &));
LLDB_REGISTER_METHOD(lldb::SBError, SBBreakpointName, SetScriptCallbackBody,
(const char *));
LLDB_REGISTER_METHOD_CONST(bool, SBBreakpointName, GetAllowList, ());
OpenPOWER on IntegriCloud