Always switch fork child to the main UI
authorPedro Alves <palves@redhat.com>
Tue, 21 Jun 2016 00:11:57 +0000 (01:11 +0100)
committerPedro Alves <palves@redhat.com>
Tue, 21 Jun 2016 00:11:57 +0000 (01:11 +0100)
commit49940788ab38b9d58c663cf38855f29c0ebb1b55
treeef322e16fd2feb6219aacba550aac37b9b38772f
parentef274d26b57336b3baa5bb0ae93b49178bc45631
Always switch fork child to the main UI

The following scenario:

 - gdb started in normal CLI mode.

 - separate MI channel created with new-ui

 - inferior output redirected with the "set inferior-tty" command.

 - use -exec-run in the MI channel to run the inferior

is presently mishandled.

When we create the inferior, in fork-child.c, right after vfork, we'll
close all the file descriptors in the vfork child, and then dup the
tty to file descriptors 0/1/2, create a session, etc.  Note that when
we close all descriptors, we close the file descriptors behind
gdb_stdin/gdb_stdout/gdb_stderr of all secondary UIs...  So if
anything goes wrong in the child and it calls warning/error, it'll end
up writting to the current UI's stdout/stderr streams, which are
backed by file descriptors that have since been closed.  Because this
happens in a vfork region, the corresponding stdin/stdout/stderr in
the parent/gdb end up corrupted.

The fix is to switch to the main UI right after the vfork, so that
gdb_stdin/gdb_stdout/gdb_stderr are correctly mapped to
stdin/stdout/stderr (and thus to file descriptors 0/1/2), so this code
works as it has always worked.

(Technically, we're doing a lot of stuff we shouldn't be doing after a
vfork, while we should only be calling async-signal-safe functions.)

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

* fork-child.c (fork_inferior): Switch the child to the main UI
right after vfork.  Save/restore the current UI in the parent.
Flush outputs of the main UI instead of the current UI.

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

* gdb.mi/mi-exec-run.exp: New file.
gdb/ChangeLog
gdb/fork-child.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.mi/mi-exec-run.exp [new file with mode: 0644]
This page took 0.027011 seconds and 4 git commands to generate.