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 *
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
50 {
51  if (evregpy_no_listeners_p (gdb_py_events.new_objfile))
52  return 0;
53 
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 *
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. */
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
91 {
92  if (evregpy_no_listeners_p (gdb_py_events.clear_objfiles))
93  return 0;
94 
96  if (event != NULL)
97  return evpy_emit_event (event.get (), gdb_py_events.clear_objfiles);
98  return -1;
99 }
int evpy_add_attribute(PyObject *event, const char *name, PyObject *attr)
Definition: py-event.c:50
PyObject * objfile_to_objfile_object(struct objfile *objfile)
Definition: py-objfile.c:624
static PyObject * create_clear_objfiles_event_object(void)
static PyObject * create_new_objfile_event_object(struct objfile *objfile)
int emit_clear_objfiles_event(void)
events_object gdb_py_events
int emit_new_objfile_event(struct objfile *objfile)
T * get() const
Definition: gdb_ref_ptr.h:130
struct program_space * current_program_space
Definition: progspace.c:35
gdbpy_ref create_event_object(PyTypeObject *py_type)
Definition: py-event.c:31
int evpy_emit_event(PyObject *event, eventregistry_object *registry)
Definition: py-event.c:83
int evregpy_no_listeners_p(eventregistry_object *registry)
PyObject * pspace_to_pspace_object(struct program_space *pspace)
Definition: py-progspace.c:346