This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Unset attach_flag when running a new process


We currently set attach_flag when attaching to a process, so we should
make sure to unset it when forking a new process.  Otherwise attach_flag
would remain set after forking, if the previous process associated with
the inferior was attached to.

[ The test is currently magically failing on extended-gdbserver.  The
  failure is:

(gdb) PASS: gdb.base/run-after-attach.exp: kill process
start
`target:/scratchpad/binutils-gdb-build/gdb/testsuite/gdb.base/run-after-attach' has disappeared; keeping its symbols.
Temporary breakpoint 1 at 0x4005aa: file /home/patrick/code/binutils-gdb/gdb/testsuite/gdb.base/run-after-attach.c, line 23.
Starting program: target:/scratchpad/binutils-gdb-build/gdb/testsuite/gdb.base/run-after-attach
Running the default executable on the remote target failed; try "set remote exec-file"?

  I do not know why restarting the program fails.  Is this a bug or a mistake on my part?

  Also, why is [is_remote target] true for gdbserver but not for extended-gdbserver?  ]

gdb/ChangeLog:

	* gdb/infcmd.c (run_comand_1): Unset attach_flag.

gdb/testsuite/ChangeLog:

	* gdb.base/run-after-attach.exp: New test file.
	* gdb.base/run-after-attach.c: New test file.
---
 gdb/infcmd.c                                |  4 ++
 gdb/testsuite/gdb.base/run-after-attach.c   | 25 ++++++++++
 gdb/testsuite/gdb.base/run-after-attach.exp | 73 +++++++++++++++++++++++++++++
 3 files changed, 102 insertions(+)
 create mode 100644 gdb/testsuite/gdb.base/run-after-attach.c
 create mode 100644 gdb/testsuite/gdb.base/run-after-attach.exp

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 4948d27..bf8b94b 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -601,6 +601,10 @@ run_command_1 (char *args, int from_tty, int tbreak_at_main)
   /* Done with ARGS.  */
   do_cleanups (args_chain);
 
+  /* Unset attach_flag, it may be set if the previous process associated with
+     the inferior was attached to.  */
+  current_inferior ()->attach_flag = 0;
+
   /* We call get_inferior_args() because we might need to compute
      the value now.  */
   run_target->to_create_inferior (run_target, exec_file, get_inferior_args (),
diff --git a/gdb/testsuite/gdb.base/run-after-attach.c b/gdb/testsuite/gdb.base/run-after-attach.c
new file mode 100644
index 0000000..2398f00
--- /dev/null
+++ b/gdb/testsuite/gdb.base/run-after-attach.c
@@ -0,0 +1,25 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2015 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/>.  */
+
+#include <unistd.h>
+
+int
+main (void)
+{
+  sleep (600);
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/run-after-attach.exp b/gdb/testsuite/gdb.base/run-after-attach.exp
new file mode 100644
index 0000000..19817f7
--- /dev/null
+++ b/gdb/testsuite/gdb.base/run-after-attach.exp
@@ -0,0 +1,73 @@
+# Copyright (C) 2015 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/>.
+
+# Check that forking a process after a previous process was attached to resets
+# attach_flag.  This is done indirectly by inspecting GDB's quit prompt.
+
+if ![can_spawn_for_attach] {
+    return 0
+}
+
+standard_testfile
+set executable $testfile
+
+if { [build_executable $testfile.exp $executable "" debug] == -1 } {
+    return -1
+}
+
+set testpid [spawn_wait_for_attach $binfile]
+
+gdb_start
+
+set test "attach to process"
+gdb_test "attach $testpid" "Attaching to process $testpid.*" $test
+
+set test "kill process"
+send_gdb "kill\n"
+gdb_expect {
+    -re ".y or n. $" {
+	send_gdb "y\n"
+	exp_continue
+    }
+    -re "$gdb_prompt $" {
+	pass $test
+    }
+    default {
+	fail $test
+    }
+}
+
+set test "restart process"
+gdb_test "start" "Temporary breakpoint .*" $test
+
+set test "attempt kill via quit"
+send_gdb "quit\n"
+# The quit prompt should warn about killing the process, not about detaching the
+# process, since this process was not attached to.
+gdb_expect {
+    -re "will be killed.*.y or n. $" {
+	pass $test
+	send_gdb "n\n"
+    }
+    -re "will be detached.*.y or n. $" {
+	fail $test
+	send_gdb "n\n"
+    }
+    default {
+	fail $test
+    }
+}
+
+remote_exec host "kill $testpid"
-- 
2.5.0.rc2.22.g69b1679.dirty


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]