Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] PR python/13598 - add before_prompt event
@ 2016-05-21  5:01 Tom Tromey
  2016-05-21  6:54 ` Eli Zaretskii
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Tom Tromey @ 2016-05-21  5:01 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This adds an event that is emitted just before GDB presents a prompt
to the user.  This provides Python code a way to react to whatever
changes might have been made by the previous command.  For example, in
my GUI I use this to track changes to the selected frame and reflect
them in the UI.

Built and regtested on x86-64 Fedora 23.

2016-05-20  Tom Tromey  <tom@tromey.com>

	PR python/13598:
	* python/python.c (gdbpy_before_prompt_hook): Emit before_prompt
	event.
	* python/py-evts.c (gdbpy_initialize_py_events): Add
	before_prompt registry.
	* python/py-events.h (events_object) <before_prompt>: New field.

2016-05-20  Tom Tromey  <tom@tromey.com>

	PR python/13598:
	* python.texi (Events In Python): Document events.before_prompt.

2016-05-20  Tom Tromey  <tom@tromey.com>

	PR python/13598:
	* gdb.python/py-events.exp: Add before_prompt event tests.
---
 gdb/ChangeLog                          |  9 +++++++++
 gdb/doc/ChangeLog                      |  5 +++++
 gdb/doc/python.texi                    |  4 ++++
 gdb/python/py-events.h                 |  1 +
 gdb/python/py-evts.c                   |  3 +++
 gdb/python/python.c                    |  5 +++++
 gdb/testsuite/ChangeLog                |  5 +++++
 gdb/testsuite/gdb.python/py-events.exp | 25 +++++++++++++++++++++++++
 8 files changed, 57 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0968b85..c0b6b06 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2016-05-20  Tom Tromey  <tom@tromey.com>
+
+	PR python/13598:
+	* python/python.c (gdbpy_before_prompt_hook): Emit before_prompt
+	event.
+	* python/py-evts.c (gdbpy_initialize_py_events): Add
+	before_prompt registry.
+	* python/py-events.h (events_object) <before_prompt>: New field.
+
 2016-05-19  Andreas Schwab  <schwab@suse.de>
 
 	* ia64-libunwind-tdep.c (libunwind_descr): Add cast from void *.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index fe2e3be..fa14b67 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2016-05-20  Tom Tromey  <tom@tromey.com>
+
+	PR python/13598:
+	* python.texi (Events In Python): Document events.before_prompt.
+
 2016-05-17  Tom Tromey  <tom@tromey.com>
 
 	* gdb.texinfo (Supported Languages): Mention Rust.  Update menu.
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index ffbf89a..e655db8 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -2962,6 +2962,10 @@ A gdb.Frame object representing the frame in which the register was modified.
 Denotes which register was modified.
 @end defvar
 
+@item events.before_prompt
+This event carries no payload.  It is emitted each time @value{GDBN}
+presents a prompt to the user.
+
 @end table
 
 @node Threads In Python
diff --git a/gdb/python/py-events.h b/gdb/python/py-events.h
index 9ecee4c..b969c15 100644
--- a/gdb/python/py-events.h
+++ b/gdb/python/py-events.h
@@ -50,6 +50,7 @@ typedef struct
   eventregistry_object *inferior_call;
   eventregistry_object *memory_changed;
   eventregistry_object *register_changed;
+  eventregistry_object *before_prompt;
 
   PyObject *module;
 
diff --git a/gdb/python/py-evts.c b/gdb/python/py-evts.c
index 95827e4..d388282 100644
--- a/gdb/python/py-evts.c
+++ b/gdb/python/py-evts.c
@@ -89,6 +89,9 @@ 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.before_prompt, "before_prompt") < 0)
+    return -1;
+
   if (gdb_pymodule_addobject (gdb_module,
 			      "events",
 			      (PyObject *) gdb_py_events.module) < 0)
diff --git a/gdb/python/python.c b/gdb/python/python.c
index c706644..d22f8dd 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -36,6 +36,7 @@
 #include <ctype.h>
 #include "location.h"
 #include "ser-event.h"
+#include "py-event.h"
 
 /* Declared constants and enum for python stack printing.  */
 static const char python_excp_none[] = "none";
@@ -1029,6 +1030,10 @@ gdbpy_before_prompt_hook (const struct extension_language_defn *extlang,
 
   cleanup = ensure_python_env (get_current_arch (), current_language);
 
+  if (!evregpy_no_listeners_p (gdb_py_events.before_prompt)
+      && evpy_emit_event (NULL, gdb_py_events.before_prompt) < 0)
+    goto fail;
+
   if (gdb_python_module
       && PyObject_HasAttrString (gdb_python_module, "prompt_hook"))
     {
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index a773c63..3f585f3 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-05-20  Tom Tromey  <tom@tromey.com>
+
+	PR python/13598:
+	* gdb.python/py-events.exp: Add before_prompt event tests.
+
 2016-05-18  Simon Marchi  <simon.marchi@ericsson.com>
 
 	* gdb.mi/mi-threads-interrupt.c: New file.
diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp
index de8de07..592367d 100644
--- a/gdb/testsuite/gdb.python/py-events.exp
+++ b/gdb/testsuite/gdb.python/py-events.exp
@@ -210,3 +210,28 @@ gdb_test "continue" ".*event type: continue.*
 .*exit code: 12.*
 .*exit inf: 2.*
 dir ok: True.*" "Inferior 2 terminated."
+
+
+# Test before_prompt event.
+gdb_py_test_multiple "define new user command" \
+    "define xxz" "End with a line saying just .end.." \
+    "set variable \$x = 72" "" \
+    "set variable \$y = 93" "" \
+    "end" ""
+
+gdb_py_test_multiple "add before_prompt listener" \
+    "python" "" \
+    "count = 0" "" \
+    "def listener():" "" \
+    "  global count" "" \
+    "  count = count + 1" "" \
+    "gdb.events.before_prompt.connect(listener)" "" \
+    "end" ""
+
+gdb_test_no_output "set variable \$x = 32" "do something"
+# Result is due to one emitted before "set var" and one emitted before
+# this command.
+gdb_test "python print(count)" 2 "check for before_prompt event"
+
+gdb_test_no_output "xxz" "run a canned sequence"
+gdb_test "python print(count)" 4 "check for before_prompt event"
-- 
2.5.5


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2017-02-14 18:03 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-21  5:01 [RFA] PR python/13598 - add before_prompt event Tom Tromey
2016-05-21  6:54 ` Eli Zaretskii
2016-07-22  9:34 ` Phil Muldoon
2016-07-22 10:01 ` Yao Qi
2016-07-22 10:22   ` Matt Rice
2016-07-23  5:00     ` Tom Tromey
2016-08-03  8:33       ` Yao Qi
2016-08-03 16:08         ` Tom Tromey
2016-08-03 16:16       ` Pedro Alves
2016-08-04 20:34         ` Tom Tromey
2016-08-05 17:30           ` Pedro Alves
2016-10-09 17:23           ` Tom Tromey
2016-07-22 13:28   ` Phil Muldoon
2017-02-11 15:33 ` Tom Tromey
2017-02-12 23:02   ` Yao Qi
2017-02-14 18:03     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox