gdb/python/py-evts.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Python interface to inferior events.

  2.    Copyright (C) 2009-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-events.h"

  16. #ifdef IS_PY3K
  17. static struct PyModuleDef EventModuleDef =
  18. {
  19.   PyModuleDef_HEAD_INIT,
  20.   "gdb.events",
  21.   NULL,
  22.   -1,
  23.   NULL,
  24.   NULL,
  25.   NULL,
  26.   NULL,
  27.   NULL
  28. };
  29. #endif

  30. /* Initialize python events.  */

  31. static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
  32. add_new_registry (eventregistry_object **registryp, char *name)
  33. {
  34.   int result;

  35.   *registryp = create_eventregistry_object ();

  36.   if (*registryp == NULL)
  37.     return -1;

  38.   return gdb_pymodule_addobject (gdb_py_events.module,
  39.                                  name,
  40.                                  (PyObject *)(*registryp));
  41. }

  42. int
  43. gdbpy_initialize_py_events (void)
  44. {
  45. #ifdef IS_PY3K
  46.   gdb_py_events.module = PyModule_Create (&EventModuleDef);
  47. #else
  48.   gdb_py_events.module = Py_InitModule ("events", NULL);
  49. #endif

  50.   if (!gdb_py_events.module)
  51.     return -1;

  52.   if (add_new_registry (&gdb_py_events.stop, "stop") < 0)
  53.     return -1;

  54.   if (add_new_registry (&gdb_py_events.cont, "cont") < 0)
  55.     return -1;

  56.   if (add_new_registry (&gdb_py_events.exited, "exited") < 0)
  57.     return -1;

  58.   if (add_new_registry (&gdb_py_events.inferior_call,
  59.                         "inferior_call") < 0)
  60.     return -1;

  61.   if (add_new_registry (&gdb_py_events.memory_changed,
  62.                         "memory_changed") < 0)
  63.     return -1;

  64.   if (add_new_registry (&gdb_py_events.register_changed,
  65.                         "register_changed") < 0)
  66.     return -1;

  67.   if (add_new_registry (&gdb_py_events.new_objfile, "new_objfile") < 0)
  68.     return -1;

  69.   if (add_new_registry (&gdb_py_events.clear_objfiles, "clear_objfiles") < 0)
  70.     return -1;

  71.   if (gdb_pymodule_addobject (gdb_module,
  72.                               "events",
  73.                               (PyObject *) gdb_py_events.module) < 0)
  74.     return -1;

  75.   return 0;
  76. }