d5a2446
2005-07-21  Jeff Johnston  <jjohnstn@redhat.com>
d5a2446
d50521f
	* gdb.base/attach-32.exp: New test for attaching in 32-bit
d50521f
	mode on 64-bit systems.
d50521f
	* gdb.base/attach-32.c: Ditto.
d50521f
	* gdb.base/attach-32b.c: Ditto.
d50521f
d50521f
2007-12-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
d50521f
d50521f
	* gdb.base/attach-32.exp: Fix forgotten $GDBFLAGS as set.
d5a2446
407ebe9
Index: gdb-6.8.50.20081128/gdb/testsuite/gdb.base/attach-32.c
407ebe9
===================================================================
407ebe9
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
407ebe9
+++ gdb-6.8.50.20081128/gdb/testsuite/gdb.base/attach-32.c	2008-12-07 10:06:03.000000000 +0100
d5a2446
@@ -0,0 +1,20 @@
d5a2446
+/* This program is intended to be started outside of gdb, and then
d5a2446
+   attached to by gdb.  Thus, it simply spins in a loop.  The loop
d5a2446
+   is exited when & if the variable 'should_exit' is non-zero.  (It
d5a2446
+   is initialized to zero in this program, so the loop will never
d5a2446
+   exit unless/until gdb sets the variable to non-zero.)
d5a2446
+   */
d5a2446
+#include <stdio.h>
d5a2446
+
d5a2446
+int  should_exit = 0;
d5a2446
+
d5a2446
+int main ()
d5a2446
+{
d5a2446
+  int  local_i = 0;
d5a2446
+
d5a2446
+  while (! should_exit)
d5a2446
+    {
d5a2446
+      local_i++;
d5a2446
+    }
d5a2446
+  return 0;
d5a2446
+}
407ebe9
Index: gdb-6.8.50.20081128/gdb/testsuite/gdb.base/attach-32.exp
407ebe9
===================================================================
407ebe9
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
407ebe9
+++ gdb-6.8.50.20081128/gdb/testsuite/gdb.base/attach-32.exp	2008-12-07 10:08:52.000000000 +0100
dd46ae6
@@ -0,0 +1,245 @@
d5a2446
+# Copyright 2005 Free Software Foundation, Inc.
d5a2446
+
d5a2446
+# This program is free software; you can redistribute it and/or modify
d5a2446
+# it under the terms of the GNU General Public License as published by
d5a2446
+# the Free Software Foundation; either version 2 of the License, or
d5a2446
+# (at your option) any later version.
d5a2446
+# 
d5a2446
+# This program is distributed in the hope that it will be useful,
d5a2446
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
d5a2446
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d5a2446
+# GNU General Public License for more details.
d5a2446
+# 
d5a2446
+# You should have received a copy of the GNU General Public License
d5a2446
+# along with this program; if not, write to the Free Software
d5a2446
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
d5a2446
+#
d5a2446
+# This test was based on attach.exp and modified for 32/64 bit Linux systems. */
d5a2446
+
d5a2446
+# On HP-UX 11.0, this test is causing a process running the program
d5a2446
+# "attach" to be left around spinning.  Until we figure out why, I am
d5a2446
+# commenting out the test to avoid polluting tiamat (our 11.0 nightly
d5a2446
+# test machine) with these processes. RT
d5a2446
+#
d5a2446
+# Setting the magic bit in the target app should work.  I added a
d5a2446
+# "kill", and also a test for the R3 register warning.  JB
d5a2446
+if { ![istarget "x86_64*-*linux*"] 
d5a2446
+     && ![istarget "powerpc64*-*linux*"]} {
d5a2446
+    return 0
d5a2446
+}
d5a2446
+
d5a2446
+# are we on a target board
d5a2446
+if [is_remote target] then {
d5a2446
+    return 0
d5a2446
+}
d5a2446
+
d5a2446
+set testfile "attach-32"
d5a2446
+set srcfile  ${testfile}.c
d5a2446
+set srcfile2 ${testfile}b.c
d5a2446
+set binfile  ${objdir}/${subdir}/${testfile}
d5a2446
+set binfile2 ${objdir}/${subdir}/${testfile}b
d5a2446
+set escapedbinfile  [string_to_regexp ${objdir}/${subdir}/${testfile}]
d5a2446
+
d5a2446
+#execute_anywhere "rm -f ${binfile} ${binfile2}"
d5a2446
+remote_exec build "rm -f ${binfile} ${binfile2}"
d5a2446
+# For debugging this test
d5a2446
+#
d5a2446
+#log_user 1
d5a2446
+
d5a2446
+# build the first test case
d5a2446
+#
d5a2446
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "additional_flags=-m32"]] != "" } {
d5a2446
+    gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
d5a2446
+}
d5a2446
+
d5a2446
+# Build the in-system-call test
d5a2446
+
d5a2446
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable [list debug "additional_flags=-m32"]] != "" } {
d5a2446
+    gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
d5a2446
+}
d5a2446
+
d5a2446
+if [get_compiler_info ${binfile}] {
d5a2446
+    return -1
d5a2446
+}
d5a2446
+
d5a2446
+proc do_attach_tests {} {
d5a2446
+    global gdb_prompt
d5a2446
+    global binfile
d5a2446
+    global escapedbinfile
d5a2446
+    global srcfile
d5a2446
+    global testfile
d5a2446
+    global objdir
d5a2446
+    global subdir
d5a2446
+    global timeout
d5a2446
+    global testpid
d5a2446
+    
d5a2446
+    # Verify that we can "see" the variable "should_exit" in the
d5a2446
+    # program, and that it is zero.
d5a2446
+   
d5a2446
+    gdb_test "print should_exit" " = 0" "after attach-32, print should_exit"
d5a2446
+
d5a2446
+    # Verify that we can modify the variable "should_exit" in the
d5a2446
+    # program.
d5a2446
+
d5a2446
+    gdb_test "set should_exit=1" "" "after attach-32, set should_exit"
d5a2446
+
d5a2446
+    # Verify that the modification really happened.
d5a2446
+
d5a2446
+    send_gdb "tbreak 19\n"
d5a2446
+    gdb_expect {
407ebe9
+	-re "reakpoint .*at.*$srcfile, line 19.*$gdb_prompt $" {
d5a2446
+	    pass "after attach-32, set tbreak postloop"
d5a2446
+	}
d5a2446
+	-re "$gdb_prompt $" {
d5a2446
+	    fail "after attach-32, set tbreak postloop"
d5a2446
+	}
d5a2446
+	timeout {
d5a2446
+	    fail "(timeout) after attach-32, set tbreak postloop"
d5a2446
+	}
d5a2446
+    }
d5a2446
+    send_gdb "continue\n"
d5a2446
+    gdb_expect {
d5a2446
+	-re "main.*at.*$srcfile:19.*$gdb_prompt $" {
d5a2446
+	    pass "after attach-32, reach tbreak postloop"
d5a2446
+	}
d5a2446
+	-re "$gdb_prompt $" {
d5a2446
+	    fail "after attach-32, reach tbreak postloop"
d5a2446
+	}
d5a2446
+	timeout {
d5a2446
+	    fail "(timeout) after attach-32, reach tbreak postloop"
d5a2446
+	}
d5a2446
+    }
d5a2446
+
d5a2446
+    # Allow the test process to exit, to cleanup after ourselves.
d5a2446
+
d5a2446
+    gdb_test "continue" "Program exited normally." "after attach-32, exit"
d5a2446
+
d5a2446
+    # Make sure we don't leave a process around to confuse
d5a2446
+    # the next test run (and prevent the compile by keeping
d5a2446
+    # the text file busy), in case the "set should_exit" didn't
d5a2446
+    # work.
d5a2446
+   
d5a2446
+    remote_exec build "kill -9 ${testpid}"
d5a2446
+
d5a2446
+    # Start the program running and then wait for a bit, to be sure
d5a2446
+    # that it can be attached to.
d5a2446
+   
d5a2446
+    set testpid [eval exec $binfile &]
d5a2446
+    exec sleep 2
d5a2446
+    if { [istarget "*-*-cygwin*"] } {
d5a2446
+	# testpid is the Cygwin PID, GDB uses the Windows PID, which might be
d5a2446
+	# different due to the way fork/exec works.
d5a2446
+	set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
d5a2446
+    }
d5a2446
+
d5a2446
+    # Verify that we can attach to the process, and find its a.out
d5a2446
+    # when we're cd'd to some directory that doesn't contain the
d5a2446
+    # a.out.  (We use the source path set by the "dir" command.)
d5a2446
+    
d5a2446
+    gdb_test "dir ${objdir}/${subdir}" "Source directories searched: .*" \
d5a2446
+	"set source path"
d5a2446
+
d5a2446
+    gdb_test "cd /tmp" "Working directory /tmp." \
d5a2446
+	"cd away from process working directory"
d5a2446
+
d5a2446
+    # Explicitly flush out any knowledge of the previous attachment.
d5a2446
+
d5a2446
+    set test "before attach-32-3, flush symbols"
d5a2446
+    gdb_test_multiple "symbol" "$test" {
d5a2446
+	-re "Discard symbol table from.*y or n. $" {
d5a2446
+	    gdb_test "y" "No symbol file now." \
d5a2446
+		"$test"
d5a2446
+	}
d5a2446
+	-re "No symbol file now.*$gdb_prompt $" {
d5a2446
+	    pass "$test"
d5a2446
+	}
d5a2446
+    }
d5a2446
+
d5a2446
+    gdb_test "exec" "No executable file now." \
d5a2446
+	"before attach-32-3, flush exec"
d5a2446
+
d5a2446
+    gdb_test "attach $testpid" \
d5a2446
+	"Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*" \
d5a2446
+	"attach-32 when process' a.out not in cwd"
d5a2446
+
d5a2446
+    set test "after attach-32-3, exit"
d5a2446
+    gdb_test_multiple "kill" "$test" {
d5a2446
+	-re "Kill the program being debugged.*y or n. $" {
d5a2446
+	    gdb_test "y" "" "$test"
d5a2446
+	}
d5a2446
+    }
d5a2446
+    
d5a2446
+    # Another "don't leave a process around"
d5a2446
+    remote_exec build "kill -9 ${testpid}"
d5a2446
+}
d5a2446
+
d5a2446
+proc do_call_attach_tests {} {
d5a2446
+    global gdb_prompt
d5a2446
+    global binfile2
d5a2446
+    global testpid
d5a2446
+    
d5a2446
+    # See if other registers are problems
d5a2446
+    
d5a2446
+    set test "info other register"
d5a2446
+    gdb_test_multiple "i r r3" "$test" {
d5a2446
+	-re "warning: reading register.*$gdb_prompt $" {
d5a2446
+	    fail "$test"
d5a2446
+	}
d5a2446
+	-re "r3.*$gdb_prompt $" {
d5a2446
+	    pass "$test"
d5a2446
+	}
d5a2446
+    }
d5a2446
+
d5a2446
+    # Get rid of the process
d5a2446
+    
d5a2446
+    gdb_test "p should_exit = 1"
d5a2446
+    gdb_test "c" "Program exited normally."
d5a2446
+   
d5a2446
+    # Be paranoid
d5a2446
+   
d5a2446
+    remote_exec build "kill -9 ${testpid}"
d5a2446
+}
d5a2446
+
d5a2446
+
d5a2446
+# Start with a fresh gdb
d5a2446
+
d5a2446
+gdb_exit
d5a2446
+set testpid [eval exec $binfile &]
d5a2446
+exec sleep 3
d5a2446
+if { [istarget "*-*-cygwin*"] } {
d5a2446
+    # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
d5a2446
+    # different due to the way fork/exec works.
d5a2446
+    set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
d5a2446
+}
d5a2446
+
d50521f
+set GDBFLAGS_orig $GDBFLAGS
d50521f
+set GDBFLAGS "--pid=$testpid"
d5a2446
+gdb_start
d50521f
+set GDBFLAGS $GDBFLAGS_orig
d50521f
+
d5a2446
+gdb_reinitialize_dir $srcdir/$subdir
d5a2446
+
d5a2446
+# This is a test of gdb's ability to attach to a running process.
d5a2446
+
d5a2446
+do_attach_tests
d5a2446
+
d5a2446
+# Test attaching when the target is inside a system call
d5a2446
+
d5a2446
+gdb_exit
d5a2446
+set testpid [eval exec $binfile2 &]
d5a2446
+exec sleep 3
d5a2446
+if { [istarget "*-*-cygwin*"] } {
d5a2446
+    # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
d5a2446
+    # different due to the way fork/exec works.
d5a2446
+    set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
d5a2446
+}
d5a2446
+
d50521f
+set GDBFLAGS_orig $GDBFLAGS
d50521f
+set GDBFLAGS "--pid=$testpid"
d5a2446
+gdb_start
d50521f
+set GDBFLAGS $GDBFLAGS_orig
d5a2446
+
d5a2446
+gdb_reinitialize_dir $srcdir/$subdir
d5a2446
+do_call_attach_tests
d5a2446
+
d5a2446
+return 0
407ebe9
Index: gdb-6.8.50.20081128/gdb/testsuite/gdb.base/attach-32b.c
407ebe9
===================================================================
407ebe9
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
407ebe9
+++ gdb-6.8.50.20081128/gdb/testsuite/gdb.base/attach-32b.c	2008-12-07 10:06:03.000000000 +0100
d5a2446
@@ -0,0 +1,24 @@
d5a2446
+/* This program is intended to be started outside of gdb, and then
d5a2446
+   attached to by gdb.  Thus, it simply spins in a loop.  The loop
d5a2446
+   is exited when & if the variable 'should_exit' is non-zero.  (It
d5a2446
+   is initialized to zero in this program, so the loop will never
d5a2446
+   exit unless/until gdb sets the variable to non-zero.)
d5a2446
+   */
d5a2446
+#include <stdio.h>
d5a2446
+#include <stdlib.h>
d5a2446
+#include <unistd.h>
d5a2446
+
d5a2446
+int  should_exit = 0;
d5a2446
+
d5a2446
+int main ()
d5a2446
+{
d5a2446
+  int  local_i = 0;
d5a2446
+
d5a2446
+  sleep( 10 ); /* System call causes register fetch to fail */
d5a2446
+               /* This is a known HPUX "feature"            */
d5a2446
+  while (! should_exit)
d5a2446
+    {
d5a2446
+      local_i++;
d5a2446
+    }
d5a2446
+  return (0);
d5a2446
+}