+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-01 Joel Brobecker <brobecker@adacore.com>
Sergio Durigan Junior <sergiodj@redhat.com>
Pedro Alves <palves@redhat.com>
}
# Detach from a process, and ensure that it exits after detaching.
-# This relies on inferior I/O.
+# This relies on inferior I/O. INF_OUTPUT_RE is the pattern that
+# matches the expected inferior output.
-proc detach_and_expect_exit {test} {
+proc detach_and_expect_exit {inf_output_re test} {
global decimal
global gdb_spawn_id
global inferior_spawn_id
}
}]
+ # Use an indirect spawn id list, and remove inferior spawn id from
+ # the expected output as soon as it matches, so that if
+ # $inf_inferior_spawn_id is $server_spawn_id and we're testing in
+ # "target remote" mode, the eof caused by gdbserver exiting is
+ # left for the caller to handle.
+ global daee_spawn_id_list
+ set daee_spawn_id_list "$inferior_spawn_id $gdb_spawn_id"
+
set saw_prompt 0
set saw_inf_exit 0
- while { !$saw_prompt && ! $saw_inf_exit } {
+ while { !$saw_prompt || ! $saw_inf_exit } {
# We don't know what order the interesting things will arrive in.
# Using a pattern of the form 'x|y|z' instead of -re x ... -re y
# ... -re z ensures that expect always chooses the match that
# first in the script that occurs anywhere in the input, so that
# we don't skip anything.
return_if_fail [gdb_test_multiple "" $test {
- -i "$inferior_spawn_id $gdb_spawn_id"
- -re "(exited, status=0)|($gdb_prompt )" {
+ -i daee_spawn_id_list
+ -re "($inf_output_re)|($gdb_prompt )" {
if {[info exists expect_out(1,string)]} {
verbose -log "saw inferior exit"
set saw_inf_exit 1
+ set daee_spawn_id_list "$gdb_spawn_id"
} elseif {[info exists expect_out(2,string)]} {
verbose -log "saw prompt"
set saw_prompt 1
+ set daee_spawn_id_list "$inferior_spawn_id"
}
array unset expect_out
}
#
# CMD indicates what to do with the parent after detaching the child.
# Can be either "detach" to detach, or "continue", to continue to
-# exit. If "continue", then CONTINUE_RE is the regexp to expect.
-# Defaults to normal exit output.
+# exit.
+#
+# CHILD_EXIT indicates how is the child expected to exit. Can be
+# either "normal" for normal exit, or "signal" for killed with signal
+# SIGKILL.
#
-proc do_detach {multi_process cmd {continue_re ""}} {
+proc do_detach {multi_process cmd child_exit} {
global decimal
global server_spawn_id
- if {$continue_re == ""} {
+ if {$child_exit == "normal"} {
set continue_re "exited normally.*"
+ set inf_output_re "exited, status=0"
+ } elseif {$child_exit == "signal"} {
+ if {$multi_process} {
+ set continue_re "exited with code 02.*"
+ } else {
+ set continue_re "terminated with signal SIGKILL.*"
+ }
+ set inf_output_re "signaled, sig=9"
+ } else {
+ error "unhandled \$child_exit: $child_exit"
}
set is_remote [expr {[target_info exists gdb_protocol]
if {$cmd == "detach"} {
# Make sure that detach works and that the parent process
# exits cleanly.
- detach_and_expect_exit "detach parent"
+ detach_and_expect_exit $inf_output_re "detach parent"
} elseif {$cmd == "continue"} {
# Make sure that continuing works and that the parent process
# exits cleanly.
# Run to _exit in the child.
continue_to_exit_bp
- do_detach $multi_process $cmd
+ do_detach $multi_process $cmd "normal"
}
}
# thread individually).
continue_to_exit_bp
- do_detach $multi_process $cmd
+ do_detach $multi_process $cmd "normal"
}
}
# Give it some time to die.
sleep 2
- if {$multi_process} {
- set continue_re "exited with code 02.*"
- } else {
- set continue_re "terminated with signal SIGKILL.*"
- }
- do_detach $multi_process $cmd $continue_re
+ do_detach $multi_process $cmd "signal"
}
}