GDB (xrefs)
Loading...
Searching...
No Matches
py-newobjfileevent.c
Go to the documentation of this file.
1/* Python interface to new object file loading events.
2
3 Copyright (C) 2011-2023 Free Software Foundation, Inc.
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
20#include "defs.h"
21#include "py-event.h"
22
23static gdbpy_ref<>
25{
26 gdbpy_ref<> objfile_event
27 = create_event_object (&new_objfile_event_object_type);
28 if (objfile_event == NULL)
29 return NULL;
30
32 if (py_objfile == NULL || evpy_add_attribute (objfile_event.get (),
33 "new_objfile",
34 py_objfile.get ()) < 0)
35 return NULL;
36
37 return objfile_event;
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
46{
47 if (evregpy_no_listeners_p (gdb_py_events.new_objfile))
48 return 0;
49
51 if (event != NULL)
52 return evpy_emit_event (event.get (), gdb_py_events.new_objfile);
53 return -1;
54}
55
56/* Create an event object representing a to-be-freed objfile. Return
57 nullptr, with the Python exception set, on error. */
58
59static gdbpy_ref<>
61{
62 gdbpy_ref<> objfile_event
63 = create_event_object (&free_objfile_event_object_type);
64 if (objfile_event == nullptr)
65 return nullptr;
66
68 if (py_objfile == nullptr
69 || evpy_add_attribute (objfile_event.get (), "objfile",
70 py_objfile.get ()) < 0)
71 return nullptr;
72
73 return objfile_event;
74}
75
76/* Callback function which notifies observers when a free objfile
77 event occurs. This function will create a new Python event object.
78 Return -1 if emit fails. */
79
80int
82{
83 if (evregpy_no_listeners_p (gdb_py_events.free_objfile))
84 return 0;
85
87 if (event == nullptr)
88 return -1;
89 return evpy_emit_event (event.get (), gdb_py_events.free_objfile);
90}
91
92
93/* Subroutine of emit_clear_objfiles_event to simplify it. */
94
95static gdbpy_ref<>
97{
98 gdbpy_ref<> objfile_event
99 = create_event_object (&clear_objfiles_event_object_type);
100 if (objfile_event == NULL)
101 return NULL;
102
103 gdbpy_ref<> py_progspace = pspace_to_pspace_object (pspace);
104 if (py_progspace == NULL || evpy_add_attribute (objfile_event.get (),
105 "progspace",
106 py_progspace.get ()) < 0)
107 return NULL;
108
109 return objfile_event;
110}
111
112/* Callback function which notifies observers when the "clear objfiles"
113 event occurs.
114 This function will create a new Python clear_objfiles event object.
115 Return -1 if emit fails. */
116
117int
119{
120 if (evregpy_no_listeners_p (gdb_py_events.clear_objfiles))
121 return 0;
122
124 if (event != NULL)
125 return evpy_emit_event (event.get (), gdb_py_events.clear_objfiles);
126 return -1;
127}
gdbpy_ref create_event_object(PyTypeObject *py_type)
Definition py-event.c:31
int evpy_add_attribute(PyObject *event, const char *name, PyObject *attr)
Definition py-event.c:50
int evpy_emit_event(PyObject *event, eventregistry_object *registry)
Definition py-event.c:83
events_object gdb_py_events
bool evregpy_no_listeners_p(eventregistry_object *registry)
static gdbpy_ref create_new_objfile_event_object(struct objfile *objfile)
int emit_clear_objfiles_event(program_space *pspace)
static gdbpy_ref create_clear_objfiles_event_object(program_space *pspace)
int emit_new_objfile_event(struct objfile *objfile)
static gdbpy_ref create_free_objfile_event_object(struct objfile *objfile)
int emit_free_objfile_event(struct objfile *objfile)
gdbpy_ref objfile_to_objfile_object(struct objfile *objfile)
Definition py-objfile.c:686
gdbpy_ref pspace_to_pspace_object(struct program_space *pspace)
gdb::ref_ptr< T, gdbpy_ref_policy< T > > gdbpy_ref
Definition py-ref.h:42