Blame SOURCES/gdb-6.3-test-pie-20050107.patch

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