GDB (xrefs)

py-newobjfileevent.c
Go to the documentation of this file.
1 /* Python interface to new object file loading events.
2
3 Copyright (C) 2011-2018 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
23 static PyObject *
24 create_new_objfile_event_object (struct objfile *objfile)
25 {
26 PyObject *py_objfile;
27
28 gdbpy_ref<> objfile_event
29 (create_event_object (&new_objfile_event_object_type));
30 if (objfile_event == NULL)
31 return NULL;
32
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 (),
37 "new_objfile",
38 py_objfile) < 0)
39 return NULL;
40
41 return objfile_event.release ();
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 {
51 if (evregpy_no_listeners_p (gdb_py_events.new_objfile))
52 return 0;
53
54 gdbpy_ref<> event (create_new_objfile_event_object (objfile));
55 if (event != NULL)
56 return evpy_emit_event (event.get (), gdb_py_events.new_objfile);
57 return -1;
58 }
59
60
61 /* Subroutine of emit_clear_objfiles_event to simplify it. */
62
63 static PyObject *
64 create_clear_objfiles_event_object (void)
65 {
66 PyObject *py_progspace;
67
68 gdbpy_ref<> objfile_event
69 (create_event_object (&clear_objfiles_event_object_type));
70 if (objfile_event == NULL)
71 return NULL;
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);
76 if (!py_progspace || evpy_add_attribute (objfile_event.get (),
77 "progspace",
78 py_progspace) < 0)
79 return NULL;
80
81 return objfile_event.release ();
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 {
92 if (evregpy_no_listeners_p (gdb_py_events.clear_objfiles))
93 return 0;
94
95 gdbpy_ref<> event (create_clear_objfiles_event_object ());
96 if (event != NULL)
97 return evpy_emit_event (event.get (), gdb_py_events.clear_objfiles);
98 return -1;
99 }
defs.h
evpy_add_attribute
int evpy_add_attribute(PyObject *event, const char *name, PyObject *attr)
Definition: py-event.c:50
gdb::ref_ptr< T, gdbpy_ref_policy< T > >
objfile_to_objfile_object
PyObject * objfile_to_objfile_object(struct objfile *objfile)
Definition: py-objfile.c:624
create_clear_objfiles_event_object
static PyObject * create_clear_objfiles_event_object(void)
Definition: py-newobjfileevent.c:64
create_new_objfile_event_object
static PyObject * create_new_objfile_event_object(struct objfile *objfile)
Definition: py-newobjfileevent.c:24
emit_clear_objfiles_event
int emit_clear_objfiles_event(void)
Definition: py-newobjfileevent.c:90
gdb_py_events
events_object gdb_py_events
Definition: py-evtregistry.c:25
objfile
Definition: objfiles.h:286
py-event.h
gdb::ref_ptr::release
T * release()
Definition: gdb_ref_ptr.h:138
emit_new_objfile_event
int emit_new_objfile_event(struct objfile *objfile)
Definition: py-newobjfileevent.c:49
gdb::ref_ptr::get
T * get() const
Definition: gdb_ref_ptr.h:130
current_program_space
struct program_space * current_program_space
Definition: progspace.c:35
create_event_object
gdbpy_ref create_event_object(PyTypeObject *py_type)
Definition: py-event.c:31
evpy_emit_event
int evpy_emit_event(PyObject *event, eventregistry_object *registry)
Definition: py-event.c:83
evregpy_no_listeners_p
int evregpy_no_listeners_p(eventregistry_object *registry)
Definition: py-evtregistry.c:120
pspace_to_pspace_object
PyObject * pspace_to_pspace_object(struct program_space *pspace)
Definition: py-progspace.c:346