1 /* Python interface to inferior function events.
3 Copyright (C) 2013-2017 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/>. */
24 /* Construct either a gdb.InferiorCallPreEvent or a
25 gdb.InferiorCallPostEvent. */
28 create_inferior_call_event_object (inferior_call_kind flag
, ptid_t ptid
,
35 case INFERIOR_CALL_PRE
:
36 event
= create_event_object (&inferior_call_pre_event_object_type
);
38 case INFERIOR_CALL_POST
:
39 event
= create_event_object (&inferior_call_post_event_object_type
);
42 gdb_assert_not_reached ("invalid inferior_call_kind");
45 gdbpy_ref
<> ptid_obj (gdbpy_create_ptid_object (ptid
));
49 if (evpy_add_attribute (event
.get (), "ptid", ptid_obj
.get ()) < 0)
52 gdbpy_ref
<> addr_obj (PyLong_FromLongLong (addr
));
56 if (evpy_add_attribute (event
.get (), "address", addr_obj
.get ()) < 0)
59 return event
.release ();
62 /* Construct a gdb.RegisterChangedEvent containing the affected
66 create_register_changed_event_object (struct frame_info
*frame
,
69 gdbpy_ref
<> event (create_event_object (®ister_changed_event_object_type
));
73 gdbpy_ref
<> frame_obj (frame_info_to_frame_object (frame
));
74 if (frame_obj
== NULL
)
77 if (evpy_add_attribute (event
.get (), "frame", frame_obj
.get ()) < 0)
80 gdbpy_ref
<> regnum_obj (PyLong_FromLongLong (regnum
));
81 if (regnum_obj
== NULL
)
84 if (evpy_add_attribute (event
.get (), "regnum", regnum_obj
.get ()) < 0)
87 return event
.release ();
90 /* Construct a gdb.MemoryChangedEvent describing the extent of the
94 create_memory_changed_event_object (CORE_ADDR addr
, ssize_t len
)
96 gdbpy_ref
<> event (create_event_object (&memory_changed_event_object_type
));
101 gdbpy_ref
<> addr_obj (PyLong_FromLongLong (addr
));
102 if (addr_obj
== NULL
)
105 if (evpy_add_attribute (event
.get (), "address", addr_obj
.get ()) < 0)
108 gdbpy_ref
<> len_obj (PyLong_FromLong (len
));
112 if (evpy_add_attribute (event
.get (), "length", len_obj
.get ()) < 0)
115 return event
.release ();
118 /* Callback function which notifies observers when an event occurs which
119 calls a function in the inferior.
120 This function will create a new Python inferior-call event object.
121 Return -1 if emit fails. */
124 emit_inferior_call_event (inferior_call_kind flag
, ptid_t thread
,
127 if (evregpy_no_listeners_p (gdb_py_events
.inferior_call
))
130 gdbpy_ref
<> event (create_inferior_call_event_object (flag
, thread
, addr
));
132 return evpy_emit_event (event
.get (), gdb_py_events
.inferior_call
);
136 /* Callback when memory is modified by the user. This function will
137 create a new Python memory changed event object. */
140 emit_memory_changed_event (CORE_ADDR addr
, ssize_t len
)
142 if (evregpy_no_listeners_p (gdb_py_events
.memory_changed
))
145 gdbpy_ref
<> event (create_memory_changed_event_object (addr
, len
));
147 return evpy_emit_event (event
.get (), gdb_py_events
.memory_changed
);
151 /* Callback when a register is modified by the user. This function
152 will create a new Python register changed event object. */
155 emit_register_changed_event (struct frame_info
* frame
, int regnum
)
157 if (evregpy_no_listeners_p (gdb_py_events
.register_changed
))
160 gdbpy_ref
<> event (create_register_changed_event_object (frame
, regnum
));
162 return evpy_emit_event (event
.get (), gdb_py_events
.register_changed
);