gdb: bool-ify ext_lang_auto_load_enabled and friends
[deliverable/binutils-gdb.git] / gdb / python / py-newobjfileevent.c
CommitLineData
01b71697
KP
1/* Python interface to new object file loading events.
2
3666a048 3 Copyright (C) 2011-2021 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
0a9db5ad
TT
31 gdbpy_ref<> py_objfile = objfile_to_objfile_object (objfile);
32 if (py_objfile == NULL || evpy_add_attribute (objfile_event.get (),
33 "new_objfile",
34 py_objfile.get ()) < 0)
abf5651e 35 return NULL;
01b71697 36
d98fc15b 37 return objfile_event;
01b71697
KP
38}
39
40/* Callback function which notifies observers when a new objfile event occurs.
41 This function will create a new Python new_objfile event object.
42 Return -1 if emit fails. */
43
44int
45emit_new_objfile_event (struct objfile *objfile)
46{
01b71697
KP
47 if (evregpy_no_listeners_p (gdb_py_events.new_objfile))
48 return 0;
49
d98fc15b 50 gdbpy_ref<> event = create_new_objfile_event_object (objfile);
abf5651e
TT
51 if (event != NULL)
52 return evpy_emit_event (event.get (), gdb_py_events.new_objfile);
01b71697
KP
53 return -1;
54}
55
4ffbba72
DE
56\f
57/* Subroutine of emit_clear_objfiles_event to simplify it. */
58
d98fc15b 59static gdbpy_ref<>
4ffbba72
DE
60create_clear_objfiles_event_object (void)
61{
7780f186 62 gdbpy_ref<> objfile_event
d98fc15b 63 = create_event_object (&clear_objfiles_event_object_type);
abf5651e
TT
64 if (objfile_event == NULL)
65 return NULL;
4ffbba72 66
3c7aa307
TT
67 gdbpy_ref<> py_progspace = pspace_to_pspace_object (current_program_space);
68 if (py_progspace == NULL || evpy_add_attribute (objfile_event.get (),
69 "progspace",
70 py_progspace.get ()) < 0)
abf5651e 71 return NULL;
4ffbba72 72
d98fc15b 73 return objfile_event;
4ffbba72
DE
74}
75
76/* Callback function which notifies observers when the "clear objfiles"
77 event occurs.
78 This function will create a new Python clear_objfiles event object.
79 Return -1 if emit fails. */
80
81int
82emit_clear_objfiles_event (void)
83{
4ffbba72
DE
84 if (evregpy_no_listeners_p (gdb_py_events.clear_objfiles))
85 return 0;
86
d98fc15b 87 gdbpy_ref<> event = create_clear_objfiles_event_object ();
abf5651e
TT
88 if (event != NULL)
89 return evpy_emit_event (event.get (), gdb_py_events.clear_objfiles);
4ffbba72
DE
90 return -1;
91}
This page took 0.977179 seconds and 4 git commands to generate.