GDB (API)
|
00001 /* Python interface to inferior exit events. 00002 00003 Copyright (C) 2009-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include "py-event.h" 00022 00023 static PyTypeObject exited_event_object_type 00024 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object"); 00025 00026 static PyObject * 00027 create_exited_event_object (const LONGEST *exit_code, struct inferior *inf) 00028 { 00029 PyObject *exited_event; 00030 PyObject *inf_obj = NULL; 00031 00032 exited_event = create_event_object (&exited_event_object_type); 00033 00034 if (!exited_event) 00035 goto fail; 00036 00037 if (exit_code) 00038 { 00039 PyObject *exit_code_obj = PyLong_FromLongLong (*exit_code); 00040 int failed; 00041 00042 if (exit_code_obj == NULL) 00043 goto fail; 00044 00045 failed = evpy_add_attribute (exited_event, "exit_code", 00046 exit_code_obj) < 0; 00047 Py_DECREF (exit_code_obj); 00048 if (failed) 00049 goto fail; 00050 } 00051 00052 inf_obj = inferior_to_inferior_object (inf); 00053 if (!inf_obj || evpy_add_attribute (exited_event, 00054 "inferior", 00055 inf_obj) < 0) 00056 goto fail; 00057 Py_DECREF (inf_obj); 00058 00059 return exited_event; 00060 00061 fail: 00062 Py_XDECREF (inf_obj); 00063 Py_XDECREF (exited_event); 00064 return NULL; 00065 } 00066 00067 /* Callback that is used when an exit event occurs. This function 00068 will create a new Python exited event object. */ 00069 00070 int 00071 emit_exited_event (const LONGEST *exit_code, struct inferior *inf) 00072 { 00073 PyObject *event; 00074 00075 if (evregpy_no_listeners_p (gdb_py_events.exited)) 00076 return 0; 00077 00078 event = create_exited_event_object (exit_code, inf); 00079 00080 if (event) 00081 return evpy_emit_event (event, gdb_py_events.exited); 00082 00083 return -1; 00084 } 00085 00086 00087 GDBPY_NEW_EVENT_TYPE (exited, 00088 "gdb.ExitedEvent", 00089 "ExitedEvent", 00090 "GDB exited event object", 00091 event_object_type, 00092 static);