1 /* Python interface to inferior function events.
3 Copyright (C) 2013-2020 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
23 /* Construct either a gdb.InferiorCallPreEvent or a
24 gdb.InferiorCallPostEvent. */
27 create_inferior_call_event_object (inferior_call_kind flag
, ptid_t ptid
,
34 case INFERIOR_CALL_PRE
:
35 event
= create_event_object (&inferior_call_pre_event_object_type
);
37 case INFERIOR_CALL_POST
:
38 event
= create_event_object (&inferior_call_post_event_object_type
);
41 gdb_assert_not_reached ("invalid inferior_call_kind");
44 gdbpy_ref
<> ptid_obj (gdbpy_create_ptid_object (ptid
));
48 if (evpy_add_attribute (event
.get (), "ptid", ptid_obj
.get ()) < 0)
51 gdbpy_ref
<> addr_obj (PyLong_FromLongLong (addr
));
55 if (evpy_add_attribute (event
.get (), "address", addr_obj
.get ()) < 0)
61 /* Construct a gdb.RegisterChangedEvent containing the affected
65 create_register_changed_event_object (struct frame_info
*frame
,
68 gdbpy_ref
<> event
= create_event_object (®ister_changed_event_object_type
);
72 gdbpy_ref
<> frame_obj (frame_info_to_frame_object (frame
));
73 if (frame_obj
== NULL
)
76 if (evpy_add_attribute (event
.get (), "frame", frame_obj
.get ()) < 0)
79 gdbpy_ref
<> regnum_obj (PyLong_FromLongLong (regnum
));
80 if (regnum_obj
== NULL
)
83 if (evpy_add_attribute (event
.get (), "regnum", regnum_obj
.get ()) < 0)
89 /* Construct a gdb.MemoryChangedEvent describing the extent of the
93 create_memory_changed_event_object (CORE_ADDR addr
, ssize_t len
)
95 gdbpy_ref
<> event
= create_event_object (&memory_changed_event_object_type
);
100 gdbpy_ref
<> addr_obj (PyLong_FromLongLong (addr
));
101 if (addr_obj
== NULL
)
104 if (evpy_add_attribute (event
.get (), "address", addr_obj
.get ()) < 0)
107 gdbpy_ref
<> len_obj (PyLong_FromLong (len
));
111 if (evpy_add_attribute (event
.get (), "length", len_obj
.get ()) < 0)
117 /* Callback function which notifies observers when an event occurs which
118 calls a function in the inferior.
119 This function will create a new Python inferior-call event object.
120 Return -1 if emit fails. */
123 emit_inferior_call_event (inferior_call_kind flag
, ptid_t thread
,
126 if (evregpy_no_listeners_p (gdb_py_events
.inferior_call
))
129 gdbpy_ref
<> event
= create_inferior_call_event_object (flag
, thread
, addr
);
131 return evpy_emit_event (event
.get (), gdb_py_events
.inferior_call
);
135 /* Callback when memory is modified by the user. This function will
136 create a new Python memory changed event object. */
139 emit_memory_changed_event (CORE_ADDR addr
, ssize_t len
)
141 if (evregpy_no_listeners_p (gdb_py_events
.memory_changed
))
144 gdbpy_ref
<> event
= create_memory_changed_event_object (addr
, len
);
146 return evpy_emit_event (event
.get (), gdb_py_events
.memory_changed
);
150 /* Callback when a register is modified by the user. This function
151 will create a new Python register changed event object. */
154 emit_register_changed_event (struct frame_info
* frame
, int regnum
)
156 if (evregpy_no_listeners_p (gdb_py_events
.register_changed
))
159 gdbpy_ref
<> event
= create_register_changed_event_object (frame
, regnum
);
161 return evpy_emit_event (event
.get (), gdb_py_events
.register_changed
);