diff options
author | Daniel Jacobowitz <drow@false.org> | 2008-01-30 00:51:50 +0000 |
---|---|---|
committer | Daniel Jacobowitz <drow@false.org> | 2008-01-30 00:51:50 +0000 |
commit | 2d717e4f8a548fbfc4fabe506fd1d53f6b81994d (patch) | |
tree | 28e3eacb77be01a42135a0df907a10fd57917d85 /gdb/testsuite | |
parent | 9dc513fc0e920994bd8f7cad33c6920c1285ce29 (diff) | |
download | gdb-2d717e4f8a548fbfc4fabe506fd1d53f6b81994d.zip gdb-2d717e4f8a548fbfc4fabe506fd1d53f6b81994d.tar.gz gdb-2d717e4f8a548fbfc4fabe506fd1d53f6b81994d.tar.bz2 |
* linux-low.c (linux_attach_lwp): Do not _exit after errors.
(linux_kill, linux_detach): Clean up the process list.
* remote-utils.c (remote_open): Improve port number parsing.
(putpkt_binary, input_interrupt): Only send interrupts if the target
is running.
* server.c (extended_protocol): Make static.
(attached): Define earlier.
(exit_requested, response_needed, program_argv): New variables.
(target_running): New.
(start_inferior): Clear attached here.
(attach_inferior): Set attached here.
(require_running): Define.
(handle_query): Use require_running and target_running. Implement
"monitor exit".
(handle_v_attach, handle_v_run): New.
(handle_v_requests): Use require_running. Handle vAttach and vRun.
(gdbserver_usage): Update.
(main): Redo argument parsing. Handle --debug and --multi. Handle
--attach along with other options or after the port. Save
program_argv. Support no initial program. Resynchronize
communication with GDB after an error. Handle "monitor exit".
Use require_running and target_running. Always allow the extended
protocol. Do not error out for Hc0 or Hc-1. Do not automatically
restart in extended mode.
* README: Refer to the GDB manual. Update --attach usage.
* remote.c (struct remote_state): Add cached_wait_status.
(remote_exec_file): New variable.
(PACKET_vAttach, PACKET_vRun): New constants.
(extended_remote_restart): Do not query for status.
(struct start_remote_args): New.
(remote_start_remote): Take it as a second argument. Check
whether the target is running. Issue an error for non-running
non-extended targets. Cache the wait status. Set inferior_ptid
here.
(remote_open_1): Prompt to disconnect non-running targets. Make
sure the target is marked running. Do not set inferior_ptid here.
Update call to remote_start_remote. Do not call remote_check_symbols
if the target is not running.
(remote_detach_1): Rename from remote_detach. Take an EXTENDED
argument. Handle a non-running target.
(remote_detach): Use it.
(extended_remote_detach): New.
(remote_disconnect): Fix typo. Use remoute_mourn_1.
(extended_remote_attach_1, extended_remote_attach)
(extended_async_remote_attach): New.
(remote_vcont_resume): Remove unused variable.
(remote_wait, remote_async_wait): Use any cached wait status.
(putpkt_binary, getpkt): Clear any cached wait status.
(extended_remoute_mourn_1): New.
(extended_remote_mourn): Use it.
(extended_async_remote_mourn, extended_remote_run): New.
(extended_remote_create_inferior_1): New.
(extended_remote_create_inferior): Use it.
(extended_remote_async_create_inferior): Likewise.
(remote_xfer_partial): Skip for non-executing targets.
(init_extended_remote_ops): Set to_detach and to_attach.
(init_extended_async_remote_ops): Likewise. Use
extended_async_remote_mourn.
(_initialize_remote): Register vAttach, vRun, and
set remote exec-file.
* NEWS: Mention vAttach, vRun, and gdbserver extended-remote support.
* gdb.server/ext-attach.c, gdb.server/ext-attach.exp,
gdb.server/ext-run.exp: New files.
* lib/gdbserver-support.exp (gdbserver_download): New.
(gdbserver_start): New. Update gdbserver expected
output.
(gdbserver_spawn): Use them.
(gdbserver_start_extended): New.
* gdb.texinfo (Using the `gdbserver' Program): Add security
warning. Rearrange into subsections and subsubsections. Document
--multi and --debug. Correct --with-sysroot typo. Update --attach
usage. Make load reference clearer. Document monitor exit.
(Remote Configuration): Document set remote exec-file, attach-packet,
and run-packet.
(Packets): Document vAttach and vRun.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 10 | ||||
-rw-r--r-- | gdb/testsuite/gdb.server/ext-attach.c | 31 | ||||
-rw-r--r-- | gdb/testsuite/gdb.server/ext-attach.exp | 77 | ||||
-rw-r--r-- | gdb/testsuite/gdb.server/ext-run.exp | 48 | ||||
-rw-r--r-- | gdb/testsuite/lib/gdbserver-support.exp | 69 |
5 files changed, 218 insertions, 17 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 3de37e7..32542a2 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,15 @@ 2008-01-29 Daniel Jacobowitz <dan@codesourcery.com> + * gdb.server/ext-attach.c, gdb.server/ext-attach.exp, + gdb.server/ext-run.exp: New files. + * lib/gdbserver-support.exp (gdbserver_download): New. + (gdbserver_start): New. Update gdbserver expected + output. + (gdbserver_spawn): Use them. + (gdbserver_start_extended): New. + +2008-01-29 Daniel Jacobowitz <dan@codesourcery.com> + * gdb.base/foll-exec.exp: Update header. Skip on remote targets. Run on GNU/Linux. (do_exec_tests): Check for systems which do not support catchpoints. diff --git a/gdb/testsuite/gdb.server/ext-attach.c b/gdb/testsuite/gdb.server/ext-attach.c new file mode 100644 index 0000000..db7c0f8 --- /dev/null +++ b/gdb/testsuite/gdb.server/ext-attach.c @@ -0,0 +1,31 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* This program is intended to be started outside of gdb, and then + attached to by gdb. It loops for a while, but not forever. */ + +#include <unistd.h> + +int main () +{ + int i; + + for (i = 0; i < 120; i++) + sleep (1); + + return 0; +} diff --git a/gdb/testsuite/gdb.server/ext-attach.exp b/gdb/testsuite/gdb.server/ext-attach.exp new file mode 100644 index 0000000..4ab1bb6 --- /dev/null +++ b/gdb/testsuite/gdb.server/ext-attach.exp @@ -0,0 +1,77 @@ +# This testcase is part of GDB, the GNU debugger. + +# Copyright 2007 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test attaching to already-running programs using extended-remote. + +load_lib gdbserver-support.exp + +set testfile "ext-attach" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +if { [skip_gdbserver_tests] } { + return 0 +} + +# On SPU, this test currently fails because "sleep" is not supported. +if { [istarget "spu*-*-*"] } { + return 0 +} + +# We need to use TCL's exec to get the pid. +if [is_remote target] then { + return 0 +} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested ext-attach.exp + return -1 +} + +gdb_exit +gdb_start +gdb_load $binfile +gdb_reinitialize_dir $srcdir/$subdir + +set target_exec [gdbserver_download] +gdbserver_start_extended + +gdb_test "set remote exec-file $target_exec" "" "set remote exec-file" + +# Start the program running and then wait for a bit, to be sure +# that it can be attached to. +set testpid [eval exec $binfile &] +exec sleep 2 +if { [istarget "*-*-cygwin*"] } { + # testpid is the Cygwin PID, GDB uses the Windows PID, which might be + # different due to the way fork/exec works. + set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ] +} + +gdb_test "attach $testpid" "Attached to.*" \ + "attach to remote program 1" +gdb_test "backtrace" ".*main.*" "backtrace 1" + +gdb_test "detach" "Detached from remote process\\." +gdb_test "backtrace" "No stack\\." "backtrace with no program" + +gdb_test "attach $testpid" "Attached to.*" \ + "attach to remote program 2" +gdb_test "backtrace" ".*main.*" "backtrace 2" + +gdb_test "kill" "" "kill" "Kill the program being debugged.*" "y" +gdb_test "monitor exit" "" diff --git a/gdb/testsuite/gdb.server/ext-run.exp b/gdb/testsuite/gdb.server/ext-run.exp new file mode 100644 index 0000000..5af5611 --- /dev/null +++ b/gdb/testsuite/gdb.server/ext-run.exp @@ -0,0 +1,48 @@ +# This testcase is part of GDB, the GNU debugger. + +# Copyright 2007 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test running programs using extended-remote. + +load_lib gdbserver-support.exp + +set testfile "server" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +if { [skip_gdbserver_tests] } { + return 0 +} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + return -1 +} + +gdb_exit +gdb_start +gdb_load $binfile +gdb_reinitialize_dir $srcdir/$subdir + +set target_exec [gdbserver_download] +gdbserver_start_extended + +gdb_test "set remote exec-file $target_exec" "" "set remote exec-file" + +gdb_breakpoint main +gdb_test "run" "Breakpoint.* main .*" "continue to main" + +gdb_test "kill" "" "kill" "Kill the program being debugged.*" "y" +gdb_test "monitor exit" "" diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp index 50dafe0..6fbaa22 100644 --- a/gdb/testsuite/lib/gdbserver-support.exp +++ b/gdb/testsuite/lib/gdbserver-support.exp @@ -132,13 +132,10 @@ proc skip_gdbserver_tests { } { return 0 } -# Start a gdbserver process running SERVER_EXEC, and connect GDB -# to it. CHILD_ARGS are passed to the inferior. -# -# Returns the target protocol and socket to connect to. +# Download the currently loaded program to the target if necessary. +# Return the target system filename. -proc gdbserver_spawn { child_args } { - global portnum +proc gdbserver_download { } { global gdbserver_host_exec global gdbserver_host_mtime global gdbserver_server_exec @@ -172,6 +169,17 @@ proc gdbserver_spawn { child_args } { } } + return $gdbserver_server_exec +} + +# Start a gdbserver process with initial OPTIONS and trailing ARGUMENTS. +# The port will be filled in between them automatically. +# +# Returns the target protocol and socket to connect to. + +proc gdbserver_start { options arguments } { + global portnum + # Port id -- either specified in baseboard file, or managed here. if [target_info exists gdb,socketport] { set portnum [target_info gdb,socketport] @@ -182,7 +190,7 @@ proc gdbserver_spawn { child_args } { # Extract the local and remote host ids from the target board struct. if [target_info exists sockethost] { - set debughost [target_info sockethost] + set debughost [target_info sockethost] } else { set debughost "localhost:" } @@ -199,23 +207,23 @@ proc gdbserver_spawn { child_args } { # Export the host:port pair. set gdbport $debughost$portnum - # Fire off the debug agent. This flavour of gdbserver takes as - # arguments the port information, the name of the executable file to - # be debugged, and any arguments. - set gdbserver_command "$gdbserver :$portnum $gdbserver_server_exec" - if { $child_args != "" } { - append gdbserver_command " $child_args" + # Fire off the debug agent. + set gdbserver_command "$gdbserver" + if { $options != "" } { + append gdbserver_command " $options" + } + append gdbserver_command " :$portnum" + if { $arguments != "" } { + append gdbserver_command " $arguments" } set server_spawn_id [remote_spawn target $gdbserver_command] - # Wait for the server to produce at least one line and an additional - # character of output. This will wait until any TCP socket has been - # created, so that GDB can connect. + # Wait for the server to open its TCP socket, so that GDB can connect. expect { -i $server_spawn_id -notransfer - -re ".*\n." { } + -re "Listening on" { } } # We can't just call close, because if gdbserver is local then that means @@ -234,6 +242,24 @@ proc gdbserver_spawn { child_args } { return [list $protocol $gdbport] } +# Start a gdbserver process running SERVER_EXEC, and connect GDB +# to it. CHILD_ARGS are passed to the inferior. +# +# Returns the target protocol and socket to connect to. + +proc gdbserver_spawn { child_args } { + set target_exec [gdbserver_download] + + # Fire off the debug agent. This flavour of gdbserver takes as + # arguments the port information, the name of the executable file to + # be debugged, and any arguments. + set arguments "$target_exec" + if { $child_args != "" } { + append arguments " $child_args" + } + return [gdbserver_start "" $arguments] +} + # Start a gdbserver process running HOST_EXEC and pass CHILD_ARGS # to it. Return 0 on success, or non-zero on failure. @@ -271,3 +297,12 @@ proc gdbserver_reconnect { } { return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] } + +# Start and connect to a gdbserver in extended mode. +proc gdbserver_start_extended { } { + set res [gdbserver_start "--multi" ""] + set gdbserver_protocol "extended-[lindex $res 0]" + set gdbserver_gdbport [lindex $res 1] + + return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] +} |