aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-04-18 17:37:56 -0600
committerTom Tromey <tom@tromey.com>2018-05-04 15:58:09 -0600
commita913fffbdee21fdd50e8de0596358be425775678 (patch)
tree4901f7f8fa47ae7127b72beb55875edba9d05150 /gdb/python
parent60b3cef2e49ba72dea55181a8ad0cb8dbf3f8a5b (diff)
downloadbinutils-a913fffbdee21fdd50e8de0596358be425775678.zip
binutils-a913fffbdee21fdd50e8de0596358be425775678.tar.gz
binutils-a913fffbdee21fdd50e8de0596358be425775678.tar.bz2
Allow breakpoint commands to be set from Python
This changes the Python API so that breakpoint commands can be set by writing to the "commands" attribute. ChangeLog 2018-05-04 Tom Tromey <tom@tromey.com> PR python/22731: * NEWS: Mention that breakpoint commands are writable. * python/py-breakpoint.c (bppy_set_commands): New function. (breakpoint_object_getset) <"commands">: Use it. doc/ChangeLog 2018-05-04 Tom Tromey <tom@tromey.com> PR python/22731: * python.texi (Breakpoints In Python): Mention that "commands" is writable. testsuite/ChangeLog 2018-05-04 Tom Tromey <tom@tromey.com> PR python/22731: * gdb.python/py-breakpoint.exp: Test setting breakpoint commands.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-breakpoint.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index d654b92..a66e553 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -510,6 +510,49 @@ bppy_get_commands (PyObject *self, void *closure)
return host_string_to_python_string (stb.c_str ());
}
+/* Set the commands attached to a breakpoint. Returns 0 on success.
+ Returns -1 on error, with a python exception set. */
+static int
+bppy_set_commands (PyObject *self, PyObject *newvalue, void *closure)
+{
+ gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
+ struct breakpoint *bp = self_bp->bp;
+ struct gdb_exception except = exception_none;
+
+ BPPY_SET_REQUIRE_VALID (self_bp);
+
+ gdb::unique_xmalloc_ptr<char> commands
+ (python_string_to_host_string (newvalue));
+ if (commands == nullptr)
+ return -1;
+
+ TRY
+ {
+ bool first = true;
+ char *save_ptr = nullptr;
+ auto reader
+ = [&] ()
+ {
+ const char *result = strtok_r (first ? commands.get () : nullptr,
+ "\n", &save_ptr);
+ first = false;
+ return result;
+ };
+
+ counted_command_line lines = read_command_lines_1 (reader, 1, nullptr);
+ breakpoint_set_commands (self_bp->bp, std::move (lines));
+ }
+ CATCH (ex, RETURN_MASK_ALL)
+ {
+ except = ex;
+ }
+ END_CATCH
+
+ GDB_PY_SET_HANDLE_EXCEPTION (except);
+
+ return 0;
+}
+
/* Python function to get the breakpoint type. */
static PyObject *
bppy_get_type (PyObject *self, void *closure)
@@ -1185,7 +1228,7 @@ when setting this property.", NULL },
{ "condition", bppy_get_condition, bppy_set_condition,
"Condition of the breakpoint, as specified by the user,\
or None if no condition set."},
- { "commands", bppy_get_commands, NULL,
+ { "commands", bppy_get_commands, bppy_set_commands,
"Commands of the breakpoint, as specified by the user."},
{ "type", bppy_get_type, NULL,
"Type of breakpoint."},