8sa1-binutils-gdb/gdb/testsuite/gdb.threads
Pedro Alves f0fb2488c9 Fix gdb.threads/process-dies-while-detaching.exp
I noticed [1] a test bug in gdb.threads/process-dies-while-detaching.exp.
Simplified, the test code in question looks somewhat like this:

~~~
  # Detach from a process, and ensure that it exits after detaching.
  # This relies on inferior I/O.

  proc detach_and_expect_exit {test} {

      gdb_test_multiple "detach" $test ....

      set saw_prompt 0
      set saw_inf_exit 0
      while { !$saw_prompt && !$saw_inf_exit } {
          gdb_test_multiple "" $test {
              -re "exited, status=0" {
                  set saw_inf_exit 1
              }
              -re "$gdb_prompt " {
                  set saw_prompt 1
              }
          }
      }

      pass $test
  }
~~~

The bug is in the while loop's condition.  We want to make sure we see
both the inferior output and the prompt, so the loop's test should be:

   -    while { !$saw_prompt && !$saw_inf_exit } {
   +    while { !$saw_prompt || !$saw_inf_exit } {

If we just fix that, the test starts failing though, because it
exposes a couple latent problems:

- When called from test_detach_killed_outside, the parent doesn't
  print "exited, status=0", because in that case the child dies with a
  signal, and so detach_and_expect_exit times out.

  Fix it by making the parent print "signaled, sig=9" in that case,
  and have the .exp expect it.

- When testing against --target_board=native-gdbserver, sometimes we'd
  get this:

    ERROR: Process no longer exists
    ERROR: : spawn id exp9 not open
	while executing
    "expect {
    -i exp8 -timeout 220
	    -i $server_spawn_id
	    eof {
		pass $test
		wait -i $server_spawn_id
		unset server_spawn_id
	    }
	    timeout {
	       ..."
	("uplevel" body line 1)
	invoked from within
    "uplevel $body" NONE : spawn id exp9 not open

  The problem is that:

   - inferior_spawn_id and server_spawn_id are the same when testing
     with gdbserver.
   - gdbserver exits after "detach", so we get an eof for
     $inferior_spawn_id in the loop in detach_and_expect_exit.
     That's the first "ERROR: Process no longer exists".
   - and then when we reach test_server_exit, server_spawn_id
     is already closed (because server_spawn_id==inferior_spawn_id).

  To handle this, make the loop in detach_and_expect_exit use an
  indirect spawn id list and remove $inferior_spawn_id from the list
  as soon as we got the inferior output we're expecting, so that the
  "eof" is left unprocessed until we reach test_server_exit.

[1] I changed GDB in a way that should have made the test fail, but it
    didn't.

gdb/testsuite/ChangeLog:
2017-12-03  Pedro Alves  <palves@redhat.com>

	* gdb.threads/process-dies-while-detaching.c: Include <errno.h>
	and <string.h>.
	(parent_function): Print distinct messages when waitpid fails, or
	the child exits with a signal, or the child exits for an unhandled
	reason.
	* gdb.threads/process-dies-while-detaching.exp
	(detach_and_expect_exit): New 'inf_output_re' parameter and use
	it.  Wait for both inferior output and GDB's prompt.  Use an
	indirect spawn id list.
	(do_detach): New parameter 'child_exit'.  Use it to compute
	expected inferior output.
	(test_detach, test_detach_watch, test_detach_killed_outside):
	Adjust to pass down the expected child exit kind.
2017-12-03 15:32:08 +00:00
..
attach-into-signal.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
attach-into-signal.exp Reindent gdb.threads/attach-into-signal.exp 2017-10-24 10:55:50 +01:00
attach-many-short-lived-threads.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
attach-many-short-lived-threads.exp testsuite: Introduce dejagnu_version 2017-03-13 18:02:07 -04:00
attach-stopped.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
attach-stopped.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
bp_in_thread.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
bp_in_thread.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
break-while-running.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
break-while-running.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
clone-attach-detach.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
clone-attach-detach.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
clone-new-thread-event.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
clone-new-thread-event.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
clone-thread_db.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
clone-thread_db.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
continue-pending-after-query.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
continue-pending-after-query.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
continue-pending-status.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
continue-pending-status.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
corethreads.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
corethreads.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
create-fail.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
create-fail.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
current-lwp-dead.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
current-lwp-dead.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
dlopen-libpthread-lib.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
dlopen-libpthread.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
dlopen-libpthread.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
execl1.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
execl.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
execl.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
fork-child-threads.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
fork-child-threads.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
fork-plus-threads.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
fork-plus-threads.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
fork-thread-pending.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
fork-thread-pending.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
forking-threads-plus-breakpoint.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
forking-threads-plus-breakpoint.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gcore-stale-thread.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gcore-stale-thread.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gcore-thread.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
hand-call-in-threads.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
hand-call-in-threads.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
hand-call-new-thread.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
hand-call-new-thread.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
ia64-sigill.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
ia64-sigill.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
info-threads-cur-sal-2.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
info-threads-cur-sal.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
info-threads-cur-sal.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
interrupt-while-step-over.c Fix PR18360 - internal error when using "interrupt -a" 2017-03-08 18:54:34 +00:00
interrupt-while-step-over.exp Fix PR18360 - internal error when using "interrupt -a" 2017-03-08 18:54:34 +00:00
interrupted-hand-call.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
interrupted-hand-call.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
kill.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
kill.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
killed.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
killed.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
leader-exit.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
leader-exit.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
linux-dp.c
linux-dp.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
local-watch-wrong-thread.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
local-watch-wrong-thread.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
manythreads.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
manythreads.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
multi-create-ns-info-thr.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
multi-create.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
multi-create.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
multiple-step-overs.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
multiple-step-overs.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
names.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
names.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
next-bp-other-thread.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
next-bp-other-thread.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
next-while-other-thread-longjmps.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
next-while-other-thread-longjmps.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
no-unwaited-for-left.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
no-unwaited-for-left.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
non-ldr-exc-1.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
non-ldr-exc-1.exp Enable gdb.threads/non-ldr-exc-*.exp on is_remote target boards 2017-10-12 18:05:33 +01:00
non-ldr-exc-2.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
non-ldr-exc-2.exp Enable gdb.threads/non-ldr-exc-*.exp on is_remote target boards 2017-10-12 18:05:33 +01:00
non-ldr-exc-3.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
non-ldr-exc-3.exp Enable gdb.threads/non-ldr-exc-*.exp on is_remote target boards 2017-10-12 18:05:33 +01:00
non-ldr-exc-4.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
non-ldr-exc-4.exp Enable gdb.threads/non-ldr-exc-*.exp on is_remote target boards 2017-10-12 18:05:33 +01:00
non-ldr-exit.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
non-ldr-exit.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
non-stop-fair-events.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
non-stop-fair-events.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
pending-step.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
pending-step.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
print-threads.c
print-threads.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
process-dies-while-detaching.c Fix gdb.threads/process-dies-while-detaching.exp 2017-12-03 15:32:08 +00:00
process-dies-while-detaching.exp Fix gdb.threads/process-dies-while-detaching.exp 2017-12-03 15:32:08 +00:00
process-dies-while-handling-bp.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
process-dies-while-handling-bp.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
pthread_cond_wait.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
pthread_cond_wait.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
pthreads.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
pthreads.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
queue-signal.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
queue-signal.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
reconnect-signal.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
reconnect-signal.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
schedlock.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
schedlock.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
siginfo-threads.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
siginfo-threads.exp Stop assuming no-debug-info functions return int 2017-09-04 20:21:13 +01:00
signal-command-handle-nopass.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
signal-command-handle-nopass.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
signal-command-multiple-signals-pending.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
signal-command-multiple-signals-pending.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
signal-delivered-right-thread.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
signal-delivered-right-thread.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
signal-sigtrap.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
signal-sigtrap.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
signal-while-stepping-over-bp-other-thread.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
signal-while-stepping-over-bp-other-thread.exp Fix PR18360 - internal error when using "interrupt -a" 2017-03-08 18:54:34 +00:00
sigstep-threads.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
sigstep-threads.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
sigthread.c
sigthread.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
staticthreads.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
staticthreads.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
step-bg-decr-pc-switch-thread.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
step-bg-decr-pc-switch-thread.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
step-over-lands-on-breakpoint.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
step-over-lands-on-breakpoint.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
step-over-trips-on-watchpoint.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
step-over-trips-on-watchpoint.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
stepi-random-signal.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
stepi-random-signal.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
switch-threads.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
switch-threads.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
thread_check.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
thread_check.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
thread_events.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
thread_events.exp Skip gdb.threads/thread_events.exp on RSP targets properly 2017-10-13 12:23:32 +01:00
thread-execl.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
thread-execl.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
thread-find.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
thread-specific-bp.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
thread-specific-bp.exp Fix racy test in gdb.threads/thread-specific-bp.exp 2017-04-05 14:46:13 +01:00
thread-specific.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
thread-specific.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
thread-unwindonsignal.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
threadapply.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
threadapply.exp Fix removing inferiors from within "thread apply" commands 2017-04-19 13:12:23 +01:00
threxit-hop-specific.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
threxit-hop-specific.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
tid-reuse.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
tid-reuse.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
tls2.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
tls-core.c Add test for fetching TLS from core file 2017-11-08 21:19:05 +00:00
tls-core.exp Add test for fetching TLS from core file 2017-11-08 21:19:05 +00:00
tls-main.c
tls-nodebug-pie.c Fix accessing TLS variables with no debug info 2017-09-06 12:32:46 +01:00
tls-nodebug-pie.exp Fix accessing TLS variables with no debug info 2017-09-06 12:32:46 +01:00
tls-nodebug.c
tls-nodebug.exp Stop assuming no-debug-info variables have type int 2017-09-04 20:21:15 +01:00
tls-shared.c
tls-shared.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
tls-so_extern_main.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
tls-so_extern.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
tls-so_extern.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
tls-var-main.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
tls-var.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
tls-var.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
tls.c
tls.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
watchpoint-fork-child.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
watchpoint-fork-mt.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
watchpoint-fork-parent.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
watchpoint-fork-st.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
watchpoint-fork.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
watchpoint-fork.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
watchthreads2.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
watchthreads2.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
watchthreads-reorder.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
watchthreads-reorder.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
watchthreads.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
watchthreads.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
wp-replication.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
wp-replication.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00