190f2a
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
190f2a
From: Fedora GDB patches <invalid@email.com>
190f2a
Date: Fri, 27 Oct 2017 21:07:50 +0200
190f2a
Subject: gdb-6.3-test-pie-20050107.patch
190f2a
190f2a
;; VSYSCALL and PIE
190f2a
;;=fedoratest
190f2a
190f2a
diff --git a/gdb/testsuite/gdb.pie/attach.c b/gdb/testsuite/gdb.pie/attach.c
190f2a
new file mode 100644
190f2a
--- /dev/null
190f2a
+++ b/gdb/testsuite/gdb.pie/attach.c
190f2a
@@ -0,0 +1,20 @@
190f2a
+/* This program is intended to be started outside of gdb, and then
190f2a
+   attached to by gdb.  Thus, it simply spins in a loop.  The loop
190f2a
+   is exited when & if the variable 'should_exit' is non-zero.  (It
190f2a
+   is initialized to zero in this program, so the loop will never
190f2a
+   exit unless/until gdb sets the variable to non-zero.)
190f2a
+   */
190f2a
+#include <stdio.h>
190f2a
+
190f2a
+int  should_exit = 0;
190f2a
+
190f2a
+int main ()
190f2a
+{
190f2a
+  int  local_i = 0;
190f2a
+
190f2a
+  while (! should_exit)
190f2a
+    {
190f2a
+      local_i++;
190f2a
+    }
190f2a
+  return 0;
190f2a
+}
190f2a
diff --git a/gdb/testsuite/gdb.pie/attach.exp b/gdb/testsuite/gdb.pie/attach.exp
190f2a
new file mode 100644
190f2a
--- /dev/null
190f2a
+++ b/gdb/testsuite/gdb.pie/attach.exp
190f2a
@@ -0,0 +1,416 @@
190f2a
+#   Copyright 1997, 1999, 2002 Free Software Foundation, Inc.
190f2a
+
190f2a
+# This program is free software; you can redistribute it and/or modify
190f2a
+# it under the terms of the GNU General Public License as published by
190f2a
+# the Free Software Foundation; either version 2 of the License, or
190f2a
+# (at your option) any later version.
190f2a
+# 
190f2a
+# This program is distributed in the hope that it will be useful,
190f2a
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
190f2a
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
190f2a
+# GNU General Public License for more details.
190f2a
+# 
190f2a
+# You should have received a copy of the GNU General Public License
190f2a
+# along with this program; if not, write to the Free Software
190f2a
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
190f2a
+
190f2a
+# On HP-UX 11.0, this test is causing a process running the program
190f2a
+# "attach" to be left around spinning.  Until we figure out why, I am
190f2a
+# commenting out the test to avoid polluting tiamat (our 11.0 nightly
190f2a
+# test machine) with these processes. RT
190f2a
+#
190f2a
+# Setting the magic bit in the target app should work.  I added a
190f2a
+# "kill", and also a test for the R3 register warning.  JB
190f2a
+if { [istarget "hppa*-*-hpux*"] } {
190f2a
+    return 0
190f2a
+}
190f2a
+
190f2a
+# are we on a target board
190f2a
+if [is_remote target] then {
190f2a
+    return 0
190f2a
+}
190f2a
+
190f2a
+set testfile "attach"
190f2a
+set srcfile  ${testfile}.c
190f2a
+set srcfile2 ${testfile}2.c
190f2a
+set binfile  [standard_output_file ${testfile}]
190f2a
+set binfile2 [standard_output_file ${testfile}2]
190f2a
+set escapedbinfile  [string_to_regexp [standard_output_file ${testfile}]]
190f2a
+set cleanupfile [standard_output_file ${testfile}.awk]
190f2a
+
190f2a
+#execute_anywhere "rm -f ${binfile} ${binfile2}"
190f2a
+remote_exec build "rm -f ${binfile} ${binfile2}"
190f2a
+# For debugging this test
190f2a
+#
190f2a
+#log_user 1
190f2a
+
190f2a
+# Clean out any old files from past runs.
190f2a
+#
190f2a
+remote_exec build "${cleanupfile}"
190f2a
+
190f2a
+# build the first test case
190f2a
+#
190f2a
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug "additional_flags= -fpie -pie"}] != "" } {
190f2a
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
190f2a
+}
190f2a
+
190f2a
+# Build the in-system-call test
190f2a
+
190f2a
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug "additional_flags= -fpie -pie"}] != "" } {
190f2a
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
190f2a
+}
190f2a
+
190f2a
+if [get_compiler_info ${binfile}] {
190f2a
+    return -1
190f2a
+}
190f2a
+
190f2a
+proc do_attach_tests {} {
190f2a
+   global gdb_prompt
190f2a
+   global binfile
190f2a
+   global escapedbinfile
190f2a
+   global srcfile
190f2a
+   global testfile
190f2a
+   global subdir
190f2a
+   global timeout
190f2a
+
190f2a
+   # Start the program running and then wait for a bit, to be sure
190f2a
+   # that it can be attached to.
190f2a
+   #
190f2a
+   set testpid [eval exec $binfile &]
190f2a
+   exec sleep 2
190f2a
+
190f2a
+   # Verify that we cannot attach to nonsense.
190f2a
+   #
190f2a
+   send_gdb "attach abc\n"
190f2a
+   gdb_expect {
190f2a
+      -re ".*Illegal process-id: abc.*$gdb_prompt $"\
190f2a
+                      {pass "attach to nonsense is prohibited"}
190f2a
+      -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
190f2a
+                      {
190f2a
+                        # Response expected from /proc-based systems.
190f2a
+                        pass "attach to nonsense is prohibited" 
190f2a
+                      }
190f2a
+      -re "Attaching to.*$gdb_prompt $"\
190f2a
+                      {fail "attach to nonsense is prohibited (bogus pid allowed)"}
190f2a
+      -re "$gdb_prompt $" {fail "attach to nonsense is prohibited"}
190f2a
+      timeout         {fail "(timeout) attach to nonsense is prohibited"}
190f2a
+   }
190f2a
+
190f2a
+   # Verify that we cannot attach to what appears to be a valid
190f2a
+   # process ID, but is a process that doesn't exist.  Traditionally,
190f2a
+   # most systems didn't have a process with ID 0, so we take that as
190f2a
+   # the default.  However, there are a few exceptions.
190f2a
+   #
190f2a
+   set boguspid 0
190f2a
+   if { [istarget "*-*-*bsd*"] } {
190f2a
+       # In FreeBSD 5.0, PID 0 is used for "swapper".  Use -1 instead
190f2a
+       # (which should have the desired effect on any version of
190f2a
+       # FreeBSD, and probably other *BSD's too).
190f2a
+       set boguspid -1
190f2a
+   }
190f2a
+   send_gdb "attach $boguspid\n"
190f2a
+   gdb_expect {
190f2a
+       -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $"\
190f2a
+	       {
190f2a
+	   # Response expected on ptrace-based systems (i.e. HP-UX 10.20).
190f2a
+	   pass "attach to nonexistent process is prohibited"
190f2a
+       }
190f2a
+       -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $"\
190f2a
+	       {
190f2a
+	   # Response expected on ttrace-based systems (i.e. HP-UX 11.0).
190f2a
+	   pass "attach to nonexistent process is prohibited"
190f2a
+       }
190f2a
+       -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $"\
190f2a
+	       {pass "attach to nonexistent process is prohibited"}
190f2a
+       -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $"\
190f2a
+	       {pass "attach to nonexistent process is prohibited"}
190f2a
+       -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
190f2a
+	       {
190f2a
+	   # Response expected from /proc-based systems.
190f2a
+	   pass "attach to nonexistent process is prohibited"
190f2a
+       }
190f2a
+       -re "$gdb_prompt $" {fail "attach to nonexistent process is prohibited"}
190f2a
+       timeout {
190f2a
+	   fail "(timeout) attach to nonexistent process is prohibited"
190f2a
+       }
190f2a
+   }
190f2a
+
190f2a
+   # Verify that we can attach to the process by first giving its
190f2a
+   # executable name via the file command, and using attach with
190f2a
+   # the process ID.
190f2a
+   #
190f2a
+   # (Actually, the test system appears to do this automatically
190f2a
+   # for us.  So, we must also be prepared to be asked if we want
190f2a
+   # to discard an existing set of symbols.)
190f2a
+   #
190f2a
+   send_gdb "file $binfile\n"
190f2a
+   gdb_expect {
190f2a
+      -re "Load new symbol table from.*y or n.*$" {
190f2a
+         send_gdb "y\n"
190f2a
+         gdb_expect {
190f2a
+            -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
190f2a
+                            {pass "(re)set file, before attach1"}
190f2a
+            -re "$gdb_prompt $" {fail "(re)set file, before attach1"}
190f2a
+            timeout         {fail "(timeout) (re)set file, before attach1"}
190f2a
+         }
190f2a
+      }
190f2a
+      -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
190f2a
+                      {pass "set file, before attach1"}
190f2a
+      -re "$gdb_prompt $" {fail "set file, before attach1"}
190f2a
+      timeout         {fail "(timeout) set file, before attach1"}
190f2a
+   }
190f2a
+
190f2a
+   send_gdb "attach $testpid\n"
190f2a
+   gdb_expect {
190f2a
+      -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $"\
190f2a
+                      {pass "attach1, after setting file"}
190f2a
+      -re "$gdb_prompt $" {fail "attach1, after setting file"}
190f2a
+      timeout         {fail "(timeout) attach1, after setting file"}
190f2a
+   }
190f2a
+
190f2a
+   # Verify that we can "see" the variable "should_exit" in the
190f2a
+   # program, and that it is zero.
190f2a
+   #
190f2a
+   send_gdb "print should_exit\n"
190f2a
+   gdb_expect {
190f2a
+      -re ".* = 0.*$gdb_prompt $"\
190f2a
+                      {pass "after attach1, print should_exit"}
190f2a
+      -re "$gdb_prompt $" {fail "after attach1, print should_exit"}
190f2a
+      timeout         {fail "(timeout) after attach1, print should_exit"}
190f2a
+   }
190f2a
+
190f2a
+   # Detach the process.
190f2a
+   #
190f2a
+   send_gdb "detach\n"
190f2a
+   gdb_expect {
190f2a
+      -re "Detaching from program: .*$escapedbinfile.*$gdb_prompt $"\
190f2a
+                      {pass "attach1 detach"}
190f2a
+      -re "$gdb_prompt $" {fail "attach1 detach"}
190f2a
+      timeout         {fail "(timeout) attach1 detach"}
190f2a
+   }
190f2a
+
190f2a
+   # Wait a bit for gdb to finish detaching
190f2a
+   #
190f2a
+   exec sleep 5
190f2a
+
190f2a
+   # Purge the symbols from gdb's brain.  (We want to be certain
190f2a
+   # the next attach, which won't be preceded by a "file" command,
190f2a
+   # is really getting the executable file without our help.)
190f2a
+   #
190f2a
+   set old_timeout $timeout
190f2a
+   set timeout 15 
190f2a
+   send_gdb "file\n"
190f2a
+   gdb_expect {
190f2a
+      -re ".*gdb internal error.*$" { 
190f2a
+          fail "Internal error, prob. Memory corruption" 
190f2a
+      }
190f2a
+      -re "No executable file now.*Discard symbol table.*y or n.*$" {
190f2a
+         send_gdb "y\n"
190f2a
+         gdb_expect {
190f2a
+            -re "No symbol file now.*$gdb_prompt $"\
190f2a
+                            {pass "attach1, purging symbols after detach"}
190f2a
+            -re "$gdb_prompt $" {fail "attach1, purging symbols after detach"}
190f2a
+            timeout         {fail "(timeout) attach1, purging symbols after detach"}
190f2a
+         }
190f2a
+      }
190f2a
+      -re "$gdb_prompt $" {fail "attach1, purging file after detach"}
190f2a
+      timeout         {
190f2a
+          fail "(timeout) attach1, purging file after detach"
190f2a
+      }
190f2a
+   }
190f2a
+   set timeout $old_timeout
190f2a
+
190f2a
+   # Verify that we can attach to the process just by giving the
190f2a
+   # process ID.
190f2a
+   #
190f2a
+   send_gdb "attach $testpid\n"
190f2a
+   gdb_expect {
190f2a
+      -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\
190f2a
+                      {pass "attach2"}
190f2a
+      -re "$gdb_prompt $" {fail "attach2"}
190f2a
+      timeout         {fail "(timeout) attach2"}
190f2a
+   }
190f2a
+
190f2a
+   # Verify that we can modify the variable "should_exit" in the
190f2a
+   # program.
190f2a
+   #
190f2a
+   send_gdb "set should_exit=1\n"
190f2a
+   gdb_expect {
190f2a
+      -re "$gdb_prompt $" {pass "after attach2, set should_exit"}
190f2a
+      timeout         {fail "(timeout) after attach2, set should_exit"}
190f2a
+   }
190f2a
+
190f2a
+   # Verify that the modification really happened.
190f2a
+   #
190f2a
+   send_gdb "tbreak 19\n"
190f2a
+   gdb_expect {
190f2a
+      -re "reakpoint .*at.*$srcfile, line 19.*$gdb_prompt $"\
190f2a
+                      {pass "after attach2, set tbreak postloop"}
190f2a
+      -re "$gdb_prompt $" {fail "after attach2, set tbreak postloop"}
190f2a
+      timeout         {fail "(timeout) after attach2, set tbreak postloop"}
190f2a
+   }
190f2a
+   send_gdb "continue\n"
190f2a
+   gdb_expect {
190f2a
+      -re "main.*at.*$srcfile:19.*$gdb_prompt $"\
190f2a
+                      {pass "after attach2, reach tbreak postloop"}
190f2a
+      -re "$gdb_prompt $" {fail "after attach2, reach tbreak postloop"}
190f2a
+      timeout         {fail "(timeout) after attach2, reach tbreak postloop"}
190f2a
+   }
190f2a
+
190f2a
+   # Allow the test process to exit, to cleanup after ourselves.
190f2a
+   #
190f2a
+   gdb_test "continue" {\[Inferior .* exited normally\]} "after attach2, exit"
190f2a
+
190f2a
+   # Make sure we don't leave a process around to confuse
190f2a
+   # the next test run (and prevent the compile by keeping
190f2a
+   # the text file busy), in case the "set should_exit" didn't
190f2a
+   # work.
190f2a
+   #
190f2a
+   remote_exec build "kill -9 ${testpid}"
190f2a
+   # Start the program running and then wait for a bit, to be sure
190f2a
+   # that it can be attached to.
190f2a
+   #
190f2a
+   set testpid [eval exec $binfile &]
190f2a
+   exec sleep 2
190f2a
+
190f2a
+   # Verify that we can attach to the process, and find its a.out
190f2a
+   # when we're cd'd to some directory that doesn't contain the
190f2a
+   # a.out.  (We use the source path set by the "dir" command.)
190f2a
+   #
190f2a
+   send_gdb "dir [file dirname [standard_output_file ${testfile}]]\n"
190f2a
+   gdb_expect {
190f2a
+      -re ".*Source directories searched: .*$gdb_prompt $"\
190f2a
+                      {pass "set source path"}
190f2a
+      -re "$gdb_prompt $" {fail "set source path"}
190f2a
+      timeout         {fail "(timeout) set source path"}
190f2a
+   }
190f2a
+
190f2a
+   send_gdb "cd /tmp\n"
190f2a
+   gdb_expect {
190f2a
+      -re ".*Working directory /tmp.*$gdb_prompt $"\
190f2a
+                      {pass "cd away from process' a.out"}
190f2a
+      -re "$gdb_prompt $" {fail "cd away from process' a.out"}
190f2a
+      timeout         {fail "(timeout) cd away from process' a.out"}
190f2a
+   }
190f2a
+
190f2a
+   # Explicitly flush out any knowledge of the previous attachment.
190f2a
+   send_gdb "symbol\n"
190f2a
+   gdb_expect {
190f2a
+      -re ".*Discard symbol table from.*y or n. $"\
190f2a
+                      {send_gdb "y\n"
190f2a
+                       gdb_expect {
190f2a
+                          -re ".*No symbol file now.*$gdb_prompt $"\
190f2a
+                                          {pass "before attach3, flush symbols"}
190f2a
+                          -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
190f2a
+                          timeout         {fail "(timeout) before attach3, flush symbols"}
190f2a
+                       }
190f2a
+                      }
190f2a
+      -re ".*No symbol file now.*$gdb_prompt $"\
190f2a
+                      {pass "before attach3, flush symbols"}
190f2a
+      -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
190f2a
+      timeout         {fail "(timeout) before attach3, flush symbols"}
190f2a
+   }
190f2a
+   send_gdb "exec\n"
190f2a
+   gdb_expect {
190f2a
+      -re ".*No executable file now.*$gdb_prompt $"\
190f2a
+                      {pass "before attach3, flush exec"}
190f2a
+      -re "$gdb_prompt $" {fail "before attach3, flush exec"}
190f2a
+      timeout         {fail "(timeout) before attach3, flush exec"}
190f2a
+   }
190f2a
+
190f2a
+   send_gdb "attach $testpid\n"
190f2a
+   gdb_expect {
190f2a
+      -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\
190f2a
+                      {pass "attach when process' a.out not in cwd"}
190f2a
+      -re "$gdb_prompt $" {fail "attach when process' a.out not in cwd"}
190f2a
+      timeout         {fail "(timeout) attach when process' a.out not in cwd"}
190f2a
+   }
190f2a
+
190f2a
+   send_gdb "kill\n"
190f2a
+   gdb_expect {
190f2a
+      -re ".*Kill the program being debugged.*y or n. $"\
190f2a
+                      {send_gdb "y\n"
190f2a
+                       gdb_expect {
190f2a
+                          -re "$gdb_prompt $" {pass "after attach3, exit"}
190f2a
+                          timeout {fail "(timeout) after attach3, exit"}
190f2a
+                       }
190f2a
+                      }
190f2a
+      -re "$gdb_prompt $" {fail "after attach3, exit"}
190f2a
+      timeout         {fail "(timeout) after attach3, exit"}
190f2a
+   }
190f2a
+
190f2a
+   # Another "don't leave a process around"
190f2a
+   remote_exec build "kill -9 ${testpid}"
190f2a
+}
190f2a
+
190f2a
+proc do_call_attach_tests {} {
190f2a
+   global gdb_prompt
190f2a
+   global binfile2
190f2a
+
190f2a
+   # Start the program running and then wait for a bit, to be sure
190f2a
+   # that it can be attached to.
190f2a
+   #
190f2a
+   set testpid [eval exec $binfile2 &]
190f2a
+   exec sleep 2
190f2a
+
190f2a
+   # Attach
190f2a
+   #
190f2a
+   gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
190f2a
+   send_gdb "attach $testpid\n"
190f2a
+   gdb_expect {
190f2a
+      -re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
190f2a
+         fail "attach call, read register 3 error"
190f2a
+     }
190f2a
+     -re "Attaching to.*process $testpid.*$gdb_prompt $" {
190f2a
+         # libc is relocated, not relocated, therefore not printed.
190f2a
+         pass "attach call"
190f2a
+     }
190f2a
+      -re "$gdb_prompt $" {fail "attach call"}
190f2a
+      timeout         {fail "(timeout) attach call"}
190f2a
+   }
190f2a
+
190f2a
+   # See if other registers are problems
190f2a
+   #
190f2a
+   send_gdb "i r r3\n"
190f2a
+   gdb_expect {
190f2a
+       -re ".*warning: reading register.*$gdb_prompt $" {
190f2a
+           pass "CHFts23490: known bug"
190f2a
+       }
190f2a
+       -re ".*r3.*$gdb_prompt $" {
190f2a
+           pass "Bug fixed, Yayyy!"
190f2a
+       }
190f2a
+       timeout { fail "timeout on info reg" }
190f2a
+   }
190f2a
+
190f2a
+   # Get rid of the process
190f2a
+   #
190f2a
+   gdb_test "p should_exit = 1" ".*"
190f2a
+   gdb_test "c" {\[Inferior .* exited normally\]}
190f2a
+   
190f2a
+   # Be paranoid
190f2a
+   #
190f2a
+    remote_exec build "kill -9 ${testpid}"
190f2a
+
190f2a
+}
190f2a
+
190f2a
+
190f2a
+# Start with a fresh gdb
190f2a
+#
190f2a
+gdb_exit
190f2a
+gdb_start
190f2a
+gdb_reinitialize_dir $srcdir/$subdir
190f2a
+gdb_load ${binfile}
190f2a
+
190f2a
+# This is a test of gdb's ability to attach to a running process.
190f2a
+#
190f2a
+do_attach_tests
190f2a
+
190f2a
+# Test attaching when the target is inside a system call
190f2a
+#
190f2a
+gdb_exit
190f2a
+gdb_start
190f2a
+
190f2a
+gdb_reinitialize_dir $srcdir/$subdir
190f2a
+do_call_attach_tests
190f2a
+
190f2a
+return 0
190f2a
diff --git a/gdb/testsuite/gdb.pie/attach2.c b/gdb/testsuite/gdb.pie/attach2.c
190f2a
new file mode 100644
190f2a
--- /dev/null
190f2a
+++ b/gdb/testsuite/gdb.pie/attach2.c
190f2a
@@ -0,0 +1,24 @@
190f2a
+/* This program is intended to be started outside of gdb, and then
190f2a
+   attached to by gdb.  Thus, it simply spins in a loop.  The loop
190f2a
+   is exited when & if the variable 'should_exit' is non-zero.  (It
190f2a
+   is initialized to zero in this program, so the loop will never
190f2a
+   exit unless/until gdb sets the variable to non-zero.)
190f2a
+   */
190f2a
+#include <stdio.h>
190f2a
+#include <stdlib.h>
190f2a
+#include <unistd.h>
190f2a
+
190f2a
+int  should_exit = 0;
190f2a
+
190f2a
+int main ()
190f2a
+{
190f2a
+  int  local_i = 0;
190f2a
+
190f2a
+  sleep( 10 ); /* System call causes register fetch to fail */
190f2a
+               /* This is a known HPUX "feature"            */
190f2a
+  while (! should_exit)
190f2a
+    {
190f2a
+      local_i++;
190f2a
+    }
190f2a
+  return (0);
190f2a
+}
190f2a
diff --git a/gdb/testsuite/gdb.pie/break.c b/gdb/testsuite/gdb.pie/break.c
190f2a
new file mode 100644
190f2a
--- /dev/null
190f2a
+++ b/gdb/testsuite/gdb.pie/break.c
190f2a
@@ -0,0 +1,146 @@
190f2a
+/* This testcase is part of GDB, the GNU debugger.
190f2a
+
190f2a
+   Copyright 1992, 1993, 1994, 1995, 1999, 2002, 2003 Free Software
190f2a
+   Foundation, Inc.
190f2a
+
190f2a
+   This program is free software; you can redistribute it and/or modify
190f2a
+   it under the terms of the GNU General Public License as published by
190f2a
+   the Free Software Foundation; either version 2 of the License, or
190f2a
+   (at your option) any later version.
190f2a
+
190f2a
+   This program is distributed in the hope that it will be useful,
190f2a
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
190f2a
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
190f2a
+   GNU General Public License for more details.
190f2a
+ 
190f2a
+   You should have received a copy of the GNU General Public License
190f2a
+   along with this program; if not, write to the Free Software
190f2a
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
190f2a
+
190f2a
+   Please email any bugs, comments, and/or additions to this file to:
190f2a
+   bug-gdb@prep.ai.mit.edu  */
190f2a
+
190f2a
+#ifdef vxworks
190f2a
+
190f2a
+#  include <stdio.h>
190f2a
+
190f2a
+/* VxWorks does not supply atoi.  */
190f2a
+static int
190f2a
+atoi (z)
190f2a
+     char *z;
190f2a
+{
190f2a
+  int i = 0;
190f2a
+
190f2a
+  while (*z >= '0' && *z <= '9')
190f2a
+    i = i * 10 + (*z++ - '0');
190f2a
+  return i;
190f2a
+}
190f2a
+
190f2a
+/* I don't know of any way to pass an array to VxWorks.  This function
190f2a
+   can be called directly from gdb.  */
190f2a
+
190f2a
+vxmain (arg)
190f2a
+char *arg;
190f2a
+{
190f2a
+  char *argv[2];
190f2a
+
190f2a
+  argv[0] = "";
190f2a
+  argv[1] = arg;
190f2a
+  main (2, argv, (char **) 0);
190f2a
+}
190f2a
+
190f2a
+#else /* ! vxworks */
190f2a
+#  include <stdio.h>
190f2a
+#  include <stdlib.h>
190f2a
+#endif /* ! vxworks */
190f2a
+
190f2a
+#ifdef PROTOTYPES
190f2a
+extern int marker1 (void);
190f2a
+extern int marker2 (int a);
190f2a
+extern void marker3 (char *a, char *b);
190f2a
+extern void marker4 (long d);
190f2a
+#else
190f2a
+extern int marker1 ();
190f2a
+extern int marker2 ();
190f2a
+extern void marker3 ();
190f2a
+extern void marker4 ();
190f2a
+#endif
190f2a
+
190f2a
+/*
190f2a
+ *	This simple classical example of recursion is useful for
190f2a
+ *	testing stack backtraces and such.
190f2a
+ */
190f2a
+
190f2a
+#ifdef PROTOTYPES
190f2a
+int factorial(int);
190f2a
+
190f2a
+int
190f2a
+main (int argc, char **argv, char **envp)
190f2a
+#else
190f2a
+int
190f2a
+main (argc, argv, envp)
190f2a
+int argc;
190f2a
+char *argv[], **envp;
190f2a
+#endif
190f2a
+{
190f2a
+#ifdef usestubs
190f2a
+    set_debug_traps();  /* set breakpoint 5 here */
190f2a
+    breakpoint();
190f2a
+#endif
190f2a
+    if (argc == 12345) {  /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 here */
190f2a
+	fprintf (stderr, "usage:  factorial <number>\n");
190f2a
+	return 1;
190f2a
+    }
190f2a
+    printf ("%d\n", factorial (atoi ("6")));  /* set breakpoint 1 here */
190f2a
+    /* set breakpoint 12 here */
190f2a
+    marker1 ();  /* set breakpoint 11 here */
190f2a
+    marker2 (43); /* set breakpoint 20 here */
190f2a
+    marker3 ("stack", "trace"); /* set breakpoint 21 here */
190f2a
+    marker4 (177601976L);
190f2a
+    argc = (argc == 12345); /* This is silly, but we can step off of it */ /* set breakpoint 2 here */
190f2a
+    return argc;  /* set breakpoint 10 here */
190f2a
+}
190f2a
+
190f2a
+#ifdef PROTOTYPES
190f2a
+int factorial (int value)
190f2a
+#else
190f2a
+int factorial (value)
190f2a
+int value;
190f2a
+#endif
190f2a
+{
190f2a
+  if (value > 1) {  /* set breakpoint 7 here */
190f2a
+	value *= factorial (value - 1);
190f2a
+    }
190f2a
+    return (value); /* set breakpoint 19 here */
190f2a
+}
190f2a
+
190f2a
+#ifdef PROTOTYPES
190f2a
+int multi_line_if_conditional (int a, int b, int c)
190f2a
+#else
190f2a
+int multi_line_if_conditional (a, b, c)
190f2a
+  int a, b, c;
190f2a
+#endif
190f2a
+{
190f2a
+  if (a    /* set breakpoint 3 here */
190f2a
+      && b
190f2a
+      && c)
190f2a
+    return 0;
190f2a
+  else
190f2a
+    return 1;
190f2a
+}
190f2a
+
190f2a
+#ifdef PROTOTYPES
190f2a
+int multi_line_while_conditional (int a, int b, int c)
190f2a
+#else
190f2a
+int multi_line_while_conditional (a, b, c)
190f2a
+  int a, b, c;
190f2a
+#endif
190f2a
+{
190f2a
+  while (a /* set breakpoint 4 here */
190f2a
+      && b
190f2a
+      && c)
190f2a
+    {
190f2a
+      a--, b--, c--;
190f2a
+    }
190f2a
+  return 0;
190f2a
+}
190f2a
diff --git a/gdb/testsuite/gdb.pie/break.exp b/gdb/testsuite/gdb.pie/break.exp
190f2a
new file mode 100644
190f2a
--- /dev/null
190f2a
+++ b/gdb/testsuite/gdb.pie/break.exp
190f2a
@@ -0,0 +1,954 @@
190f2a
+#   Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
190f2a
+#   2000, 2002, 2003, 2004
190f2a
+#   Free Software Foundation, Inc.
190f2a
+
190f2a
+# This program is free software; you can redistribute it and/or modify
190f2a
+# it under the terms of the GNU General Public License as published by
190f2a
+# the Free Software Foundation; either version 2 of the License, or
190f2a
+# (at your option) any later version.
190f2a
+# 
190f2a
+# This program is distributed in the hope that it will be useful,
190f2a
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
190f2a
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
190f2a
+# GNU General Public License for more details.
190f2a
+# 
190f2a
+# You should have received a copy of the GNU General Public License
190f2a
+# along with this program; if not, write to the Free Software
190f2a
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
190f2a
+
190f2a
+# Please email any bugs, comments, and/or additions to this file to:
190f2a
+# bug-gdb@prep.ai.mit.edu
190f2a
+
190f2a
+# This file was written by Rob Savoye. (rob@cygnus.com)
190f2a
+
190f2a
+# Test the same stuff but with PIE executables
190f2a
+
190f2a
+set testfile "break"
190f2a
+set srcfile ${testfile}.c
190f2a
+set srcfile1 ${testfile}1.c
190f2a
+set binfile [standard_output_file ${testfile}]
190f2a
+
190f2a
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug "additional_flags=-w -fpie -pie"}] != "" } {
190f2a
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
190f2a
+}
190f2a
+
190f2a
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug "additional_flags=-w -fpie -pie"}] != "" } {
190f2a
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
190f2a
+}
190f2a
+
190f2a
+if  { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug "additional_flags=-w -fpie -pie"}] != "" } {
190f2a
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
190f2a
+}
190f2a
+
190f2a
+if [get_compiler_info ${binfile}] {
190f2a
+    return -1
190f2a
+}
190f2a
+
190f2a
+gdb_exit
190f2a
+gdb_start
190f2a
+gdb_reinitialize_dir $srcdir/$subdir
190f2a
+gdb_load ${binfile}
190f2a
+
190f2a
+if [target_info exists gdb_stub] {
190f2a
+    gdb_step_for_stub;
190f2a
+}
190f2a
+#
190f2a
+# test simple breakpoint setting commands
190f2a
+#
190f2a
+
190f2a
+# Test deleting all breakpoints when there are none installed,
190f2a
+# GDB should not prompt for confirmation.
190f2a
+# Note that gdb-init.exp provides a "delete_breakpoints" proc
190f2a
+# for general use elsewhere.
190f2a
+
190f2a
+send_gdb "delete breakpoints\n"
190f2a
+gdb_expect {
190f2a
+     -re "Delete all breakpoints.*$" {
190f2a
+	    send_gdb "y\n"
190f2a
+	    gdb_expect {
190f2a
+		-re "$gdb_prompt $" {
190f2a
+		    fail "Delete all breakpoints when none (unexpected prompt)"
190f2a
+		}
190f2a
+		timeout	{ fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
190f2a
+	    }
190f2a
+	}
190f2a
+     -re ".*$gdb_prompt $"       { pass "Delete all breakpoints when none" }
190f2a
+    timeout	            { fail "Delete all breakpoints when none (timeout)" }
190f2a
+}
190f2a
+
190f2a
+#
190f2a
+# test break at function
190f2a
+#
190f2a
+gdb_test "break main" \
190f2a
+    "Breakpoint.*at.* file .*$srcfile, line.*" \
190f2a
+    "breakpoint function"
190f2a
+
190f2a
+#
190f2a
+# test break at quoted function
190f2a
+#
190f2a
+gdb_test "break \"marker2\"" \
190f2a
+    "Breakpoint.*at.* file .*$srcfile1, line.*" \
190f2a
+    "breakpoint quoted function"
190f2a
+
190f2a
+#
190f2a
+# test break at function in file
190f2a
+#
190f2a
+gdb_test "break $srcfile:factorial" \
190f2a
+    "Breakpoint.*at.* file .*$srcfile, line.*" \
190f2a
+    "breakpoint function in file"
190f2a
+
190f2a
+set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
190f2a
+
190f2a
+#
190f2a
+# test break at line number
190f2a
+#
190f2a
+# Note that the default source file is the last one whose source text
190f2a
+# was printed.  For native debugging, before we've executed the
190f2a
+# program, this is the file containing main, but for remote debugging,
190f2a
+# it's wherever the processor was stopped when we connected to the
190f2a
+# board.  So, to be sure, we do a list command.
190f2a
+#
190f2a
+gdb_test "list main" \
190f2a
+    ".*main \\(argc, argv, envp\\).*" \
190f2a
+    "use `list' to establish default source file"
190f2a
+gdb_test "break $bp_location1" \
190f2a
+    "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
190f2a
+    "breakpoint line number"
190f2a
+
190f2a
+#
190f2a
+# test duplicate breakpoint
190f2a
+#
190f2a
+gdb_test "break $bp_location1" \
190f2a
+    "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
190f2a
+    "breakpoint duplicate"
190f2a
+
190f2a
+set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
190f2a
+
190f2a
+#
190f2a
+# test break at line number in file
190f2a
+#
190f2a
+gdb_test "break $srcfile:$bp_location2" \
190f2a
+    "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
190f2a
+    "breakpoint line number in file"
190f2a
+
190f2a
+set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
190f2a
+set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
190f2a
+
190f2a
+#
190f2a
+# Test putting a break at the start of a multi-line if conditional.
190f2a
+# Verify the breakpoint was put at the start of the conditional.
190f2a
+#
190f2a
+gdb_test "break multi_line_if_conditional" \
190f2a
+    "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
190f2a
+    "breakpoint at start of multi line if conditional"
190f2a
+
190f2a
+gdb_test "break multi_line_while_conditional" \
190f2a
+    "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
190f2a
+    "breakpoint at start of multi line while conditional"
190f2a
+
190f2a
+set bp_location5 [gdb_get_line_number "set breakpoint 5 here"]
190f2a
+set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
190f2a
+
190f2a
+#
190f2a
+# check to see what breakpoints are set
190f2a
+#
190f2a
+if [target_info exists gdb_stub] {
190f2a
+    set main_line $bp_location5
190f2a
+} else {
190f2a
+    set main_line $bp_location6
190f2a
+}
190f2a
+
190f2a
+set proto ""
190f2a
+
190f2a
+set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
190f2a
+set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
190f2a
+set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
190f2a
+
190f2a
+# Test a pending breakpoint in PIE executable does not crash later GDB.
190f2a
+gdb_breakpoint "non_existent_function" allow-pending
190f2a
+
190f2a
+gdb_test "info break" \
190f2a
+    "Num\[ \]+Type\[ \]+Disp Enb Address\[ \]+What.*
190f2a
+\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$main_line.*
190f2a
+\[0-9\]+\[\t \]+breakpoint     keep y.* in marker2 at .*$srcfile1:($bp_location8|$bp_location9).*
190f2a
+\[0-9\]+\[\t \]+breakpoint     keep y.* in factorial$proto at .*$srcfile:$bp_location7.*
190f2a
+\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$bp_location1.*
190f2a
+\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$bp_location1.*
190f2a
+\[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$bp_location2.*
190f2a
+\[0-9\]+\[\t \]+breakpoint     keep y.* in multi_line_if_conditional at .*$srcfile:$bp_location3.*
190f2a
+\[0-9\]+\[\t \]+breakpoint     keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4.*
190f2a
+\[0-9\]+\[\t \]+breakpoint     keep y.* <PENDING> *non_existent_function" \
190f2a
+    "breakpoint info"
190f2a
+
190f2a
+# FIXME: The rest of this test doesn't work with anything that can't
190f2a
+# handle arguments.
190f2a
+# Huh? There doesn't *appear* to be anything that passes arguments
190f2a
+# below.
190f2a
+if [istarget "mips-idt-*"] then {
190f2a
+    return
190f2a
+}
190f2a
+
190f2a
+#
190f2a
+# run until the breakpoint at main is hit. For non-stubs-using targets.
190f2a
+#
190f2a
+if ![target_info exists use_gdb_stub] {
190f2a
+  if [istarget "*-*-vxworks*"] then {
190f2a
+    send_gdb "run vxmain \"2\"\n"
190f2a
+    set timeout 120
190f2a
+    verbose "Timeout is now $timeout seconds" 2
190f2a
+  } else {
190f2a
+	send_gdb "run\n"
190f2a
+  }
190f2a
+  gdb_expect {
190f2a
+    -re "The program .* has been started already.*y or n. $" {
190f2a
+	send_gdb "y\n"
190f2a
+	exp_continue
190f2a
+    }
190f2a
+    -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
190f2a
+	                    { pass "run until function breakpoint" }
190f2a
+    -re ".*$gdb_prompt $"       { fail "run until function breakpoint" }
190f2a
+    timeout	            { fail "run until function breakpoint (timeout)" }
190f2a
+  }
190f2a
+} else {
190f2a
+    if ![target_info exists gdb_stub] {
190f2a
+	gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue"
190f2a
+    }
190f2a
+}
190f2a
+
190f2a
+#
190f2a
+# run until the breakpoint at a line number
190f2a
+#
190f2a
+gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
190f2a
+			"run until breakpoint set at a line number"
190f2a
+
190f2a
+#
190f2a
+# Run until the breakpoint set in a function in a file
190f2a
+#
190f2a
+for {set i 6} {$i >= 1} {incr i -1} {
190f2a
+	gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
190f2a
+			"run until file:function($i) breakpoint"
190f2a
+}
190f2a
+
190f2a
+#
190f2a
+# Run until the breakpoint set at a quoted function
190f2a
+#
190f2a
+gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*" \
190f2a
+		"run until quoted breakpoint"
190f2a
+#
190f2a
+# run until the file:function breakpoint at a line number in a file
190f2a
+#
190f2a
+gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
190f2a
+		"run until file:linenum breakpoint"
190f2a
+
190f2a
+# Test break at offset +1
190f2a
+set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
190f2a
+
190f2a
+gdb_test "break +1" \
190f2a
+    "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
190f2a
+    "breakpoint offset +1"
190f2a
+
190f2a
+# Check to see if breakpoint is hit when stepped onto
190f2a
+
190f2a
+gdb_test "step" \
190f2a
+    ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
190f2a
+    "step onto breakpoint"
190f2a
+
190f2a
+#
190f2a
+# delete all breakpoints so we can start over, course this can be a test too
190f2a
+#
190f2a
+delete_breakpoints
190f2a
+
190f2a
+#
190f2a
+# test temporary breakpoint at function
190f2a
+#
190f2a
+
190f2a
+gdb_test "tbreak main" "reakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
190f2a
+
190f2a
+#
190f2a
+# test break at function in file
190f2a
+#
190f2a
+
190f2a
+gdb_test "tbreak $srcfile:factorial" "reakpoint.*at.* file .*$srcfile, line.*" \
190f2a
+	"Temporary breakpoint function in file"
190f2a
+
190f2a
+#
190f2a
+# test break at line number
190f2a
+#
190f2a
+send_gdb "tbreak $bp_location1\n"
190f2a
+gdb_expect {
190f2a
+    -re "reakpoint.*at.* file .*$srcfile, line $bp_location1.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
190f2a
+	-re ".*$gdb_prompt $"   { pass "Temporary breakpoint line number #1" }
190f2a
+	timeout	    { fail "breakpoint line number #1 (timeout)" }
190f2a
+}
190f2a
+
190f2a
+gdb_test "tbreak $bp_location6" "reakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2"
190f2a
+
190f2a
+#
190f2a
+# test break at line number in file
190f2a
+#
190f2a
+send_gdb "tbreak $srcfile:$bp_location2\n"
190f2a
+gdb_expect {
190f2a
+    -re "reakpoint.*at.* file .*$srcfile, line $bp_location2.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
190f2a
+	-re ".*$gdb_prompt $"   { pass "Temporary breakpoint line number in file #1" }
190f2a
+	timeout	    { fail "Temporary breakpoint line number in file #1 (timeout)" }
190f2a
+}
190f2a
+
190f2a
+set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
190f2a
+gdb_test  "tbreak $srcfile:$bp_location11" "reakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
190f2a
+
190f2a
+#
190f2a
+# check to see what breakpoints are set (temporary this time)
190f2a
+#
190f2a
+gdb_test "info break" "Num.*Type.*Disp Enb Address.*What.*\[\r\n\]
190f2a
+\[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
190f2a
+\[0-9\]+\[\t \]+breakpoint     del.*y.*in factorial$proto at .*$srcfile:$bp_location7.*\[\r\n\]
190f2a
+\[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
190f2a
+\[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
190f2a
+\[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
190f2a
+\[0-9\]+\[\t \]+breakpoint     del.*y.*in main at .*$srcfile:$bp_location11.*" \
190f2a
+    "Temporary breakpoint info"
190f2a
+
190f2a
+
190f2a
+#***********
190f2a
+
190f2a
+# Verify that catchpoints for fork, vfork and exec don't trigger
190f2a
+# inappropriately.  (There are no calls to those system functions
190f2a
+# in this test program.)
190f2a
+#
190f2a
+if ![runto_main] then { fail "break tests suppressed" }
190f2a
+
190f2a
+send_gdb "catch\n"
190f2a
+gdb_expect {
190f2a
+  -re "Catch requires an event name.*$gdb_prompt $"\
190f2a
+          {pass "catch requires an event name"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "catch requires an event name"}
190f2a
+  timeout {fail "(timeout) catch requires an event name"}
190f2a
+}
190f2a
+
190f2a
+
190f2a
+set name "set catch fork, never expected to trigger"
190f2a
+send_gdb "catch fork\n"
190f2a
+gdb_expect {
190f2a
+  -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
190f2a
+          {pass $name}
190f2a
+  -re "Catch of fork not yet implemented.*$gdb_prompt $"
190f2a
+	  {pass $name}
190f2a
+  -re "$gdb_prompt $"
190f2a
+          {fail $name}
190f2a
+  timeout {fail "(timeout) $name"}
190f2a
+}
190f2a
+
190f2a
+
190f2a
+set name "set catch vfork, never expected to trigger"
190f2a
+send_gdb "catch vfork\n"
190f2a
+
190f2a
+# If we are on HP-UX 10.20, we expect an error message to be
190f2a
+# printed if we type "catch vfork" at the gdb gdb_prompt.  This is
190f2a
+# because on HP-UX 10.20, we cannot catch vfork events.
190f2a
+
190f2a
+if [istarget "hppa*-hp-hpux10.20"] then {
190f2a
+    gdb_expect {
190f2a
+	-re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
190f2a
+		{pass $name}
190f2a
+	-re "$gdb_prompt $"
190f2a
+		{fail $name}
190f2a
+	timeout {fail "(timeout) $name"}
190f2a
+    }
190f2a
+} else {
190f2a
+    gdb_expect {
190f2a
+	-re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
190f2a
+		{pass $name}
190f2a
+	-re "Catch of vfork not yet implemented.*$gdb_prompt $"
190f2a
+		{pass $name}
190f2a
+	-re "$gdb_prompt $"
190f2a
+		{fail $name}
190f2a
+	timeout {fail "(timeout) $name"}
190f2a
+    }
190f2a
+}
190f2a
+
190f2a
+set name "set catch exec, never expected to trigger"
190f2a
+send_gdb "catch exec\n"
190f2a
+gdb_expect {
190f2a
+  -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
190f2a
+          {pass $name}
190f2a
+  -re "Catch of exec not yet implemented.*$gdb_prompt $"
190f2a
+	  {pass $name}
190f2a
+  -re "$gdb_prompt $" {fail $name}
190f2a
+  timeout {fail "(timeout) $name"}
190f2a
+}
190f2a
+
190f2a
+# Verify that GDB responds gracefully when asked to set a breakpoint
190f2a
+# on a nonexistent source line.
190f2a
+#
190f2a
+gdb_test_no_output "set breakpoint pending off"
190f2a
+gdb_test "break 999" \
190f2a
+    "No line 999 in the current file." \
190f2a
+    "break on non-existent source line"
190f2a
+
190f2a
+# Run to the desired default location. If not positioned here, the
190f2a
+# tests below don't work.
190f2a
+#
190f2a
+gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" "until bp_location1"
190f2a
+
190f2a
+
190f2a
+# Verify that GDB allows one to just say "break", which is treated
190f2a
+# as the "default" breakpoint.  Note that GDB gets cute when printing
190f2a
+# the informational message about other breakpoints at the same
190f2a
+# location.  We'll hit that bird with this stone too.
190f2a
+#
190f2a
+send_gdb "break\n"
190f2a
+gdb_expect {
190f2a
+  -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
190f2a
+          {pass "break on default location, 1st time"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "break on default location, 1st time"}
190f2a
+  timeout {fail "(timeout) break on default location, 1st time"}
190f2a
+}
190f2a
+
190f2a
+send_gdb "break\n"
190f2a
+gdb_expect {
190f2a
+  -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
190f2a
+          {pass "break on default location, 2nd time"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "break on default location, 2nd time"}
190f2a
+  timeout {fail "(timeout) break on default location, 2nd time"}
190f2a
+}
190f2a
+
190f2a
+send_gdb "break\n"
190f2a
+gdb_expect {
190f2a
+  -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
190f2a
+          {pass "break on default location, 3rd time"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "break on default location, 3rd time"}
190f2a
+  timeout {fail "(timeout) break on default location, 3rd time"}
190f2a
+}
190f2a
+
190f2a
+send_gdb "break\n"
190f2a
+gdb_expect {
190f2a
+  -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
190f2a
+          {pass "break on default location, 4th time"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "break on default location, 4th time"}
190f2a
+  timeout {fail "(timeout) break on default location, 4th time"}
190f2a
+}
190f2a
+
190f2a
+# Verify that a "silent" breakpoint can be set, and that GDB is indeed
190f2a
+# "silent" about its triggering.
190f2a
+#
190f2a
+if ![runto_main] then { fail "break tests suppressed" }
190f2a
+
190f2a
+send_gdb "break $bp_location1\n"
190f2a
+gdb_expect {
190f2a
+  -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $"\
190f2a
+          {pass "set to-be-silent break bp_location1"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "set to-be-silent break bp_location1"}
190f2a
+  timeout {fail "(timeout) set to-be-silent break bp_location1"}
190f2a
+}
190f2a
+
190f2a
+send_gdb "commands $expect_out(1,string)\n"
190f2a
+send_gdb "silent\n"
190f2a
+send_gdb "end\n"
190f2a
+gdb_expect {
190f2a
+  -re ".*$gdb_prompt $"\
190f2a
+          {pass "set silent break bp_location1"}
190f2a
+  timeout {fail "(timeout) set silent break bp_location1"}
190f2a
+}
190f2a
+
190f2a
+send_gdb "info break $expect_out(1,string)\n"
190f2a
+gdb_expect {
190f2a
+  -re "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*$gdb_prompt $"\
190f2a
+          {pass "info silent break bp_location1"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "info silent break bp_location1"}
190f2a
+  timeout {fail "(timeout) info silent break bp_location1"}
190f2a
+}
190f2a
+send_gdb "continue\n"
190f2a
+gdb_expect {
190f2a
+  -re "Continuing.\r\n$gdb_prompt $"\
190f2a
+          {pass "hit silent break bp_location1"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "hit silent break bp_location1"}
190f2a
+  timeout {fail "(timeout) hit silent break bp_location1"}
190f2a
+}
190f2a
+send_gdb "bt\n"
190f2a
+gdb_expect {
190f2a
+  -re "#0  main .* at .*:$bp_location1.*$gdb_prompt $"\
190f2a
+          {pass "stopped for silent break bp_location1"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "stopped for silent break bp_location1"}
190f2a
+  timeout {fail "(timeout) stopped for silent break bp_location1"}
190f2a
+}
190f2a
+
190f2a
+# Verify that GDB can at least parse a breakpoint with the
190f2a
+# "thread" keyword.  (We won't attempt to test here that a
190f2a
+# thread-specific breakpoint really triggers appropriately.
190f2a
+# The gdb.threads subdirectory contains tests for that.)
190f2a
+#
190f2a
+set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
190f2a
+send_gdb "break $bp_location12 thread 999\n"
190f2a
+gdb_expect {
190f2a
+  -re "Unknown thread 999.*$gdb_prompt $"\
190f2a
+          {pass "thread-specific breakpoint on non-existent thread disallowed"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "thread-specific breakpoint on non-existent thread disallowed"}
190f2a
+  timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
190f2a
+}
190f2a
+
190f2a
+gdb_test "break $bp_location12 thread foo" \
190f2a
+    "Invalid thread ID: foo" \
190f2a
+    "thread-specific breakpoint on bogus thread ID disallowed"
190f2a
+
190f2a
+# Verify that GDB responds gracefully to a breakpoint command with
190f2a
+# trailing garbage.
190f2a
+#
190f2a
+send_gdb "break $bp_location12 foo\n"
190f2a
+gdb_expect {
190f2a
+  -re "malformed linespec error: unexpected string, \"foo\"\r\n$gdb_prompt $"\
190f2a
+          {pass "breakpoint with trailing garbage disallowed"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "breakpoint with trailing garbage disallowed"}
190f2a
+  timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
190f2a
+}
190f2a
+
190f2a
+# Verify that GDB responds gracefully to a "clear" command that has
190f2a
+# no matching breakpoint.  (First, get us off the current source line,
190f2a
+# which we know has a breakpoint.)
190f2a
+#
190f2a
+send_gdb "next\n"
190f2a
+gdb_expect {
190f2a
+  -re ".*$gdb_prompt $"\
190f2a
+          {pass "step over breakpoint"}
190f2a
+  timeout {fail "(timeout) step over breakpoint"}
190f2a
+}
190f2a
+send_gdb "clear 81\n"
190f2a
+gdb_expect {
190f2a
+  -re "No breakpoint at 81..*$gdb_prompt $"\
190f2a
+          {pass "clear line has no breakpoint disallowed"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "clear line has no breakpoint disallowed"}
190f2a
+  timeout {fail "(timeout) clear line has no breakpoint disallowed"}
190f2a
+}
190f2a
+send_gdb "clear\n"
190f2a
+gdb_expect {
190f2a
+  -re "No breakpoint at this line..*$gdb_prompt $"\
190f2a
+          {pass "clear current line has no breakpoint disallowed"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "clear current line has no breakpoint disallowed"}
190f2a
+  timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
190f2a
+}
190f2a
+
190f2a
+# Verify that we can set and clear multiple breakpoints.
190f2a
+#
190f2a
+# We don't test that it deletes the correct breakpoints.  We do at
190f2a
+# least test that it deletes more than one breakpoint.
190f2a
+#
190f2a
+gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
190f2a
+gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
190f2a
+gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
190f2a
+
190f2a
+# Verify that a breakpoint can be set via a convenience variable.
190f2a
+#
190f2a
+send_gdb "set \$foo=$bp_location11\n"
190f2a
+gdb_expect {
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {pass "set convenience variable \$foo to bp_location11"}
190f2a
+  timeout {fail "(timeout) set convenience variable \$foo to bp_location11"}
190f2a
+}
190f2a
+send_gdb "break \$foo\n"
190f2a
+gdb_expect {
190f2a
+  -re "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*$gdb_prompt $"\
190f2a
+          {pass "set breakpoint via convenience variable"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "set breakpoint via convenience variable"}
190f2a
+  timeout {fail "(timeout) set breakpoint via convenience variable"}
190f2a
+}
190f2a
+
190f2a
+# Verify that GDB responds gracefully to an attempt to set a
190f2a
+# breakpoint via a convenience variable whose type is not integer.
190f2a
+#
190f2a
+send_gdb "set \$foo=81.5\n"
190f2a
+gdb_expect {
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {pass "set convenience variable \$foo to 81.5"}
190f2a
+  timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
190f2a
+}
190f2a
+send_gdb "break \$foo\n"
190f2a
+gdb_expect {
190f2a
+  -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
190f2a
+          {pass "set breakpoint via non-integer convenience variable disallowed"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "set breakpoint via non-integer convenience variable disallowed"}
190f2a
+  timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
190f2a
+}
190f2a
+
190f2a
+# Verify that we can set and trigger a breakpoint in a user-called function.
190f2a
+#
190f2a
+send_gdb "break marker2\n"
190f2a
+gdb_expect {
190f2a
+    -re "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*$gdb_prompt $"\
190f2a
+          {pass "set breakpoint on to-be-called function"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "set breakpoint on to-be-called function"}
190f2a
+  timeout {fail "(timeout) set breakpoint on to-be-called function"}
190f2a
+}
190f2a
+send_gdb "print marker2(99)\n"
190f2a
+gdb_expect {
190f2a
+  -re "The program being debugged stopped while in a function called from GDB.\r\nEvaluation of the expression containing the function\r\n.marker2$proto. will be abandoned.\r\nWhen the function is done executing, GDB will silently stop.\r\n$gdb_prompt $"\
190f2a
+          {pass "hit breakpoint on called function"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "hit breakpoint on called function"}
190f2a
+  timeout {fail "(timeout) hit breakpoint on called function"}
190f2a
+}
190f2a
+
190f2a
+# As long as we're stopped (breakpointed) in a called function,
190f2a
+# verify that we can successfully backtrace & such from here.
190f2a
+#
190f2a
+# In this and the following test, the _sr4export check apparently is needed
190f2a
+# for hppa*-*-hpux.
190f2a
+#
190f2a
+send_gdb "bt\n"
190f2a
+gdb_expect {
190f2a
+    -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $"\
190f2a
+            {pass "backtrace while in called function"}
190f2a
+    -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $"\
190f2a
+	    {pass "backtrace while in called function"}
190f2a
+    -re "$gdb_prompt $"\
190f2a
+            {fail "backtrace while in called function"}
190f2a
+    timeout {fail "(timeout) backtrace while in called function"}
190f2a
+}
190f2a
+
190f2a
+# Return from the called function.  For remote targets, it's important to do
190f2a
+# this before runto_main, which otherwise may silently stop on the dummy
190f2a
+# breakpoint inserted by GDB at the program's entry point.
190f2a
+#
190f2a
+send_gdb "finish\n"
190f2a
+gdb_expect {
190f2a
+    -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $"\
190f2a
+            {pass "finish from called function"}
190f2a
+    -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $"\
190f2a
+            {pass "finish from called function"}
190f2a
+    -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $"\
190f2a
+            {pass "finish from called function"}
190f2a
+    -re "$gdb_prompt $"\
190f2a
+            {fail "finish from called function"}
190f2a
+    timeout {fail "(timeout) finish from called function"}
190f2a
+}
190f2a
+
190f2a
+# Verify that GDB responds gracefully to a "finish" command with
190f2a
+# arguments.
190f2a
+#
190f2a
+if ![runto_main] then { fail "break tests suppressed" }
190f2a
+
190f2a
+send_gdb "finish 123\n"
190f2a
+gdb_expect {
190f2a
+  -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
190f2a
+          {pass "finish with arguments disallowed"}
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "finish with arguments disallowed"}
190f2a
+  timeout {fail "(timeout) finish with arguments disallowed"}
190f2a
+}
190f2a
+
190f2a
+# Verify that GDB responds gracefully to a request to "finish" from
190f2a
+# the outermost frame.  On a stub that never exits, this will just
190f2a
+# run to the stubs routine, so we don't get this error...  Thus the 
190f2a
+# second condition.
190f2a
+#
190f2a
+
190f2a
+send_gdb "finish\n"
190f2a
+gdb_expect {
190f2a
+  -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
190f2a
+          {pass "finish from outermost frame disallowed"}
190f2a
+  -re "Run till exit from.*\r\n$gdb_prompt $" {
190f2a
+     pass "finish from outermost frame disallowed"
190f2a
+  }
190f2a
+  -re "$gdb_prompt $"\
190f2a
+          {fail "finish from outermost frame disallowed"}
190f2a
+  timeout {fail "(timeout) finish from outermost frame disallowed"}
190f2a
+}
190f2a
+
190f2a
+# Verify that we can explicitly ask GDB to stop on all shared library
190f2a
+# events, and that it does so.
190f2a
+#
190f2a
+if [istarget "hppa*-*-hpux*"] then {
190f2a
+  if ![runto_main] then { fail "break tests suppressed" }
190f2a
+
190f2a
+  send_gdb "set stop-on-solib-events 1\n"
190f2a
+  gdb_expect {
190f2a
+    -re "$gdb_prompt $"\
190f2a
+            {pass "set stop-on-solib-events"}
190f2a
+    timeout {fail "(timeout) set stop-on-solib-events"}
190f2a
+  }
190f2a
+
190f2a
+  send_gdb "run\n"
190f2a
+  gdb_expect {
190f2a
+    -re ".*Start it from the beginning.*y or n. $"\
190f2a
+            {send_gdb "y\n"
190f2a
+             gdb_expect {
190f2a
+               -re ".*Stopped due to shared library event.*$gdb_prompt $"\
190f2a
+                       {pass "triggered stop-on-solib-events"}
190f2a
+               -re "$gdb_prompt $"\
190f2a
+                       {fail "triggered stop-on-solib-events"}
190f2a
+               timeout {fail "(timeout) triggered stop-on-solib-events"}
190f2a
+             }
190f2a
+            }
190f2a
+    -re "$gdb_prompt $"\
190f2a
+            {fail "rerun for stop-on-solib-events"}
190f2a
+    timeout {fail "(timeout) rerun for stop-on-solib-events"}
190f2a
+  }
190f2a
+
190f2a
+  send_gdb "set stop-on-solib-events 0\n"
190f2a
+  gdb_expect {
190f2a
+    -re "$gdb_prompt $"\
190f2a
+            {pass "reset stop-on-solib-events"}
190f2a
+    timeout {fail "(timeout) reset stop-on-solib-events"}
190f2a
+  }
190f2a
+}
190f2a
+
190f2a
+# Hardware breakpoints are unsupported on HP-UX.  Verify that GDB
190f2a
+# gracefully responds to requests to create them.
190f2a
+#
190f2a
+if [istarget "hppa*-*-hpux*"] then {
190f2a
+  if ![runto_main] then { fail "break tests suppressed" }
190f2a
+
190f2a
+  send_gdb "hbreak\n"
190f2a
+  gdb_expect {
190f2a
+    -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
190f2a
+            {pass "hw breaks disallowed"}
190f2a
+    -re "$gdb_prompt $"\
190f2a
+            {fail "hw breaks disallowed"}
190f2a
+    timeout {fail "(timeout) hw breaks disallowed"}
190f2a
+  }
190f2a
+
190f2a
+  send_gdb "thbreak\n"
190f2a
+  gdb_expect {
190f2a
+    -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
190f2a
+            {pass "temporary hw breaks disallowed"}
190f2a
+    -re "$gdb_prompt $"\
190f2a
+            {fail "temporary hw breaks disallowed"}
190f2a
+    timeout {fail "(timeout) temporary hw breaks disallowed"}
190f2a
+  }
190f2a
+}
190f2a
+
190f2a
+#********
190f2a
+
190f2a
+
190f2a
+#
190f2a
+# Test "next" over recursive function call.
190f2a
+#
190f2a
+
190f2a
+proc test_next_with_recursion {} { 
190f2a
+    global gdb_prompt
190f2a
+    global decimal
190f2a
+    global binfile
190f2a
+
190f2a
+    if [target_info exists use_gdb_stub] {
190f2a
+	# Reload the program.
190f2a
+	delete_breakpoints
190f2a
+	gdb_load ${binfile};
190f2a
+    } else {
190f2a
+	# FIXME: should be using runto
190f2a
+	gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
190f2a
+
190f2a
+	delete_breakpoints
190f2a
+    }
190f2a
+
190f2a
+    gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
190f2a
+
190f2a
+    # Run until we call factorial with 6
190f2a
+
190f2a
+    if [istarget "*-*-vxworks*"] then {
190f2a
+	send_gdb "run vxmain \"6\"\n"
190f2a
+    } else {
190f2a
+	gdb_run_cmd
190f2a
+    }
190f2a
+    gdb_expect {
190f2a
+	-re "Break.* factorial .value=6. .*$gdb_prompt $" {}
190f2a
+	-re ".*$gdb_prompt $" {
190f2a
+	    fail "run to factorial(6)";
190f2a
+	    gdb_suppress_tests;
190f2a
+	}
190f2a
+	timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
190f2a
+    }
190f2a
+
190f2a
+    # Continue until we call factorial recursively with 5.
190f2a
+
190f2a
+    if [gdb_test "continue" \
190f2a
+	"Continuing.*Break.* factorial .value=5. .*" \
190f2a
+	"continue to factorial(5)"] then { gdb_suppress_tests }
190f2a
+
190f2a
+    # Do a backtrace just to confirm how many levels deep we are.
190f2a
+
190f2a
+    if [gdb_test "backtrace" \
190f2a
+	"#0\[ \t\]+ factorial .value=5..*" \
190f2a
+	"backtrace from factorial(5)"] then { gdb_suppress_tests }
190f2a
+
190f2a
+    # Now a "next" should position us at the recursive call, which
190f2a
+    # we will be performing with 4.
190f2a
+
190f2a
+    if [gdb_test "next" \
190f2a
+	".* factorial .value - 1.;.*" \
190f2a
+	"next to recursive call"] then { gdb_suppress_tests }
190f2a
+
190f2a
+    # Disable the breakpoint at the entry to factorial by deleting them all.
190f2a
+    # The "next" should run until we return to the next line from this
190f2a
+    # recursive call to factorial with 4.
190f2a
+    # Buggy versions of gdb will stop instead at the innermost frame on
190f2a
+    # the line where we are trying to "next" to.
190f2a
+
190f2a
+    delete_breakpoints
190f2a
+
190f2a
+    if [istarget "mips*tx39-*"] {
190f2a
+	set timeout 60
190f2a
+    }
190f2a
+    # We used to set timeout here for all other targets as well.  This
190f2a
+    # is almost certainly wrong.  The proper timeout depends on the
190f2a
+    # target system in use, and how we communicate with it, so there
190f2a
+    # is no single value appropriate for all targets.  The timeout
190f2a
+    # should be established by the Dejagnu config file(s) for the
190f2a
+    # board, and respected by the test suite.
190f2a
+    #
190f2a
+    # For example, if I'm running GDB over an SSH tunnel talking to a
190f2a
+    # portmaster in California talking to an ancient 68k board running
190f2a
+    # a crummy ROM monitor (a situation I can only wish were
190f2a
+    # hypothetical), then I need a large timeout.  But that's not the
190f2a
+    # kind of knowledge that belongs in this file.
190f2a
+
190f2a
+    gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
190f2a
+	    "next over recursive call"
190f2a
+
190f2a
+    # OK, we should be back in the same stack frame we started from.
190f2a
+    # Do a backtrace just to confirm.
190f2a
+
190f2a
+    set result [gdb_test "backtrace" \
190f2a
+	    "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
190f2a
+	    "backtrace from factorial(5.1)"]
190f2a
+    if { $result != 0 } { gdb_suppress_tests }
190f2a
+
190f2a
+    if [target_info exists gdb,noresults] { gdb_suppress_tests }
190f2a
+  gdb_continue_to_end "recursive next test"
190f2a
+   gdb_stop_suppressing_tests;
190f2a
+}
190f2a
+
190f2a
+test_next_with_recursion
190f2a
+
190f2a
+
190f2a
+#********
190f2a
+
190f2a
+# build a new file with optimization enabled so that we can try breakpoints
190f2a
+# on targets with optimized prologues
190f2a
+
190f2a
+set binfileo2 [standard_output_file ${testfile}o2]
190f2a
+
190f2a
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}O0.o" object {debug "additional_flags=-w -O2 -fpie -pie"}] != "" } {
190f2a
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
190f2a
+}
190f2a
+
190f2a
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}O1.o" object {debug "additional_flags=-w -O2 -fpie -pie"}] != "" } {
190f2a
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
190f2a
+}
190f2a
+
190f2a
+if  { [gdb_compile "${binfile}O0.o ${binfile}O1.o" "${binfileo2}" executable {debug "additional_flags=-w -fpie -pie"}] != "" } {
190f2a
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
190f2a
+}
190f2a
+
190f2a
+if [get_compiler_info ${binfileo2}] {
190f2a
+    return -1
190f2a
+}
190f2a
+
190f2a
+gdb_exit
190f2a
+gdb_start
190f2a
+gdb_reinitialize_dir $srcdir/$subdir
190f2a
+gdb_load ${binfileo2}
190f2a
+
190f2a
+if [target_info exists gdb_stub] {
190f2a
+    gdb_step_for_stub;
190f2a
+}
190f2a
+
190f2a
+#
190f2a
+# test break at function
190f2a
+#
190f2a
+gdb_test "break main" \
190f2a
+    "Breakpoint.*at.* file .*$srcfile, line.*" \
190f2a
+    "breakpoint function, optimized file"
190f2a
+
190f2a
+#
190f2a
+# test break at function
190f2a
+#
190f2a
+gdb_test "break marker4" \
190f2a
+    "Breakpoint.*at.* file .*$srcfile1, line.*" \
190f2a
+    "breakpoint small function, optimized file"
190f2a
+
190f2a
+#
190f2a
+# run until the breakpoint at main is hit. For non-stubs-using targets.
190f2a
+#
190f2a
+if ![target_info exists use_gdb_stub] {
190f2a
+  if [istarget "*-*-vxworks*"] then {
190f2a
+    send_gdb "run vxmain \"2\"\n"
190f2a
+    set timeout 120
190f2a
+    verbose "Timeout is now $timeout seconds" 2
190f2a
+  } else {
190f2a
+	send_gdb "run\n"
190f2a
+  }
190f2a
+  gdb_expect {
190f2a
+    -re "The program .* has been started already.*y or n. $" {
190f2a
+	send_gdb "y\n"
190f2a
+	exp_continue
190f2a
+    }
190f2a
+    -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
190f2a
+	                    { pass "run until function breakpoint, optimized file" }
190f2a
+    -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $"\
190f2a
+	                    { pass "run until function breakpoint, optimized file (code motion)" }
190f2a
+    -re ".*$gdb_prompt $"       { fail "run until function breakpoint, optimized file" }
190f2a
+    timeout	            { fail "run until function breakpoint, optimized file (timeout)" }
190f2a
+  }
190f2a
+} else {
190f2a
+    if ![target_info exists gdb_stub] {
190f2a
+	gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue, optimized file"
190f2a
+    }
190f2a
+}
190f2a
+
190f2a
+#
190f2a
+# run until the breakpoint at a small function
190f2a
+#
190f2a
+
190f2a
+#
190f2a
+# Add a second pass pattern.  The behavior differs here between stabs
190f2a
+# and dwarf for one-line functions.  Stabs preserves two line symbols
190f2a
+# (one before the prologue and one after) with the same line number, 
190f2a
+# but dwarf regards these as duplicates and discards one of them.
190f2a
+# Therefore the address after the prologue (where the breakpoint is)
190f2a
+# has no exactly matching line symbol, and GDB reports the breakpoint
190f2a
+# as if it were in the middle of a line rather than at the beginning.
190f2a
+
190f2a
+set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
190f2a
+set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
190f2a
+send_gdb "continue\n"
190f2a
+gdb_expect {
190f2a
+    -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
190f2a
+	pass "run until breakpoint set at small function, optimized file"
190f2a
+    }
190f2a
+    -re "Breakpoint $decimal, $hex in marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
190f2a
+	pass "run until breakpoint set at small function, optimized file"
190f2a
+    }
190f2a
+    -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
190f2a
+        # marker4() is defined at line 46 when compiled with -DPROTOTYPES
190f2a
+	pass "run until breakpoint set at small function, optimized file (line bp_location14)"
190f2a
+    }
190f2a
+    -re ".*$gdb_prompt " {
190f2a
+	fail "run until breakpoint set at small function, optimized file"
190f2a
+    }
190f2a
+    timeout {
190f2a
+	fail "run until breakpoint set at small function, optimized file (timeout)"
190f2a
+    }
190f2a
+}
190f2a
+
190f2a
+
190f2a
+# Reset the default arguments for VxWorks
190f2a
+if [istarget "*-*-vxworks*"] {
190f2a
+    set timeout 10
190f2a
+    verbose "Timeout is now $timeout seconds" 2
190f2a
+    send_gdb "set args main\n"
190f2a
+    gdb_expect -re ".*$gdb_prompt $" {}
190f2a
+}
190f2a
diff --git a/gdb/testsuite/gdb.pie/break1.c b/gdb/testsuite/gdb.pie/break1.c
190f2a
new file mode 100644
190f2a
--- /dev/null
190f2a
+++ b/gdb/testsuite/gdb.pie/break1.c
190f2a
@@ -0,0 +1,44 @@
190f2a
+/* This testcase is part of GDB, the GNU debugger.
190f2a
+
190f2a
+   Copyright 1992, 1993, 1994, 1995, 1999, 2002, 2003 Free Software
190f2a
+   Foundation, Inc.
190f2a
+
190f2a
+   This program is free software; you can redistribute it and/or modify
190f2a
+   it under the terms of the GNU General Public License as published by
190f2a
+   the Free Software Foundation; either version 2 of the License, or
190f2a
+   (at your option) any later version.
190f2a
+
190f2a
+   This program is distributed in the hope that it will be useful,
190f2a
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
190f2a
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
190f2a
+   GNU General Public License for more details.
190f2a
+ 
190f2a
+   You should have received a copy of the GNU General Public License
190f2a
+   along with this program; if not, write to the Free Software
190f2a
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
190f2a
+
190f2a
+   Please email any bugs, comments, and/or additions to this file to:
190f2a
+   bug-gdb@prep.ai.mit.edu  */
190f2a
+
190f2a
+/* The code for this file was extracted from the gdb testsuite
190f2a
+   testcase "break.c". */
190f2a
+
190f2a
+/* The following functions do nothing useful.  They are included
190f2a
+   simply as places to try setting breakpoints at.  They are
190f2a
+   explicitly "one-line functions" to verify that this case works
190f2a
+   (some versions of gcc have or have had problems with this).
190f2a
+  
190f2a
+   These functions are in a separate source file to prevent an
190f2a
+   optimizing compiler from inlining them and optimizing them away. */
190f2a
+
190f2a
+#ifdef PROTOTYPES
190f2a
+int marker1 (void) { return (0); }	/* set breakpoint 15 here */
190f2a
+int marker2 (int a) { return (1); }	/* set breakpoint 8 here */
190f2a
+void marker3 (char *a, char *b) {}	/* set breakpoint 17 here */
190f2a
+void marker4 (long d) {}		/* set breakpoint 14 here */
190f2a
+#else
190f2a
+int marker1 () { return (0); }		/* set breakpoint 16 here */
190f2a
+int marker2 (a) int a; { return (1); }	/* set breakpoint 9 here */
190f2a
+void marker3 (a, b) char *a, *b; {}	/* set breakpoint 18 here */
190f2a
+void marker4 (d) long d; {}		/* set breakpoint 13 here */
190f2a
+#endif
190f2a
diff --git a/gdb/testsuite/gdb.pie/corefile.exp b/gdb/testsuite/gdb.pie/corefile.exp
190f2a
new file mode 100644
190f2a
--- /dev/null
190f2a
+++ b/gdb/testsuite/gdb.pie/corefile.exp
190f2a
@@ -0,0 +1,233 @@
190f2a
+# Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
190f2a
+# Free Software Foundation, Inc.
190f2a
+
190f2a
+# This program is free software; you can redistribute it and/or modify
190f2a
+# it under the terms of the GNU General Public License as published by
190f2a
+# the Free Software Foundation; either version 2 of the License, or
190f2a
+# (at your option) any later version.
190f2a
+# 
190f2a
+# This program is distributed in the hope that it will be useful,
190f2a
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
190f2a
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
190f2a
+# GNU General Public License for more details.
190f2a
+# 
190f2a
+# You should have received a copy of the GNU General Public License
190f2a
+# along with this program; if not, write to the Free Software
190f2a
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
190f2a
+
190f2a
+# This file was written by Fred Fish. (fnf@cygnus.com)
190f2a
+
190f2a
+# are we on a target board
190f2a
+if ![isnative] then {
190f2a
+    return
190f2a
+}
190f2a
+
190f2a
+set testfile "coremaker"
190f2a
+set srcfile ${testfile}.c
190f2a
+set binfile [standard_output_file ${testfile}]
190f2a
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug "additional_flags=-fpie -pie"}] != "" } {
190f2a
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
190f2a
+}
190f2a
+
190f2a
+# Create and source the file that provides information about the compiler
190f2a
+# used to compile the test case.
190f2a
+if [get_compiler_info ${binfile}] {
190f2a
+    return -1;
190f2a
+}
190f2a
+
190f2a
+# Create a core file named "corefile" rather than just "core", to
190f2a
+# avoid problems with sys admin types that like to regularly prune all
190f2a
+# files named "core" from the system.
190f2a
+#
190f2a
+# Arbitrarily try setting the core size limit to "unlimited" since
190f2a
+# this does not hurt on systems where the command does not work and
190f2a
+# allows us to generate a core on systems where it does.
190f2a
+#
190f2a
+# Some systems append "core" to the name of the program; others append
190f2a
+# the name of the program to "core"; still others (like Linux, as of
190f2a
+# May 2003) create cores named "core.PID".  In the latter case, we
190f2a
+# could have many core files lying around, and it may be difficult to
190f2a
+# tell which one is ours, so let's run the program in a subdirectory.
190f2a
+set found 0
190f2a
+set coredir [standard_output_file coredir.[getpid]]
190f2a
+file mkdir $coredir
190f2a
+catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile}; true) >/dev/null 2>&1\""
190f2a
+#      remote_exec host "${binfile}"
190f2a
+foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
190f2a
+    if [remote_file build exists $i] {
190f2a
+	remote_exec build "mv $i [standard_output_file corefile]"
190f2a
+	set found 1
190f2a
+    }
190f2a
+}
190f2a
+# Check for "core.PID".
190f2a
+if { $found == 0 } {
190f2a
+    set names [glob -nocomplain -directory $coredir core.*]
190f2a
+    if {[llength $names] == 1} {
190f2a
+        set corefile [file join $coredir [lindex $names 0]]
190f2a
+        remote_exec build "mv $corefile [standard_output_file corefile]"
190f2a
+        set found 1
190f2a
+    }
190f2a
+}
190f2a
+if { $found == 0 } {
190f2a
+    # The braindamaged HPUX shell quits after the ulimit -c above
190f2a
+    # without executing ${binfile}.  So we try again without the
190f2a
+    # ulimit here if we didn't find a core file above.
190f2a
+    # Oh, I should mention that any "braindamaged" non-Unix system has
190f2a
+    # the same problem. I like the cd bit too, it's really neat'n stuff.
190f2a
+    catch "system \"(cd [file dirname [standard_output_file ${binfile}]]; ${binfile}; true) >/dev/null 2>&1\""
190f2a
+    foreach i "[standard_output_file core] [standard_output_file core.coremaker.c] ${binfile}.core" {
190f2a
+	if [remote_file build exists $i] {
190f2a
+	    remote_exec build "mv $i [standard_output_file corefile]"
190f2a
+	    set found 1
190f2a
+	}
190f2a
+    }
190f2a
+}
190f2a
+
190f2a
+# Try to clean up after ourselves. 
190f2a
+remote_file build delete [file join $coredir coremmap.data]
190f2a
+remote_exec build "rmdir $coredir"
190f2a
+    
190f2a
+if { $found == 0  } {
190f2a
+    warning "can't generate a core file - core tests suppressed - check ulimit -c"
190f2a
+    return 0
190f2a
+}
190f2a
+
190f2a
+#
190f2a
+# Test that we can simply startup with a "-core=corefile" command line arg
190f2a
+# and recognize that the core file is a valid, usable core file.
190f2a
+# To do this, we must shutdown the currently running gdb and restart
190f2a
+# with the -core args.  We can't use gdb_start because it looks for
190f2a
+# the first gdb prompt, and the message we are looking for occurs
190f2a
+# before the first prompt.  Also, we can't include GDBFLAGS because
190f2a
+# if it is empty, this confuses gdb with an empty argument that it
190f2a
+# grumbles about (said grumbling currently being ignored in gdb_start).
190f2a
+# **FIXME**
190f2a
+#
190f2a
+# Another problem is that on some systems (solaris for example), there
190f2a
+# is apparently a limit on the length of a fully specified path to 
190f2a
+# the coremaker executable, at about 80 chars.  For this case, consider
190f2a
+# it a pass, but note that the program name is bad.
190f2a
+
190f2a
+gdb_exit
190f2a
+if $verbose>1 then {
190f2a
+    send_user "Spawning $GDB -nw $GDBFLAGS -core=[standard_output_file corefile]\n"
190f2a
+}
190f2a
+
190f2a
+set oldtimeout $timeout
190f2a
+set timeout [expr "$timeout + 60"]
190f2a
+verbose "Timeout is now $timeout seconds" 2
190f2a
+eval "spawn $GDB -nw $GDBFLAGS -core=[standard_output_file corefile]"
190f2a
+expect {
190f2a
+    -re "Couldn't find .* registers in core file.*$gdb_prompt $" {
190f2a
+        fail "args: -core=corefile (couldn't find regs)"
190f2a
+    }
190f2a
+    -re "Core was generated by .*coremaker.*\r\n\#0  .*\(\).*\r\n$gdb_prompt $" {
190f2a
+	pass "args: -core=corefile"
190f2a
+    }
190f2a
+    -re "Core was generated by .*\r\n\#0  .*\(\).*\r\n$gdb_prompt $" {
190f2a
+	pass "args: -core=corefile (with bad program name)"
190f2a
+    }
190f2a
+    -re ".*registers from core file: File in wrong format.* $" {
190f2a
+	fail "args: -core=corefile (could not read registers from core file)"
190f2a
+    }
190f2a
+    -re ".*$gdb_prompt $"	{ fail "args: -core=corefile" }
190f2a
+    timeout 		{ fail "(timeout) starting with -core" }
190f2a
+}
190f2a
+
190f2a
+
190f2a
+#
190f2a
+# Test that startup with both an executable file and -core argument.
190f2a
+# See previous comments above, they are still applicable.
190f2a
+#
190f2a
+
190f2a
+close;
190f2a
+
190f2a
+if $verbose>1 then {
190f2a
+    send_user "Spawning $GDB -nw $GDBFLAGS $binfile -core=[standard_output_file corefile]\n"
190f2a
+}
190f2a
+
190f2a
+
190f2a
+eval "spawn $GDB -nw $GDBFLAGS $binfile -core=[standard_output_file corefile]";
190f2a
+expect {
190f2a
+    -re "Core was generated by .*coremaker.*\r\n\#0  .*\(\).*\r\n$gdb_prompt $" {
190f2a
+	pass "args: execfile -core=corefile"
190f2a
+    }
190f2a
+    -re "Core was generated by .*\r\n\#0  .*\(\).*\r\n$gdb_prompt $"	 {
190f2a
+	pass "args: execfile -core=corefile (with bad program name)"
190f2a
+    }
190f2a
+    -re ".*registers from core file: File in wrong format.* $" {
190f2a
+	fail "args: execfile -core=corefile (could not read registers from core file)"
190f2a
+    }
190f2a
+    -re ".*$gdb_prompt $"	{ fail "args: execfile -core=corefile" }
190f2a
+    timeout 		{ fail "(timeout) starting with -core" }
190f2a
+}
190f2a
+set timeout $oldtimeout
190f2a
+verbose "Timeout is now $timeout seconds" 2
190f2a
+
190f2a
+close;
190f2a
+
190f2a
+# Now restart normally.
190f2a
+
190f2a
+gdb_start
190f2a
+gdb_reinitialize_dir $srcdir/$subdir
190f2a
+gdb_load ${binfile}
190f2a
+
190f2a
+# Test basic corefile recognition via core-file command.
190f2a
+
190f2a
+send_gdb "core-file [standard_output_file corefile]\n"
190f2a
+gdb_expect {
190f2a
+    -re ".* program is being debugged already.*y or n. $" {
190f2a
+	# gdb_load may connect us to a gdbserver.
190f2a
+	send_gdb "y\n"
190f2a
+	exp_continue;
190f2a
+    }
190f2a
+    -re "Core was generated by .*coremaker.*\r\n\#0  .*\(\).*\r\n$gdb_prompt $" {
190f2a
+	pass "core-file command"
190f2a
+    }
190f2a
+    -re "Core was generated by .*\r\n\#0  .*\(\).*\r\n$gdb_prompt $" {
190f2a
+	pass "core-file command (with bad program name)"
190f2a
+    }
190f2a
+    -re ".*registers from core file: File in wrong format.* $" {
190f2a
+	fail "core-file command (could not read registers from core file)"
190f2a
+    }
190f2a
+    -re ".*$gdb_prompt $"	{ fail "core-file command" }
190f2a
+    timeout 		{ fail "(timeout) core-file command" }
190f2a
+}
190f2a
+
190f2a
+# Test correct mapping of corefile sections by printing some variables.
190f2a
+
190f2a
+gdb_test "print coremaker_data" "\\\$$decimal = 202"
190f2a
+gdb_test "print coremaker_bss" "\\\$$decimal = 10"
190f2a
+gdb_test "print coremaker_ro" "\\\$$decimal = 201"
190f2a
+
190f2a
+gdb_test "print func2::coremaker_local" "\\\$$decimal = \\{0, 1, 2, 3, 4\\}"
190f2a
+
190f2a
+# Somehow we better test the ability to read the registers out of the core
190f2a
+# file correctly.  I don't think the other tests do this.
190f2a
+
190f2a
+gdb_test "bt" "abort.*func2.*func1.*main.*" "backtrace in corefile.exp"
190f2a
+gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp"
190f2a
+
190f2a
+# Test ability to read mmap'd data
190f2a
+
190f2a
+gdb_test "x/8bd buf1" ".*:.*0.*1.*2.*3.*4.*5.*6.*7" "accessing original mmap data in core file"
190f2a
+setup_xfail "*-*-sunos*" "*-*-ultrix*" "*-*-aix*"
190f2a
+set test "accessing mmapped data in core file"
190f2a
+gdb_test_multiple "x/8bd buf2" "$test" {
190f2a
+    -re ".*:.*0.*1.*2.*3.*4.*5.*6.*7.*$gdb_prompt $" {
190f2a
+	pass "$test"
190f2a
+    }
190f2a
+    -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" {
190f2a
+	fail "$test (mapping failed at runtime)"
190f2a
+    }
190f2a
+    -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" {
190f2a
+	fail "$test (mapping address not found in core file)"
190f2a
+    }
190f2a
+}
190f2a
+
190f2a
+# test reinit_frame_cache
190f2a
+
190f2a
+gdb_load ${binfile}
190f2a
+gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp (reinit)"
190f2a
+
190f2a
+gdb_test "core" "No core file now."
190f2a
diff --git a/gdb/testsuite/gdb.pie/coremaker.c b/gdb/testsuite/gdb.pie/coremaker.c
190f2a
new file mode 100644
190f2a
--- /dev/null
190f2a
+++ b/gdb/testsuite/gdb.pie/coremaker.c
190f2a
@@ -0,0 +1,142 @@
190f2a
+/* Copyright 1992, 1993, 1994, 1995, 1996, 1999
190f2a
+   Free Software Foundation, Inc.
190f2a
+
190f2a
+   This file is part of GDB.
190f2a
+
190f2a
+   This program is free software; you can redistribute it and/or modify
190f2a
+   it under the terms of the GNU General Public License as published by
190f2a
+   the Free Software Foundation; either version 2 of the License, or (at
190f2a
+   your option) any later version.
190f2a
+
190f2a
+   This program is distributed in the hope that it will be useful, but
190f2a
+   WITHOUT ANY WARRANTY; without even the implied warranty of
190f2a
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
190f2a
+   General Public License for more details.
190f2a
+
190f2a
+   You should have received a copy of the GNU General Public License
190f2a
+   along with this program; if not, write to the Free Software
190f2a
+   Foundation, Inc., 59 Temple Place - Suite 330,
190f2a
+   Boston, MA 02111-1307, USA.  */
190f2a
+
190f2a
+/* Simple little program that just generates a core dump from inside some
190f2a
+   nested function calls. */
190f2a
+
190f2a
+#include <stdio.h>
190f2a
+#include <sys/types.h>
190f2a
+#include <fcntl.h>
190f2a
+#include <sys/mman.h>
190f2a
+#include <signal.h>
190f2a
+#include <stdlib.h>
190f2a
+#include <unistd.h>
190f2a
+
190f2a
+#ifndef __STDC__
190f2a
+#define	const	/**/
190f2a
+#endif
190f2a
+
190f2a
+#define MAPSIZE (8 * 1024)
190f2a
+
190f2a
+/* Don't make these automatic vars or we will have to walk back up the
190f2a
+   stack to access them. */
190f2a
+
190f2a
+char *buf1;
190f2a
+char *buf2;
190f2a
+
190f2a
+int coremaker_data = 1;	/* In Data section */
190f2a
+int coremaker_bss;	/* In BSS section */
190f2a
+
190f2a
+const int coremaker_ro = 201;	/* In Read-Only Data section */
190f2a
+
190f2a
+/* Note that if the mapping fails for any reason, we set buf2
190f2a
+   to -1 and the testsuite notices this and reports it as
190f2a
+   a failure due to a mapping error.  This way we don't have
190f2a
+   to test for specific errors when running the core maker. */
190f2a
+
190f2a
+void
190f2a
+mmapdata ()
190f2a
+{
190f2a
+  int j, fd;
190f2a
+
190f2a
+  /* Allocate and initialize a buffer that will be used to write
190f2a
+     the file that is later mapped in. */
190f2a
+
190f2a
+  buf1 = (char *) malloc (MAPSIZE);
190f2a
+  for (j = 0; j < MAPSIZE; ++j)
190f2a
+    {
190f2a
+      buf1[j] = j;
190f2a
+    }
190f2a
+
190f2a
+  /* Write the file to map in */
190f2a
+
190f2a
+  fd = open ("coremmap.data", O_CREAT | O_RDWR, 0666);
190f2a
+  if (fd == -1)
190f2a
+    {
190f2a
+      perror ("coremmap.data open failed");
190f2a
+      buf2 = (char *) -1;
190f2a
+      return;
190f2a
+    }
190f2a
+  write (fd, buf1, MAPSIZE);
190f2a
+
190f2a
+  /* Now map the file into our address space as buf2 */
190f2a
+
190f2a
+  buf2 = (char *) mmap (0, MAPSIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
190f2a
+  if (buf2 == (char *) -1)
190f2a
+    {
190f2a
+      perror ("mmap failed");
190f2a
+      return;
190f2a
+    }
190f2a
+
190f2a
+  /* Verify that the original data and the mapped data are identical.
190f2a
+     If not, we'd rather fail now than when trying to access the mapped
190f2a
+     data from the core file. */
190f2a
+
190f2a
+  for (j = 0; j < MAPSIZE; ++j)
190f2a
+    {
190f2a
+      if (buf1[j] != buf2[j])
190f2a
+	{
190f2a
+	  fprintf (stderr, "mapped data is incorrect");
190f2a
+	  buf2 = (char *) -1;
190f2a
+	  return;
190f2a
+	}
190f2a
+    }
190f2a
+}
190f2a
+
190f2a
+void
190f2a
+func2 ()
190f2a
+{
190f2a
+  int coremaker_local[5];
190f2a
+  int i;
190f2a
+
190f2a
+#ifdef SA_FULLDUMP
190f2a
+  /* Force a corefile that includes the data section for AIX.  */
190f2a
+  {
190f2a
+    struct sigaction sa;
190f2a
+
190f2a
+    sigaction (SIGABRT, (struct sigaction *)0, &sa);
190f2a
+    sa.sa_flags |= SA_FULLDUMP;
190f2a
+    sigaction (SIGABRT, &sa, (struct sigaction *)0);
190f2a
+  }
190f2a
+#endif
190f2a
+
190f2a
+  /* Make sure that coremaker_local doesn't get optimized away. */
190f2a
+  for (i = 0; i < 5; i++)
190f2a
+    coremaker_local[i] = i;
190f2a
+  coremaker_bss = 0;
190f2a
+  for (i = 0; i < 5; i++)
190f2a
+    coremaker_bss += coremaker_local[i];
190f2a
+  coremaker_data = coremaker_ro + 1;
190f2a
+  abort ();
190f2a
+}
190f2a
+
190f2a
+void
190f2a
+func1 ()
190f2a
+{
190f2a
+  func2 ();
190f2a
+}
190f2a
+
190f2a
+int main ()
190f2a
+{
190f2a
+  mmapdata ();
190f2a
+  func1 ();
190f2a
+  return 0;
190f2a
+}
190f2a
+