Copyright year update in most files of the GDB Project.
[deliverable/binutils-gdb.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. */
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 Py_INCREF (thread);
43
44 return thread;
45 }
46
47 PyObject *
48 create_thread_event_object (PyTypeObject *py_type)
49 {
50 PyObject *thread = NULL;
51 PyObject *thread_event_obj = NULL;
52
53 thread_event_obj = create_event_object (py_type);
54 if (!thread_event_obj)
55 goto fail;
56
57 thread = get_event_thread ();
58 if (!thread)
59 goto fail;
60
61 if (evpy_add_attribute (thread_event_obj,
62 "inferior_thread",
63 thread) < 0)
64 goto fail;
65
66 return thread_event_obj;
67
68 fail:
69 Py_XDECREF (thread_event_obj);
70 return NULL;
71 }
72
73 GDBPY_NEW_EVENT_TYPE (thread,
74 "gdb.ThreadEvent",
75 "ThreadEvent",
76 "GDB thread event object",
77 event_object_type,
78 /*no qual*/);
This page took 0.035446 seconds and 5 git commands to generate.