rpms/gdb/devel gdb-6.3-attach-stop-20051011.patch, NONE, 1.1 gdb.spec, 1.160, 1.161

fedora-cvs-commits at redhat.com fedora-cvs-commits at redhat.com
Wed Oct 12 18:57:17 UTC 2005


Author: jjohnstn

Update of /cvs/dist/rpms/gdb/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv16537

Modified Files:
	gdb.spec 
Added Files:
	gdb-6.3-attach-stop-20051011.patch 
Log Message:

* Tue Oct 11 2005 Jeff Johnston <jjohnstn at redhat.com>   6.3.0.0-1.81
- Bump up release number.

* Tue Oct 11 2005 Jeff Johnston <jjohnstn at redhat.com>   6.3.0.0-1.78
- Support gdb attaching to a stopped process.




gdb-6.3-attach-stop-20051011.patch:
 inferior.h                        |    4 
 infptrace.c                       |   36 +++++++
 infrun.c                          |    5 +
 target.c                          |    7 +
 testsuite/gdb.base/attachstop.c   |   29 ++++++
 testsuite/gdb.base/attachstop.exp |  177 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 258 insertions(+)

--- NEW FILE gdb-6.3-attach-stop-20051011.patch ---
2005-10-11  Jeff Johnston  <jjohnstn at redhat.com>

	* infptrace.c (attach): When attaching, look if we are attaching
	to a stopped process and if so, continue the process to get
	an event to process and set a flag.
	(detach): When detaching, pass SIGSTOP as a signal if
	we are detaching from a stopped process that the user didn't continue.
	* infrun.c (proceed): Reset attach_stopped_flag.
	* inferior.h (attach_stopped_flag): New flag declaration.
	* target.c (attach_stopped_flag): New flag definition.

testsuite:

2005-10-11  Jeff Johnston  <jjohnstn at redhat.com>

	* gdb.base/attachstop.exp: New test.
	* gdb.base/attachstop.c: Ditto.

