/* Python interface to breakpoints
- Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2008-2012 Free Software Foundation, Inc.
This file is part of GDB.
#include "value.h"
#include "exceptions.h"
#include "python-internal.h"
+#include "python.h"
#include "charset.h"
#include "breakpoint.h"
#include "gdbcmd.h"
#include "arch-utils.h"
#include "language.h"
-static PyTypeObject breakpoint_object_type;
-
/* Number of live breakpoints. */
static int bppy_live;
/* Variables used to pass information between the Breakpoint
constructor and the breakpoint-created hook function. */
-static breakpoint_object *bppy_pending_object;
+breakpoint_object *bppy_pending_object;
/* Function that is called when a Python condition is evaluated. */
static char * const stop_func = "stop";
-struct breakpoint_object
-{
- PyObject_HEAD
-
- /* The breakpoint number according to gdb. */
- int number;
-
- /* The gdb breakpoint object, or NULL if the breakpoint has been
- deleted. */
- struct breakpoint *bp;
-};
-
-/* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
- exception if it is invalid. */
-#define BPPY_REQUIRE_VALID(Breakpoint) \
- do { \
- if ((Breakpoint)->bp == NULL) \
- return PyErr_Format (PyExc_RuntimeError, \
- _("Breakpoint %d is invalid."), \
- (Breakpoint)->number); \
- } while (0)
-
-/* Require that BREAKPOINT be a valid breakpoint ID; throw a Python
- exception if it is invalid. This macro is for use in setter functions. */
-#define BPPY_SET_REQUIRE_VALID(Breakpoint) \
- do { \
- if ((Breakpoint)->bp == NULL) \
- { \
- PyErr_Format (PyExc_RuntimeError, _("Breakpoint %d is invalid."), \
- (Breakpoint)->number); \
- return -1; \
- } \
- } while (0)
-
/* This is used to initialize various gdb.bp_* constants. */
struct pybp_code
{
{
breakpoint_object *self_bp = (breakpoint_object *) self;
int cmp;
+ volatile struct gdb_exception except;
BPPY_SET_REQUIRE_VALID (self_bp);
cmp = PyObject_IsTrue (newvalue);
if (cmp < 0)
return -1;
- else if (cmp == 1)
- enable_breakpoint (self_bp->bp);
- else
- disable_breakpoint (self_bp->bp);
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ if (cmp == 1)
+ enable_breakpoint (self_bp->bp);
+ else
+ disable_breakpoint (self_bp->bp);
+ }
+ GDB_PY_SET_HANDLE_EXCEPTION (except);
+
return 0;
}
{
breakpoint_object *self_bp = (breakpoint_object *) self;
long id;
+ int valid_id = 0;
+ volatile struct gdb_exception except;
BPPY_SET_REQUIRE_VALID (self_bp);
if (! gdb_py_int_as_long (newvalue, &id))
return -1;
- if (! valid_task_id (id))
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ valid_id = valid_task_id (id);
+ }
+ GDB_PY_SET_HANDLE_EXCEPTION (except);
+
+ if (! valid_id)
{
PyErr_SetString (PyExc_RuntimeError,
_("Invalid task ID."));
bppy_delete_breakpoint (PyObject *self, PyObject *args)
{
breakpoint_object *self_bp = (breakpoint_object *) self;
+ volatile struct gdb_exception except;
BPPY_REQUIRE_VALID (self_bp);
- delete_breakpoint (self_bp->bp);
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ delete_breakpoint (self_bp->bp);
+ }
+ GDB_PY_HANDLE_EXCEPTION (except);
Py_RETURN_NONE;
}
{
breakpoint_object *self_bp = (breakpoint_object *) self;
long value;
+ volatile struct gdb_exception except;
BPPY_SET_REQUIRE_VALID (self_bp);
if (value < 0)
value = 0;
- set_ignore_count (self_bp->number, (int) value, 0);
+
+ TRY_CATCH (except, RETURN_MASK_ALL)
+ {
+ set_ignore_count (self_bp->number, (int) value, 0);
+ }
+ GDB_PY_SET_HANDLE_EXCEPTION (except);
return 0;
}
string_file = mem_fileopen ();
chain = make_cleanup_ui_file_delete (string_file);
- ui_out_redirect (uiout, string_file);
+ ui_out_redirect (current_uiout, string_file);
TRY_CATCH (except, RETURN_MASK_ALL)
{
- print_command_lines (uiout, breakpoint_commands (bp), 0);
+ print_command_lines (current_uiout, breakpoint_commands (bp), 0);
}
- ui_out_redirect (uiout, NULL);
+ ui_out_redirect (current_uiout, NULL);
GDB_PY_HANDLE_EXCEPTION (except);
cmdstr = ui_file_xstrdup (string_file, &length);
case bp_breakpoint:
{
create_breakpoint (python_gdbarch,
- copy, NULL, -1,
+ copy, NULL, -1, NULL,
0,
0, bp_breakpoint,
0,
AUTO_BOOLEAN_TRUE,
&bkpt_breakpoint_ops,
- 0, 1, internal_bp);
+ 0, 1, internal_bp, 0);
break;
}
case bp_watchpoint:
PyObject *
gdbpy_breakpoints (PyObject *self, PyObject *args)
{
- PyObject *list;
+ PyObject *list, *tuple;
if (bppy_live == 0)
Py_RETURN_NONE;
return NULL;
}
- return PyList_AsTuple (list);
+ tuple = PyList_AsTuple (list);
+ Py_DECREF (list);
+
+ return tuple;
}
/* Call the "stop" method (if implemented) in the breakpoint
struct gdbarch *garch = b->gdbarch ? b->gdbarch : get_current_arch ();
struct cleanup *cleanup = ensure_python_env (garch, current_language);
+ if (bp_obj->is_finish_bp)
+ bpfinishpy_pre_stop_hook (bp_obj);
+
if (PyObject_HasAttrString (py_bp, stop_func))
{
PyObject *result = PyObject_CallMethod (py_bp, stop_func, NULL);
else
gdbpy_print_stack ();
}
+
+ if (bp_obj->is_finish_bp)
+ bpfinishpy_post_stop_hook (bp_obj);
+
do_cleanups (cleanup);
return stop;
newbp->number = bp->number;
newbp->bp = bp;
newbp->bp->py_bp_object = newbp;
+ newbp->is_finish_bp = 0;
Py_INCREF (newbp);
++bppy_live;
}
state = PyGILState_Ensure ();
bp = get_breakpoint (num);
- if (! bp)
- return;
-
- bp_obj = bp->py_bp_object;
- if (bp_obj)
+ if (bp)
{
- bp_obj->bp = NULL;
- --bppy_live;
- Py_DECREF (bp_obj);
+ bp_obj = bp->py_bp_object;
+ if (bp_obj)
+ {
+ bp_obj->bp = NULL;
+ --bppy_live;
+ Py_DECREF (bp_obj);
+ }
}
PyGILState_Release (state);
}
{
int i;
+ breakpoint_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&breakpoint_object_type) < 0)
return;
{ NULL } /* Sentinel. */
};
-static PyTypeObject breakpoint_object_type =
+PyTypeObject breakpoint_object_type =
{
PyObject_HEAD_INIT (NULL)
0, /*ob_size*/
0, /* tp_dictoffset */
bppy_init, /* tp_init */
0, /* tp_alloc */
- PyType_GenericNew /* tp_new */
};