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