Make it simpler to add events to Python
authorTom Tromey <tom@tromey.com>
Fri, 8 Sep 2017 21:38:12 +0000 (15:38 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 11 Sep 2017 20:15:22 +0000 (14:15 -0600)
The first patch in this series went through several iterations as I'd
forgotten how many places had to be touched to add a new event and a
new event type.

This patch simplifies the process using two new ".def" files.  Now, a
new event type can be added by adding a line to "py-event-types.def",
and a new event registry can be added by adding a line to
"py-all-events.def".

ChangeLog
2017-09-11  Tom Tromey  <tom@tromey.com>

* python/python.c (do_start_initialization): Use
py-event-types.def to initialize types.
Define all object type structures.
* python/python-internal.h: Don't declare event initialization
functions.
* python/py-threadevent.c (thread_event_object_type): Don't
define.
* python/py-stopevent.c (stop_event_object_type): Don't define.
* python/py-signalevent.c (signal_event_object_type): Don't
declare or define.
* python/py-newobjfileevent.c (new_objfile_event_object_type)
(clear_objfiles_event_object_type): Don't declare or define.
* python/py-infevents.c (inferior_call_pre_event_object_type)
(inferior_call_post_event_object_type)
(register_changed_event_object_type)
(memory_changed_event_object_type): Don't declare or define.
* python/py-inferior.c (new_thread_event_object_type)
(new_inferior_event_object_type)
(inferior_deleted_event_object_type): Don't declare or define.
* python/py-exitedevent.c (exited_event_object_type): Don't
declare or define.
* python/py-evts.c (gdbpy_initialize_py_events): Use
py-all-events.def.
* python/py-events.h (thread_event_object_type): Don't declare.
(events_object): Use py-all-events.def.
* python/py-event.h (GDBPY_NEW_EVENT_TYPE): Remove.  Use
py-event-types.def.
* python/py-event-types.def: New file.
* python/py-continueevent.c (create_continue_event_object): Don't
declare or define.
* python/py-bpevent.c (breakpoint_event_object_type): Don't
declare or define.
* python/py-all-events.def: New file.

17 files changed:
gdb/ChangeLog
gdb/python/py-all-events.def [new file with mode: 0644]
gdb/python/py-bpevent.c
gdb/python/py-continueevent.c
gdb/python/py-event-types.def [new file with mode: 0644]
gdb/python/py-event.h
gdb/python/py-events.h
gdb/python/py-evts.c
gdb/python/py-exitedevent.c
gdb/python/py-inferior.c
gdb/python/py-infevents.c
gdb/python/py-newobjfileevent.c
gdb/python/py-signalevent.c
gdb/python/py-stopevent.c
gdb/python/py-threadevent.c
gdb/python/python-internal.h
gdb/python/python.c

index 61fb77efe9bcf0580d46a2869a31aeeb7bde7593..fa94de422883470a1e9a163e2a12f3536718e177 100644 (file)
@@ -1,3 +1,39 @@
+2017-09-11  Tom Tromey  <tom@tromey.com>
+
+       * python/python.c (do_start_initialization): Use
+       py-event-types.def to initialize types.
+       Define all object type structures.
+       * python/python-internal.h: Don't declare event initialization
+       functions.
+       * python/py-threadevent.c (thread_event_object_type): Don't
+       define.
+       * python/py-stopevent.c (stop_event_object_type): Don't define.
+       * python/py-signalevent.c (signal_event_object_type): Don't
+       declare or define.
+       * python/py-newobjfileevent.c (new_objfile_event_object_type)
+       (clear_objfiles_event_object_type): Don't declare or define.
+       * python/py-infevents.c (inferior_call_pre_event_object_type)
+       (inferior_call_post_event_object_type)
+       (register_changed_event_object_type)
+       (memory_changed_event_object_type): Don't declare or define.
+       * python/py-inferior.c (new_thread_event_object_type)
+       (new_inferior_event_object_type)
+       (inferior_deleted_event_object_type): Don't declare or define.
+       * python/py-exitedevent.c (exited_event_object_type): Don't
+       declare or define.
+       * python/py-evts.c (gdbpy_initialize_py_events): Use
+       py-all-events.def.
+       * python/py-events.h (thread_event_object_type): Don't declare.
+       (events_object): Use py-all-events.def.
+       * python/py-event.h (GDBPY_NEW_EVENT_TYPE): Remove.  Use
+       py-event-types.def.
+       * python/py-event-types.def: New file.
+       * python/py-continueevent.c (create_continue_event_object): Don't
+       declare or define.
+       * python/py-bpevent.c (breakpoint_event_object_type): Don't
+       declare or define.
+       * python/py-all-events.def: New file.
+
 2017-09-11  Tom Tromey  <tom@tromey.com>
 
        * python/py-threadevent.c (create_thread_event_object): Return
diff --git a/gdb/python/py-all-events.def b/gdb/python/py-all-events.def
new file mode 100644 (file)
index 0000000..cdede6b
--- /dev/null
@@ -0,0 +1,40 @@
+/* Python event definitions -*- c++ -*-
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* To use this file, define GDB_PY_DEFINE_EVENT to expand how you
+   like, then include the file.
+
+   GDB_PY_DEFINE_EVENT has one parameter, the name of the event.
+*/
+
+GDB_PY_DEFINE_EVENT(stop)
+GDB_PY_DEFINE_EVENT(cont)
+GDB_PY_DEFINE_EVENT(exited)
+GDB_PY_DEFINE_EVENT(new_objfile)
+GDB_PY_DEFINE_EVENT(clear_objfiles)
+GDB_PY_DEFINE_EVENT(new_inferior)
+GDB_PY_DEFINE_EVENT(inferior_deleted)
+GDB_PY_DEFINE_EVENT(new_thread)
+GDB_PY_DEFINE_EVENT(inferior_call)
+GDB_PY_DEFINE_EVENT(memory_changed)
+GDB_PY_DEFINE_EVENT(register_changed)
+GDB_PY_DEFINE_EVENT(breakpoint_created)
+GDB_PY_DEFINE_EVENT(breakpoint_deleted)
+GDB_PY_DEFINE_EVENT(breakpoint_modified)
+GDB_PY_DEFINE_EVENT(before_prompt)
index 021c83aff9236d5577e46cbd770a304db2143ae2..1cb3f9a45ca624691947bdcfe8cb50845e9506d8 100644 (file)
@@ -21,9 +21,6 @@
 #include "py-stopevent.h"
 #include "py-ref.h"
 
-extern PyTypeObject breakpoint_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-
 /* Create and initialize a BreakpointEvent object.  This acquires new
    references to BREAKPOINT_LIST and FIRST_BP.  */
 
@@ -47,9 +44,3 @@ create_breakpoint_event_object (PyObject *breakpoint_list, PyObject *first_bp)
 
   return breakpoint_event_obj;
 }
