aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/attach.exp
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2014-09-11 13:04:15 +0100
committerPedro Alves <palves@redhat.com>2014-09-11 13:08:21 +0100
commit98880d46bdb1e88db447f876a8ac1f2a4de97dae (patch)
tree75090eec406fd8e71498ad3d4d0f954c676dfb32 /gdb/testsuite/gdb.base/attach.exp
parent4c92ff2c35392b68ee9172af979483b32aaa3d7b (diff)
downloadgdb-98880d46bdb1e88db447f876a8ac1f2a4de97dae.zip
gdb-98880d46bdb1e88db447f876a8ac1f2a4de97dae.tar.gz
gdb-98880d46bdb1e88db447f876a8ac1f2a4de97dae.tar.bz2
gdb/17347 - Regression: GDB stopped on run with attached process
Doing: gdb --pid=PID -ex run Results in GDB getting a SIGTTIN, and thus ending stopped. That's usually indicative of a missing target_terminal_ours call. E.g., from the PR: $ sleep 1h & p=$!; sleep 0.1; gdb -batch sleep $p -ex run [1] 28263 [1] Killed sleep 1h [2]+ Stopped gdb -batch sleep $p -ex run The workaround is doing: gdb -ex "attach $PID" -ex "run" instead of gdb [-p] $PID -ex "run" With the former, gdb waits for the attach command to complete before moving on to the "run" command, because the interpreter is in sync mode at this point, within execute_command. But for the latter, attach_command is called directly from captured_main, and thus misses that waiting. IOW, "run" is running before the attach continuation has run, before the program stops and attach completes. The broken terminal settings are just one symptom of that. Any command that queries or requires input results in the same. The fix is to wait in catch_command_errors (which is specific to main.c nowadays), just like we wait in execute_command. gdb/ChangeLog: 2014-09-11 Pedro Alves <palves@redhat.com> PR gdb/17347 * main.c: Include "infrun.h". (catch_command_errors, catch_command_errors_const): Wait for the foreground command to complete. * top.c (maybe_wait_sync_command_done): New function, factored out from ... (maybe_wait_sync_command_done): ... here. * top.h (maybe_wait_sync_command_done): New declaration. gdb/testsuite/ChangeLog: 2014-09-11 Pedro Alves <palves@redhat.com> PR gdb/17347 * lib/gdb.exp (gdb_spawn_with_cmdline_opts): New procedure. * gdb.base/attach.exp (test_command_line_attach_run): New procedure. (top level): Call it.
Diffstat (limited to 'gdb/testsuite/gdb.base/attach.exp')
-rw-r--r--gdb/testsuite/gdb.base/attach.exp45
1 files changed, 45 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.base/attach.exp b/gdb/testsuite/gdb.base/attach.exp
index a20c51a..6340496 100644
--- a/gdb/testsuite/gdb.base/attach.exp
+++ b/gdb/testsuite/gdb.base/attach.exp
@@ -396,6 +396,49 @@ proc do_command_attach_tests {} {
remote_exec build "kill -9 ${testpid}"
}
+# Test ' gdb --pid PID -ex "run" '. GDB used to have a bug where
+# "run" would run before the attach finished - PR17347.
+
+proc test_command_line_attach_run {} {
+ global gdb_prompt
+ global binfile
+
+ if ![isnative] then {
+ unsupported "commandline attach run test"
+ return 0
+ }
+
+ with_test_prefix "cmdline attach run" {
+ set testpid [spawn_wait_for_attach $binfile]
+
+ set test "run to prompt"
+ gdb_exit
+
+ set res [gdb_spawn_with_cmdline_opts \
+ "-iex \"set height 0\" -iex \"set width 0\" --pid=$testpid -ex \"start\""]
+ if { $res != 0} {
+ fail $test
+ return $res
+ }
+ gdb_test_multiple "" $test {
+ -re {Attaching to.*Start it from the beginning\? \(y or n\) } {
+ pass $test
+ }
+ }
+
+ send_gdb "y\n"
+
+ set test "run to main"
+ gdb_test_multiple "" $test {
+ -re "Temporary breakpoint .* main .*$gdb_prompt $" {
+ pass $test
+ }
+ }
+
+ # Get rid of the process
+ remote_exec build "kill -9 ${testpid}"
+ }
+}
# Start with a fresh gdb
@@ -420,4 +463,6 @@ do_call_attach_tests
do_command_attach_tests
+test_command_line_attach_run
+
return 0