binutils-gdb/gdb/testsuite/gdb.mi
Pedro Alves 49940788ab 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.
2016-06-21 01:11:57 +01:00
..
array.f
basics.c
ChangeLog-1999-2003
dw2-ref-missing-frame-func.c
dw2-ref-missing-frame-main.c
dw2-ref-missing-frame.exp
dw2-ref-missing-frame.S
gdb669.exp
gdb680.exp
gdb701.c
gdb701.exp
gdb792.cc
gdb792.exp
gdb2549.exp
mi2-amd64-entry-value.c
mi2-amd64-entry-value.exp
mi2-amd64-entry-value.s
mi2-prompt.exp
mi2-var-child.exp
mi-async-run.c Fix -exec-run not running asynchronously with mi-async on (PR gdb/18077) 2016-05-17 16:46:18 -04:00
mi-async-run.exp Fix -exec-run not running asynchronously with mi-async on (PR gdb/18077) 2016-05-17 16:46:18 -04:00
mi-async.exp
mi-basics.exp
mi-break.exp Make mi-break.exp always expect breakpoint commands output on the main UI 2016-06-21 01:11:56 +01:00
mi-breakpoint-changed.exp Fix gdb.mi/mi-breakpoint-changed.exp for remote targets 2016-04-04 10:31:30 -04:00
mi-catch-load-so.c
mi-catch-load.c
mi-catch-load.exp
mi-cli.exp
mi-cmd-param-changed.exp
mi-condbreak-call-thr-state-mt.c
mi-condbreak-call-thr-state-st.c
mi-condbreak-call-thr-state.c
mi-condbreak-call-thr-state.exp
mi-console.c
mi-console.exp
mi-detach.exp
mi-disassemble.exp
mi-dprintf-pending.c
mi-dprintf-pending.exp
mi-dprintf-pendshr.c
mi-dprintf.c
mi-dprintf.exp
mi-editing.exp Make command line editing (use of readline) be per UI 2016-06-21 01:11:48 +01:00
mi-eval.exp
mi-exec-run.exp Always switch fork child to the main UI 2016-06-21 01:11:57 +01:00
mi-exit-code.c
mi-exit-code.exp
mi-file-transfer.exp
mi-file.exp
mi-fill-memory.exp
mi-fullname-deleted.exp
mi-hack-cli.exp
mi-i-cmd.exp
mi-info-os.exp
mi-inheritance-syntax-error.cc
mi-inheritance-syntax-error.exp
mi-language.exp
mi-linespec-err-cp.cc
mi-linespec-err-cp.exp
mi-logging.exp
mi-memory-changed.exp mi-memory-changed.exp: Fix filename passed to untested 2016-06-02 10:08:28 -04:00
mi-nonstop-exit.exp
mi-nonstop.exp
mi-ns-stale-regcache.exp
mi-nsintrall.exp
mi-nsmoribund.exp
mi-nsthrexec.exp
mi-pending.c
mi-pending.exp
mi-pendshr2.c
mi-pendshr.c
mi-pthreads.exp
mi-read-memory.c
mi-read-memory.exp
mi-record-changed.exp Add method/format information to =record-started 2016-06-06 17:10:18 -04:00
mi-reg-undefined.c
mi-reg-undefined.exp
mi-reg-undefined.S
mi-regs.exp
mi-return.exp
mi-reverse.exp
mi-simplerun.exp
mi-solib.exp
mi-stack.c
mi-stack.exp
mi-start.c
mi-start.exp
mi-stepi.exp
mi-stepn.c
mi-stepn.exp
mi-syn-frame.c
mi-syn-frame.exp
mi-threads-interrupt.c Add mi-threads-interrupt.exp test (PR 20039) 2016-05-18 10:13:16 -04:00
mi-threads-interrupt.exp Add mi-threads-interrupt.exp test (PR 20039) 2016-05-18 10:13:16 -04:00
mi-undefined-cmd.exp
mi-until.exp
mi-var-block.exp
mi-var-child-f.exp
mi-var-child.c
mi-var-child.exp
mi-var-cmd.exp
mi-var-cp.cc
mi-var-cp.exp
mi-var-create-rtti.c
mi-var-create-rtti.exp
mi-var-display.exp
mi-var-invalidate.exp
mi-var-list-children-invalid-grandchild.c
mi-var-list-children-invalid-grandchild.exp
mi-var-rtti.cc
mi-var-rtti.exp
mi-vla-c99.exp
mi-vla-fortran.exp
mi-watch-nonstop.exp
mi-watch.exp Send deleted watchpoint-scope output to all UIs 2016-06-21 01:11:56 +01:00
non-stop-exit.c
non-stop.c
ns-stale-regcache.c
nsintrall.c
nsmoribund.c
nsthrexec.c
pending.c
pendshr1.c
pendshr2.c
pr11022.c
pr11022.exp
pthreads.c
solib-lib.c
solib-main.c
testcmds
until.c
var-cmd.c
vla.c
vla.f90
watch-nonstop.c