]> Git Repo - binutils.git/blob - gdb/python/py-threadevent.c
Refactor Python "gdb" module into a proper Python package, by introducing
[binutils.git] / gdb / python / py-threadevent.c
1 /* Copyright (C) 2009-2012 Free Software Foundation, Inc.
2
3    This file is part of GDB.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18 #include "py-event.h"
19
20 /* thread events can either be thread specific or process wide.  If gdb is
21    running in non-stop mode then the event is thread specific, otherwise
22    it is process wide.
23    This function returns the currently stopped thread in non-stop mode and
24    Py_None otherwise.  In each case it returns a borrowed reference.  */
25
26 static PyObject *
27 get_event_thread (void)
28 {
29   PyObject *thread = NULL;
30
31   if (non_stop)
32     thread = (PyObject *) find_thread_object (inferior_ptid);
33   else
34     thread = Py_None;
35
36   if (!thread)
37     {
38       PyErr_SetString (PyExc_RuntimeError, "Could not find event thread");
39       return NULL;
40     }
41
42   return thread;
43 }
44
45 PyObject *
46 create_thread_event_object (PyTypeObject *py_type)
47 {
48   PyObject *thread = NULL;
49   PyObject *thread_event_obj = NULL;
50
51   thread_event_obj = create_event_object (py_type);
52   if (!thread_event_obj)
53     goto fail;
54
55   thread = get_event_thread ();
56   if (!thread)
57     goto fail;
58
59   if (evpy_add_attribute (thread_event_obj,
60                           "inferior_thread",
61                           thread) < 0)
62     goto fail;
63
64   return thread_event_obj;
65
66   fail:
67    Py_XDECREF (thread_event_obj);
68    return NULL;
69 }
70
71 GDBPY_NEW_EVENT_TYPE (thread,
72                       "gdb.ThreadEvent",
73                       "ThreadEvent",
74                       "GDB thread event object",
75                       event_object_type,
76                       /*no qual*/);
This page took 0.03285 seconds and 4 git commands to generate.