From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27651 invoked by alias); 23 Aug 2009 15:36:25 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 27632 invoked by uid 22791); 23 Aug 2009 15:36:22 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org MIME-Version: 1.0 Date: Sun, 23 Aug 2009 15:36:00 -0000 Message-ID: <36a35d480908230836x6c8f4eaap142f85744484318b@mail.gmail.com> Subject: [RFC][3/5] Stop event subclasses From: Oguz Kayral To: archer@sourceware.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2009-q3/txt/msg00151.txt.bz2 These three new files contain subclasses to event class adding more functionality for stop events. python-stopevent.c: /* Python interface to inferior stop events. Copyright (C) 2009 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 . */ #include "defs.h" #include "command.h" #include "python-internal.h" #include "inferior.h" static void stop_evpy_dealloc (PyObject *self) { Py_DECREF (((stop_event_object *) self)->stop_reason); self->ob_type->tp_free (self); } /* Python function to get the stop event's stop reason. */ static PyObject * stop_evpy_get_stop_reason (PyObject *self, void *closure) { stop_event_object *stop_event_obj = (stop_event_object *) self; Py_INCREF (stop_event_obj->stop_reason); return (PyObject *) (stop_event_obj->stop_reason); } stop_event_object * create_stop_event_object (const char *stop_reason) { stop_event_object *stop_event_obj; stop_event_obj = PyObject_New (stop_event_object, &stop_event_object_type); if (!stop_event_obj) return NULL; stop_event_obj->event.inferior_thread = find_thread_object (inferior_ptid); Py_INCREF (stop_event_obj->event.inferior_thread); stop_event_obj->event.event_type = (PyStringObject *) PyString_FromString ("stop"); stop_event_obj->stop_reason = (PyStringObject *) PyString_FromString (stop_reason); return stop_event_obj; } /* Initialize the Python stop event code. */ void gdbpy_initialize_stop_event (void) { stop_event_object_type.tp_base = &event_object_type; if (PyType_Ready (&stop_event_object_type) < 0) return; Py_INCREF (&stop_event_object_type); PyModule_AddObject (gdb_module, "StopEvent", (PyObject *) &stop_event_object_type); } /* Callback that is used when a stop event occurs. This function will create a new Python stop event object. */ void emit_stop_event (struct bpstats *bs, const char *stop_signal) { thread_object *inferior_thread; PyObject *callback_list; PyObject *args_tuple; Py_ssize_t i; stop_event_object *stop_event_obj; inferior_thread = find_thread_object (inferior_ptid); if (bs) { stop_event_obj = create_stop_event_object ("breakpoint"); emit_breakpoint_stop_event (bs); } /* Check if the signal is "Signal 0" or "Trace/breakpoint trap". */ if ((strcmp (stop_signal, "0") != 0) && (strcmp (stop_signal, "SIGTRAP") != 0)) { stop_event_obj = create_stop_event_object ("signal"); emit_signal_stop_event (stop_signal); } if (!stop_event_obj) stop_event_obj = create_stop_event_object ("unknown"); callback_list = (PyObject *) (inferior_thread->stop_eventregistry->callbacks); args_tuple = PyTuple_New ((Py_ssize_t) 1); PyTuple_SetItem (args_tuple, (Py_ssize_t) 0, (PyObject *) stop_event_obj); for (i = 0; i < PyList_Size (callback_list); i++) { PyObject_CallObject (PyList_GET_ITEM (callback_list, i), args_tuple); } } static PyGetSetDef stop_event_object_getset[] = { { "stop_reason", stop_evpy_get_stop_reason, NULL, "Stop reason.", NULL }, { NULL } /* Sentinel. */ }; PyTypeObject stop_event_object_type = { PyObject_HEAD_INIT (NULL) 0, /* ob_size */ "gdb.StopEvent", /* tp_name */ sizeof (stop_event_object), /* tp_basicsize */ 0, /* tp_itemsize */ stop_evpy_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 stop event 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 */ stop_event_object_getset, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0 /* tp_alloc */ }; python-signalstopevent.c: /* Python interface to inferior signal stop events. Copyright (C) 2009 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 . */ #include "defs.h" #include "command.h" #include "python-internal.h" #include "inferior.h" static PyTypeObject signal_stop_event_object_type; typedef struct { stop_event_object stop_event; PyStringObject *stop_signal; } signal_stop_event_object; static void sig_stop_evpy_dealloc (PyObject *self) { Py_DECREF (((signal_stop_event_object *) self)->stop_signal); self->ob_type->tp_free (self); } /* Python function to get the stop event's stop signal. */ static PyObject * sig_stop_evpy_get_stop_signal (PyObject *self, void *closure) { signal_stop_event_object *signal_stop_event_obj = (signal_stop_event_object *) self; Py_INCREF (signal_stop_event_obj->stop_signal); return (PyObject *) (signal_stop_event_obj->stop_signal); } signal_stop_event_object * create_signal_stop_event_object (const char *stop_signal) { signal_stop_event_object *signal_stop_event_obj; signal_stop_event_obj = PyObject_New (signal_stop_event_object, &signal_stop_event_object_type); if (!signal_stop_event_obj) return NULL; signal_stop_event_obj->stop_event.event.inferior_thread = find_thread_object (inferior_ptid); Py_INCREF (signal_stop_event_obj->stop_event.event.inferior_thread); signal_stop_event_obj->stop_event.event.event_type = (PyStringObject *) PyString_FromString ("stop"); signal_stop_event_obj->stop_event.stop_reason = (PyStringObject *) PyString_FromString ("signal"); signal_stop_event_obj->stop_signal = (PyStringObject *) PyString_FromString (stop_signal); return signal_stop_event_obj; } /* Initialize the Python stop event code. */ void gdbpy_initialize_signal_stop_event (void) { signal_stop_event_object_type.tp_base = &stop_event_object_type; if (PyType_Ready (&signal_stop_event_object_type) < 0) return; Py_INCREF (&signal_stop_event_object_type); PyModule_AddObject (gdb_module, "SignalStopEvent", (PyObject *) &signal_stop_event_object_type); } /* Callback that is used when a signal stop event occurs. This function will create a new Python signal stop event object. */ void emit_signal_stop_event (const char *stop_signal) { thread_object *inferior_thread; PyObject *callback_list; PyObject *args_tuple; Py_ssize_t i; signal_stop_event_object *signal_stop_event_obj; inferior_thread = find_thread_object (inferior_ptid); signal_stop_event_obj = create_signal_stop_event_object (stop_signal); callback_list = (PyObject *) (inferior_thread->signal_stop_eventregistry->callbacks); args_tuple = PyTuple_New ((Py_ssize_t) 1); PyTuple_SetItem (args_tuple, (Py_ssize_t) 0, (PyObject *) signal_stop_event_obj); for (i = 0; i < PyList_Size (callback_list); i++) { PyObject_CallObject (PyList_GET_ITEM (callback_list, i), args_tuple); } } static PyGetSetDef signal_stop_event_object_getset[] = { { "stop_signal", sig_stop_evpy_get_stop_signal, NULL, "Stop signal.", NULL }, { NULL } /* Sentinel. */ }; static PyTypeObject signal_stop_event_object_type = { PyObject_HEAD_INIT (NULL) 0, /* ob_size */ "gdb.SignalStopEvent", /* tp_name */ sizeof (signal_stop_event_object), /* tp_basicsize */ 0, /* tp_itemsize */ sig_stop_evpy_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, /* tp_flags */ "GDB signal stop event 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 */ signal_stop_event_object_getset, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0 /* tp_alloc */ }; python-breakpointstopevent.c: /* Python interface to inferior breakpoint stop events. Copyright (C) 2009 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 . */ #include "defs.h" #include "command.h" #include "python-internal.h" #include "inferior.h" static PyTypeObject breakpoint_stop_event_object_type; typedef struct { stop_event_object stop_event; breakpoint_object *breakpoint; } breakpoint_stop_event_object; static void bp_stop_evpy_dealloc (PyObject *self) { Py_DECREF (((breakpoint_stop_event_object *) self)->breakpoint); self->ob_type->tp_free (self); } /* Python function to get the stop event's breakpoint. */ static PyObject * bp_stop_evpy_get_breakpoint (PyObject *self, void *closure) { breakpoint_stop_event_object *breakpoint_stop_event_obj = (breakpoint_stop_event_object *) self; Py_INCREF (breakpoint_stop_event_obj->breakpoint); return (PyObject *) (breakpoint_stop_event_obj->breakpoint); } breakpoint_stop_event_object * create_breakpoint_stop_event_object (breakpoint_object *bp) { breakpoint_stop_event_object *breakpoint_stop_event_obj; breakpoint_stop_event_obj = PyObject_New (breakpoint_stop_event_object, &breakpoint_stop_event_object_type); if (!breakpoint_stop_event_obj) return NULL; breakpoint_stop_event_obj->stop_event.event.inferior_thread = find_thread_object (inferior_ptid); Py_INCREF (breakpoint_stop_event_obj->stop_event.event.inferior_thread); breakpoint_stop_event_obj->stop_event.event.event_type = (PyStringObject *) PyString_FromString ("stop"); breakpoint_stop_event_obj->stop_event.stop_reason = (PyStringObject *) PyString_FromString ("breakpoint"); breakpoint_stop_event_obj->breakpoint = bp; Py_INCREF (breakpoint_stop_event_obj->breakpoint); return breakpoint_stop_event_obj; } /* Initialize the Python breakpoint stop event code. */ void gdbpy_initialize_breakpoint_stop_event (void) { breakpoint_stop_event_object_type.tp_base = &stop_event_object_type; if (PyType_Ready (&breakpoint_stop_event_object_type) < 0) return; Py_INCREF (&breakpoint_stop_event_object_type); PyModule_AddObject (gdb_module, "BreakpointStopEvent", (PyObject *) &breakpoint_stop_event_object_type); } /* Callback that is used when a stop event occurs. This function will create a new Python breakpoint stop event object. */ void emit_breakpoint_stop_event (struct bpstats *bs) { thread_object *inferior_thread; PyObject *callback_list; PyObject *args_tuple; Py_ssize_t i; breakpoint_object *breakpoint; breakpoint_stop_event_object *breakpoint_stop_event_obj; inferior_thread = find_thread_object (inferior_ptid); breakpoint = gdbpy_breakpoint_from_bpstats (bs); breakpoint_stop_event_obj = create_breakpoint_stop_event_object (breakpoint); callback_list = (PyObject *) (inferior_thread->breakpoint_stop_eventregistry->callbacks); args_tuple = PyTuple_New ((Py_ssize_t) 1); PyTuple_SetItem (args_tuple, (Py_ssize_t) 0, (PyObject *) breakpoint_stop_event_obj); for (i = 0; i < PyList_Size (callback_list); i++) { PyObject_CallObject (PyList_GET_ITEM (callback_list, i), args_tuple); } } static PyGetSetDef breakpoint_stop_event_object_getset[] = { { "breakpoint", bp_stop_evpy_get_breakpoint, NULL, "Breakpoint.", NULL }, { NULL } /* Sentinel. */ }; static PyTypeObject breakpoint_stop_event_object_type = { PyObject_HEAD_INIT (NULL) 0, /* ob_size */ "gdb.BreakpointStopEvent", /* tp_name */ sizeof (breakpoint_stop_event_object), /* tp_basicsize */ 0, /* tp_itemsize */ bp_stop_evpy_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, /* tp_flags */ "GDB breakpoint stop event 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 */ breakpoint_stop_event_object_getset, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0 /* tp_alloc */ };