1 /* Python interface to inferior function events.
3 Copyright (C) 2013-2016 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 extern PyTypeObject inferior_call_pre_event_object_type
24 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
25 extern PyTypeObject inferior_call_post_event_object_type
26 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
27 extern PyTypeObject register_changed_event_object_type
28 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
29 extern PyTypeObject memory_changed_event_object_type
30 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
32 /* Construct either a gdb.InferiorCallPreEvent or a
33 gdb.InferiorCallPostEvent. */
36 create_inferior_call_event_object (inferior_call_kind flag
, ptid_t ptid
,
40 PyObject
*ptid_obj
= NULL
;
41 PyObject
*addr_obj
= NULL
;
43 struct cleanup
*cleanups
;
44 struct cleanup
*member_cleanups
;
48 case INFERIOR_CALL_PRE
:
49 event
= create_event_object (&inferior_call_pre_event_object_type
);
51 case INFERIOR_CALL_POST
:
52 event
= create_event_object (&inferior_call_post_event_object_type
);
58 cleanups
= make_cleanup_py_decref (event
);
60 ptid_obj
= gdbpy_create_ptid_object (ptid
);
63 member_cleanups
= make_cleanup_py_decref (ptid_obj
);
65 failed
= evpy_add_attribute (event
, "ptid", ptid_obj
) < 0;
69 addr_obj
= PyLong_FromLongLong (addr
);
72 make_cleanup_py_decref (addr_obj
);
74 failed
= evpy_add_attribute (event
, "address", addr_obj
) < 0;
78 do_cleanups (member_cleanups
);
79 discard_cleanups (cleanups
);
83 do_cleanups (cleanups
);
87 /* Construct a gdb.RegisterChangedEvent containing the affected
91 create_register_changed_event_object (struct frame_info
*frame
,
95 PyObject
*frame_obj
= NULL
;
96 PyObject
*regnum_obj
= NULL
;
98 struct cleanup
*cleanups
;
99 struct cleanup
*member_cleanups
;
101 event
= create_event_object (®ister_changed_event_object_type
);
105 cleanups
= make_cleanup_py_decref (event
);
107 frame_obj
= frame_info_to_frame_object (frame
);
108 if (frame_obj
== NULL
)
110 member_cleanups
= make_cleanup_py_decref (frame_obj
);
112 failed
= evpy_add_attribute (event
, "frame", frame_obj
) < 0;
116 regnum_obj
= PyLong_FromLongLong (regnum
);
117 if (regnum_obj
== NULL
)
119 make_cleanup_py_decref (regnum_obj
);
121 failed
= evpy_add_attribute (event
, "regnum", regnum_obj
) < 0;
125 do_cleanups (member_cleanups
);
126 discard_cleanups (cleanups
);
130 do_cleanups (cleanups
);
134 /* Construct a gdb.MemoryChangedEvent describing the extent of the
138 create_memory_changed_event_object (CORE_ADDR addr
, ssize_t len
)
141 PyObject
*addr_obj
= NULL
;
142 PyObject
*len_obj
= NULL
;
144 struct cleanup
*cleanups
;
145 struct cleanup
*member_cleanups
;
147 event
= create_event_object (&memory_changed_event_object_type
);
151 cleanups
= make_cleanup_py_decref (event
);
153 addr_obj
= PyLong_FromLongLong (addr
);
154 if (addr_obj
== NULL
)
156 member_cleanups
= make_cleanup_py_decref (addr_obj
);
158 failed
= evpy_add_attribute (event
, "address", addr_obj
) < 0;
162 len_obj
= PyLong_FromLong (len
);
165 make_cleanup_py_decref (len_obj
);
167 failed
= evpy_add_attribute (event
, "length", len_obj
) < 0;
171 do_cleanups (member_cleanups
);
172 discard_cleanups (cleanups
);
176 do_cleanups (cleanups
);
180 /* Callback function which notifies observers when an event occurs which
181 calls a function in the inferior.
182 This function will create a new Python inferior-call event object.
183 Return -1 if emit fails. */
186 emit_inferior_call_event (inferior_call_kind flag
, ptid_t thread
,
191 if (evregpy_no_listeners_p (gdb_py_events
.inferior_call
))
194 event
= create_inferior_call_event_object (flag
, thread
, addr
);
196 return evpy_emit_event (event
, gdb_py_events
.inferior_call
);
200 /* Callback when memory is modified by the user. This function will
201 create a new Python memory changed event object. */
204 emit_memory_changed_event (CORE_ADDR addr
, ssize_t len
)
208 if (evregpy_no_listeners_p (gdb_py_events
.memory_changed
))
211 event
= create_memory_changed_event_object (addr
, len
);
213 return evpy_emit_event (event
, gdb_py_events
.memory_changed
);
217 /* Callback when a register is modified by the user. This function
218 will create a new Python register changed event object. */
221 emit_register_changed_event (struct frame_info
* frame
, int regnum
)
225 if (evregpy_no_listeners_p (gdb_py_events
.register_changed
))
228 event
= create_register_changed_event_object (frame
, regnum
);
230 return evpy_emit_event (event
, gdb_py_events
.register_changed
);
235 GDBPY_NEW_EVENT_TYPE (inferior_call_pre
,
236 "gdb.InferiorCallPreEvent",
237 "InferiorCallPreEvent",
238 "GDB inferior function pre-call event object",
241 GDBPY_NEW_EVENT_TYPE (inferior_call_post
,
242 "gdb.InferiorCallPostEvent",
243 "InferiorCallPostEvent",
244 "GDB inferior function post-call event object",
247 GDBPY_NEW_EVENT_TYPE (register_changed
,
248 "gdb.RegisterChangedEvent",
249 "RegisterChangedEvent",
250 "GDB register change event object",
253 GDBPY_NEW_EVENT_TYPE (memory_changed
,
254 "gdb.MemoryChangedEvent",
255 "MemoryChangedEvent",
256 "GDB memory change event object",