]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
target_terminal::ours_for_output before printing signal received
authorPedro Alves <pedro@palves.net>
Thu, 3 Jun 2021 18:39:19 +0000 (19:39 +0100)
committerPedro Alves <pedro@palves.net>
Mon, 14 Jun 2021 20:53:54 +0000 (21:53 +0100)
A following patch will make GDB put spawned inferiors in their own
terminal/session (on GNU/Linux).  In that case, GDB is in control of
when is the inferior's output flushed to the screen.  A sync point is
when target_terminal state goes from inferior -> ours/ours_for_output.

The gdb.multi/multi-term-settings.exp testcase exposed a bug where an
inferior output flush is missing, resulting in this regression:

Good:

 (gdb) PASS: gdb.multi/multi-term-settings.exp: inf1_how=run-share: inf2_how=run-session: info inferiors
 continue
 Continuing.
 pid=1275538, count=0
 pid=1276069, count=0

 Thread 1.1 "multi-term-sett" received signal SIGTTOU, Stopped (tty output).
 [Switching to process 1275538]
 0x00007ffff7ecda14 in __tcsetattr (fd=0, optional_actions=0, termios_p=0x7fffffffd450) at ../sysdeps/unix/sysv/linux/tcsetattr.c:83
 83 ../sysdeps/unix/sysv/linux/tcsetattr.c: No such file or directory.
 (gdb) PASS: gdb.multi/multi-term-settings.exp: inf1_how=run-share: inf2_how=run-session: continue (expected SIGTTOU)
 Quit
 (gdb) PASS: gdb.multi/multi-term-settings.exp: inf1_how=run-share: inf2_how=run-session: stop with control-c (Quit)

Bad:

 (gdb) PASS: gdb.multi/multi-term-settings.exp: inf1_how=run-share: inf2_how=run-session: info inferiors
 continue
 Continuing.
 pid=1287638, count=0

 Thread 1.1 "multi-term-sett" received signal SIGTTOU, Stopped (tty output).
 pid=1287663, count=0                      <<<<<< HERE
 [Switching to process 1287638]
 0x00007ffff7ecda14 in __tcsetattr (fd=0, optional_actions=0, termios_p=0x7fffffffd450) at ../sysdeps/unix/sysv/linux/tcsetattr.c:83
 83 ../sysdeps/unix/sysv/linux/tcsetattr.c: No such file or directory.
 (gdb) FAIL: gdb.multi/multi-term-settings.exp: inf1_how=run-share: inf2_how=run-session: continue
 Quit
 (gdb) PASS: gdb.multi/multi-term-settings.exp: inf1_how=run-share: inf2_how=run-session: stop with control-c (Quit)

Notice the "<<<<<< HERE" line in the "Bad" output above -- that is
inferior output being printed on the screen _after_ GDB says the
thread stopped...  That's obviously bogus, the output was printed by
the inferior before it was stopped.

The fix is to claim back the terminal for output before printing the
"signal received SIGTTOU" message.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <pedro@palves.net>

* infrun.c (normal_stop): Call target_terminal::ours_for_output
before calling signal_received observers.

Change-Id: Iea106c33b4c585562fc3579ca85d43481fa214f0

gdb/infrun.c

index 4bd21fde590790d8b442db5d387870ae26733022..1eb7526d246d3753f3c63db689e48370aba10f9e 100644 (file)
@@ -8537,7 +8537,10 @@ normal_stop (void)
   update_thread_list ();
 
   if (last.kind == TARGET_WAITKIND_STOPPED && stopped_by_random_signal)
-    gdb::observers::signal_received.notify (inferior_thread ()->suspend.stop_signal);
+    {
+      target_terminal::ours_for_output ();
+      gdb::observers::signal_received.notify (inferior_thread ()->suspend.stop_signal);
+    }
 
   /* As with the notification of thread events, we want to delay
      notifying the user that we've switched thread context until