Blame SOURCES/gdb-6.3-inferior-notification-20050721.patch

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