From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23007 invoked by alias); 12 Jul 2006 20:16:19 -0000 Received: (qmail 22991 invoked by uid 22791); 12 Jul 2006 20:16:16 -0000 X-Spam-Check-By: sourceware.org Received: from nevyn.them.org (HELO nevyn.them.org) (66.93.172.17) by sourceware.org (qpsmtpd/0.31.1) with ESMTP; Wed, 12 Jul 2006 20:16:14 +0000 Received: from drow by nevyn.them.org with local (Exim 4.54) id 1G0l7x-00082A-4w for gdb-patches@sourceware.org; Wed, 12 Jul 2006 16:16:09 -0400 Date: Wed, 12 Jul 2006 20:16:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sourceware.org Subject: Re: RFC: Don't kill the program after "file" Message-ID: <20060712201609.GQ24622@nevyn.them.org> Mail-Followup-To: gdb-patches@sourceware.org References: <20060613205014.GA20822@nevyn.them.org> <20060626120020.020b6482@ironwood.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060626120020.020b6482@ironwood.lan> User-Agent: Mutt/1.5.11+cvs20060403 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-07/txt/msg00129.txt.bz2 On Mon, Jun 26, 2006 at 12:00:20PM -0700, Kevin Buettner wrote: > > > Another thing which just > > > occured to me would be to make the file command succeed if you say "n" > > > at the query. > > > > I think something like that is workable. What if we simply left the > > killing to the 'kill' and 'run' commands, and let the prompt say: > > > > A program is being debugged already. > > Are you sure you want to change the file? (y or n) > > > > Saying 'y' would not kill the program. > > > > This would mean that 'exec-file; run' when a program is running would > > ask the user two questions: one to confirm the file change, and then > > another to confirm the kill before restarting. > > Jim's proposal sounds reasonable to me. Me too! Here is an implementation. It gives the prompt suggested by Jim if there is a TTY, calls error if the user declines (which prevents "file" from trying to do "symbol-file" afterwards), and otherwise succeeds. "file" never kills the running program. Any opinions on this patch? Shall I commit it? Tested on x86_64-pc-linux-gnu. -- Daniel Jacobowitz CodeSourcery 2006-07-12 Daniel Jacobowitz * corefile.c (reopen_exec_file): Only check for an open exec file. Use exec_file_attach. * exec.c (exec_open): Make static. (exec_file_command): Don't use target_preopen. Query directly about changing the file. * gdbcore.h (exec_open): Remove prototype. 2006-07-12 Daniel Jacobowitz * gdb.base/completion.exp: Update for change in "file" behavior. * gdb.stabs/weird.exp: Likewise. * lib/mi-support.exp (mi_gdb_file_cmd): Likewise. * lib/gdb.exp (gdb_file_cmd): Likewise. Kill the program explicitly. Index: corefile.c =================================================================== RCS file: /cvs/src/src/gdb/corefile.c,v retrieving revision 1.37 diff -u -p -r1.37 corefile.c --- corefile.c 10 Jan 2006 23:01:44 -0000 1.37 +++ corefile.c 12 Jul 2006 20:12:06 -0000 @@ -156,8 +156,8 @@ reopen_exec_file (void) struct stat st; long mtime; - /* Don't do anything if the current target isn't exec. */ - if (exec_bfd == NULL || strcmp (target_shortname, "exec") != 0) + /* Don't do anything if there isn't an exec file. */ + if (exec_bfd == NULL) return; /* If the timestamp of the exec file has changed, reopen it. */ @@ -167,9 +167,7 @@ reopen_exec_file (void) res = stat (filename, &st); if (mtime && mtime != st.st_mtime) - { - exec_open (filename, 0); - } + exec_file_attach (filename, 0); #endif } Index: exec.c =================================================================== RCS file: /cvs/src/src/gdb/exec.c,v retrieving revision 1.61 diff -u -p -r1.61 exec.c --- exec.c 18 Apr 2006 19:20:06 -0000 1.61 +++ exec.c 12 Jul 2006 20:12:06 -0000 @@ -85,7 +85,7 @@ show_write_files (struct ui_file *file, struct vmap *vmap; -void +static void exec_open (char *args, int from_tty) { target_preopen (from_tty); @@ -286,8 +286,11 @@ exec_file_command (char *args, int from_ { char **argv; char *filename; - - target_preopen (from_tty); + + if (from_tty && target_has_execution + && !query (_("A program is being debugged already.\n" + "Are you sure you want to change the file? "))) + error (_("File not changed.")); if (args) { Index: gdbcore.h =================================================================== RCS file: /cvs/src/src/gdb/gdbcore.h,v retrieving revision 1.20 diff -u -p -r1.20 gdbcore.h --- gdbcore.h 17 Dec 2005 22:34:00 -0000 1.20 +++ gdbcore.h 12 Jul 2006 20:12:06 -0000 @@ -123,8 +123,6 @@ extern int write_files; extern void core_file_command (char *filename, int from_tty); -extern void exec_open (char *filename, int from_tty); - extern void exec_file_attach (char *filename, int from_tty); extern void exec_file_clear (int from_tty); Index: testsuite/gdb.base/completion.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/completion.exp,v retrieving revision 1.22 diff -u -p -r1.22 completion.exp --- testsuite/gdb.base/completion.exp 7 Mar 2006 15:23:32 -0000 1.22 +++ testsuite/gdb.base/completion.exp 12 Jul 2006 20:12:06 -0000 @@ -671,19 +671,14 @@ sleep 1 gdb_expect { -re "^file ./gdb.base/completion\\.exp $"\ { send_gdb "\n" - gdb_expect { - -re "\r\nA program is being debugged already\\. Kill it\\? \\(y or n\\) $" - { send_gdb "n\n" - gdb_expect { - -re "\r\nProgram not killed\\.\r\n$gdb_prompt $"\ - { pass "complete 'file ./gdb.base/complet'"} - -re ".*$gdb_prompt $" { fail "complete 'file ./gdb.base/complet'"} - timeout {fail "(timeout) complete 'file ./gdb.base/complet'"} - } - } - -re ".*$gdb_prompt $" { fail "complete 'file ./gdb.base/complet'"} - timeout {fail "(timeout) complete 'file ./gdb.base/complet'"} - } + # Ignore the exact error message. + gdb_test_multiple "" "complete 'file ./gdb.base/complet'" { + -re "\r\nA program is being debugged already\\.\[\r\n\]+Are you sure you want to change the file\\? \\(y or n\\) $" { + send_gdb "n\n" + exp_continue + } + -re ".*$gdb_prompt $" { pass "complete 'file ./gdb.base/complet'" } + } } -re ".*$gdb_prompt $" { fail "complete 'file ./gdb.base/complet'" } timeout { fail "(timeout) complete 'file ./gdb.base/complet'" } Index: testsuite/gdb.stabs/weird.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.stabs/weird.exp,v retrieving revision 1.8 diff -u -p -r1.8 weird.exp --- testsuite/gdb.stabs/weird.exp 22 Apr 2004 17:55:46 -0000 1.8 +++ testsuite/gdb.stabs/weird.exp 12 Jul 2006 20:12:07 -0000 @@ -313,7 +313,7 @@ gdb_expect 60 { -re "^file (\[^ \]| +\008)*\r*\n" { exp_continue } - -re "A program is being debugged already. Kill it\\? \\(y or n\\)" { + -re "A program is being debugged already.\[\r\n\]+Are you sure you want to change the file\\? \\(y or n\\)" { send_gdb "y\n" exp_continue } Index: testsuite/lib/gdb.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/lib/gdb.exp,v retrieving revision 1.68 diff -u -p -r1.68 gdb.exp --- testsuite/lib/gdb.exp 22 Jun 2006 19:17:09 -0000 1.68 +++ testsuite/lib/gdb.exp 12 Jul 2006 20:12:07 -0000 @@ -1008,6 +1008,20 @@ proc gdb_file_cmd { arg } { } } + # The file command used to kill the remote target. For the benefit + # of the testsuite, preserve this behavior. + send_gdb "kill\n" + gdb_expect 120 { + -re "Kill the program being debugged. .y or n. $" { + send_gdb "y\n" + verbose "\t\tKilling previous program being debugged" + exp_continue + } + -re "$gdb_prompt $" { + # OK. + } + } + send_gdb "file $arg\n" gdb_expect 120 { -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" { @@ -1020,11 +1034,6 @@ proc gdb_file_cmd { arg } { set gdb_file_cmd_debug_info "debug" return 0 } - -re "A program is being debugged already.*Kill it.*y or n. $" { - send_gdb "y\n" - verbose "\t\tKilling previous program being debugged" - exp_continue - } -re "Load new symbol table from \".*\".*y or n. $" { send_gdb "y\n" gdb_expect 120 { Index: testsuite/lib/mi-support.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/lib/mi-support.exp,v retrieving revision 1.32 diff -u -p -r1.32 mi-support.exp --- testsuite/lib/mi-support.exp 27 Sep 2005 22:39:04 -0000 1.32 +++ testsuite/lib/mi-support.exp 12 Jul 2006 20:12:07 -0000 @@ -411,11 +411,6 @@ proc mi_gdb_file_cmd { arg } { perror "$arg wasn't compiled with \"-g\"" return -1 } - -re "A program is being debugged already.*Kill it.*y or n. $" { - send_gdb "y\n" - verbose "\t\tKilling previous program being debugged" - exp_continue - } -re "Load new symbol table from \".*\".*y or n. $" { send_gdb "y\n" gdb_expect 120 {