GDB (API)
|
00001 /* Copyright (C) 2009-2013 Free Software Foundation, Inc. 00002 00003 This file is part of GDB. 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00017 00018 #include "defs.h" 00019 #include "py-event.h" 00020 00021 /* thread events can either be thread specific or process wide. If gdb is 00022 running in non-stop mode then the event is thread specific, otherwise 00023 it is process wide. 00024 This function returns the currently stopped thread in non-stop mode and 00025 Py_None otherwise. In each case it returns a borrowed reference. */ 00026 00027 static PyObject *get_event_thread (void) 00028 CPYCHECKER_RETURNS_BORROWED_REF; 00029 00030 static PyObject * 00031 get_event_thread (void) 00032 { 00033 PyObject *thread = NULL; 00034 00035 if (non_stop) 00036 thread = (PyObject *) find_thread_object (inferior_ptid); 00037 else 00038 thread = Py_None; 00039 00040 if (!thread) 00041 { 00042 PyErr_SetString (PyExc_RuntimeError, "Could not find event thread"); 00043 return NULL; 00044 } 00045 00046 return thread; 00047 } 00048 00049 PyObject * 00050 create_thread_event_object (PyTypeObject *py_type) 00051 { 00052 PyObject *thread = NULL; 00053 PyObject *thread_event_obj = NULL; 00054 00055 thread_event_obj = create_event_object (py_type); 00056 if (!thread_event_obj) 00057 goto fail; 00058 00059 thread = get_event_thread (); 00060 if (!thread) 00061 goto fail; 00062 00063 if (evpy_add_attribute (thread_event_obj, 00064 "inferior_thread", 00065 thread) < 0) 00066 goto fail; 00067 00068 return thread_event_obj; 00069 00070 fail: 00071 Py_XDECREF (thread_event_obj); 00072 return NULL; 00073 } 00074 00075 GDBPY_NEW_EVENT_TYPE (thread, 00076 "gdb.ThreadEvent", 00077 "ThreadEvent", 00078 "GDB thread event object", 00079 event_object_type, 00080 /*no qual*/);