/* Python interface to breakpoints
- Copyright (C) 2008-2017 Free Software Foundation, Inc.
+ Copyright (C) 2008-2018 Free Software Foundation, Inc.
This file is part of GDB.
#include "breakpoint.h"
#include "gdbcmd.h"
#include "gdbthread.h"
-#include "observer.h"
+#include "observable.h"
#include "cli/cli-script.h"
#include "ada-lang.h"
#include "arch-utils.h"
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 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)
{
static const char *keywords[] = { "spec", "type", "wp_class", "internal",
"temporary","source", "function",
- "label", "line", NULL };
+ "label", "line", "qualified", NULL };
const char *spec = NULL;
enum bptype type = bp_breakpoint;
int access_type = hw_write;
char *label = NULL;
char *source = NULL;
char *function = NULL;
+ PyObject * qualified = NULL;
- if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssO", keywords,
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO", keywords,
&spec, &type, &access_type,
&internal,
&temporary, &source,
- &function, &label, &lineobj))
+ &function, &label, &lineobj,
+ &qualified))
return -1;
case bp_breakpoint:
{
event_location_up location;
+ symbol_name_match_type func_name_match_type
+ = (qualified != NULL && PyObject_IsTrue (qualified)
+ ? symbol_name_match_type::FULL
+ : symbol_name_match_type::WILD);
if (spec != NULL)
{
const char *copy = copy_holder.get ();
location = string_to_event_location (©,
- current_language);
+ current_language,
+ func_name_match_type);
}
else
{
explicit_loc.line_offset =
linespec_parse_line_offset (line.get ());
+ explicit_loc.func_name_match_type = func_name_match_type;
+
location = new_explicit_location (&explicit_loc);
}
(PyObject *) &breakpoint_object_type) < 0)
return -1;
- observer_attach_breakpoint_created (gdbpy_breakpoint_created);
- observer_attach_breakpoint_deleted (gdbpy_breakpoint_deleted);
- observer_attach_breakpoint_modified (gdbpy_breakpoint_modified);
+ gdb::observers::breakpoint_created.attach (gdbpy_breakpoint_created);
+ gdb::observers::breakpoint_deleted.attach (gdbpy_breakpoint_deleted);
+ gdb::observers::breakpoint_modified.attach (gdbpy_breakpoint_modified);
/* Add breakpoint types constants. */
for (i = 0; pybp_codes[i].name; ++i)
{ "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."},