gdb/python/py-newobjfileevent.c - gdb

Functions defined

Source code

  1. /* Python interface to new object file loading events.

  2.    Copyright (C) 2011-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "py-event.h"

  16. static PyTypeObject new_objfile_event_object_type
  17.     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
  18. static PyTypeObject clear_objfiles_event_object_type
  19.     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");

  20. static PyObject *
  21. create_new_objfile_event_object (struct objfile *objfile)
  22. {
  23.   PyObject *objfile_event;
  24.   PyObject *py_objfile;

  25.   objfile_event = create_event_object (&new_objfile_event_object_type);
  26.   if (!objfile_event)
  27.     goto fail;

  28.   /* Note that objfile_to_objfile_object returns a borrowed reference,
  29.      so we don't need a decref here.  */
  30.   py_objfile = objfile_to_objfile_object (objfile);
  31.   if (!py_objfile || evpy_add_attribute (objfile_event,
  32.                                          "new_objfile",
  33.                                          py_objfile) < 0)
  34.     goto fail;

  35.   return objfile_event;

  36. fail:
  37.   Py_XDECREF (objfile_event);
  38.   return NULL;
  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. int
  44. emit_new_objfile_event (struct objfile *objfile)
  45. {
  46.   PyObject *event;

  47.   if (evregpy_no_listeners_p (gdb_py_events.new_objfile))
  48.     return 0;

  49.   event = create_new_objfile_event_object (objfile);
  50.   if (event)
  51.     return evpy_emit_event (event, gdb_py_events.new_objfile);
  52.   return -1;
  53. }

  54. GDBPY_NEW_EVENT_TYPE (new_objfile,
  55.                       "gdb.NewObjFileEvent",
  56.                       "NewObjFileEvent",
  57.                       "GDB new object file event object",
  58.                       event_object_type,
  59.                       static);

  60. /* Subroutine of emit_clear_objfiles_event to simplify it.  */

  61. static PyObject *
  62. create_clear_objfiles_event_object (void)
  63. {
  64.   PyObject *objfile_event;
  65.   PyObject *py_progspace;

  66.   objfile_event = create_event_object (&clear_objfiles_event_object_type);
  67.   if (!objfile_event)
  68.     goto fail;

  69.   /* Note that pspace_to_pspace_object returns a borrowed reference,
  70.      so we don't need a decref here.  */
  71.   py_progspace = pspace_to_pspace_object (current_program_space);
  72.   if (!py_progspace || evpy_add_attribute (objfile_event,
  73.                                            "progspace",
  74.                                            py_progspace) < 0)
  75.     goto fail;

  76.   return objfile_event;

  77. fail:
  78.   Py_XDECREF (objfile_event);
  79.   return NULL;
  80. }

  81. /* Callback function which notifies observers when the "clear objfiles"
  82.    event occurs.
  83.    This function will create a new Python clear_objfiles event object.
  84.    Return -1 if emit fails.  */

  85. int
  86. emit_clear_objfiles_event (void)
  87. {
  88.   PyObject *event;

  89.   if (evregpy_no_listeners_p (gdb_py_events.clear_objfiles))
  90.     return 0;

  91.   event = create_clear_objfiles_event_object ();
  92.   if (event)
  93.     return evpy_emit_event (event, gdb_py_events.clear_objfiles);
  94.   return -1;
  95. }

  96. GDBPY_NEW_EVENT_TYPE (clear_objfiles,
  97.                       "gdb.ClearObjFilesEvent",
  98.                       "ClearObjFilesEvent",
  99.                       "GDB clear object files event object",
  100.                       event_object_type,
  101.                       static);