gdb: bool-ify ext_lang_auto_load_enabled and friends
[deliverable/binutils-gdb.git] / gdb / python / py-stopevent.c
CommitLineData
c17a9e46
HZ
1/* Python interface to inferior stop events.
2
3666a048 3 Copyright (C) 2009-2021 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
d071a26b 20#include "defs.h"
c17a9e46
HZ
21#include "py-stopevent.h"
22
35c61a1d 23gdbpy_ref<>
c17a9e46
HZ
24create_stop_event_object (PyTypeObject *py_type)
25{
db1337cc
TT
26 gdbpy_ref<> thread = py_get_event_thread (inferior_ptid);
27 return create_thread_event_object (py_type, thread.get ());
c17a9e46
HZ
28}
29
30/* Callback observers when a stop event occurs. This function will create a
31 new Python stop event object. If only a specific thread is stopped the
32 thread object of the event will be set to that thread. Otherwise, if all
33 threads are stopped thread object will be set to None.
34 return 0 if the event was created and emitted successfully otherwise
35 returns -1. */
36
37int
2ea28649 38emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
c17a9e46 39{
7780f186
TT
40 gdbpy_ref<> stop_event_obj;
41 gdbpy_ref<> list;
6839b47f
KP
42 PyObject *first_bp = NULL;
43 struct bpstats *current_bs;
c17a9e46
HZ
44
45 if (evregpy_no_listeners_p (gdb_py_events.stop))
46 return 0;
47
6839b47f
KP
48 /* Add any breakpoint set at this location to the list. */
49 for (current_bs = bs; current_bs != NULL; current_bs = current_bs->next)
c17a9e46 50 {
6839b47f 51 if (current_bs->breakpoint_at
dda83cd7
SM
52 && current_bs->breakpoint_at->py_bp_object)
53 {
54 PyObject *current_py_bp =
55 (PyObject *) current_bs->breakpoint_at->py_bp_object;
56
57 if (list == NULL)
58 {
59 list.reset (PyList_New (0));
60 if (list == NULL)
abf5651e 61 return -1;
dda83cd7 62 }
6839b47f 63
dda83cd7 64 if (PyList_Append (list.get (), current_py_bp))
abf5651e 65 return -1;
6839b47f 66
dda83cd7
SM
67 if (first_bp == NULL)
68 first_bp = current_py_bp;
69 }
6839b47f
KP
70 }
71
72 if (list != NULL)
73 {
35c61a1d
TT
74 stop_event_obj = create_breakpoint_event_object (list.get (),
75 first_bp);
abf5651e
TT
76 if (stop_event_obj == NULL)
77 return -1;
c17a9e46
HZ
78 }
79
80 /* Check if the signal is "Signal 0" or "Trace/breakpoint trap". */
a493e3e2
PA
81 if (stop_signal != GDB_SIGNAL_0
82 && stop_signal != GDB_SIGNAL_TRAP)
c17a9e46 83 {
35c61a1d 84 stop_event_obj = create_signal_event_object (stop_signal);
abf5651e
TT
85 if (stop_event_obj == NULL)
86 return -1;
c17a9e46
HZ
87 }
88
89 /* If all fails emit an unknown stop event. All event types should
90 be known and this should eventually be unused. */
abf5651e 91 if (stop_event_obj == NULL)
c17a9e46 92 {
35c61a1d 93 stop_event_obj = create_stop_event_object (&stop_event_object_type);
abf5651e
TT
94 if (stop_event_obj == NULL)
95 return -1;
c17a9e46
HZ
96 }
97
abf5651e 98 return evpy_emit_event (stop_event_obj.get (), gdb_py_events.stop);
c17a9e46 99}
This page took 0.974749 seconds and 4 git commands to generate.