Commit | Line | Data |
---|---|---|
01b71697 KP |
1 | /* Python interface to new object file loading events. |
2 | ||
61baf725 | 3 | Copyright (C) 2011-2017 Free Software Foundation, Inc. |
01b71697 KP |
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" |
01b71697 KP |
21 | #include "py-event.h" |
22 | ||
49a8461d | 23 | static PyObject * |
01b71697 KP |
24 | create_new_objfile_event_object (struct objfile *objfile) |
25 | { | |
f1070426 | 26 | PyObject *py_objfile; |
01b71697 | 27 | |
7780f186 | 28 | gdbpy_ref<> objfile_event |
abf5651e TT |
29 | (create_event_object (&new_objfile_event_object_type)); |
30 | if (objfile_event == NULL) | |
31 | return NULL; | |
01b71697 | 32 | |
f1070426 TT |
33 | /* Note that objfile_to_objfile_object returns a borrowed reference, |
34 | so we don't need a decref here. */ | |
01b71697 | 35 | py_objfile = objfile_to_objfile_object (objfile); |
abf5651e | 36 | if (!py_objfile || evpy_add_attribute (objfile_event.get (), |
01b71697 KP |
37 | "new_objfile", |
38 | py_objfile) < 0) | |
abf5651e | 39 | return NULL; |
01b71697 | 40 | |
abf5651e | 41 | return objfile_event.release (); |
01b71697 KP |
42 | } |
43 | ||
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. */ | |
47 | ||
48 | int | |
49 | emit_new_objfile_event (struct objfile *objfile) | |
50 | { | |
01b71697 KP |
51 | if (evregpy_no_listeners_p (gdb_py_events.new_objfile)) |
52 | return 0; | |
53 | ||
7780f186 | 54 | gdbpy_ref<> event (create_new_objfile_event_object (objfile)); |
abf5651e TT |
55 | if (event != NULL) |
56 | return evpy_emit_event (event.get (), gdb_py_events.new_objfile); | |
01b71697 KP |
57 | return -1; |
58 | } | |
59 | ||
4ffbba72 DE |
60 | \f |
61 | /* Subroutine of emit_clear_objfiles_event to simplify it. */ | |
62 | ||
63 | static PyObject * | |
64 | create_clear_objfiles_event_object (void) | |
65 | { | |
4ffbba72 DE |
66 | PyObject *py_progspace; |
67 | ||
7780f186 | 68 | gdbpy_ref<> objfile_event |
abf5651e TT |
69 | (create_event_object (&clear_objfiles_event_object_type)); |
70 | if (objfile_event == NULL) | |
71 | return NULL; | |
4ffbba72 DE |
72 | |
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); | |
abf5651e | 76 | if (!py_progspace || evpy_add_attribute (objfile_event.get (), |
4ffbba72 DE |
77 | "progspace", |
78 | py_progspace) < 0) | |
abf5651e | 79 | return NULL; |
4ffbba72 | 80 | |
abf5651e | 81 | return objfile_event.release (); |
4ffbba72 DE |
82 | } |
83 | ||
84 | /* Callback function which notifies observers when the "clear objfiles" | |
85 | event occurs. | |
86 | This function will create a new Python clear_objfiles event object. | |
87 | Return -1 if emit fails. */ | |
88 | ||
89 | int | |
90 | emit_clear_objfiles_event (void) | |
91 | { | |
4ffbba72 DE |
92 | if (evregpy_no_listeners_p (gdb_py_events.clear_objfiles)) |
93 | return 0; | |
94 | ||
7780f186 | 95 | gdbpy_ref<> event (create_clear_objfiles_event_object ()); |
abf5651e TT |
96 | if (event != NULL) |
97 | return evpy_emit_event (event.get (), gdb_py_events.clear_objfiles); | |
4ffbba72 DE |
98 | return -1; |
99 | } |