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