1 /* Python interface to inferior stop events. 2 3 Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. 4 5 This file is part of GDB. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 20 #include "py-stopevent.h" 21 22 PyObject * 23 create_stop_event_object (PyTypeObject *py_type) 24 { 25 PyObject *stop_event_obj = create_thread_event_object (py_type); 26 27 if (!stop_event_obj) 28 goto fail; 29 30 return stop_event_obj; 31 32 fail: 33 Py_XDECREF (stop_event_obj); 34 return NULL; 35 } 36 37 /* Callback observers when a stop event occurs. This function will create a 38 new Python stop event object. If only a specific thread is stopped the 39 thread object of the event will be set to that thread. Otherwise, if all 40 threads are stopped thread object will be set to None. 41 return 0 if the event was created and emitted successfully otherwise 42 returns -1. */ 43 44 int 45 emit_stop_event (struct bpstats *bs, enum target_signal stop_signal) 46 { 47 PyObject *stop_event_obj = NULL; /* Appease GCC warning. */ 48 49 if (evregpy_no_listeners_p (gdb_py_events.stop)) 50 return 0; 51 52 if (bs && bs->breakpoint_at 53 && bs->breakpoint_at->py_bp_object) 54 { 55 stop_event_obj = create_breakpoint_event_object ((PyObject *) bs 56 ->breakpoint_at 57 ->py_bp_object); 58 if (!stop_event_obj) 59 goto fail; 60 } 61 62 /* Check if the signal is "Signal 0" or "Trace/breakpoint trap". */ 63 if (stop_signal != TARGET_SIGNAL_0 64 && stop_signal != TARGET_SIGNAL_TRAP) 65 { 66 stop_event_obj = 67 create_signal_event_object (stop_signal); 68 if (!stop_event_obj) 69 goto fail; 70 } 71 72 /* If all fails emit an unknown stop event. All event types should 73 be known and this should eventually be unused. */ 74 if (!stop_event_obj) 75 { 76 stop_event_obj = create_stop_event_object (&stop_event_object_type); 77 if (!stop_event_obj) 78 goto fail; 79 } 80 81 return evpy_emit_event (stop_event_obj, gdb_py_events.stop); 82 83 fail: 84 return -1; 85 } 86 87 GDBPY_NEW_EVENT_TYPE (stop, 88 "gdb.StopEvent", 89 "StopEvent", 90 "GDB stop event object", 91 thread_event_object_type, 92 /*no qual*/); 93