--- gdb-6.3/gdb/testsuite/gdb.base/attachstop.exp.fix	2005-10-11 16:54:48.000000000 -0400
+++ gdb-6.3/gdb/testsuite/gdb.base/attachstop.exp	2005-10-12 13:36:33.000000000 -0400
@@ -0,0 +1,177 @@
+# Copyright 2005
+
+# 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# This test was created by modifying attach.exp.
+# This file was created by Jeff Johnston <jjohnstn at redhat.com>.
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+# This test only works on Linux
+if { ![istarget "*-*-linux-gnu*"] } {
+    return 0
+}
+
+set testfile "attachstop"
+set srcfile  ${testfile}.c
+set binfile  ${objdir}/${subdir}/${testfile}
+set escapedbinfile  [string_to_regexp ${objdir}/${subdir}/${testfile}]
+
+#execute_anywhere "rm -f ${binfile}"
+remote_exec build "rm -f ${binfile}"
+# For debugging this test
+#
+#log_user 1
+
+# build the test case
+#
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+    gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+if [get_compiler_info ${binfile}] {
+    return -1
+}
+
+# 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
+   
+# Stop the program 
+remote_exec build "kill -s STOP ${testpid}"
+
+# Start with clean gdb
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+# Verify that we can attach to the process by first giving its
+# executable name via the file command, and using attach with the
+# process ID.
+
+set test "set file, before attach1 to stopped process"
+gdb_test_multiple "file $binfile" "$test" {
+   -re "Load new symbol table from.*y or n. $" {
+        gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
+		"$test (re-read)"
+    }
+    -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
+        pass "$test"
+    }
+}
+
+set test "attach1 to stopped, after setting file"
+gdb_test_multiple "attach $testpid" "$test" {
+    -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
+        pass "$test"
+    }
+}
+
+gdb_test "bt" ".*sleep.*main.*" "attach1 to stopped bt"
+
+# Exit and detach the process.
+   
+gdb_exit
+
+set fileid [open /proc/${testpid}/status r];
+gets $fileid line1
+gets $fileid line2
+close $fileid;
+
+set test "attach1, exit leaves process stopped"
+if {[string match "*(stopped)*" $line2]} {
+  pass $test
+} else {
+  fail $test
+}
+
+# At this point, the process should still be stopped
+
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+# Verify that we can attach to the process just by giving the
+# process ID.
+   
+set test "attach2 to stopped, after setting file"
+gdb_test_multiple "attach $testpid" "$test" {
+    -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
+        pass "$test"
+    }
+}
+
+gdb_test "bt" ".*sleep.*main.*" "attach2 to stopped bt"
+gdb_breakpoint [gdb_get_line_number "Second sleep"]
+set test "attach2 continue"
+send_gdb "continue\n"
+gdb_expect {
+  -re "Continuing"
+    { pass "continue ($test)" }
+  timeout
+    { fail "continue ($test) (timeout)" }
+}
+
+# For this to work we must be sure to consume the "Continuing."
+# message first, or GDB's signal handler may not be in place.
+after 1000 {send_gdb "\003"}
+set test "attach2 stop by interrupt"
+gdb_expect {
+  -re "Program received signal SIGINT.*$gdb_prompt $"
+    {
+      pass $test
+    }
+  -re "Breakpoint \[0-9\].*$srcfile.*$gdb_prompt $"
+    {
+      pass $test
+    }
+  timeout
+    {
+      fail "$test (timeout)"
+    }
+}
+
+gdb_exit
+
+# At this point, the process should be sleeping
+
+set fileid [open /proc/${testpid}/status r];
+gets $fileid line1
+gets $fileid line2
+close $fileid;
+
+set test "attach2, exit leaves process sleeping"
+if {[string match "*(sleeping)*" $line2]} {
+  pass $test
+} else {
+  fail $test
+}
+
+# Make sure we don't leave a process around to confuse
+# the next test run (and prevent the compile by keeping
+# the text file busy), in case the "set should_exit" didn't
+# work.
+   
+remote_exec build "kill -9 ${testpid}"
+
+return 0
--- gdb-6.3/gdb/testsuite/gdb.base/attachstop.c.fix	2005-10-11 16:54:52.000000000 -0400
+++ gdb-6.3/gdb/testsuite/gdb.base/attachstop.c	2005-10-12 13:27:07.000000000 -0400
@@ -0,0 +1,29 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2005 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 2 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, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/* This program is intended to be started outside of gdb, then
+   manually stopped via a signal.  */
+
+#include <unistd.h>
+
+int main ()
+{
+  sleep (10000);  /* Ridiculous time, but we will eventually kill it.  */
+  sleep (10000);  /* Second sleep.  */
+  return 0;
+}
--- gdb-6.3/gdb/infptrace.c.fix	2005-10-11 16:43:30.000000000 -0400
+++ gdb-6.3/gdb/infptrace.c	2005-10-11 16:53:49.000000000 -0400
@@ -35,6 +35,8 @@
 #include <sys/param.h>
 #include "gdb_dirent.h"
 #include <signal.h>
+#include <string.h>
+#include <stdio.h>
 #include <sys/ioctl.h>
 
 #include "gdb_ptrace.h"
@@ -232,8 +234,39 @@ attach (int pid)
 #ifdef PT_ATTACH
   errno = 0;
   ptrace (PT_ATTACH, pid, (PTRACE_TYPE_ARG3) 0, 0);
+  attach_stopped_flag = 0;
   if (errno != 0)
     perror_with_name ("ptrace");
+  else
+    {
+      FILE *fp;
+      char name[40];
+      char buf[100];
+      int have_state = 0;
+
+      sprintf (name, "/proc/%d/status", pid);
+
+      if ((fp = fopen (name, "r")) > 0)
+        {
+	  while (fgets (buf, 100, fp))
+	    {
+	      if (!strncmp (buf, "State:", 6))
+		{
+		  have_state = 1;
+		  break;
+		}
+	    }
+	  if (have_state)
+	    {
+	      if (strstr (buf, "T (stopped)"))
+		{
+		  attach_stopped_flag = 1;
+                  ptrace (PT_CONTINUE, pid, (PTRACE_TYPE_ARG3)1, 
+		          target_signal_to_host (TARGET_SIGNAL_STOP));
+		}
+	    }
+	}
+    }
   attach_flag = 1;
   return pid;
 #else
@@ -251,6 +284,9 @@ detach (int signal)
   int pid = PIDGET (inferior_ptid);
 
   errno = 0;
