* [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events
2017-09-09 0:34 [RFA 0/3] add a few Python events Tom Tromey
2017-09-09 0:34 ` [RFA 3/3] Make it simpler to add events to Python Tom Tromey
@ 2017-09-09 0:34 ` Tom Tromey
2017-09-09 6:55 ` Eli Zaretskii
2017-09-09 16:48 ` Simon Marchi
2017-09-09 0:34 ` [RFA 2/3] Small event ownership clean up in Python layer Tom Tromey
2 siblings, 2 replies; 18+ messages in thread
From: Tom Tromey @ 2017-09-09 0:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This adds a few new events to gdb's Python layer: new_inferior,
inferior_deleted, and new_thread. I wanted to be able to add a
combined inferior/thread display window to my GUI, and I needed a few
events to make this work. This is PR python/15622.
gdb/ChangeLog
2017-09-08 Tom Tromey <tom@tromey.com>
PR python/15622:
* NEWS: Add entry.
* python/python.c (do_start_initialization): Initialize new event
types.
* python/python-internal.h (gdbpy_initialize_new_inferior_event)
(gdbpy_initialize_inferior_deleted_event)
(gdbpy_initialize_new_thread_event): Declare.
* python/py-threadevent.c (create_thread_event_object): Add option
"thread" parameter.
* python/py-inferior.c (new_thread_event_object_type)
(new_inferior_event_object_type)
(inferior_deleted_event_object_type): Declare.
(python_new_inferior, python_inferior_deleted): New functions.
(add_thread_object): Emit new_thread event.
(gdbpy_initialize_inferior): Attach new functions to corresponding
observers.
(new_thread, new_inferior, inferior_deleted): Define new event
types.
* python/py-evts.c (gdbpy_initialize_py_events): Add new
registries.
* python/py-events.h (events_object) <new_inferior,
inferior_deleted, new_thread>: New fields.
* python/py-event.h (create_thread_event_breakpoint): Add optional
"thread" parameter.
gdb/doc/ChangeLog
2017-09-08 Tom Tromey <tom@tromey.com>
* python.texi (Events In Python): Document new events.
gdb/testsuite/ChangeLog
2017-09-08 Tom Tromey <tom@tromey.com>
* gdb.python/py-infthread.exp: Add tests for new_thread event.
* gdb.python/py-inferior.exp: Add tests for new inferior events.
---
gdb/ChangeLog | 27 ++++++++++
gdb/NEWS | 6 +++
gdb/doc/ChangeLog | 6 ++-
gdb/doc/python.texi | 30 +++++++++++
gdb/python/py-event.h | 3 +-
gdb/python/py-events.h | 3 ++
gdb/python/py-evts.c | 9 ++++
gdb/python/py-inferior.c | 88 +++++++++++++++++++++++++++++++
gdb/python/py-threadevent.c | 13 ++---
gdb/python/python-internal.h | 6 +++
gdb/python/python.c | 3 ++
gdb/testsuite/ChangeLog | 5 ++
gdb/testsuite/gdb.python/py-inferior.exp | 24 +++++++++
gdb/testsuite/gdb.python/py-infthread.exp | 12 +++++
14 files changed, 227 insertions(+), 8 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 96369d5..88520ea 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,30 @@
+2017-09-08 Tom Tromey <tom@tromey.com>
+
+ PR python/15622:
+ * NEWS: Add entry.
+ * python/python.c (do_start_initialization): Initialize new event
+ types.
+ * python/python-internal.h (gdbpy_initialize_new_inferior_event)
+ (gdbpy_initialize_inferior_deleted_event)
+ (gdbpy_initialize_new_thread_event): Declare.
+ * python/py-threadevent.c (create_thread_event_object): Add option
+ "thread" parameter.
+ * python/py-inferior.c (new_thread_event_object_type)
+ (new_inferior_event_object_type)
+ (inferior_deleted_event_object_type): Declare.
+ (python_new_inferior, python_inferior_deleted): New functions.
+ (add_thread_object): Emit new_thread event.
+ (gdbpy_initialize_inferior): Attach new functions to corresponding
+ observers.
+ (new_thread, new_inferior, inferior_deleted): Define new event
+ types.
+ * python/py-evts.c (gdbpy_initialize_py_events): Add new
+ registries.
+ * python/py-events.h (events_object) <new_inferior,
+ inferior_deleted, new_thread>: New fields.
+ * python/py-event.h (create_thread_event_breakpoint): Add optional
+ "thread" parameter.
+
2017-09-08 Keith Seitz <keiths@redhat.com>
* dwarf2read.c (struct field_info) <fnfields>: Remove unused
diff --git a/gdb/NEWS b/gdb/NEWS
index f6ed614..2e6d48c 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -15,6 +15,12 @@
the remote inferior is started by the GDBserver, use the "unset
environment" command.
+* Python Scripting
+
+ ** New events gdb.new_inferior, gdb.inferior_deleted, and
+ gdb.new_thread are emitted. See the manual for further
+ description of these.
+
* New features in the GDB remote stub, GDBserver
** New "--selftest" command line option runs some GDBserver self
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 72f3d9e..65147f7 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2017-09-08 Tom Tromey <tom@tromey.com>
+
+ * python.texi (Events In Python): Document new events.
+
2017-09-04 Pedro Alves <palves@redhat.com>
* gdb.texinfo (Variables) <Program Variables>: Document inspecting
@@ -12039,7 +12043,7 @@ Wed Feb 26 18:04:40 1992 K. Richard Pixley (rich@cygnus.com)
* Makefile.in, configure.in: removed traces of namesubdir,
-subdirs, $(subdir), $(unsubdir), some rcs triggers. Forced
- copyrights to '92, '13, changed some from Cygnus to FSF.
+ copyrights to '92, '13, '17, changed some from Cygnus to FSF.
Fri Dec 13 09:47:31 1991 John Gilmore (gnu at cygnus.com)
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 32d7939..83d078b 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -2989,6 +2989,36 @@ invalid state; that is, the @code{is_valid} method will return
This event carries no payload. It is emitted each time @value{GDBN}
presents a prompt to the user.
+@item events.new_inferior
+This is notified when a new inferior is created. Note that the
+inferior is not necessarily running; in fact, it may not even have an
+associated executable.
+
+The event is of type @code{gdb.NewInferiorEvent}. This has a single
+attribute:
+
+@defvar NewInferiorEvent.inferior
+The new inferior, a @code{gdb.Inferior} object.
+@end defvar
+
+@item events.inferior_deleted
+This is notified when an inferior has been deleted. Note that this is
+not the same as process exit; it is notified when the inferior itself
+is removed, say via @code{remove-inferiors}.
+
+The event is of type @code{gdb.InferiorDeletedEvent}. This has a single
+attribute:
+
+@defvar NewInferiorEvent.inferior
+The inferior that is being removed, a @code{gdb.Inferior} object.
+@end defvar
+
+@item events.new_thread
+This emitted when @value{GDBN} notices a new thread. The event is of
+type @code{gdb.NewThreadEvent}, which extends @code{gdb.ThreadEvent}.
+The @code{new_thread} event always sets the @code{inferior_thread}
+attribute on the event object, regardless of the non-stop setting.
+
@end table
@node Threads In Python
diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
index ccb8513..2f02c5f 100644
--- a/gdb/python/py-event.h
+++ b/gdb/python/py-event.h
@@ -125,7 +125,8 @@ extern int evpy_emit_event (PyObject *event,
eventregistry_object *registry);
extern PyObject *create_event_object (PyTypeObject *py_type);
-extern PyObject *create_thread_event_object (PyTypeObject *py_type);
+extern PyObject *create_thread_event_object (PyTypeObject *py_type,
+ PyObject *thread = nullptr);
extern int emit_new_objfile_event (struct objfile *objfile);
extern int emit_clear_objfiles_event (void);
diff --git a/gdb/python/py-events.h b/gdb/python/py-events.h
index 348dabc..2275d89 100644
--- a/gdb/python/py-events.h
+++ b/gdb/python/py-events.h
@@ -47,6 +47,9 @@ typedef struct
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;
diff --git a/gdb/python/py-evts.c b/gdb/python/py-evts.c
index 126d18c..ad99241 100644
--- a/gdb/python/py-evts.c
+++ b/gdb/python/py-evts.c
@@ -89,6 +89,15 @@ gdbpy_initialize_py_events (void)
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;
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index f6a24a0..d7c6810 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -30,6 +30,13 @@
#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;
@@ -235,6 +242,60 @@ inferior_to_inferior_object (struct inferior *inferior)
return (PyObject *) inf_obj;
}
+/* Called when a new inferior is created. Notifies any Python event
+ listeners. */
+static void
+python_new_inferior (struct inferior *inf)
+{
+ if (!gdb_python_initialized)
+ return;
+
+ gdbpy_enter enter_py (python_gdbarch, python_language);
+
+ if (evregpy_no_listeners_p (gdb_py_events.new_inferior))
+ return;
+
+ gdbpy_ref<> inf_obj (inferior_to_inferior_object (inf));
+ if (inf_obj == NULL)
+ {
+ gdbpy_print_stack ();
+ return;
+ }
+
+ gdbpy_ref<> event (create_event_object (&new_inferior_event_object_type));
+ if (event == NULL
+ || evpy_add_attribute (event.get (), "inferior", inf_obj.get ()) < 0
+ || evpy_emit_event (event.get (), gdb_py_events.new_inferior) < 0)
+ gdbpy_print_stack ();
+}
+
+/* Called when an inferior is removed. Notifies any Python event
+ listeners. */
+static void
+python_inferior_deleted (struct inferior *inf)
+{
+ if (!gdb_python_initialized)
+ return;
+
+ gdbpy_enter enter_py (python_gdbarch, python_language);
+
+ if (evregpy_no_listeners_p (gdb_py_events.inferior_deleted))
+ return;
+
+ gdbpy_ref<> inf_obj (inferior_to_inferior_object (inf));
+ if (inf_obj == NULL)
+ {
+ gdbpy_print_stack ();
+ return;
+ }
+
+ gdbpy_ref<> event (create_event_object (&inferior_deleted_event_object_type));
+ if (event == NULL
+ || evpy_add_attribute (event.get (), "inferior", inf_obj.get ()) < 0
+ || evpy_emit_event (event.get (), gdb_py_events.inferior_deleted) < 0)
+ gdbpy_print_stack ();
+}
+
/* Finds the Python Inferior object for the given PID. Returns a
reference, or NULL if PID does not match any inferior object. */
@@ -298,6 +359,15 @@ add_thread_object (struct thread_info *tp)
inf_obj->threads = entry;
inf_obj->nthreads++;
+
+ if (evregpy_no_listeners_p (gdb_py_events.new_thread))
+ return;
+
+ gdbpy_ref<> event (create_thread_event_object (&new_thread_event_object_type,
+ (PyObject *) thread_obj));
+ if (event == NULL
+ || evpy_emit_event (event.get (), gdb_py_events.new_thread) < 0)
+ gdbpy_print_stack ();
}
static void
@@ -823,6 +893,8 @@ gdbpy_initialize_inferior (void)
observer_attach_register_changed (python_on_register_change);
observer_attach_inferior_exit (python_inferior_exit);
observer_attach_new_objfile (python_new_objfile);
+ observer_attach_inferior_added (python_new_inferior);
+ observer_attach_inferior_removed (python_inferior_deleted);
membuf_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&membuf_object_type) < 0)
@@ -970,3 +1042,19 @@ 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-threadevent.c b/gdb/python/py-threadevent.c
index 9217444..7211fa2 100644
--- a/gdb/python/py-threadevent.c
+++ b/gdb/python/py-threadevent.c
@@ -48,17 +48,18 @@ get_event_thread (void)
}
PyObject *
-create_thread_event_object (PyTypeObject *py_type)
+create_thread_event_object (PyTypeObject *py_type, PyObject *thread)
{
- PyObject *thread = NULL;
-
gdbpy_ref<> thread_event_obj (create_event_object (py_type));
if (thread_event_obj == NULL)
return NULL;
- thread = get_event_thread ();
- if (!thread)
- return NULL;
+ if (thread == NULL)
+ {
+ thread = get_event_thread ();
+ if (!thread)
+ return NULL;
+ }
if (evpy_add_attribute (thread_event_obj.get (),
"inferior_thread",
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index ebb83f0..0c3582f 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -630,6 +630,12 @@ 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 f40fe89..7ff84e4 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1609,6 +1609,9 @@ do_start_initialization ()
|| 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)
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 8d8dc3c..e982684 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-09-08 Tom Tromey <tom@tromey.com>
+
+ * gdb.python/py-infthread.exp: Add tests for new_thread event.
+ * gdb.python/py-inferior.exp: Add tests for new inferior events.
+
2017-09-08 Christoph Weinmann <christoph.t.weinmann@intel.com>
* gdb.fortran/printing-types.exp: New file.
diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
index c2ea2c2..715c693 100644
--- a/gdb/testsuite/gdb.python/py-inferior.exp
+++ b/gdb/testsuite/gdb.python/py-inferior.exp
@@ -214,12 +214,33 @@ with_test_prefix "is_valid" {
gdb_test "python print (inf_list\[0\].is_valid())" "True" \
"check inferior validity 1"
+ gdb_py_test_multiple "install new inferior event handler" \
+ "python" "" \
+ "my_inferior_count = 1" "" \
+ "def new_inf_handler(evt):" "" \
+ " global my_inferior_count" "" \
+ " if evt.inferior is not None:" "" \
+ " my_inferior_count = my_inferior_count + 1" "" \
+ "gdb.events.new_inferior.connect(new_inf_handler)" "" \
+ "end" ""
+ gdb_py_test_multiple "install inferior deleted event handler" \
+ "python" "" \
+ "def del_inf_handler(evt):" "" \
+ " global my_inferior_count" "" \
+ " if evt.inferior is not None:" "" \
+ " my_inferior_count = my_inferior_count - 1" "" \
+ "gdb.events.inferior_deleted.connect(del_inf_handler)" "" \
+ "end" ""
+
gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2"
gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get new list" 1
gdb_test "python print (len(inf_list))" "2" "get inferior list length 2"
gdb_test "python print (inf_list\[0\].is_valid())" "True" \
"check inferior validity 2"
+ gdb_test "python print (my_inferior_count)" "2" \
+ "test new-inferior event handler"
+
gdb_test "python print (inf_list\[1\].is_valid())" "True" \
"check inferior validity 3"
@@ -229,6 +250,9 @@ with_test_prefix "is_valid" {
gdb_test "python print (inf_list\[1\].is_valid())" "False" \
"check inferior validity 5"
+
+ gdb_test "python print (my_inferior_count)" "1" \
+ "test inferior-deleted event handler"
}
# Test gdb.selected_inferior()
diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp
index a5fed8d..0711d69 100644
--- a/gdb/testsuite/gdb.python/py-infthread.exp
+++ b/gdb/testsuite/gdb.python/py-infthread.exp
@@ -30,6 +30,16 @@ clean_restart ${testfile}
# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }
+gdb_py_test_multiple "install new_thread event handler" \
+ "python" "" \
+ "seen_a_thread = False" "" \
+ "def thread_handler(evt):" "" \
+ " if evt.inferior_thread is not None:" "" \
+ " global seen_a_thread" "" \
+ " seen_a_thread = True" "" \
+ "gdb.events.new_thread.connect(thread_handler)" "" \
+ "end" ""
+
# The following tests require execution.
if ![runto_main] then {
@@ -37,6 +47,8 @@ if ![runto_main] then {
return 0
}
+gdb_test "python print(seen_a_thread)" "True"
+
# Test basic gdb.Inferior attributes and methods.
gdb_py_test_silent_cmd "python t0 = gdb.selected_thread ()" "test gdb.selected_thread" 1
--
2.9.4
^ permalink raw reply [flat|nested] 18+ messages in thread
* [RFA 3/3] Make it simpler to add events to Python
2017-09-09 0:34 [RFA 0/3] add a few Python events Tom Tromey
@ 2017-09-09 0:34 ` Tom Tromey
2017-09-09 14:40 ` Tom Tromey
2017-09-09 17:05 ` Simon Marchi
2017-09-09 0:34 ` [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events Tom Tromey
2017-09-09 0:34 ` [RFA 2/3] Small event ownership clean up in Python layer Tom Tromey
2 siblings, 2 replies; 18+ messages in thread
From: Tom Tromey @ 2017-09-09 0:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
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".
2017-09-08 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.
---
gdb/ChangeLog | 36 ++++++++++++
gdb/python/py-all-events.def | 40 ++++++++++++++
gdb/python/py-bpevent.c | 9 ---
gdb/python/py-continueevent.c | 9 ---
gdb/python/py-event-types.def | 120 ++++++++++++++++++++++++++++++++++++++++
gdb/python/py-event.h | 74 ++-----------------------
gdb/python/py-events.h | 22 ++------
gdb/python/py-evts.c | 52 ++---------------
gdb/python/py-exitedevent.c | 10 ----
gdb/python/py-inferior.c | 23 --------
gdb/python/py-infevents.c | 34 ------------
gdb/python/py-newobjfileevent.c | 16 ------
gdb/python/py-signalevent.c | 9 ---
gdb/python/py-stopevent.c | 6 --
gdb/python/py-threadevent.c | 6 --
gdb/python/python-internal.h | 32 -----------
gdb/python/python.c | 67 +++++++++++++++++-----
17 files changed, 262 insertions(+), 303 deletions(-)
create mode 100644 gdb/python/py-all-events.def
create mode 100644 gdb/python/py-event-types.def
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f49b428..6590a50 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,41 @@
2017-09-08 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-08 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..d35cbe5
--- /dev/null
+++ b/gdb/python/py-event-types.def
@@ -0,0 +1,120 @@
+/* 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.
+
+ 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.
+*/
+
+GDB_PY_DEFINE_EVENT_TYPE (breakpoint,
+ "gdb.BreakpointEvent",
+ "BreakpointEvent",
+ "GDB breakpoint stop event object",
+ stop_event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (continue,
+ "gdb.ContinueEvent",
+ "ContinueEvent",
+ "GDB continue event object",
+ thread_event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (exited,
+ "gdb.ExitedEvent",
+ "ExitedEvent",
+ "GDB exited event object",
+ event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (new_thread,
+ "gdb.NewThreadEvent",
+ "NewThreadEvent",
+ "GDB new thread event object",
+ thread_event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (new_inferior,
+ "gdb.NewInferiorEvent",
+ "NewInferiorEvent",
+ "GDB new inferior event object",
+ event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (inferior_deleted,
+ "gdb.InferiorDeletedEvent",
+ "InferiorDeletedEvent",
+ "GDB inferior deleted event object",
+ event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (inferior_call_pre,
+ "gdb.InferiorCallPreEvent",
+ "InferiorCallPreEvent",
+ "GDB inferior function pre-call event object",
+ event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (inferior_call_post,
+ "gdb.InferiorCallPostEvent",
+ "InferiorCallPostEvent",
+ "GDB inferior function post-call event object",
+ event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (register_changed,
+ "gdb.RegisterChangedEvent",
+ "RegisterChangedEvent",
+ "GDB register change event object",
+ event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (memory_changed,
+ "gdb.MemoryChangedEvent",
+ "MemoryChangedEvent",
+ "GDB memory change event object",
+ event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (new_objfile,
+ "gdb.NewObjFileEvent",
+ "NewObjFileEvent",
+ "GDB new object file event object",
+ event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (clear_objfiles,
+ "gdb.ClearObjFilesEvent",
+ "ClearObjFilesEvent",
+ "GDB clear object files event object",
+ event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (signal,
+ "gdb.SignalEvent",
+ "SignalEvent",
+ "GDB signal event object",
+ stop_event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (stop,
+ "gdb.StopEvent",
+ "StopEvent",
+ "GDB stop event object",
+ thread_event_object_type);
+
+GDB_PY_DEFINE_EVENT_TYPE (thread,
+ "gdb.ThreadEvent",
+ "ThreadEvent",
+ "GDB thread event object",
+ event_object_type);
diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
index 27db828..28a1b58 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_path, 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);
\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);
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 7ff84e4..9f3606f 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1597,26 +1597,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_path, 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;
@@ -1970,3 +1961,49 @@ struct PyModuleDef python_GdbModuleDef =
};
#endif
#endif /* HAVE_PYTHON */
+
+/* Define all the event objects. */
+#define GDB_PY_DEFINE_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 */ \
+ };
+#include "py-event-types.def"
+#undef GDB_PY_DEFINE_EVENT_TYPE
--
2.9.4
^ permalink raw reply [flat|nested] 18+ messages in thread
* [RFA 2/3] Small event ownership clean up in Python layer
2017-09-09 0:34 [RFA 0/3] add a few Python events Tom Tromey
2017-09-09 0:34 ` [RFA 3/3] Make it simpler to add events to Python Tom Tromey
2017-09-09 0:34 ` [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events Tom Tromey
@ 2017-09-09 0:34 ` Tom Tromey
2017-09-09 17:05 ` Simon Marchi
2 siblings, 1 reply; 18+ messages in thread
From: Tom Tromey @ 2017-09-09 0:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
It seems cleaner to me for functions like create_thread_event_object,
which pass object ownership to their callers, to directly return a
gdb_ref<>. This way the ownership transfer is part of the API. This
patch makes this change.
2017-09-08 Tom Tromey <tom@tromey.com>
* python/py-threadevent.c (create_thread_event_object): Return
gdbpy_ref.
* python/py-stopevent.h (create_stop_event_object)
(create_breakpoint_event_object, create_signal_event_object):
Update.
* python/py-stopevent.c (create_stop_event_object): Return
gdbpy_ref.
(emit_stop_event): Update.
* python/py-signalevent.c (create_signal_event_object): Return
gdbpy_ref.
* python/py-infevents.c (create_inferior_call_event_object):
Update.
* python/py-event.h (create_event_object)
(create_thread_event_object): Update.
* python/py-event.c (create_event_object): Return gdbpy_ref.
* python/py-continueevent.c: Return gdbpy_ref.
* python/py-bpevent.c (create_breakpoint_event_object): Return
gdbpy_ref.
---
gdb/ChangeLog | 21 +++++++++++++++++++++
gdb/python/py-bpevent.c | 4 ++--
gdb/python/py-continueevent.c | 2 +-
gdb/python/py-event.c | 4 ++--
gdb/python/py-event.h | 6 +++---
gdb/python/py-infevents.c | 4 ++--
gdb/python/py-signalevent.c | 4 ++--
gdb/python/py-stopevent.c | 10 +++++-----
gdb/python/py-stopevent.h | 8 ++++----
gdb/python/py-threadevent.c | 4 ++--
10 files changed, 44 insertions(+), 23 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 88520ea..f49b428 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,26 @@
2017-09-08 Tom Tromey <tom@tromey.com>
+ * python/py-threadevent.c (create_thread_event_object): Return
+ gdbpy_ref.
+ * python/py-stopevent.h (create_stop_event_object)
+ (create_breakpoint_event_object, create_signal_event_object):
+ Update.
+ * python/py-stopevent.c (create_stop_event_object): Return
+ gdbpy_ref.
+ (emit_stop_event): Update.
+ * python/py-signalevent.c (create_signal_event_object): Return
+ gdbpy_ref.
+ * python/py-infevents.c (create_inferior_call_event_object):
+ Update.
+ * python/py-event.h (create_event_object)
+ (create_thread_event_object): Update.
+ * python/py-event.c (create_event_object): Return gdbpy_ref.
+ * python/py-continueevent.c: Return gdbpy_ref.
+ * python/py-bpevent.c (create_breakpoint_event_object): Return
+ gdbpy_ref.
+
+2017-09-08 Tom Tromey <tom@tromey.com>
+
PR python/15622:
* NEWS: Add entry.
* python/python.c (do_start_initialization): Initialize new event
diff --git a/gdb/python/py-bpevent.c b/gdb/python/py-bpevent.c
index c5a85b6..021c83a 100644
--- a/gdb/python/py-bpevent.c
+++ b/gdb/python/py-bpevent.c
@@ -27,7 +27,7 @@ extern PyTypeObject breakpoint_event_object_type
/* Create and initialize a BreakpointEvent object. This acquires new
references to BREAKPOINT_LIST and FIRST_BP. */
-PyObject *
+gdbpy_ref<>
create_breakpoint_event_object (PyObject *breakpoint_list, PyObject *first_bp)
{
gdbpy_ref<> breakpoint_event_obj
@@ -45,7 +45,7 @@ create_breakpoint_event_object (PyObject *breakpoint_list, PyObject *first_bp)
breakpoint_list) < 0)
return NULL;
- return breakpoint_event_obj.release ();
+ return breakpoint_event_obj;
}
GDBPY_NEW_EVENT_TYPE (breakpoint,
diff --git a/gdb/python/py-continueevent.c b/gdb/python/py-continueevent.c
index 8be28c2..ca2927f 100644
--- a/gdb/python/py-continueevent.c
+++ b/gdb/python/py-continueevent.c
@@ -24,7 +24,7 @@
extern PyTypeObject continue_event_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-static PyObject *
+static gdbpy_ref<>
create_continue_event_object (void)
{
return create_thread_event_object (&continue_event_object_type);
diff --git a/gdb/python/py-event.c b/gdb/python/py-event.c
index b349891..9d84e33 100644
--- a/gdb/python/py-event.c
+++ b/gdb/python/py-event.c
@@ -27,7 +27,7 @@ evpy_dealloc (PyObject *self)
Py_TYPE (self)->tp_free (self);
}
-PyObject *
+gdbpy_ref<>
create_event_object (PyTypeObject *py_type)
{
gdbpy_ref<event_object> event_obj (PyObject_New (event_object, py_type));
@@ -38,7 +38,7 @@ create_event_object (PyTypeObject *py_type)
if (!event_obj->dict)
return NULL;
- return (PyObject*) event_obj.release ();
+ return gdbpy_ref<> ((PyObject *) event_obj.release ());
}
/* Add the attribute ATTR to the event object EVENT. In
diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
index 2f02c5f..27db828 100644
--- a/gdb/python/py-event.h
+++ b/gdb/python/py-event.h
@@ -124,9 +124,9 @@ extern int emit_memory_changed_event (CORE_ADDR addr, ssize_t len);
extern int evpy_emit_event (PyObject *event,
eventregistry_object *registry);
-extern PyObject *create_event_object (PyTypeObject *py_type);
-extern PyObject *create_thread_event_object (PyTypeObject *py_type,
- PyObject *thread = nullptr);
+extern gdbpy_ref<> create_event_object (PyTypeObject *py_type);
+extern gdbpy_ref<> create_thread_event_object (PyTypeObject *py_type,
+ PyObject *thread = nullptr);
extern int emit_new_objfile_event (struct objfile *objfile);
extern int emit_clear_objfiles_event (void);
diff --git a/gdb/python/py-infevents.c b/gdb/python/py-infevents.c
index 6e3c8c8..8a63b79 100644
--- a/gdb/python/py-infevents.c
+++ b/gdb/python/py-infevents.c
@@ -43,10 +43,10 @@ create_inferior_call_event_object (inferior_call_kind flag, ptid_t ptid,
switch (flag)
{
case INFERIOR_CALL_PRE:
- event.reset (create_event_object (&inferior_call_pre_event_object_type));
+ event = create_event_object (&inferior_call_pre_event_object_type);
break;
case INFERIOR_CALL_POST:
- event.reset (create_event_object (&inferior_call_post_event_object_type));
+ event = create_event_object (&inferior_call_post_event_object_type);
break;
default:
gdb_assert_not_reached ("invalid inferior_call_kind");
diff --git a/gdb/python/py-signalevent.c b/gdb/python/py-signalevent.c
index a8f41c2..c2391de 100644
--- a/gdb/python/py-signalevent.c
+++ b/gdb/python/py-signalevent.c
@@ -23,7 +23,7 @@
extern PyTypeObject signal_event_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-PyObject *
+gdbpy_ref<>
create_signal_event_object (enum gdb_signal stop_signal)
{
const char *signal_name;
@@ -43,7 +43,7 @@ create_signal_event_object (enum gdb_signal stop_signal)
signal_name_obj.get ()) < 0)
return NULL;
- return signal_event_obj.release ();
+ return signal_event_obj;
}
GDBPY_NEW_EVENT_TYPE (signal,
diff --git a/gdb/python/py-stopevent.c b/gdb/python/py-stopevent.c
index cfa4591..a0be5f2 100644
--- a/gdb/python/py-stopevent.c
+++ b/gdb/python/py-stopevent.c
@@ -20,7 +20,7 @@
#include "defs.h"
#include "py-stopevent.h"
-PyObject *
+gdbpy_ref<>
create_stop_event_object (PyTypeObject *py_type)
{
return create_thread_event_object (py_type);
@@ -70,8 +70,8 @@ emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
if (list != NULL)
{
- stop_event_obj.reset (create_breakpoint_event_object (list.get (),
- first_bp));
+ stop_event_obj = create_breakpoint_event_object (list.get (),
+ first_bp);
if (stop_event_obj == NULL)
return -1;
}
@@ -80,7 +80,7 @@ emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
if (stop_signal != GDB_SIGNAL_0
&& stop_signal != GDB_SIGNAL_TRAP)
{
- stop_event_obj.reset (create_signal_event_object (stop_signal));
+ stop_event_obj = create_signal_event_object (stop_signal);
if (stop_event_obj == NULL)
return -1;
}
@@ -89,7 +89,7 @@ emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
be known and this should eventually be unused. */
if (stop_event_obj == NULL)
{
- stop_event_obj.reset (create_stop_event_object (&stop_event_object_type));
+ stop_event_obj = create_stop_event_object (&stop_event_object_type);
if (stop_event_obj == NULL)
return -1;
}
diff --git a/gdb/python/py-stopevent.h b/gdb/python/py-stopevent.h
index a56ca7e..62c52d7 100644
--- a/gdb/python/py-stopevent.h
+++ b/gdb/python/py-stopevent.h
@@ -22,15 +22,15 @@
#include "py-event.h"
-extern PyObject *create_stop_event_object (PyTypeObject *py_type);
+extern gdbpy_ref<> create_stop_event_object (PyTypeObject *py_type);
extern void stop_evpy_dealloc (PyObject *self);
extern int emit_stop_event (struct bpstats *bs,
enum gdb_signal stop_signal);
-extern PyObject *create_breakpoint_event_object (PyObject *breakpoint_list,
- PyObject *first_bp);
+extern gdbpy_ref<> create_breakpoint_event_object (PyObject *breakpoint_list,
+ PyObject *first_bp);
-extern PyObject *create_signal_event_object (enum gdb_signal stop_signal);
+extern gdbpy_ref<> create_signal_event_object (enum gdb_signal stop_signal);
#endif /* GDB_PY_STOPEVENT_H */
diff --git a/gdb/python/py-threadevent.c b/gdb/python/py-threadevent.c
index 7211fa2..8b742ca 100644
--- a/gdb/python/py-threadevent.c
+++ b/gdb/python/py-threadevent.c
@@ -47,7 +47,7 @@ get_event_thread (void)
return thread;
}
-PyObject *
+gdbpy_ref<>
create_thread_event_object (PyTypeObject *py_type, PyObject *thread)
{
gdbpy_ref<> thread_event_obj (create_event_object (py_type));
@@ -66,7 +66,7 @@ create_thread_event_object (PyTypeObject *py_type, PyObject *thread)
thread) < 0)
return NULL;
- return thread_event_obj.release ();
+ return thread_event_obj;
}
GDBPY_NEW_EVENT_TYPE (thread,
--
2.9.4
^ permalink raw reply [flat|nested] 18+ messages in thread
* [RFA 0/3] add a few Python events
@ 2017-09-09 0:34 Tom Tromey
2017-09-09 0:34 ` [RFA 3/3] Make it simpler to add events to Python Tom Tromey
` (2 more replies)
0 siblings, 3 replies; 18+ messages in thread
From: Tom Tromey @ 2017-09-09 0:34 UTC (permalink / raw)
To: gdb-patches
This started as a series to fix PR python/15622 -- adding a few new
events to the Python layer. In particular it adds new_inferior,
inferior_deleted, and new_thread events.
After that I noticed that object ownership in some spots could be
clearer; and that adding a new event or new event type to Python was
too hard, so I added patches to fix these things.
Regression tested on the buildbot.
Tom
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events
2017-09-09 0:34 ` [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events Tom Tromey
@ 2017-09-09 6:55 ` Eli Zaretskii
2017-09-09 16:47 ` Simon Marchi
2017-09-09 16:48 ` Simon Marchi
1 sibling, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2017-09-09 6:55 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches, tom
> From: Tom Tromey <tom@tromey.com>
> Cc: Tom Tromey <tom@tromey.com>
> Date: Fri, 8 Sep 2017 18:33:51 -0600
>
> This adds a few new events to gdb's Python layer: new_inferior,
> inferior_deleted, and new_thread. I wanted to be able to add a
> combined inferior/thread display window to my GUI, and I needed a few
> events to make this work. This is PR python/15622.
>
> gdb/ChangeLog
> 2017-09-08 Tom Tromey <tom@tromey.com>
>
> PR python/15622:
> * NEWS: Add entry.
> * python/python.c (do_start_initialization): Initialize new event
> types.
> * python/python-internal.h (gdbpy_initialize_new_inferior_event)
> (gdbpy_initialize_inferior_deleted_event)
> (gdbpy_initialize_new_thread_event): Declare.
> * python/py-threadevent.c (create_thread_event_object): Add option
> "thread" parameter.
> * python/py-inferior.c (new_thread_event_object_type)
> (new_inferior_event_object_type)
> (inferior_deleted_event_object_type): Declare.
> (python_new_inferior, python_inferior_deleted): New functions.
> (add_thread_object): Emit new_thread event.
> (gdbpy_initialize_inferior): Attach new functions to corresponding
> observers.
> (new_thread, new_inferior, inferior_deleted): Define new event
> types.
> * python/py-evts.c (gdbpy_initialize_py_events): Add new
> registries.
> * python/py-events.h (events_object) <new_inferior,
> inferior_deleted, new_thread>: New fields.
> * python/py-event.h (create_thread_event_breakpoint): Add optional
> "thread" parameter.
>
> gdb/doc/ChangeLog
> 2017-09-08 Tom Tromey <tom@tromey.com>
>
> * python.texi (Events In Python): Document new events.
>
> gdb/testsuite/ChangeLog
> 2017-09-08 Tom Tromey <tom@tromey.com>
>
> * gdb.python/py-infthread.exp: Add tests for new_thread event.
> * gdb.python/py-inferior.exp: Add tests for new inferior events.
OK for the documentation parts.
Thanks.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFA 3/3] Make it simpler to add events to Python
2017-09-09 0:34 ` [RFA 3/3] Make it simpler to add events to Python Tom Tromey
@ 2017-09-09 14:40 ` Tom Tromey
2017-09-09 17:05 ` Simon Marchi
1 sibling, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2017-09-09 14:40 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
Tom> This patch simplifies the process using two new ".def" files.
A python-less build showed that this patch needed one tweak:
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
[...]
#endif /* HAVE_PYTHON */
+
+/* Define all the event objects. */
+#define GDB_PY_DEFINE_EVENT_TYPE(name, py_path, py_name, doc, base) \
The addition here has to come before the #endif, so that it is only
compiled in the HAVE_PYTHON case.
Tom
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events
2017-09-09 6:55 ` Eli Zaretskii
@ 2017-09-09 16:47 ` Simon Marchi
2017-09-09 20:41 ` Tom Tromey
2017-09-10 0:21 ` Tom Tromey
0 siblings, 2 replies; 18+ messages in thread
From: Simon Marchi @ 2017-09-09 16:47 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Tom Tromey, gdb-patches
On 2017-09-09 08:55, Eli Zaretskii wrote:
>> From: Tom Tromey <tom@tromey.com>
>> Cc: Tom Tromey <tom@tromey.com>
>> Date: Fri, 8 Sep 2017 18:33:51 -0600
>>
>> This adds a few new events to gdb's Python layer: new_inferior,
>> inferior_deleted, and new_thread. I wanted to be able to add a
>> combined inferior/thread display window to my GUI, and I needed a few
>> events to make this work. This is PR python/15622.
>>
>> gdb/ChangeLog
>> 2017-09-08 Tom Tromey <tom@tromey.com>
>>
>> PR python/15622:
>> * NEWS: Add entry.
>> * python/python.c (do_start_initialization): Initialize new event
>> types.
>> * python/python-internal.h (gdbpy_initialize_new_inferior_event)
>> (gdbpy_initialize_inferior_deleted_event)
>> (gdbpy_initialize_new_thread_event): Declare.
>> * python/py-threadevent.c (create_thread_event_object): Add option
>> "thread" parameter.
>> * python/py-inferior.c (new_thread_event_object_type)
>> (new_inferior_event_object_type)
>> (inferior_deleted_event_object_type): Declare.
>> (python_new_inferior, python_inferior_deleted): New functions.
>> (add_thread_object): Emit new_thread event.
>> (gdbpy_initialize_inferior): Attach new functions to corresponding
>> observers.
>> (new_thread, new_inferior, inferior_deleted): Define new event
>> types.
>> * python/py-evts.c (gdbpy_initialize_py_events): Add new
>> registries.
>> * python/py-events.h (events_object) <new_inferior,
>> inferior_deleted, new_thread>: New fields.
>> * python/py-event.h (create_thread_event_breakpoint): Add optional
>> "thread" parameter.
>>
>> gdb/doc/ChangeLog
>> 2017-09-08 Tom Tromey <tom@tromey.com>
>>
>> * python.texi (Events In Python): Document new events.
>>
>> gdb/testsuite/ChangeLog
>> 2017-09-08 Tom Tromey <tom@tromey.com>
>>
>> * gdb.python/py-infthread.exp: Add tests for new_thread event.
>> * gdb.python/py-inferior.exp: Add tests for new inferior events.
>
> OK for the documentation parts.
>
> Thanks.
I find the resulting documentation page about Python Events a bit hard
to follow. The "events.new_thread" event registry refers to the
gdb.ThreadEvent type, which itself is defined under the "events.cont"
registry. There it says that inferior_thread is always not None in
none-stop, and always None in all-stop. That is contradictory with the
text under "events.new_thread". If it is possible for event types to be
emitted by different event registries, I think they should be documented
separately (on the same page, but in two sections).
Simon
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events
2017-09-09 0:34 ` [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events Tom Tromey
2017-09-09 6:55 ` Eli Zaretskii
@ 2017-09-09 16:48 ` Simon Marchi
1 sibling, 0 replies; 18+ messages in thread
From: Simon Marchi @ 2017-09-09 16:48 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 2017-09-09 02:33, Tom Tromey wrote:
> This adds a few new events to gdb's Python layer: new_inferior,
> inferior_deleted, and new_thread. I wanted to be able to add a
> combined inferior/thread display window to my GUI, and I needed a few
> events to make this work. This is PR python/15622.
Apart for my comment about documentation, this patch LGTM.
Thanks,
Simon
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFA 3/3] Make it simpler to add events to Python
2017-09-09 0:34 ` [RFA 3/3] Make it simpler to add events to Python Tom Tromey
2017-09-09 14:40 ` Tom Tromey
@ 2017-09-09 17:05 ` Simon Marchi
2017-09-10 0:24 ` Tom Tromey
1 sibling, 1 reply; 18+ messages in thread
From: Simon Marchi @ 2017-09-09 17:05 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 2017-09-09 02:33, Tom Tromey wrote:
> 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".
Hi Tom,
This looks great. The patch is ok, I have two little nits below, which
you can address before pushing if you agree.
> diff --git a/gdb/python/py-event-types.def
> b/gdb/python/py-event-types.def
> new file mode 100644
> index 0000000..d35cbe5
> --- /dev/null
> +++ b/gdb/python/py-event-types.def
> @@ -0,0 +1,120 @@
> +/* 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.
> +
I think it would be clearer if you added the macro "prototype" here,
otherwise the parameter names refer to nothing.
GDB_PY_DEFINE_EVENT_TYPE (name, py_path, py_bame, doc, base) ...
> + 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.
> +*/
> +
> +GDB_PY_DEFINE_EVENT_TYPE (breakpoint,
> + "gdb.BreakpointEvent",
> + "BreakpointEvent",
The py_path and py_name are duplicated everywhere. We could get rid of
py_path. At the only place where it is used, we can replace it with
"gdb." py_name
Thanks,
Simon
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFA 2/3] Small event ownership clean up in Python layer
2017-09-09 0:34 ` [RFA 2/3] Small event ownership clean up in Python layer Tom Tromey
@ 2017-09-09 17:05 ` Simon Marchi
0 siblings, 0 replies; 18+ messages in thread
From: Simon Marchi @ 2017-09-09 17:05 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 2017-09-09 02:33, Tom Tromey wrote:
> It seems cleaner to me for functions like create_thread_event_object,
> which pass object ownership to their callers, to directly return a
> gdb_ref<>. This way the ownership transfer is part of the API. This
> patch makes this change.
LGTM.
Simon
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events
2017-09-09 16:47 ` Simon Marchi
@ 2017-09-09 20:41 ` Tom Tromey
2017-09-09 21:09 ` Simon Marchi
2017-09-10 0:21 ` Tom Tromey
1 sibling, 1 reply; 18+ messages in thread
From: Tom Tromey @ 2017-09-09 20:41 UTC (permalink / raw)
To: Simon Marchi; +Cc: Eli Zaretskii, Tom Tromey, gdb-patches
Simon> I find the resulting documentation page about Python Events a bit hard
Simon> to follow. The "events.new_thread" event registry refers to the
Simon> gdb.ThreadEvent type, which itself is defined under the "events.cont"
Simon> registry. There it says that inferior_thread is always not None in
Simon> none-stop, and always None in all-stop. That is contradictory with
Simon> the text under "events.new_thread". If it is possible for event types
Simon> to be emitted by different event registries, I think they should be
Simon> documented separately (on the same page, but in two sections).
I can just make this not be a subclass of ThreadEvent and then clean up
the docs. Though, there's a PR open about ThreadEvent.inferior_thread
not being set in the all-stop case.
Tom
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events
2017-09-09 20:41 ` Tom Tromey
@ 2017-09-09 21:09 ` Simon Marchi
0 siblings, 0 replies; 18+ messages in thread
From: Simon Marchi @ 2017-09-09 21:09 UTC (permalink / raw)
To: Tom Tromey; +Cc: Eli Zaretskii, gdb-patches
On 2017-09-09 22:41, Tom Tromey wrote:
> I can just make this not be a subclass of ThreadEvent and then clean up
> the docs. Though, there's a PR open about ThreadEvent.inferior_thread
> not being set in the all-stop case.
>
> Tom
I am not sure I understand. Making NewThreadEvent a subclass of
ThreadEvent makes sense to me, since it is an event that concerns one
thread. Right now inferior_thread field of ThreadEvent subclasses is
always None in all-stop, but I don't think it has to stay that way for
new events we introduce (changing the behavior of existing events should
be done more carefully, of course).
Simon
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events
2017-09-09 16:47 ` Simon Marchi
2017-09-09 20:41 ` Tom Tromey
@ 2017-09-10 0:21 ` Tom Tromey
2017-09-10 19:37 ` Simon Marchi
1 sibling, 1 reply; 18+ messages in thread
From: Tom Tromey @ 2017-09-10 0:21 UTC (permalink / raw)
To: Simon Marchi; +Cc: Eli Zaretskii, Tom Tromey, gdb-patches
>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
Simon> I find the resulting documentation page about Python Events a bit hard
Simon> to follow. The "events.new_thread" event registry refers to the
Simon> gdb.ThreadEvent type, which itself is defined under the "events.cont"
Simon> registry. There it says that inferior_thread is always not None in
Simon> none-stop, and always None in all-stop. That is contradictory with
Simon> the text under "events.new_thread". If it is possible for event types
Simon> to be emitted by different event registries, I think they should be
Simon> documented separately (on the same page, but in two sections).
How about this doc patch instead?
Tom
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 32d7939..1e96dbc 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -2989,6 +2989,39 @@ invalid state; that is, the @code{is_valid} method will return
This event carries no payload. It is emitted each time @value{GDBN}
presents a prompt to the user.
+@item events.new_inferior
+This is notified when a new inferior is created. Note that the
+inferior is not necessarily running; in fact, it may not even have an
+associated executable.
+
+The event is of type @code{gdb.NewInferiorEvent}. This has a single
+attribute:
+
+@defvar NewInferiorEvent.inferior
+The new inferior, a @code{gdb.Inferior} object.
+@end defvar
+
+@item events.inferior_deleted
+This is notified when an inferior has been deleted. Note that this is
+not the same as process exit; it is notified when the inferior itself
+is removed, say via @code{remove-inferiors}.
+
+The event is of type @code{gdb.InferiorDeletedEvent}. This has a single
+attribute:
+
+@defvar NewInferiorEvent.inferior
+The inferior that is being removed, a @code{gdb.Inferior} object.
+@end defvar
+
+@item events.new_thread
+This emitted when @value{GDBN} notices a new thread. The event is of
+type @code{gdb.NewThreadEvent}, which extends @code{gdb.ThreadEvent}.
+This has a single attribute:
+
+@defvar NewThreadEvent.inferior_thread
+The new thread.
+@end defvar
+
@end table
@node Threads In Python
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFA 3/3] Make it simpler to add events to Python
2017-09-09 17:05 ` Simon Marchi
@ 2017-09-10 0:24 ` Tom Tromey
0 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2017-09-10 0:24 UTC (permalink / raw)
To: Simon Marchi; +Cc: Tom Tromey, gdb-patches
>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
Simon> I think it would be clearer if you added the macro "prototype" here,
Simon> otherwise the parameter names refer to nothing.
Simon> GDB_PY_DEFINE_EVENT_TYPE (name, py_path, py_bame, doc, base) ...
Sounds good.
Simon> The py_path and py_name are duplicated everywhere. We could get rid
Simon> of py_path. At the only place where it is used, we can replace it
Simon> with
Simon> "gdb." py_name
Good point.
I've made both of these changes locally.
Tom
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events
2017-09-10 0:21 ` Tom Tromey
@ 2017-09-10 19:37 ` Simon Marchi
2017-09-10 21:52 ` Tom Tromey
0 siblings, 1 reply; 18+ messages in thread
From: Simon Marchi @ 2017-09-10 19:37 UTC (permalink / raw)
To: Tom Tromey; +Cc: Eli Zaretskii, gdb-patches
On 2017-09-10 02:21, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
>
> Simon> I find the resulting documentation page about Python Events a
> bit hard
> Simon> to follow. The "events.new_thread" event registry refers to the
> Simon> gdb.ThreadEvent type, which itself is defined under the
> "events.cont"
> Simon> registry. There it says that inferior_thread is always not None
> in
> Simon> none-stop, and always None in all-stop. That is contradictory
> with
> Simon> the text under "events.new_thread". If it is possible for event
> types
> Simon> to be emitted by different event registries, I think they should
> be
> Simon> documented separately (on the same page, but in two sections).
>
> How about this doc patch instead?
That's fine with me, I think it makes it clear enough that the comments
about the inferior_thread field under events.cont don't apply here.
> diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
> index 32d7939..1e96dbc 100644
> --- a/gdb/doc/python.texi
> +++ b/gdb/doc/python.texi
> @@ -2989,6 +2989,39 @@ invalid state; that is, the @code{is_valid}
> method will return
> This event carries no payload. It is emitted each time @value{GDBN}
> presents a prompt to the user.
>
> +@item events.new_inferior
> +This is notified when a new inferior is created. Note that the
> +inferior is not necessarily running; in fact, it may not even have an
> +associated executable.
> +
> +The event is of type @code{gdb.NewInferiorEvent}. This has a single
> +attribute:
> +
> +@defvar NewInferiorEvent.inferior
> +The new inferior, a @code{gdb.Inferior} object.
> +@end defvar
> +
> +@item events.inferior_deleted
> +This is notified when an inferior has been deleted. Note that this is
> +not the same as process exit; it is notified when the inferior itself
> +is removed, say via @code{remove-inferiors}.
> +
> +The event is of type @code{gdb.InferiorDeletedEvent}. This has a
> single
> +attribute:
> +
> +@defvar NewInferiorEvent.inferior
> +The inferior that is being removed, a @code{gdb.Inferior} object.
> +@end defvar
> +
> +@item events.new_thread
> +This emitted when @value{GDBN} notices a new thread. The event is of
"This emitted". I also noticed that for other events you used "This is
notified". Perhaps it would be better to stick with "This is emitted"
everywhere to be consistent.
If Eli is fine with this version of the doc, I think this patch is ready
to go in.
Thanks,
Simon
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events
2017-09-10 19:37 ` Simon Marchi
@ 2017-09-10 21:52 ` Tom Tromey
2017-09-11 11:54 ` Simon Marchi
0 siblings, 1 reply; 18+ messages in thread
From: Tom Tromey @ 2017-09-10 21:52 UTC (permalink / raw)
To: Simon Marchi; +Cc: Tom Tromey, Eli Zaretskii, gdb-patches
>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
Simon> "This emitted". I also noticed that for other events you used "This
Simon> is notified". Perhaps it would be better to stick with "This is
Simon> emitted" everywhere to be consistent.
How's this then?
Tom
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 32d7939..39def2a 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -2989,6 +2989,39 @@ invalid state; that is, the @code{is_valid} method will return
This event carries no payload. It is emitted each time @value{GDBN}
presents a prompt to the user.
+@item events.new_inferior
+This is emitted when a new inferior is created. Note that the
+inferior is not necessarily running; in fact, it may not even have an
+associated executable.
+
+The event is of type @code{gdb.NewInferiorEvent}. This has a single
+attribute:
+
+@defvar NewInferiorEvent.inferior
+The new inferior, a @code{gdb.Inferior} object.
+@end defvar
+
+@item events.inferior_deleted
+This is emitted when an inferior has been deleted. Note that this is
+not the same as process exit; it is notified when the inferior itself
+is removed, say via @code{remove-inferiors}.
+
+The event is of type @code{gdb.InferiorDeletedEvent}. This has a single
+attribute:
+
+@defvar NewInferiorEvent.inferior
+The inferior that is being removed, a @code{gdb.Inferior} object.
+@end defvar
+
+@item events.new_thread
+This is emitted when @value{GDBN} notices a new thread. The event is of
+type @code{gdb.NewThreadEvent}, which extends @code{gdb.ThreadEvent}.
+This has a single attribute:
+
+@defvar NewThreadEvent.inferior_thread
+The new thread.
+@end defvar
+
@end table
@node Threads In Python
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events
2017-09-10 21:52 ` Tom Tromey
@ 2017-09-11 11:54 ` Simon Marchi
2017-09-11 14:29 ` Eli Zaretskii
0 siblings, 1 reply; 18+ messages in thread
From: Simon Marchi @ 2017-09-11 11:54 UTC (permalink / raw)
To: Tom Tromey; +Cc: Eli Zaretskii, gdb-patches
On 2017-09-10 23:52, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
>
> Simon> "This emitted". I also noticed that for other events you used
> "This
> Simon> is notified". Perhaps it would be better to stick with "This is
> Simon> emitted" everywhere to be consistent.
>
> How's this then?
>
> Tom
>
> diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
> index 32d7939..39def2a 100644
> --- a/gdb/doc/python.texi
> +++ b/gdb/doc/python.texi
> @@ -2989,6 +2989,39 @@ invalid state; that is, the @code{is_valid}
> method will return
> This event carries no payload. It is emitted each time @value{GDBN}
> presents a prompt to the user.
>
> +@item events.new_inferior
> +This is emitted when a new inferior is created. Note that the
> +inferior is not necessarily running; in fact, it may not even have an
> +associated executable.
> +
> +The event is of type @code{gdb.NewInferiorEvent}. This has a single
> +attribute:
> +
> +@defvar NewInferiorEvent.inferior
> +The new inferior, a @code{gdb.Inferior} object.
> +@end defvar
> +
> +@item events.inferior_deleted
> +This is emitted when an inferior has been deleted. Note that this is
> +not the same as process exit; it is notified when the inferior itself
> +is removed, say via @code{remove-inferiors}.
> +
> +The event is of type @code{gdb.InferiorDeletedEvent}. This has a
> single
> +attribute:
> +
> +@defvar NewInferiorEvent.inferior
> +The inferior that is being removed, a @code{gdb.Inferior} object.
> +@end defvar
> +
> +@item events.new_thread
> +This is emitted when @value{GDBN} notices a new thread. The event is
> of
> +type @code{gdb.NewThreadEvent}, which extends @code{gdb.ThreadEvent}.
> +This has a single attribute:
> +
> +@defvar NewThreadEvent.inferior_thread
> +The new thread.
> +@end defvar
> +
> @end table
>
> @node Threads In Python
LGTM, but please give Eli time to comment.
SImon
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events
2017-09-11 11:54 ` Simon Marchi
@ 2017-09-11 14:29 ` Eli Zaretskii
0 siblings, 0 replies; 18+ messages in thread
From: Eli Zaretskii @ 2017-09-11 14:29 UTC (permalink / raw)
To: Simon Marchi; +Cc: tom, gdb-patches
> Date: Mon, 11 Sep 2017 13:54:33 +0200
> From: Simon Marchi <simon.marchi@polymtl.ca>
> Cc: Eli Zaretskii <eliz@gnu.org>, gdb-patches@sourceware.org
>
> LGTM, but please give Eli time to comment.
I'm okay with this version, thanks.
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2017-09-11 14:29 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-09 0:34 [RFA 0/3] add a few Python events Tom Tromey
2017-09-09 0:34 ` [RFA 3/3] Make it simpler to add events to Python Tom Tromey
2017-09-09 14:40 ` Tom Tromey
2017-09-09 17:05 ` Simon Marchi
2017-09-10 0:24 ` Tom Tromey
2017-09-09 0:34 ` [RFA 1/3] Add new_inferior, inferior_deleted, and new_thread events Tom Tromey
2017-09-09 6:55 ` Eli Zaretskii
2017-09-09 16:47 ` Simon Marchi
2017-09-09 20:41 ` Tom Tromey
2017-09-09 21:09 ` Simon Marchi
2017-09-10 0:21 ` Tom Tromey
2017-09-10 19:37 ` Simon Marchi
2017-09-10 21:52 ` Tom Tromey
2017-09-11 11:54 ` Simon Marchi
2017-09-11 14:29 ` Eli Zaretskii
2017-09-09 16:48 ` Simon Marchi
2017-09-09 0:34 ` [RFA 2/3] Small event ownership clean up in Python layer Tom Tromey
2017-09-09 17:05 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox