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