Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RFC: Don't kill the program after "file"
@ 2006-06-13 20:50 Daniel Jacobowitz
  2006-06-14 19:55 ` Jim Blandy
  2006-06-14 20:06 ` Jim Blandy
  0 siblings, 2 replies; 10+ messages in thread
From: Daniel Jacobowitz @ 2006-06-13 20:50 UTC (permalink / raw)
  To: gdb-patches

The "file" command currently prompts if a program is running:

(gdb) file /bin/cat
A program is being debugged already.  Kill it? (y or n) 

I've encountered a couple problems with this:

1. If you say "no", it aborts the "file" command.  So there is no way
to deliberately change the file.
2. If you say yes, it doesn't just do the equivalent of "kill", but
"kill" and "disconnect".  For target extended-remote, this means you
come unexpectedly disconnected from your target.

This patch completely removes the prompt.  Instead, we simply allow it.
It's occasionally useful, even during native debugging (at least I know
I've attached to a running program with the wrong file specified
before).  It's more useful during remote debugging, where I've seen
users frequently confused that "target remote; file" doesn't work even
though "file; target remote" does.

I talked with Jim about this.  He wasn't entirely happy with discarding
the prompt for native debugging, where it traditionally makes sense; we
didn't quite make it to an agreement on what ought to happen.  He
suggested adding a "process-oriented" flag to target vectors.  For a
process oriented target (i.e. one which can handle "run" and "kill" and
so forth) it makes sense to offer to kill at this point; for
board oriented targets it makes less sense.  Another thing which just
occured to me would be to make the file command succeed if you say "n"
at the query.

Any comments?  I'm definitely not planning to commit this patch without
more discussion.  Tested on x86_64-pc-linux-gnu.

-- 
Daniel Jacobowitz
CodeSourcery

2006-06-13  Daniel Jacobowitz  <dan@codesourcery.com>

	* 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.
	* gdbcore.h (exec_open): Remove prototype.

2006-06-13  Daniel Jacobowitz  <dan@codesourcery.com>

	* gdb.base/completion.exp: Remove support for kill prompt after
	"file".
	* 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	13 Jun 2006 20:35:35 -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.  */
+  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
 }
 \f
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	13 Jun 2006 20:35:35 -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);
@@ -287,8 +287,6 @@ exec_file_command (char *args, int from_
   char **argv;
   char *filename;
   
-  target_preopen (from_tty);
-
   if (args)
     {
       /* Scan through the args and pick up the first non option arg
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	13 Jun 2006 20:35:35 -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	13 Jun 2006 20:35:35 -0000
@@ -671,19 +671,10 @@ 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 ".*$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	13 Jun 2006 20:35:35 -0000
@@ -313,10 +313,6 @@ gdb_expect 60 {
     -re "^file (\[^ \]| +\008)*\r*\n" {
 	exp_continue
     }
-    -re "A program is being debugged already.  Kill it\\? \\(y or n\\)" {
-	send_gdb "y\n"
-	exp_continue
-    }
     -re "^Reading symbols from .*$binfile\\.\\.\\.done\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)\r\n$gdb_prompt $" {
 	pass "weirdx.o read without error"
     }
Index: testsuite/lib/gdb.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/lib/gdb.exp,v
retrieving revision 1.66
diff -u -p -r1.66 gdb.exp
--- testsuite/lib/gdb.exp	13 Jun 2006 13:20:25 -0000	1.66
+++ testsuite/lib/gdb.exp	13 Jun 2006 20:35:36 -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	13 Jun 2006 20:35:36 -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 {


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: RFC: Don't kill the program after "file"
@ 2006-08-01 20:17 Fred Fish
  2006-08-01 22:11 ` Daniel Jacobowitz
  0 siblings, 1 reply; 10+ messages in thread
From: Fred Fish @ 2006-08-01 20:17 UTC (permalink / raw)
  To: gdb-patches; +Cc: fnf

I'm currently getting new failures with a mips-elf toolchain, and
other toolchains, when using the simulator for testing.  I'm not
entirely sure that they are due to this change, but it seems likely.

Here is a snippet from the gdb.log file:

(gdb) dir /src/latest/trunk/src/gdb/gdb/testsuite/gdb.base
Source directories searched: /src/latest/trunk/src/gdb/gdb/testsuite/gdb.base:$cdir:$cwd
(gdb) kill
The program is not being run.
(gdb) file /links/build/latest/trunk/mips-elf/gdb/gdb/testsuite/gdb.base/opaque
A program is being debugged already.
Are you sure you want to change the file? (y or n) ERROR: couldn't load /links/build/latest/trunk/mips-elf/gdb/gdb/testsuite/gdb.base/opaque into /links/build/latest/trunk/mips-elf/gdb/gdb/testsuite/../../gdb/gdb (timed out).
delete breakpoints
Please answer y or n.
A program is being debugged already.
Are you sure you want to change the file? (y or n) ERROR: Delete all breakpoints in delete_breakpoints (timeout)
break main
Please answer y or n.
A program is being debugged already.
Are you sure you want to change the file? (y or n) UNRESOLVED: gdb.base/opaque.exp: setting breakpoint at main (timeout)
ERROR: cannot run to breakpoint at main
ERROR: Got interactive prompt.
UNRESOLVED: gdb.base/opaque.exp: whatis on opaque struct pointer (dynamically)
ERROR: Got interactive prompt.
UNRESOLVED: gdb.base/opaque.exp: ptype on opaque struct pointer (dynamically) 1
ERROR: Got interactive prompt.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2006-08-17  2:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-13 20:50 RFC: Don't kill the program after "file" Daniel Jacobowitz
2006-06-14 19:55 ` Jim Blandy
2006-06-14 20:06 ` Jim Blandy
2006-06-26 19:00   ` Kevin Buettner
2006-07-12 20:16     ` Daniel Jacobowitz
2006-07-24 20:36       ` Daniel Jacobowitz
2006-08-01 20:17 Fred Fish
2006-08-01 22:11 ` Daniel Jacobowitz
2006-08-10 20:08   ` Fred Fish
2006-08-17 18:48   ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox