[RFA 7/8] Allow breakpoint commands to be set from Python
Pedro Alves
palves@redhat.com
Tue Apr 24 16:43:00 GMT 2018
On 04/19/2018 08:15 PM, Tom Tromey wrote:
> +/* 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;
> + gdb::function_view<const char * ()> reader
> + = [&] ()
Like in the other patch, binding to a temporary. Use "auto".
Otherwise looks fine to me.
> + {
> + 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
> +
Thanks,
Pedro Alves
More information about the Gdb-patches
mailing list