-
-GDBPY_NEW_EVENT_TYPE (breakpoint,
-                      "gdb.BreakpointEvent",
-                      "BreakpointEvent",
-                      "GDB breakpoint stop event object",
-                      stop_event_object_type);
index ca2927fcf35a4fe02ed31d23ac44b701c1f2937f..8c704b930f32135c89b4ec886e324732ac641d32 100644 (file)
@@ -21,9 +21,6 @@
 #include "py-event.h"
 #include "py-ref.h"
 
-extern PyTypeObject continue_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-
 static gdbpy_ref<>
 create_continue_event_object (void)
 {
@@ -45,9 +42,3 @@ emit_continue_event (ptid_t ptid)
     return evpy_emit_event (event.get (), gdb_py_events.cont);
   return -1;
 }
-
-GDBPY_NEW_EVENT_TYPE (continue,
-                      "gdb.ContinueEvent",
-                      "ContinueEvent",
-                      "GDB continue event object",
-                      thread_event_object_type);
diff --git a/gdb/python/py-event-types.def b/gdb/python/py-event-types.def
new file mode 100644 (file)
index 0000000..f571f66
--- /dev/null
@@ -0,0 +1,107 @@
+/* Python event definitions -*- c++ -*-
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* To use this file, define GDB_PY_DEFINE_EVENT_TYPE to expand how you
+   like, then include the file.
+
+   Each invocation is of the form:
+
+   GDB_PY_DEFINE_EVENT_TYPE(name, py_name, doc, base)
+
+   NAME is the name of the event.
+   PY_NAME a string representing what the event should be called in
+   python.
+   DOC Python documentation for the new event type
+   BASE the base event for this event usually just event_object_type.
+*/
+
+GDB_PY_DEFINE_EVENT_TYPE (breakpoint,
+                         "BreakpointEvent",
+                         "GDB breakpoint stop event object",
+                         stop_event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (continue,
+                         "ContinueEvent",
+                         "GDB continue event object",
+                         thread_event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (exited,
+                         "ExitedEvent",
+                         "GDB exited event object",
+                         event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (new_thread,
+                         "NewThreadEvent",
+                         "GDB new thread event object",
+                         thread_event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (new_inferior,
+                         "NewInferiorEvent",
+                         "GDB new inferior event object",
+                         event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (inferior_deleted,
+                         "InferiorDeletedEvent",
+                         "GDB inferior deleted event object",
+                         event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (inferior_call_pre,
+                         "InferiorCallPreEvent",
+                         "GDB inferior function pre-call event object",
+                         event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (inferior_call_post,
+                         "InferiorCallPostEvent",
+                         "GDB inferior function post-call event object",
+                         event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (register_changed,
+                         "RegisterChangedEvent",
+                         "GDB register change event object",
+                         event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (memory_changed,
+                         "MemoryChangedEvent",
+                         "GDB memory change event object",
+                         event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (new_objfile,
+                         "NewObjFileEvent",
+                         "GDB new object file event object",
+                         event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (clear_objfiles,
+                         "ClearObjFilesEvent",
+                         "GDB clear object files event object",
+                         event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (signal,
+                         "SignalEvent",
+                         "GDB signal event object",
+                         stop_event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (stop,
+                         "StopEvent",
+                         "GDB stop event object",
+                         thread_event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (thread,
+                         "ThreadEvent",
+                         "GDB thread event object",
+                         event_object_type);
index 27db8287bb5839e11913410bb3730ec19fe6c3b3..2444260865351cf8bc51d6c73fa3cb9fb650222c 100644 (file)
 #include "inferior.h"
 #include "py-ref.h"
 
-/* This macro creates the following functions:
-
-     gdbpy_initialize_{NAME}_event
-     Used to add the newly created event type to the gdb module.
-
-   and the python type data structure for the event:
-
-     struct PyTypeObject {NAME}_event_object_type
-
-  NAME is the name of the event.
-  PY_PATH is a string representing the module and python name of
-    the event.
-  PY_NAME a string representing what the event should be called in
-    python.
-  DOC Python documentation for the new event type
-  BASE the base event for this event usually just event_object_type.
-*/
-
-#define GDBPY_NEW_EVENT_TYPE(name, py_path, py_name, doc, base) \
-\
-  PyTypeObject name##_event_object_type                    \
-        CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object") \
-    = { \
-      PyVarObject_HEAD_INIT (NULL, 0)                          \
-      py_path,                                    /* tp_name */ \
-      sizeof (event_object),                      /* tp_basicsize */ \
-      0,                                          /* tp_itemsize */ \
-      evpy_dealloc,                               /* tp_dealloc */ \
-      0,                                          /* tp_print */ \
-      0,                                          /* tp_getattr */ \
-      0,                                          /* tp_setattr */ \
-      0,                                          /* tp_compare */ \
-      0,                                          /* tp_repr */ \
-      0,                                          /* tp_as_number */ \
-      0,                                          /* tp_as_sequence */ \
-      0,                                          /* tp_as_mapping */ \
-      0,                                          /* tp_hash  */ \
-      0,                                          /* tp_call */ \
-      0,                                          /* tp_str */ \
-      0,                                          /* tp_getattro */ \
-      0,                                          /* tp_setattro */ \
-      0,                                          /* tp_as_buffer */ \
-      Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,   /* tp_flags */ \
-      doc,                                        /* tp_doc */ \
-      0,                                          /* tp_traverse */ \
-      0,                                          /* tp_clear */ \
-      0,                                          /* tp_richcompare */ \
-      0,                                          /* tp_weaklistoffset */ \
-      0,                                          /* tp_iter */ \
-      0,                                          /* tp_iternext */ \
-      0,                                          /* tp_methods */ \
-      0,                                          /* tp_members */ \
-      0,                                          /* tp_getset */ \
-      &base,                                      /* tp_base */ \
-      0,                                          /* tp_dict */ \
-      0,                                          /* tp_descr_get */ \
-      0,                                          /* tp_descr_set */ \
-      0,                                          /* tp_dictoffset */ \
-      0,                                          /* tp_init */ \
-      0                                           /* tp_alloc */ \
-    }; \
-\
-int \
-gdbpy_initialize_##name##_event (void) \
-{ \
-  return gdbpy_initialize_event_generic (&name##_event_object_type, \
-                                        py_name);                  \
-}
+/* Declare all event types.  */
+#define GDB_PY_DEFINE_EVENT_TYPE(name, py_name, doc, base) \
+  extern PyTypeObject name##_event_object_type             \
+        CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
+#include "py-event-types.def"
+#undef GDB_PY_DEFINE_EVENT_TYPE
 
 typedef struct
 {
index 2275d896e64fafa90176f7a08eb7cf2b8a69a3e1..876b564fbc61bf7e0a3b8a48270447ba90104897 100644 (file)
@@ -24,9 +24,6 @@
 #include "python-internal.h"
 #include "inferior.h"
 
-extern PyTypeObject thread_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-
 /* Stores a list of objects to be notified when the event for which this
    registry tracks occurs.  */
 
@@ -42,21 +39,10 @@ typedef struct
 
 typedef struct
 {
-  eventregistry_object *stop;
-  eventregistry_object *cont;
-  eventregistry_object *exited;
-  eventregistry_object *new_objfile;
-  eventregistry_object *clear_objfiles;
-  eventregistry_object *new_inferior;
-  eventregistry_object *inferior_deleted;
-  eventregistry_object *new_thread;
-  eventregistry_object *inferior_call;
-  eventregistry_object *memory_changed;
-  eventregistry_object *register_changed;
-  eventregistry_object *breakpoint_created;
-  eventregistry_object *breakpoint_deleted;
-  eventregistry_object *breakpoint_modified;
-  eventregistry_object *before_prompt;
+#define GDB_PY_DEFINE_EVENT(name)              \
+  eventregistry_object *name;
+#include "py-all-events.def"
+#undef GDB_PY_DEFINE_EVENT
 
   PyObject *module;
 
index ad9924190c3db2e71b138d433f9631e771ffa22e..0faf280045f72107318d5faa9742a628534a92bc 100644 (file)
@@ -62,55 +62,11 @@ gdbpy_initialize_py_events (void)
   if (!gdb_py_events.module)
     return -1;
 
-  if (add_new_registry (&gdb_py_events.stop, "stop") < 0)
-    return -1;
-
-  if (add_new_registry (&gdb_py_events.cont, "cont") < 0)
-    return -1;
-
-  if (add_new_registry (&gdb_py_events.exited, "exited") < 0)
-    return -1;
-
-  if (add_new_registry (&gdb_py_events.inferior_call,
-                       "inferior_call") < 0)
-    return -1;
-
-  if (add_new_registry (&gdb_py_events.memory_changed,
-                       "memory_changed") < 0)
-    return -1;
-
-  if (add_new_registry (&gdb_py_events.register_changed,
-                       "register_changed") < 0)
-    return -1;
-
-  if (add_new_registry (&gdb_py_events.new_objfile, "new_objfile") < 0)
-    return -1;
-
-  if (add_new_registry (&gdb_py_events.clear_objfiles, "clear_objfiles") < 0)
-    return -1;
-
-  if (add_new_registry (&gdb_py_events.new_inferior, "new_inferior") < 0)
-    return -1;
-
-  if (add_new_registry (&gdb_py_events.inferior_deleted, "inferior_deleted") < 0)
-    return -1;
-
-  if (add_new_registry (&gdb_py_events.new_thread, "new_thread") < 0)
-    return -1;
-
-  if (add_new_registry (&gdb_py_events.breakpoint_created,
-                       "breakpoint_created") < 0)
-    return -1;
-
-  if (add_new_registry (&gdb_py_events.breakpoint_deleted,
-                       "breakpoint_deleted") < 0)
-    return -1;
-  if (add_new_registry (&gdb_py_events.breakpoint_modified,
-                       "breakpoint_modified") < 0)
-    return -1;
-
-  if (add_new_registry (&gdb_py_events.before_prompt, "before_prompt") < 0)
+#define GDB_PY_DEFINE_EVENT(name)                              \
+  if (add_new_registry (&gdb_py_events.name, #name) < 0)       \
     return -1;
+#include "py-all-events.def"
+#undef GDB_PY_DEFINE_EVENT
 
   if (gdb_pymodule_addobject (gdb_module,
                              "events",
index 967fb1bdebffe6c09190ed43f90e1c521db4c4a8..aa4aefb73298a1a853af27e36f24516f11190ff0 100644 (file)
@@ -20,9 +20,6 @@
 #include "defs.h"
 #include "py-event.h"
 
-extern PyTypeObject exited_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-
 static PyObject *
 create_exited_event_object (const LONGEST *exit_code, struct inferior *inf)
 {
@@ -67,10 +64,3 @@ emit_exited_event (const LONGEST *exit_code, struct inferior *inf)
 
   return -1;
 }
-
-
-GDBPY_NEW_EVENT_TYPE (exited,
-                      "gdb.ExitedEvent",
-                      "ExitedEvent",
-                      "GDB exited event object",
-                      event_object_type);
index d7c6810884fbb7d48576249127f7c7c4a74935bc..5cad042f820ff20680438189980b2a63bb65a92f 100644 (file)
 #include "py-event.h"
 #include "py-stopevent.h"
 
-extern PyTypeObject new_thread_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-extern PyTypeObject new_inferior_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-extern PyTypeObject inferior_deleted_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-
 struct threadlist_entry {
   thread_object *thread_obj;
   struct threadlist_entry *next;
@@ -1042,19 +1035,3 @@ PyTypeObject membuf_object_type = {
   0,                             /* tp_init */
   0,                             /* tp_alloc */
 };
-
-GDBPY_NEW_EVENT_TYPE (new_thread,
-                     "gdb.NewThreadEvent",
-                     "NewThreadEvent",
-                     "GDB new thread event object",
-                     thread_event_object_type);
-GDBPY_NEW_EVENT_TYPE (new_inferior,
-                     "gdb.NewInferiorEvent",
-                     "NewInferiorEvent",
-                     "GDB new inferior event object",
-                     event_object_type);
-GDBPY_NEW_EVENT_TYPE (inferior_deleted,
-                     "gdb.InferiorDeletedEvent",
-                     "InferiorDeletedEvent",
-                     "GDB inferior deleted event object",
-                     event_object_type);
index 8a63b79450e414d62de43c5fda7b097b31420f25..825a89205d678b34773423fa73bb8f15e624f99e 100644 (file)
 #include "py-event.h"
 #include "py-ref.h"
 
-extern PyTypeObject inferior_call_pre_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-extern PyTypeObject inferior_call_post_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-extern PyTypeObject register_changed_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-extern PyTypeObject memory_changed_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-
 /* Construct either a gdb.InferiorCallPreEvent or a
    gdb.InferiorCallPostEvent. */
 
@@ -172,28 +163,3 @@ emit_register_changed_event (struct frame_info* frame, int regnum)
     return evpy_emit_event (event.get (), gdb_py_events.register_changed);
   return -1;
 }
-
-
-GDBPY_NEW_EVENT_TYPE (inferior_call_pre,
-                     "gdb.InferiorCallPreEvent",
-                     "InferiorCallPreEvent",
-                     "GDB inferior function pre-call event object",
-                     event_object_type);
-
-GDBPY_NEW_EVENT_TYPE (inferior_call_post,
-                     "gdb.InferiorCallPostEvent",
-                     "InferiorCallPostEvent",
-                     "GDB inferior function post-call event object",
-                     event_object_type);
-
-GDBPY_NEW_EVENT_TYPE (register_changed,
-                     "gdb.RegisterChangedEvent",
-                     "RegisterChangedEvent",
-                     "GDB register change event object",
-                     event_object_type);
-
-GDBPY_NEW_EVENT_TYPE (memory_changed,
-                     "gdb.MemoryChangedEvent",
-                     "MemoryChangedEvent",
-                     "GDB memory change event object",
-                     event_object_type);
index dc09e0f83497ca1075f488bb12a0e0c6959b5e35..227f4a48f1ed25d23feb2014ff790fbfe723704a 100644 (file)
 #include "defs.h"
 #include "py-event.h"
 
-extern PyTypeObject new_objfile_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-extern PyTypeObject clear_objfiles_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-
 static PyObject *
 create_new_objfile_event_object (struct objfile *objfile)
 {
@@ -62,11 +57,6 @@ emit_new_objfile_event (struct objfile *objfile)
   return -1;
 }
 
-GDBPY_NEW_EVENT_TYPE (new_objfile,
-                      "gdb.NewObjFileEvent",
-                      "NewObjFileEvent",
-                      "GDB new object file event object",
-                      event_object_type);
 \f
 /* Subroutine of emit_clear_objfiles_event to simplify it.  */
 
@@ -107,9 +97,3 @@ emit_clear_objfiles_event (void)
     return evpy_emit_event (event.get (), gdb_py_events.clear_objfiles);
   return -1;
 }
-
-GDBPY_NEW_EVENT_TYPE (clear_objfiles,
-                     "gdb.ClearObjFilesEvent",
-                     "ClearObjFilesEvent",
-                     "GDB clear object files event object",
-                     event_object_type);
index c2391def087850a939f2065ceac6ba9e403622fc..185e6f513fb27dc798ca5351dc829d6a8711b0b7 100644 (file)
@@ -20,9 +20,6 @@
 #include "defs.h"
 #include "py-stopevent.h"
 
-extern PyTypeObject signal_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-
 gdbpy_ref<>
 create_signal_event_object (enum gdb_signal stop_signal)
 {
@@ -45,9 +42,3 @@ create_signal_event_object (enum gdb_signal stop_signal)
 
   return signal_event_obj;
 }
-
-GDBPY_NEW_EVENT_TYPE (signal,
-                      "gdb.SignalEvent",
-                      "SignalEvent",
-                      "GDB signal event object",
-                      stop_event_object_type);
index a0be5f2a26f6093b94621495d989b9c0266f6940..57179478bc1a85551c507eafc5e2f14f538f210e 100644 (file)
@@ -96,9 +96,3 @@ emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
 
   return evpy_emit_event (stop_event_obj.get (), gdb_py_events.stop);
 }
-
-GDBPY_NEW_EVENT_TYPE (stop,
-                      "gdb.StopEvent",
-                      "StopEvent",
-                      "GDB stop event object",
-                      thread_event_object_type);
index 8b742ca94a71eb717dc4860d6964904e5c52da89..322fa266ebc77b113c930e6e66b798b2733afc87 100644 (file)
@@ -68,9 +68,3 @@ create_thread_event_object (PyTypeObject *py_type, PyObject *thread)
 
   return thread_event_obj;
 }
-
-GDBPY_NEW_EVENT_TYPE (thread,
-                      "gdb.ThreadEvent",
-                      "ThreadEvent",
-                      "GDB thread event object",
-                      event_object_type);
index 0c3582f180f664a3f2e42ff3392678efecff88bf..abfec91a561b9f2a873552d27fd54de84a27786b 100644 (file)
@@ -373,8 +373,6 @@ extern PyTypeObject symbol_object_type
     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("symbol_object");
 extern PyTypeObject event_object_type
     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-extern PyTypeObject stop_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
 extern PyTypeObject breakpoint_object_type
     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("breakpoint_object");
 extern PyTypeObject frame_object_type
@@ -606,36 +604,6 @@ int gdbpy_initialize_event (void)
   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
 int gdbpy_initialize_py_events (void)
   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_stop_event (void)
-  CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_signal_event (void)
-  CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_breakpoint_event (void)
-  CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_continue_event (void)
-  CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_inferior_call_pre_event (void)
-  CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_inferior_call_post_event (void)
-  CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_register_changed_event (void)
-  CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_memory_changed_event (void)
-  CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_exited_event (void)
-  CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_thread_event (void)
-  CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_new_objfile_event (void)
-  CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_clear_objfiles_event (void)
-  CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_new_inferior_event (void)
-  CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_inferior_deleted_event (void)
-  CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_new_thread_event (void)
-  CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
 int gdbpy_initialize_arch (void)
   CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
 int gdbpy_initialize_xmethods (void)
index fbb4747c5fa635d2855156a84663a9df693d8981..ff757fdc421e56f85bd66b5a887409b59441cc8b 100644 (file)
@@ -1591,26 +1591,17 @@ do_start_initialization ()
       || gdbpy_initialize_eventregistry () < 0
       || gdbpy_initialize_py_events () < 0
       || gdbpy_initialize_event () < 0
-      || gdbpy_initialize_stop_event () < 0
-      || gdbpy_initialize_signal_event () < 0
-      || gdbpy_initialize_breakpoint_event () < 0
-      || gdbpy_initialize_continue_event () < 0
-      || gdbpy_initialize_inferior_call_pre_event () < 0
-      || gdbpy_initialize_inferior_call_post_event () < 0
-      || gdbpy_initialize_register_changed_event () < 0
-      || gdbpy_initialize_memory_changed_event () < 0
-      || gdbpy_initialize_exited_event () < 0
-      || gdbpy_initialize_thread_event () < 0
-      || gdbpy_initialize_new_objfile_event ()  < 0
-      || gdbpy_initialize_clear_objfiles_event ()  < 0
-      || gdbpy_initialize_new_inferior_event () < 0
-      || gdbpy_initialize_inferior_deleted_event () < 0
-      || gdbpy_initialize_new_thread_event () < 0
       || gdbpy_initialize_arch () < 0
       || gdbpy_initialize_xmethods () < 0
       || gdbpy_initialize_unwind () < 0)
     return false;
 
+#define GDB_PY_DEFINE_EVENT_TYPE(name, py_name, doc, base)     \
+  if (gdbpy_initialize_event_generic (&name##_event_object_type, py_name) < 0) \
+    return false;
+#include "py-event-types.def"
+#undef GDB_PY_DEFINE_EVENT_TYPE
+
   gdbpy_to_string_cst = PyString_FromString ("to_string");
   if (gdbpy_to_string_cst == NULL)
     return false;
@@ -1963,4 +1954,51 @@ struct PyModuleDef python_GdbModuleDef =
   NULL
 };
 #endif
+
+/* Define all the event objects.  */
+#define GDB_PY_DEFINE_EVENT_TYPE(name, py_name, doc, base) \
+  PyTypeObject name##_event_object_type                    \
+        CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object") \
+    = { \
+      PyVarObject_HEAD_INIT (NULL, 0)                          \
+      "gdb." py_name,                             /* tp_name */ \
+      sizeof (event_object),                      /* tp_basicsize */ \
+      0,                                          /* tp_itemsize */ \
+      evpy_dealloc,                               /* tp_dealloc */ \
+      0,                                          /* tp_print */ \
+      0,                                          /* tp_getattr */ \
+      0,                                          /* tp_setattr */ \
+      0,                                          /* tp_compare */ \
+      0,                                          /* tp_repr */ \
+      0,                                          /* tp_as_number */ \
+      0,                                          /* tp_as_sequence */ \
+      0,                                          /* tp_as_mapping */ \
+      0,                                          /* tp_hash  */ \
+      0,                                          /* tp_call */ \
+      0,                                          /* tp_str */ \
+      0,                                          /* tp_getattro */ \
+      0,                                          /* tp_setattro */ \
+      0,                                          /* tp_as_buffer */ \
+      Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,   /* tp_flags */ \
+      doc,                                        /* tp_doc */ \
+      0,                                          /* tp_traverse */ \
+      0,                                          /* tp_clear */ \
+      0,                                          /* tp_richcompare */ \
+      0,                                          /* tp_weaklistoffset */ \
+      0,                                          /* tp_iter */ \
+      0,                                          /* tp_iternext */ \
+      0,                                          /* tp_methods */ \
+      0,                                          /* tp_members */ \
+      0,                                          /* tp_getset */ \
+      &base,                                      /* tp_base */ \
+      0,                                          /* tp_dict */ \
+      0,                                          /* tp_descr_get */ \
+      0,                                          /* tp_descr_set */ \
+      0,                                          /* tp_dictoffset */ \
+      0,                                          /* tp_init */ \
+      0                                           /* tp_alloc */ \
+    };
+#include "py-event-types.def"
+#undef GDB_PY_DEFINE_EVENT_TYPE
+
 #endif /* HAVE_PYTHON */