1 /* Python interface to new object file loading events.
3 Copyright (C) 2011-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 create_new_objfile_event_object (struct objfile *objfile)
28 gdbpy_ref<> objfile_event
29 (create_event_object (&new_objfile_event_object_type));
30 if (objfile_event == NULL)
33 /* Note that objfile_to_objfile_object returns a borrowed reference,
34 so we don't need a decref here. */
35 py_objfile = objfile_to_objfile_object (objfile);
36 if (!py_objfile || evpy_add_attribute (objfile_event.get (),
41 return objfile_event.release ();
44 /* Callback function which notifies observers when a new objfile event occurs.
45 This function will create a new Python new_objfile event object.
46 Return -1 if emit fails. */
49 emit_new_objfile_event (struct objfile *objfile)
51 if (evregpy_no_listeners_p (gdb_py_events.new_objfile))
54 gdbpy_ref<> event (create_new_objfile_event_object (objfile));
56 return evpy_emit_event (event.get (), gdb_py_events.new_objfile);
61 /* Subroutine of emit_clear_objfiles_event to simplify it. */
64 create_clear_objfiles_event_object (void)
66 PyObject *py_progspace;
68 gdbpy_ref<> objfile_event
69 (create_event_object (&clear_objfiles_event_object_type));
70 if (objfile_event == NULL)
73 /* Note that pspace_to_pspace_object returns a borrowed reference,
74 so we don't need a decref here. */
75 py_progspace = pspace_to_pspace_object (current_program_space);
76 if (!py_progspace || evpy_add_attribute (objfile_event.get (),
81 return objfile_event.release ();
84 /* Callback function which notifies observers when the "clear objfiles"
86 This function will create a new Python clear_objfiles event object.
87 Return -1 if emit fails. */
90 emit_clear_objfiles_event (void)
92 if (evregpy_no_listeners_p (gdb_py_events.clear_objfiles))
95 gdbpy_ref<> event (create_clear_objfiles_event_object ());
97 return evpy_emit_event (event.get (), gdb_py_events.clear_objfiles);