+  if (attach_stopped_flag && signal == 0)
+    signal = target_signal_to_host (TARGET_SIGNAL_STOP);
+  attach_stopped_flag = 0;
   ptrace (PT_DETACH, pid, (PTRACE_TYPE_ARG3) 1, signal);
   if (errno != 0)
     perror_with_name ("ptrace");
--- gdb-6.3/gdb/inferior.h.fix	2005-10-11 16:43:45.000000000 -0400
+++ gdb-6.3/gdb/inferior.h	2005-10-11 16:52:02.000000000 -0400
@@ -426,6 +426,10 @@ extern struct regcache *stop_registers;
    than forked.  */
 
 extern int attach_flag;
+
+/* Nonzero if attach_flag is nonzero and the inferior is already stopped.  */
+
+extern int attach_stopped_flag;
 
 /* Possible values for CALL_DUMMY_LOCATION.  */
 #define ON_STACK 1
--- gdb-6.3/gdb/infrun.c.fix	2005-10-11 16:43:51.000000000 -0400
+++ gdb-6.3/gdb/infrun.c	2005-10-11 16:51:54.000000000 -0400
@@ -794,6 +794,11 @@ proceed (CORE_ADDR addr, enum target_sig
      updated correctly when the inferior is stopped.  */
   prev_pc = read_pc ();
 
+  /* At this point, we are going to resume the inferior and if we
+     have attached to a stopped process, we no longer should leave
+     it as stopped if the user detachs.  */
+  attach_stopped_flag = 0;
+
   /* Resume inferior.  */
   resume (oneproc || step || bpstat_should_step (), stop_signal);
 
--- gdb-6.3/gdb/target.c.fix	2005-10-11 16:51:12.000000000 -0400
+++ gdb-6.3/gdb/target.c	2005-10-11 16:52:06.000000000 -0400
@@ -201,6 +201,13 @@ static struct cmd_list_element *targetli
 
 int attach_flag;
 
+/* Nonzero if we are debugging an attached outside process
+   and the process was already stopped.  This is needed for
+   Linux whereby attaching does not result in a kernel event
+   to check and waiting results in a hang.  */
+
+int attach_stopped_flag;
+
 /* Non-zero if we want to see trace of target level stuff.  */
 
 static int targetdebug = 0;


Index: gdb.spec
===================================================================
RCS file: /cvs/dist/rpms/gdb/devel/gdb.spec,v
retrieving revision 1.160
retrieving revision 1.161
diff -u -r1.160 -r1.161
--- gdb.spec	29 Sep 2005 22:41:56 -0000	1.160
+++ gdb.spec	12 Oct 2005 18:57:10 -0000	1.161
@@ -11,7 +11,7 @@
 Version: 6.3.0.0
 
 # The release always contains a leading reserved number, start it at 0.
-Release: 1.77
+Release: 1.81
 
 License: GPL
 Group: Development/Debuggers
@@ -252,6 +252,9 @@
 # Fix DSO read logic for attached process
 Patch167: gdb-6.3-attach-dso-20050929.patch
 
+# Support gdb attaching to a stopped process
+Patch168: gdb-6.3-attach-stop-20051011.patch
+
 %ifarch ia64
 BuildRequires: ncurses-devel glibc-devel gcc make gzip texinfo dejagnu libunwind >= 0.96-3
 %else
@@ -351,6 +354,7 @@
 %patch165 -p1
 %patch166 -p1
 %patch167 -p1
+%patch168 -p1
 
 # Change the version that gets printed at GDB startup, so it is RedHat
 # specific.
@@ -519,6 +523,12 @@
 # don't include the files in include, they are part of binutils
 
 %changelog
+* Tue Oct 11 2005 Jeff Johnston	<jjohnstn at redhat.com>	6.3.0.0-1.81
+- Bump up release number.
+
+* Tue Oct 11 2005 Jeff Johnston	<jjohnstn at redhat.com>	6.3.0.0-1.78
+- Support gdb attaching to a stopped process.
+
 * Thu Sep 29 2005 Jeff Johnston	<jjohnstn at redhat.com>	6.3.0.0-1.77
 - Bump up release number.
 




More information about the fedora-cvs-commits mailing list