gdbpy_breakpoint_object *bppy_pending_object;
/* Function that is called when a Python condition is evaluated. */
-static char * const stop_func = "stop";
+static const char stop_func[] = "stop";
/* This is used to initialize various gdb.bp_* constants. */
struct pybp_code
if (obj->bp->type != bp_breakpoint)
Py_RETURN_NONE;
- str = event_location_to_string (obj->bp->location);
+ str = event_location_to_string (obj->bp->location.get ());
if (! str)
str = "";
return host_string_to_python_string (str);
static PyObject *
bppy_get_expression (PyObject *self, void *closure)
{
- char *str;
+ const char *str;
gdbpy_breakpoint_object *obj = (gdbpy_breakpoint_object *) self;
struct watchpoint *wp;
gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
struct breakpoint *bp = self_bp->bp;
long length;
- struct ui_file *string_file;
PyObject *result;
- struct cleanup *chain;
BPPY_REQUIRE_VALID (self_bp);
if (! self_bp->bp->commands)
Py_RETURN_NONE;
- string_file = mem_fileopen ();
- chain = make_cleanup_ui_file_delete (string_file);
+ string_file stb;
- current_uiout->redirect (string_file);
+ current_uiout->redirect (&stb);
TRY
{
print_command_lines (current_uiout, breakpoint_commands (bp), 0);
CATCH (except, RETURN_MASK_ALL)
{
current_uiout->redirect (NULL);
- do_cleanups (chain);
gdbpy_convert_exception (except);
return NULL;
}
END_CATCH
current_uiout->redirect (NULL);
- std::string cmdstr = ui_file_as_string (string_file);
- result = host_string_to_python_string (cmdstr.c_str ());
- do_cleanups (chain);
- return result;
+ return host_string_to_python_string (stb.c_str ());
}
/* Python function to get the breakpoint type. */
static int
bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
{
- static char *keywords[] = { "spec", "type", "wp_class", "internal",
- "temporary", NULL };
+ static const char *keywords[] = { "spec", "type", "wp_class", "internal",
+ "temporary", NULL };
const char *spec;
int type = bp_breakpoint;
int access_type = hw_write;
int internal_bp = 0;
int temporary_bp = 0;
- if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiOO", keywords,
- &spec, &type, &access_type,
- &internal, &temporary))
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiOO", keywords,
+ &spec, &type, &access_type,
+ &internal, &temporary))
return -1;
if (internal)
TRY
{
gdb::unique_xmalloc_ptr<char>
- copy_holder (xstrdup (skip_spaces_const (spec)));
+ copy_holder (xstrdup (skip_spaces (spec)));
char *copy = copy_holder.get ();
switch (type)
{
case bp_breakpoint:
{
- struct event_location *location;
- struct cleanup *cleanup;
-
- location
+ event_location_up location
= string_to_event_location_basic (©, current_language);
- cleanup = make_cleanup_delete_event_location (location);
create_breakpoint (python_gdbarch,
- location, NULL, -1, NULL,
+ location.get (), NULL, -1, NULL,
0,
temporary_bp, bp_breakpoint,
0,
AUTO_BOOLEAN_TRUE,
&bkpt_breakpoint_ops,
0, 1, internal_bp, 0);
-
- do_cleanups (cleanup);
break;
}
case bp_watchpoint:
if (bppy_live == 0)
return PyTuple_New (0);
- gdbpy_ref list (PyList_New (0));
+ gdbpy_ref<> list (PyList_New (0));
if (list == NULL)
return NULL;
if (PyObject_HasAttrString (py_bp, stop_func))
{
- gdbpy_ref result (PyObject_CallMethod (py_bp, stop_func, NULL));
+ gdbpy_ref<> result (PyObject_CallMethod (py_bp, stop_func, NULL));
stop = 1;
if (result != NULL)
int num = b->number;
PyGILState_STATE state;
struct breakpoint *bp = NULL;
- gdbpy_breakpoint_object *bp_obj;
state = PyGILState_Ensure ();
bp = get_breakpoint (num);
if (bp)
{
- bp_obj = bp->py_bp_object;
- if (bp_obj)
+ gdbpy_ref<gdbpy_breakpoint_object> bp_obj (bp->py_bp_object);
+ if (bp_obj != NULL)
{
if (!evregpy_no_listeners_p (gdb_py_events.breakpoint_deleted))
{
- if (evpy_emit_event ((PyObject *) bp_obj,
+ if (evpy_emit_event ((PyObject *) bp_obj.get (),
gdb_py_events.breakpoint_deleted) < 0)
gdbpy_print_stack ();
}
bp_obj->bp = NULL;
--bppy_live;
- Py_DECREF (bp_obj);
}
}
PyGILState_Release (state);
extlang = get_breakpoint_cond_ext_lang (obj->bp, EXT_LANG_PYTHON);
if (extlang != NULL)
{
- char *error_text;
-
- error_text
- = xstrprintf (_("Only one stop condition allowed. There is"
- " currently a %s stop condition defined for"
- " this breakpoint."),
- ext_lang_capitalized_name (extlang));
- PyErr_SetString (PyExc_RuntimeError, error_text);
- xfree (error_text);
+ std::string error_text
+ = string_printf (_("Only one stop condition allowed. There is"
+ " currently a %s stop condition defined for"
+ " this breakpoint."),
+ ext_lang_capitalized_name (extlang));
+ PyErr_SetString (PyExc_RuntimeError, error_text.c_str ());
return -1;
}
}
return PyObject_GenericSetAttr ((PyObject *)self, name, v);
}
-static PyGetSetDef breakpoint_object_getset[] = {
+static gdb_PyGetSetDef breakpoint_object_getset[] = {
{ "enabled", bppy_get_enabled, bppy_set_enabled,
"Boolean telling whether the breakpoint is enabled.", NULL },
{ "silent", bppy_get_silent, bppy_set_silent,