diff options
author | Kevin Pouget <kpouget@sourceware.org> | 2011-12-23 17:06:16 +0000 |
---|---|---|
committer | Kevin Pouget <kpouget@sourceware.org> | 2011-12-23 17:06:16 +0000 |
commit | cc72b2a2da6d6372cbdb1d14639a5fce84e1a325 (patch) | |
tree | 5fd4fd97f8ba3702213bfc77d8be5d0a68fe86a3 /gdb/python | |
parent | 6538471c25155c4230f325e022a091d782a81fad (diff) | |
download | gdb-cc72b2a2da6d6372cbdb1d14639a5fce84e1a325.zip gdb-cc72b2a2da6d6372cbdb1d14639a5fce84e1a325.tar.gz gdb-cc72b2a2da6d6372cbdb1d14639a5fce84e1a325.tar.bz2 |
Introduce gdb.FinishBreakpoint in Python
* Makefile.in (SUBDIR_PYTHON_OBS): Add py-finishbreakpoint.o.
(SUBDIR_PYTHON_SRCS): Add python/py-finishbreakpoint.c.
Add build rule for this file.
* infcmd.c (print_return_value): Split to create get_return_value.
(get_return_value): New function based on print_return_value. Handle
case where stop_registers are not set.
* inferior.h (get_return_value): New prototype.
* python/py-breakpoint.c (bppy_pending_object): Make non-static.
(gdbpy_breakpoint_created): Set is_py_finish_bp is necessary.
(struct breakpoint_object): Move to python-internal.h
(BPPY_REQUIRE_VALID): Likewise.
(BPPY_SET_REQUIRE_VALID): Likewise.
(gdbpy_breakpoint_created): Initialize is_finish_bp.
(gdbpy_should_stop): Add pre/post hooks before/after calling stop
method.
* python/python-internal.h (breakpoint_object_type): Add as extern.
(bppy_pending_object): Likewise.
(typedef struct breakpoint_object) Removed.
(struct breakpoint_object): Moved from py-breakpoint.c.
Add field is_finish_bp.
(BPPY_REQUIRE_VALID): Moved from py-breakpoint.c.
(BPPY_SET_REQUIRE_VALID): Likewise.
(frame_object_to_frame_info): New prototype.
(gdbpy_initialize_finishbreakpoints): New prototype.
(bpfinishpy_is_finish_bp): Likewise.
(bpfinishpy_pre_stop_hook): Likewise.
(bpfinishpy_post_stop_hook): Likewise.
* python/py-finishbreakpoint.c: New file.
* python/py-frame.c(frame_object_to_frame_info): Make non-static and
accept PyObject instead of frame_object.
(frapy_is_valid): Don't cast to frame_object.
(frapy_name): Likewise.
(frapy_type): Likewise.
(frapy_unwind_stop_reason): Likewise.
(frapy_pc): Likewise.
(frapy_block): Likewise.
(frapy_function): Likewise.
(frapy_older): Likewise.
(frapy_newer): Likewise.
(frapy_find_sal): Likewise.
(frapy_read_var): Likewise.
(frapy_select): Likewise.
* python/python.c (gdbpy_is_stopped_at_finish_bp): New noop function.
(_initialize_python): Add gdbpy_initialize_finishbreakpoints.
* python/python.h: Include breakpoint.h
(gdbpy_is_stopped_at_finish_bp): New prototype.
doc/
* gdb.texinfo (Finish Breakpoints in Python): New subsection.
(Python API): Add menu entry for Finish Breakpoints.
testsuite/
* Makefile.in (EXECUTABLES): Add py-finish-breakpoint and
py-finish-breakpoint2
(MISCALLANEOUS): Add py-events-shlib.so and py-events-shlib-nodebug.so
* gdb.python/py-breakpoint.exp (mult_line): Define and use variable
instead of line number.
* gdb.python/py-finish-breakpoint.c: New file.
* gdb.python/py-finish-breakpoint.exp: New file.
* gdb.python/py-finish-breakpoint.py: New file.
* gdb.python/py-finish-breakpoint2.cc: New file.
* gdb.python/py-finish-breakpoint2.exp: New file.
* gdb.python/py-finish-breakpoint2.py: New file.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-breakpoint.c | 48 | ||||
-rw-r--r-- | gdb/python/py-finishbreakpoint.c | 462 | ||||
-rw-r--r-- | gdb/python/py-frame.c | 32 | ||||
-rw-r--r-- | gdb/python/python-internal.h | 50 | ||||
-rw-r--r-- | gdb/python/python.c | 1 |
5 files changed, 537 insertions, 56 deletions
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 11d60fe..64ef45f 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -31,52 +31,16 @@ #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 { @@ -762,6 +726,9 @@ gdbpy_should_stop (struct breakpoint_object *bp_obj) 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); @@ -783,6 +750,10 @@ gdbpy_should_stop (struct breakpoint_object *bp_obj) else gdbpy_print_stack (); } + + if (bp_obj->is_finish_bp) + bpfinishpy_post_stop_hook (bp_obj); + do_cleanups (cleanup); return stop; @@ -845,6 +816,7 @@ gdbpy_breakpoint_created (struct breakpoint *bp) newbp->number = bp->number; newbp->bp = bp; newbp->bp->py_bp_object = newbp; + newbp->is_finish_bp = 0; Py_INCREF (newbp); ++bppy_live; } @@ -1006,7 +978,7 @@ static PyMethodDef breakpoint_object_methods[] = { NULL } /* Sentinel. */ }; -static PyTypeObject breakpoint_object_type = +PyTypeObject breakpoint_object_type = { PyObject_HEAD_INIT (NULL) 0, /*ob_size*/ diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c new file mode 100644 index 0000000..a2d8165 --- /dev/null +++ b/gdb/python/py-finishbreakpoint.c @@ -0,0 +1,462 @@ +/* Python interface to finish breakpoints + + Copyright (C) 2011 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + + + +#include "defs.h" +#include "exceptions.h" +#include "python-internal.h" +#include "breakpoint.h" +#include "frame.h" +#include "gdbthread.h" +#include "arch-utils.h" +#include "language.h" +#include "observer.h" +#include "inferior.h" + +static PyTypeObject finish_breakpoint_object_type; + +/* Function that is called when a Python finish bp is found out of scope. */ +static char * const outofscope_func = "out_of_scope"; + +/* struct implementing the gdb.FinishBreakpoint object by extending + the gdb.Breakpoint class. */ +struct finish_breakpoint_object +{ + /* gdb.Breakpoint base class. */ + breakpoint_object py_bp; + /* gdb.Type object of the value return by the breakpointed function. + May be NULL if no debug information was available or return type + was VOID. */ + PyObject *return_type; + /* gdb.Type object of the function finished by this breakpoint. Will be + NULL if return_type is NULL. */ + PyObject *function_type; + /* When stopped at this FinishBreakpoint, gdb.Value object returned by + the function; Py_None if the value is not computable; NULL if GDB is + not stopped at a FinishBreakpoint. */ + PyObject *return_value; +}; + +/* Python function to get the 'return_value' attribute of + FinishBreakpoint. */ + +static PyObject * +bpfinishpy_get_returnvalue (PyObject *self, void *closure) +{ + struct finish_breakpoint_object *self_finishbp = + (struct finish_breakpoint_object *) self; + + if (!self_finishbp->return_value) + Py_RETURN_NONE; + + Py_INCREF (self_finishbp->return_value); + return self_finishbp->return_value; +} + +/* Deallocate FinishBreakpoint object. */ + +static void +bpfinishpy_dealloc (PyObject *self) +{ + struct finish_breakpoint_object *self_bpfinish = + (struct finish_breakpoint_object *) self; + + Py_XDECREF (self_bpfinish->function_type); + Py_XDECREF (self_bpfinish->return_type); + Py_XDECREF (self_bpfinish->return_value); +} + +/* Triggered when gdbpy_should_stop is about to execute the `stop' callback + of the gdb.FinishBreakpoint object BP_OBJ. Will compute and cache the + `return_value', if possible. */ + +void +bpfinishpy_pre_stop_hook (struct breakpoint_object *bp_obj) +{ + struct finish_breakpoint_object *self_finishbp = + (struct finish_breakpoint_object *) bp_obj; + volatile struct gdb_exception except; + + /* Can compute return_value only once. */ + gdb_assert (!self_finishbp->return_value); + + if (!self_finishbp->return_type) + return; + + TRY_CATCH (except, RETURN_MASK_ALL) + { + struct value *ret = + get_return_value (type_object_to_type (self_finishbp->function_type), + type_object_to_type (self_finishbp->return_type)); + + if (ret) + { + self_finishbp->return_value = value_to_value_object (ret); + if (!self_finishbp->return_value) + gdbpy_print_stack (); + } + else + { + Py_INCREF (Py_None); + self_finishbp->return_value = Py_None; + } + } + if (except.reason < 0) + { + gdbpy_convert_exception (except); + gdbpy_print_stack (); + } +} + +/* Triggered when gdbpy_should_stop has triggered the `stop' callback + of the gdb.FinishBreakpoint object BP_OBJ. */ + +void +bpfinishpy_post_stop_hook (struct breakpoint_object *bp_obj) +{ + volatile struct gdb_exception except; + + TRY_CATCH (except, RETURN_MASK_ALL) + { + /* Can't delete it here, but it will be removed at the next stop. */ + disable_breakpoint (bp_obj->bp); + gdb_assert (bp_obj->bp->disposition == disp_del); + } + if (except.reason < 0) + { + gdbpy_convert_exception (except); + gdbpy_print_stack (); + } +} + +/* Python function to create a new breakpoint. */ + +static int +bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs) +{ + static char *keywords[] = { "frame", "internal", NULL }; + struct finish_breakpoint_object *self_bpfinish = + (struct finish_breakpoint_object *) self; + int type = bp_breakpoint; + PyObject *frame_obj = NULL; + int thread; + struct frame_info *frame, *prev_frame = NULL; + struct frame_id frame_id; + PyObject *internal = NULL; + int internal_bp = 0; + CORE_ADDR finish_pc, pc; + volatile struct gdb_exception except; + char *addr_str, small_buf[100]; + struct symbol *function; + + if (!PyArg_ParseTupleAndKeywords (args, kwargs, "|OO", keywords, + &frame_obj, &internal)) + return -1; + + /* Default frame to gdb.newest_frame if necessary. */ + if (!frame_obj) + frame_obj = gdbpy_newest_frame (NULL, NULL); + else + Py_INCREF (frame_obj); + + frame = frame_object_to_frame_info (frame_obj); + Py_DECREF (frame_obj); + + if (frame == NULL) + goto invalid_frame; + + TRY_CATCH (except, RETURN_MASK_ALL) + { + prev_frame = get_prev_frame (frame); + if (prev_frame == 0) + { + PyErr_SetString (PyExc_ValueError, _("\"FinishBreakpoint\" not " \ + "meaningful in the outermost "\ + "frame.")); + } + else if (get_frame_type (prev_frame) == DUMMY_FRAME) + { + PyErr_SetString (PyExc_ValueError, _("\"FinishBreakpoint\" cannot "\ + "be set on a dummy frame.")); + } + else + { + frame_id = get_frame_id (prev_frame); + if (frame_id_eq (frame_id, null_frame_id)) + PyErr_SetString (PyExc_ValueError, + _("Invalid ID for the `frame' object.")); + } + } + if (except.reason < 0) + { + gdbpy_convert_exception (except); + return -1; + } + else if (PyErr_Occurred ()) + return -1; + + thread = pid_to_thread_id (inferior_ptid); + if (thread == 0) + { + PyErr_SetString (PyExc_ValueError, + _("No thread currently selected.")); + return -1; + } + + if (internal) + { + internal_bp = PyObject_IsTrue (internal); + if (internal_bp == -1) + { + PyErr_SetString (PyExc_ValueError, + _("The value of `internal' must be a boolean.")); + return -1; + } + } + + /* Find the function we will return from. */ + self_bpfinish->return_type = NULL; + self_bpfinish->function_type = NULL; + + TRY_CATCH (except, RETURN_MASK_ALL) + { + if (get_frame_pc_if_available (frame, &pc)) + { + function = find_pc_function (pc); + if (function != NULL) + { + struct type *ret_type = + TYPE_TARGET_TYPE (SYMBOL_TYPE (function)); + + /* Remember only non-void return types. */ + if (TYPE_CODE (ret_type) != TYPE_CODE_VOID) + { + /* Ignore Python errors at this stage. */ + self_bpfinish->return_type = type_to_type_object (ret_type); + PyErr_Clear (); + self_bpfinish->function_type = + type_to_type_object (SYMBOL_TYPE (function)); + PyErr_Clear (); + } + } + } + } + if (except.reason < 0 + || !self_bpfinish->return_type || !self_bpfinish->function_type) + { + /* Won't be able to compute return value. */ + Py_XDECREF (self_bpfinish->return_type); + Py_XDECREF (self_bpfinish->function_type); + + self_bpfinish->return_type = NULL; + self_bpfinish->function_type = NULL; + } + + bppy_pending_object = &self_bpfinish->py_bp; + bppy_pending_object->number = -1; + bppy_pending_object->bp = NULL; + + TRY_CATCH (except, RETURN_MASK_ALL) + { + /* Set a breakpoint on the return address. */ + finish_pc = get_frame_pc (prev_frame); + sprintf (small_buf, "*%s", hex_string (finish_pc)); + addr_str = small_buf; + + create_breakpoint (python_gdbarch, + addr_str, NULL, thread, + 0, + 1 /*temp_flag*/, + bp_breakpoint, + 0, + AUTO_BOOLEAN_TRUE, + &bkpt_breakpoint_ops, + 0, 1, internal_bp); + } + GDB_PY_SET_HANDLE_EXCEPTION (except); + + self_bpfinish->py_bp.bp->frame_id = frame_id; + self_bpfinish->py_bp.is_finish_bp = 1; + + /* Bind the breakpoint with the current program space. */ + self_bpfinish->py_bp.bp->pspace = current_program_space; + + return 0; + + invalid_frame: + PyErr_SetString (PyExc_ValueError, + _("Invalid ID for the `frame' object.")); + return -1; +} + +/* Called when GDB notices that the finish breakpoint BP_OBJ is out of + the current callstack. Triggers the method OUT_OF_SCOPE if implemented, + then delete the breakpoint. */ + +static void +bpfinishpy_out_of_scope (struct finish_breakpoint_object *bpfinish_obj) +{ + volatile struct gdb_exception except; + breakpoint_object *bp_obj = (breakpoint_object *) bpfinish_obj; + PyObject *py_obj = (PyObject *) bp_obj; + + if (bpfinish_obj->py_bp.bp->enable_state == bp_enabled + && PyObject_HasAttrString (py_obj, outofscope_func)) + { + if (!PyObject_CallMethod (py_obj, outofscope_func, NULL)) + gdbpy_print_stack (); + } + + delete_breakpoint (bpfinish_obj->py_bp.bp); +} + +/* Callback for `bpfinishpy_detect_out_scope'. Triggers Python's + `B->out_of_scope' function if B is a FinishBreakpoint out of its scope. */ + +static int +bpfinishpy_detect_out_scope_cb (struct breakpoint *b, void *args) +{ + volatile struct gdb_exception except; + struct breakpoint *bp_stopped = (struct breakpoint *) args; + PyObject *py_bp = (PyObject *) b->py_bp_object; + struct gdbarch *garch = b->gdbarch ? b->gdbarch : get_current_arch (); + + /* Trigger out_of_scope if this is a FinishBreakpoint and its frame is + not anymore in the current callstack. */ + if (py_bp != NULL && b->py_bp_object->is_finish_bp) + { + struct finish_breakpoint_object *finish_bp = + (struct finish_breakpoint_object *) py_bp; + + /* Check scope if not currently stopped at the FinishBreakpoint. */ + if (b != bp_stopped) + { + TRY_CATCH (except, RETURN_MASK_ALL) + { + if (b->pspace == current_inferior ()->pspace + && (!target_has_registers + || frame_find_by_id (b->frame_id) == NULL)) + bpfinishpy_out_of_scope (finish_bp); + } + if (except.reason < 0) + { + gdbpy_convert_exception (except); + gdbpy_print_stack (); + } + } + } + + return 0; +} + +/* Attached to `stop' notifications, check if the execution has run + out of the scope of any FinishBreakpoint before it has been hit. */ + +static void +bpfinishpy_handle_stop (struct bpstats *bs, int print_frame) +{ + struct cleanup *cleanup = ensure_python_env (get_current_arch (), + current_language); + + iterate_over_breakpoints (bpfinishpy_detect_out_scope_cb, + bs == NULL ? NULL : bs->breakpoint_at); + + do_cleanups (cleanup); +} + +/* Attached to `exit' notifications, triggers all the necessary out of + scope notifications. */ + +static void +bpfinishpy_handle_exit (struct inferior *inf) +{ + struct cleanup *cleanup = ensure_python_env (target_gdbarch, + current_language); + + iterate_over_breakpoints (bpfinishpy_detect_out_scope_cb, NULL); + + do_cleanups (cleanup); +} + +/* Initialize the Python finish breakpoint code. */ + +void +gdbpy_initialize_finishbreakpoints (void) +{ + if (PyType_Ready (&finish_breakpoint_object_type) < 0) + return; + + Py_INCREF (&finish_breakpoint_object_type); + PyModule_AddObject (gdb_module, "FinishBreakpoint", + (PyObject *) &finish_breakpoint_object_type); + + observer_attach_normal_stop (bpfinishpy_handle_stop); + observer_attach_inferior_exit (bpfinishpy_handle_exit); +} + +static PyGetSetDef finish_breakpoint_object_getset[] = { + { "return_value", bpfinishpy_get_returnvalue, NULL, + "gdb.Value object representing the return value, if any. \ +None otherwise.", NULL }, + { NULL } /* Sentinel. */ +}; + +static PyTypeObject finish_breakpoint_object_type = +{ + PyObject_HEAD_INIT (NULL) + 0, /*ob_size*/ + "gdb.FinishBreakpoint", /*tp_name*/ + sizeof (struct finish_breakpoint_object), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + bpfinishpy_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro */ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "GDB finish breakpoint object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + finish_breakpoint_object_getset,/* tp_getset */ + &breakpoint_object_type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + bpfinishpy_init, /* tp_init */ + 0, /* tp_alloc */ + 0 /* tp_new */ +}; diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c index 20064ca..c334f63 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -60,9 +60,10 @@ static PyTypeObject frame_object_type; object. If the frame doesn't exist anymore (the frame id doesn't correspond to any frame in the inferior), returns NULL. */ -static struct frame_info * -frame_object_to_frame_info (frame_object *frame_obj) +struct frame_info * +frame_object_to_frame_info (PyObject *obj) { + frame_object *frame_obj = (frame_object *) obj; struct frame_info *frame; frame = frame_find_by_id (frame_obj->frame_id); @@ -106,7 +107,7 @@ frapy_is_valid (PyObject *self, PyObject *args) TRY_CATCH (except, RETURN_MASK_ALL) { - frame = frame_object_to_frame_info ((frame_object *) self); + frame = frame_object_to_frame_info (self); } GDB_PY_HANDLE_EXCEPTION (except); @@ -130,7 +131,7 @@ frapy_name (PyObject *self, PyObject *args) TRY_CATCH (except, RETURN_MASK_ALL) { - FRAPY_REQUIRE_VALID ((frame_object *) self, frame); + FRAPY_REQUIRE_VALID (self, frame); find_frame_funname (frame, &name, &lang, NULL); } @@ -159,7 +160,7 @@ frapy_type (PyObject *self, PyObject *args) TRY_CATCH (except, RETURN_MASK_ALL) { - FRAPY_REQUIRE_VALID ((frame_object *) self, frame); + FRAPY_REQUIRE_VALID (self, frame); type = get_frame_type (frame); } @@ -180,7 +181,7 @@ frapy_unwind_stop_reason (PyObject *self, PyObject *args) TRY_CATCH (except, RETURN_MASK_ALL) { - FRAPY_REQUIRE_VALID ((frame_object *) self, frame); + FRAPY_REQUIRE_VALID (self, frame); } GDB_PY_HANDLE_EXCEPTION (except); @@ -201,7 +202,7 @@ frapy_pc (PyObject *self, PyObject *args) TRY_CATCH (except, RETURN_MASK_ALL) { - FRAPY_REQUIRE_VALID ((frame_object *) self, frame); + FRAPY_REQUIRE_VALID (self, frame); pc = get_frame_pc (frame); } @@ -222,7 +223,7 @@ frapy_block (PyObject *self, PyObject *args) TRY_CATCH (except, RETURN_MASK_ALL) { - FRAPY_REQUIRE_VALID ((frame_object *) self, frame); + FRAPY_REQUIRE_VALID (self, frame); block = get_frame_block (frame, NULL); } GDB_PY_HANDLE_EXCEPTION (except); @@ -263,7 +264,7 @@ frapy_function (PyObject *self, PyObject *args) TRY_CATCH (except, RETURN_MASK_ALL) { - FRAPY_REQUIRE_VALID ((frame_object *) self, frame); + FRAPY_REQUIRE_VALID (self, frame); sym = find_pc_function (get_frame_address_in_block (frame)); } @@ -330,7 +331,7 @@ frapy_older (PyObject *self, PyObject *args) TRY_CATCH (except, RETURN_MASK_ALL) { - FRAPY_REQUIRE_VALID ((frame_object *) self, frame); + FRAPY_REQUIRE_VALID (self, frame); prev = get_prev_frame (frame); if (prev) @@ -359,7 +360,7 @@ frapy_newer (PyObject *self, PyObject *args) TRY_CATCH (except, RETURN_MASK_ALL) { - FRAPY_REQUIRE_VALID ((frame_object *) self, frame); + FRAPY_REQUIRE_VALID (self, frame); next = get_next_frame (frame); if (next) @@ -388,7 +389,7 @@ frapy_find_sal (PyObject *self, PyObject *args) TRY_CATCH (except, RETURN_MASK_ALL) { - FRAPY_REQUIRE_VALID ((frame_object *) self, frame); + FRAPY_REQUIRE_VALID (self, frame); find_frame_sal (frame, &sal); sal_obj = symtab_and_line_to_sal_object (sal); @@ -444,7 +445,7 @@ frapy_read_var (PyObject *self, PyObject *args) TRY_CATCH (except, RETURN_MASK_ALL) { - FRAPY_REQUIRE_VALID ((frame_object *) self, frame); + FRAPY_REQUIRE_VALID (self, frame); if (!block) block = get_frame_block (frame, NULL); @@ -472,7 +473,7 @@ frapy_read_var (PyObject *self, PyObject *args) TRY_CATCH (except, RETURN_MASK_ALL) { - FRAPY_REQUIRE_VALID ((frame_object *) self, frame); + FRAPY_REQUIRE_VALID (self, frame); val = read_var_value (var, frame); } @@ -487,12 +488,11 @@ static PyObject * frapy_select (PyObject *self, PyObject *args) { struct frame_info *fi; - frame_object *frame = (frame_object *) self; volatile struct gdb_exception except; TRY_CATCH (except, RETURN_MASK_ALL) { - FRAPY_REQUIRE_VALID (frame, fi); + FRAPY_REQUIRE_VALID (self, fi); select_frame (fi); } diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index ef39d5d..1ba7133 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -120,9 +120,50 @@ extern PyTypeObject symbol_object_type; extern PyTypeObject event_object_type; extern PyTypeObject events_object_type; extern PyTypeObject stop_event_object_type; +extern PyTypeObject breakpoint_object_type; + +typedef 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; + + /* 1 is this is a FinishBreakpoint object, 0 otherwise. */ + int is_finish_bp; +} breakpoint_object; + +/* 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) + + +/* Variables used to pass information between the Breakpoint + constructor and the breakpoint-created hook function. */ +extern breakpoint_object *bppy_pending_object; -/* Defined in py-breakpoint.c */ -typedef struct breakpoint_object breakpoint_object; typedef struct { @@ -188,6 +229,7 @@ struct value *convert_value_from_python (PyObject *obj); struct type *type_object_to_type (PyObject *obj); struct symtab *symtab_object_to_symtab (PyObject *obj); struct symtab_and_line *sal_object_to_symtab_and_line (PyObject *obj); +struct frame_info *frame_object_to_frame_info (PyObject *frame_obj); void gdbpy_initialize_auto_load (void); void gdbpy_initialize_values (void); @@ -202,6 +244,7 @@ void gdbpy_initialize_functions (void); void gdbpy_initialize_pspace (void); void gdbpy_initialize_objfile (void); void gdbpy_initialize_breakpoints (void); +void gdbpy_initialize_finishbreakpoints (void); void gdbpy_initialize_lazy_string (void); void gdbpy_initialize_parameters (void); void gdbpy_initialize_thread (void); @@ -275,6 +318,9 @@ PyObject *gdbpy_get_varobj_pretty_printer (struct value *value); char *gdbpy_get_display_hint (PyObject *printer); PyObject *gdbpy_default_visualizer (PyObject *self, PyObject *args); +void bpfinishpy_pre_stop_hook (struct breakpoint_object *bp_obj); +void bpfinishpy_post_stop_hook (struct breakpoint_object *bp_obj); + extern PyObject *gdbpy_doc_cst; extern PyObject *gdbpy_children_cst; extern PyObject *gdbpy_to_string_cst; diff --git a/gdb/python/python.c b/gdb/python/python.c index 9b00cdc..13ac15e 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1243,6 +1243,7 @@ message == an error message without a stack will be printed."), gdbpy_initialize_pspace (); gdbpy_initialize_objfile (); gdbpy_initialize_breakpoints (); + gdbpy_initialize_finishbreakpoints (); gdbpy_initialize_lazy_string (); gdbpy_initialize_thread (); gdbpy_initialize_inferior (); |