Prepare gdb.python/mi-py-events.exp for Python/MI in separate channels
authorPedro Alves <palves@redhat.com>
Tue, 21 Jun 2016 00:11:43 +0000 (01:11 +0100)
committerPedro Alves <palves@redhat.com>
Tue, 21 Jun 2016 00:11:43 +0000 (01:11 +0100)
Similarly to 5068630ad34dce5fefbe68d70d3a50cd8b92f71e
(gdb.python/py-events.exp and normal_stop observers ordering) [1],
this commit makes the gdb.python/py-mi-events.exp test not rely on
order in which MI and Python observers run, or even on where each
observer sends its output to.

This shows up as a problem when testing with MI running as a separate
terminal, for example, where Python event output and MI output go to
different channels, even.  But in any case, relying on the order in
which observers run is always going to be fragile.

The fix is to save the string output in the handlers in some variables
and then having MI print them explicitly, instead of printing them
directly from the Python events.

Tested on x86_64 Fedora 23.

https://sourceware.org/ml/gdb-patches/2015-07/msg00290.html

gdb/testsuite/ChangeLog:
2016-06-21  Pedro Alves  <palves@redhat.com>

* gdb.python/py-mi-events-gdb.py (stop_handler_str)
(cont_handler_str): New.
(signal_stop_handler): Set stop_handler_str instead of printing to
stdout.
(continue_handler): Set cont_handler_str instead of printing to
stdout.
* gdb.python/py-mi-events.exp: Ues mi_execute_to instead of
mi_send_resuming_command.  Print stop_handler_str and
cont_handler_str instead of expecting the python events print
directly.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-mi-events-gdb.py
gdb/testsuite/gdb.python/py-mi-events.exp

index e5f1c543c78f344c163a68c6cb8f6b6c22cb11f7..b33e1be731547c6430b6802d5fadb037753ff0df 100644 (file)
@@ -1,3 +1,16 @@
+2016-06-21  Pedro Alves  <palves@redhat.com>
+
+       * gdb.python/py-mi-events-gdb.py (stop_handler_str)
+       (cont_handler_str): New.
+       (signal_stop_handler): Set stop_handler_str instead of printing to
+       stdout.
+       (continue_handler): Set cont_handler_str instead of printing to
+       stdout.
+       * gdb.python/py-mi-events.exp: Ues mi_execute_to instead of
+       mi_send_resuming_command.  Print stop_handler_str and
+       cont_handler_str instead of expecting the python events print
+       directly.
+
 2016-06-17  Sanjoy Das  <sanjoy@playingwithpointers.com>
 
        * gdb.base/jit-reader.exp: New file.
index 975ff2f3a05479d00b2b78e8f29976e78dd5e7f0..2bcb1faff160668da327580b7a5d02f71f40c553 100644 (file)
 
 import gdb
 
+stop_handler_str = ""
+cont_handler_str = ""
 
 def signal_stop_handler (event):
     """Stop event handler"""
     assert (isinstance (event, gdb.StopEvent))
-    print ("stop_handler")
-    print (gdb.execute("info break", False, True))
+    global stop_handler_str
+    stop_handler_str = "stop_handler\n"
+    stop_handler_str += gdb.execute("info break", False, True)
 
 
 def continue_handler (event):
     """Continue event handler"""
     assert (isinstance (event, gdb.ContinueEvent))
-    print ("continue_handler")
-    print (gdb.execute("info break", False, True))
+    global cont_handler_str
+    cont_handler_str = "continue_handler\n"
+    cont_handler_str += gdb.execute("info break", False, True)
 
 
 class test_events (gdb.Command):
index 6f063e1b14b70f8aede3ffb2a63d8fde69eb5c50..d20ae985d9d73d40fbd7cd3485663ffec905f56a 100644 (file)
@@ -58,14 +58,16 @@ mi_gdb_test "test-events" \
     "register events"
 
 
+set lineno [gdb_get_line_number "i++;"]
+
 # set a breakpoint into the for loop
-mi_gdb_test "break ${srcfile}:[gdb_get_line_number "i++;"]" \
+mi_gdb_test "break ${srcfile}:$lineno" \
     ".*Breakpoint $decimal at 0x\[0-9a-fA-F\]+: file .*${srcfile}.*\\\.*\\^done" \
     "set the breakpoint"
 
 
 # resume the program
-mi_send_resuming_command "exec-continue" "continue"
+mi_execute_to "exec-continue" "breakpoint-hit" "main" "" ".*$srcfile" "$lineno" { "" "disp=\"keep\"" } "continue"
 
 
 # test the python event handlers execution. The following checks are performed:
@@ -73,12 +75,13 @@ mi_send_resuming_command "exec-continue" "continue"
 # - the continue handler prints "info breakpoints" output in console format
 # - breakpoint is hit and python stop handler is executed
 # - the stop handler prints "info breakpoints" output in console format
-mi_gdb_test "" ".*continue_handler.*
-.*Num.*Type.*Disp.*Enb.*Address.*\
-.*$decimal.*breakpoint.*keep.*y.* 0x\[0-9a-fA-F\]+.*${srcfile}.*
-.*stop_handler.*
-.*Num.*Type.*Disp.*Enb.*Address.*\
-.*$decimal.*breakpoint.*keep.*y.* 0x\[0-9a-fA-F\]+.*${srcfile}.*" \
-"check python continue and stop handlers"
+
+mi_gdb_test "python print (stop_handler_str)" \
+".*stop_handler.*Num.*Type.*Disp.*Enb.*Address.*$decimal.*breakpoint.*keep.*y.* 0x\[0-9a-fA-F\]+.*${srcfile}.*" \
+"python stop handler ran"
+
+mi_gdb_test "python print (cont_handler_str)" \
+".*continue_handler.*Num.*Type.*Disp.*Enb.*Address.*$decimal.*breakpoint.*keep.*y.* 0x\[0-9a-fA-F\]+.*${srcfile}.*" \
+"python continue handler ran"
 
 mi_gdb_exit