Enable readline in Python in a GDB-specific way and block the
[deliverable/binutils-gdb.git] / gdb / python / py-stopevent.c
CommitLineData
c17a9e46
HZ
1/* Python interface to inferior stop events.
2
0b302171 3 Copyright (C) 2009-2012 Free Software Foundation, Inc.
c17a9e46
HZ
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "py-stopevent.h"
21
22PyObject *
23create_stop_event_object (PyTypeObject *py_type)
24{
25 PyObject *stop_event_obj = create_thread_event_object (py_type);
26
27 if (!stop_event_obj)
28 goto fail;
29
30 return stop_event_obj;
31
32 fail:
33 Py_XDECREF (stop_event_obj);
34 return NULL;
35}
36
37/* Callback observers when a stop event occurs. This function will create a
38 new Python stop event object. If only a specific thread is stopped the
39 thread object of the event will be set to that thread. Otherwise, if all
40 threads are stopped thread object will be set to None.
41 return 0 if the event was created and emitted successfully otherwise
42 returns -1. */
43
44int
2ea28649 45emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
c17a9e46
HZ
46{
47 PyObject *stop_event_obj = NULL; /* Appease GCC warning. */
6839b47f
KP
48 PyObject *list = NULL;
49 PyObject *first_bp = NULL;
50 struct bpstats *current_bs;
c17a9e46
HZ
51
52 if (evregpy_no_listeners_p (gdb_py_events.stop))
53 return 0;
54
6839b47f
KP
55 /* Add any breakpoint set at this location to the list. */
56 for (current_bs = bs; current_bs != NULL; current_bs = current_bs->next)
c17a9e46 57 {
6839b47f
KP
58 if (current_bs->breakpoint_at
59 && current_bs->breakpoint_at->py_bp_object)
60 {
61 PyObject *current_py_bp =
62 (PyObject *) current_bs->breakpoint_at->py_bp_object;
63
64 if (list == NULL)
65 {
66 list = PyList_New (0);
67 if (!list)
68 goto fail;
69 }
70
71 if (PyList_Append (list, current_py_bp))
72 goto fail;
73
74 if (first_bp == NULL)
75 first_bp = current_py_bp;
76 }
77 }
78
79 if (list != NULL)
80 {
81 stop_event_obj = create_breakpoint_event_object (list, first_bp);
c17a9e46 82 if (!stop_event_obj)
6839b47f 83 goto fail;
db6573d6 84 Py_DECREF (list);
c17a9e46
HZ
85 }
86
87 /* Check if the signal is "Signal 0" or "Trace/breakpoint trap". */
a493e3e2
PA
88 if (stop_signal != GDB_SIGNAL_0
89 && stop_signal != GDB_SIGNAL_TRAP)
c17a9e46
HZ
90 {
91 stop_event_obj =
92 create_signal_event_object (stop_signal);
93 if (!stop_event_obj)
94 goto fail;
95 }
96
97 /* If all fails emit an unknown stop event. All event types should
98 be known and this should eventually be unused. */
99 if (!stop_event_obj)
100 {
101 stop_event_obj = create_stop_event_object (&stop_event_object_type);
102 if (!stop_event_obj)
6839b47f 103 goto fail;
c17a9e46
HZ
104 }
105
106 return evpy_emit_event (stop_event_obj, gdb_py_events.stop);
107
6839b47f
KP
108 fail:
109 Py_XDECREF (list);
110 return -1;
c17a9e46
HZ
111}
112
113GDBPY_NEW_EVENT_TYPE (stop,
114 "gdb.StopEvent",
115 "StopEvent",
116 "GDB stop event object",
117 thread_event_object_type,
118 /*no qual*/);
This page took 0.187185 seconds and 4 git commands to generate.