diff options
author | Tom Tromey <tom@tromey.com> | 2017-09-08 15:38:12 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-09-11 14:15:22 -0600 |
commit | 7d221d749c0239f06ca571be6c9452cd22b5d582 (patch) | |
tree | 0195f0e127b789e980939faeb79c6ed13ef7fd3d | |
parent | 35c61a1dd5462ceab42618c48c9a60238245761b (diff) | |
download | gdb-7d221d749c0239f06ca571be6c9452cd22b5d582.zip gdb-7d221d749c0239f06ca571be6c9452cd22b5d582.tar.gz gdb-7d221d749c0239f06ca571be6c9452cd22b5d582.tar.bz2 |
Make it simpler to add events to Python
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.
-rw-r--r-- | gdb/ChangeLog | 36 | ||||
-rw-r--r-- | gdb/python/py-all-events.def | 40 | ||||
-rw-r--r-- | gdb/python/py-bpevent.c | 9 | ||||
-rw-r--r-- | gdb/python/py-continueevent.c | 9 | ||||
-rw-r--r-- | gdb/python/py-event-types.def | 107 | ||||
-rw-r--r-- | gdb/python/py-event.h | 74 | ||||
-rw-r--r-- | gdb/python/py-events.h | 22 | ||||
-rw-r--r-- | gdb/python/py-evts.c | 52 | ||||
-rw-r--r-- | gdb/python/py-exitedevent.c | 10 | ||||
-rw-r--r-- | gdb/python/py-inferior.c | 23 | ||||
-rw-r--r-- | gdb/python/py-infevents.c | 34 | ||||
-rw-r--r-- | gdb/python/py-newobjfileevent.c | 16 | ||||
-rw-r--r-- | gdb/python/py-signalevent.c | 9 | ||||
-rw-r--r-- | gdb/python/py-stopevent.c | 6 | ||||
-rw-r--r-- | gdb/python/py-threadevent.c | 6 | ||||
-rw-r--r-- | gdb/python/python-internal.h | 32 | ||||
-rw-r--r-- | gdb/python/python.c | 68 |
17 files changed, 250 insertions, 303 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 61fb77e..fa94de4 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,41 @@ 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 gdbpy_ref. * python/py-stopevent.h (create_stop_event_object) diff --git a/gdb/python/py-all-events.def b/gdb/python/py-all-events.def new file mode 100644 index 0000000..cdede6b --- /dev/null +++ b/gdb/python/py-all-events.def @@ -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) diff --git a/gdb/python/py-bpevent.c b/gdb/python/py-bpevent.c index 021c83a..1cb3f9a 100644 --- a/gdb/python/py-bpevent.c +++ b/gdb/python/py-bpevent.c @@ -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); diff --git a/gdb/python/py-continueevent.c b/gdb/python/py-continueevent.c index ca2927f..8c704b9 100644 --- a/gdb/python/py-continueevent.c +++ b/gdb/python/py-continueevent.c @@ -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 index 0000000..f571f66 --- /dev/null +++ b/gdb/python/py-event-types.def @@ -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); diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h index 27db828..2444260 100644 --- a/gdb/python/py-event.h +++ b/gdb/python/py-event.h @@ -26,74 +26,12 @@ #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 { diff --git a/gdb/python/py-events.h b/gdb/python/py-events.h index 2275d89..876b564 100644 --- a/gdb/python/py-events.h +++ b/gdb/python/py-events.h @@ -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; diff --git a/gdb/python/py-evts.c b/gdb/python/py-evts.c index ad99241..0faf280 100644 --- a/gdb/python/py-evts.c +++ b/gdb/python/py-evts.c @@ -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", diff --git a/gdb/python/py-exitedevent.c b/gdb/python/py-exitedevent.c index 967fb1b..aa4aefb 100644 --- a/gdb/python/py-exitedevent.c +++ b/gdb/python/py-exitedevent.c @@ -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); diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index d7c6810..5cad042 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -30,13 +30,6 @@ #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); diff --git a/gdb/python/py-infevents.c b/gdb/python/py-infevents.c index 8a63b79..825a892 100644 --- a/gdb/python/py-infevents.c +++ b/gdb/python/py-infevents.c @@ -21,15 +21,6 @@ #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); diff --git a/gdb/python/py-newobjfileevent.c b/gdb/python/py-newobjfileevent.c index dc09e0f..227f4a4 100644 --- a/gdb/python/py-newobjfileevent.c +++ b/gdb/python/py-newobjfileevent.c @@ -20,11 +20,6 @@ #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); /* 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); diff --git a/gdb/python/py-signalevent.c b/gdb/python/py-signalevent.c index c2391de..185e6f5 100644 --- a/gdb/python/py-signalevent.c +++ b/gdb/python/py-signalevent.c @@ -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); diff --git a/gdb/python/py-stopevent.c b/gdb/python/py-stopevent.c index a0be5f2..5717947 100644 --- a/gdb/python/py-stopevent.c +++ b/gdb/python/py-stopevent.c @@ -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); diff --git a/gdb/python/py-threadevent.c b/gdb/python/py-threadevent.c index 8b742ca..322fa26 100644 --- a/gdb/python/py-threadevent.c +++ b/gdb/python/py-threadevent.c @@ -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); diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 0c3582f..abfec91 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -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) diff --git a/gdb/python/python.c b/gdb/python/python.c index fbb4747..ff757fd 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -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 */ |