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