py-evts.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Python interface to inferior events.
  2. Copyright (C) 2009-2022 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. static struct PyModuleDef EventModuleDef =
  17. {
  18. PyModuleDef_HEAD_INIT,
  19. "gdb.events",
  20. NULL,
  21. -1,
  22. NULL,
  23. NULL,
  24. NULL,
  25. NULL,
  26. NULL
  27. };
  28. /* Initialize python events. */
  29. static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
  30. add_new_registry (eventregistry_object **registryp, const char *name)
  31. {
  32. *registryp = create_eventregistry_object ();
  33. if (*registryp == NULL)
  34. return -1;
  35. return gdb_pymodule_addobject (gdb_py_events.module,
  36. name,
  37. (PyObject *)(*registryp));
  38. }
  39. int
  40. gdbpy_initialize_py_events (void)
  41. {
  42. gdb_py_events.module = PyModule_Create (&EventModuleDef);
  43. if (!gdb_py_events.module)
  44. return -1;
  45. #define GDB_PY_DEFINE_EVENT(name) \
  46. if (add_new_registry (&gdb_py_events.name, #name) < 0) \
  47. return -1;
  48. #include "py-all-events.def"
  49. #undef GDB_PY_DEFINE_EVENT
  50. if (gdb_pymodule_addobject (gdb_module,
  51. "events",
  52. (PyObject *) gdb_py_events.module) < 0)
  53. return -1;
  54. return 0;
  55. }