Add more methods to gdb.Progspace
[deliverable/binutils-gdb.git] / gdb / python / py-newobjfileevent.c
CommitLineData
01b71697
KP
1/* Python interface to new object file loading events.
2
e2882c85 3 Copyright (C) 2011-2018 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
d98fc15b 23static gdbpy_ref<>
01b71697
KP
24create_new_objfile_event_object (struct objfile *objfile)
25{
7780f186 26 gdbpy_ref<> objfile_event
d98fc15b 27 = create_event_object (&new_objfile_event_object_type);
abf5651e
TT
28 if (objfile_event == NULL)
29 return NULL;
01b71697 30
f1070426
TT
31 /* Note that objfile_to_objfile_object returns a borrowed reference,
32 so we don't need a decref here. */
d98fc15b 33 PyObject *py_objfile = objfile_to_objfile_object (objfile);
abf5651e 34 if (!py_objfile || evpy_add_attribute (objfile_event.get (),
01b71697
KP
35 "new_objfile",
36 py_objfile) < 0)
abf5651e 37 return NULL;
01b71697 38
d98fc15b 39 return objfile_event;
01b71697
KP
40}
41
42/* Callback function which notifies observers when a new objfile event occurs.
43 This function will create a new Python new_objfile event object.
44 Return -1 if emit fails. */
45
46int
47emit_new_objfile_event (struct objfile *objfile)
48{
01b71697
KP
49 if (evregpy_no_listeners_p (gdb_py_events.new_objfile))
50 return 0;
51
d98fc15b 52 gdbpy_ref<> event = create_new_objfile_event_object (objfile);
abf5651e
TT
53 if (event != NULL)
54 return evpy_emit_event (event.get (), gdb_py_events.new_objfile);
01b71697
KP
55 return -1;
56}
57
4ffbba72
DE
58\f
59/* Subroutine of emit_clear_objfiles_event to simplify it. */
60
d98fc15b 61static gdbpy_ref<>
4ffbba72
DE
62create_clear_objfiles_event_object (void)
63{
7780f186 64 gdbpy_ref<> objfile_event
d98fc15b 65 = create_event_object (&clear_objfiles_event_object_type);
abf5651e
TT
66 if (objfile_event == NULL)
67 return NULL;
4ffbba72
DE
68
69 /* Note that pspace_to_pspace_object returns a borrowed reference,
70 so we don't need a decref here. */
d98fc15b 71 PyObject *py_progspace = pspace_to_pspace_object (current_program_space);
abf5651e 72 if (!py_progspace || evpy_add_attribute (objfile_event.get (),
4ffbba72
DE
73 "progspace",
74 py_progspace) < 0)
abf5651e 75 return NULL;
4ffbba72 76
d98fc15b 77 return objfile_event;
4ffbba72
DE
78}
79
80/* Callback function which notifies observers when the "clear objfiles"
81 event occurs.
82 This function will create a new Python clear_objfiles event object.
83 Return -1 if emit fails. */
84
85int
86emit_clear_objfiles_event (void)
87{
4ffbba72
DE
88 if (evregpy_no_listeners_p (gdb_py_events.clear_objfiles))
89 return 0;
90
d98fc15b 91 gdbpy_ref<> event = create_clear_objfiles_event_object ();
abf5651e
TT
92 if (event != NULL)
93 return evpy_emit_event (event.get (), gdb_py_events.clear_objfiles);
4ffbba72
DE
94 return -1;
95}
This page took 0.682945 seconds and 4 git commands to generate.