]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-6.3-test-pie-20050107.patch
- update to gdb-7.0-7.fc12.src.rpm; but leave cactus patches as these seem newer
[packages/gdb.git] / gdb-6.3-test-pie-20050107.patch
CommitLineData
7566401a 1Index: gdb-6.8.50.20090909/gdb/testsuite/configure.ac
3a58abaf 2===================================================================
7566401a
ER
3--- gdb-6.8.50.20090909.orig/gdb/testsuite/configure.ac 2009-07-31 17:38:16.000000000 +0200
4+++ gdb-6.8.50.20090909/gdb/testsuite/configure.ac 2009-09-09 19:06:01.000000000 +0200
5@@ -144,6 +144,6 @@ AC_OUTPUT([Makefile \
3a58abaf
AM
6 gdb.cp/Makefile gdb.disasm/Makefile gdb.dwarf2/Makefile \
7 gdb.fortran/Makefile gdb.server/Makefile \
8 gdb.java/Makefile gdb.mi/Makefile gdb.modula2/Makefile \
9- gdb.objc/Makefile gdb.opt/Makefile gdb.pascal/Makefile \
10+ gdb.objc/Makefile gdb.opt/Makefile gdb.pascal/Makefile gdb.pie/Makefile \
7566401a 11 gdb.python/Makefile gdb.reverse/Makefile \
3a58abaf 12 gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile])
7566401a 13Index: gdb-6.8.50.20090909/gdb/testsuite/configure
3a58abaf 14===================================================================
7566401a
ER
15--- gdb-6.8.50.20090909.orig/gdb/testsuite/configure 2009-08-22 18:56:43.000000000 +0200
16+++ gdb-6.8.50.20090909/gdb/testsuite/configure 2009-09-09 19:06:27.000000000 +0200
17@@ -3515,7 +3515,7 @@ done
3a58abaf
AM
18
19
20
7566401a
ER
21-ac_config_files="$ac_config_files Makefile gdb.ada/Makefile gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile gdb.cp/Makefile gdb.disasm/Makefile gdb.dwarf2/Makefile gdb.fortran/Makefile gdb.server/Makefile gdb.java/Makefile gdb.mi/Makefile gdb.modula2/Makefile gdb.objc/Makefile gdb.opt/Makefile gdb.pascal/Makefile gdb.python/Makefile gdb.reverse/Makefile gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile"
22+ac_config_files="$ac_config_files Makefile gdb.ada/Makefile gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile gdb.cp/Makefile gdb.disasm/Makefile gdb.dwarf2/Makefile gdb.fortran/Makefile gdb.server/Makefile gdb.java/Makefile gdb.mi/Makefile gdb.modula2/Makefile gdb.objc/Makefile gdb.opt/Makefile gdb.pascal/Makefile gdb.pie/Makefile gdb.python/Makefile gdb.reverse/Makefile gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile"
23
3a58abaf
AM
24 cat >confcache <<\_ACEOF
25 # This file is a shell script that caches the results of configure
7566401a
ER
26@@ -4231,6 +4231,7 @@ do
27 "gdb.objc/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.objc/Makefile" ;;
28 "gdb.opt/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.opt/Makefile" ;;
29 "gdb.pascal/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.pascal/Makefile" ;;
30+ "gdb.pie/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.pie/Makefile" ;;
31 "gdb.python/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.python/Makefile" ;;
32 "gdb.reverse/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.reverse/Makefile" ;;
33 "gdb.threads/Makefile") CONFIG_FILES="$CONFIG_FILES gdb.threads/Makefile" ;;
34Index: gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/attach.c
3a58abaf
AM
35===================================================================
36--- /dev/null 1970-01-01 00:00:00.000000000 +0000
7566401a 37+++ gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/attach.c 2009-09-09 19:06:01.000000000 +0200
3a58abaf
AM
38@@ -0,0 +1,20 @@
39+/* This program is intended to be started outside of gdb, and then
40+ attached to by gdb. Thus, it simply spins in a loop. The loop
41+ is exited when & if the variable 'should_exit' is non-zero. (It
42+ is initialized to zero in this program, so the loop will never
43+ exit unless/until gdb sets the variable to non-zero.)
44+ */
45+#include <stdio.h>
46+
47+int should_exit = 0;
48+
49+int main ()
50+{
51+ int local_i = 0;
52+
53+ while (! should_exit)
54+ {
55+ local_i++;
56+ }
57+ return 0;
58+}
7566401a 59Index: gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/attach2.c
3a58abaf
AM
60===================================================================
61--- /dev/null 1970-01-01 00:00:00.000000000 +0000
7566401a 62+++ gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/attach2.c 2009-09-09 19:06:01.000000000 +0200
3a58abaf
AM
63@@ -0,0 +1,24 @@
64+/* This program is intended to be started outside of gdb, and then
65+ attached to by gdb. Thus, it simply spins in a loop. The loop
66+ is exited when & if the variable 'should_exit' is non-zero. (It
67+ is initialized to zero in this program, so the loop will never
68+ exit unless/until gdb sets the variable to non-zero.)
69+ */
70+#include <stdio.h>
71+#include <stdlib.h>
72+#include <unistd.h>
73+
74+int should_exit = 0;
75+
76+int main ()
77+{
78+ int local_i = 0;
79+
80+ sleep( 10 ); /* System call causes register fetch to fail */
81+ /* This is a known HPUX "feature" */
82+ while (! should_exit)
83+ {
84+ local_i++;
85+ }
86+ return (0);
87+}
7566401a 88Index: gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/break.c
3a58abaf
AM
89===================================================================
90--- /dev/null 1970-01-01 00:00:00.000000000 +0000
7566401a 91+++ gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/break.c 2009-09-09 19:06:01.000000000 +0200
3a58abaf
AM
92@@ -0,0 +1,146 @@
93+/* This testcase is part of GDB, the GNU debugger.
94+
95+ Copyright 1992, 1993, 1994, 1995, 1999, 2002, 2003 Free Software
96+ Foundation, Inc.
97+
98+ This program is free software; you can redistribute it and/or modify
99+ it under the terms of the GNU General Public License as published by
100+ the Free Software Foundation; either version 2 of the License, or
101+ (at your option) any later version.
102+
103+ This program is distributed in the hope that it will be useful,
104+ but WITHOUT ANY WARRANTY; without even the implied warranty of
105+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
106+ GNU General Public License for more details.
107+
108+ You should have received a copy of the GNU General Public License
109+ along with this program; if not, write to the Free Software
110+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
111+
112+ Please email any bugs, comments, and/or additions to this file to:
113+ bug-gdb@prep.ai.mit.edu */
114+
115+#ifdef vxworks
116+
117+# include <stdio.h>
118+
119+/* VxWorks does not supply atoi. */
120+static int
121+atoi (z)
122+ char *z;
123+{
124+ int i = 0;
125+
126+ while (*z >= '0' && *z <= '9')
127+ i = i * 10 + (*z++ - '0');
128+ return i;
129+}
130+
131+/* I don't know of any way to pass an array to VxWorks. This function
132+ can be called directly from gdb. */
133+
134+vxmain (arg)
135+char *arg;
136+{
137+ char *argv[2];
138+
139+ argv[0] = "";
140+ argv[1] = arg;
141+ main (2, argv, (char **) 0);
142+}
143+
144+#else /* ! vxworks */
145+# include <stdio.h>
146+# include <stdlib.h>
147+#endif /* ! vxworks */
148+
149+#ifdef PROTOTYPES
150+extern int marker1 (void);
151+extern int marker2 (int a);
152+extern void marker3 (char *a, char *b);
153+extern void marker4 (long d);
154+#else
155+extern int marker1 ();
156+extern int marker2 ();
157+extern void marker3 ();
158+extern void marker4 ();
159+#endif
160+
161+/*
162+ * This simple classical example of recursion is useful for
163+ * testing stack backtraces and such.
164+ */
165+
166+#ifdef PROTOTYPES
167+int factorial(int);
168+
169+int
170+main (int argc, char **argv, char **envp)
171+#else
172+int
173+main (argc, argv, envp)
174+int argc;
175+char *argv[], **envp;
176+#endif
177+{
178+#ifdef usestubs
179+ set_debug_traps(); /* set breakpoint 5 here */
180+ breakpoint();
181+#endif
182+ if (argc == 12345) { /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 here */
183+ fprintf (stderr, "usage: factorial <number>\n");
184+ return 1;
185+ }
186+ printf ("%d\n", factorial (atoi ("6"))); /* set breakpoint 1 here */
187+ /* set breakpoint 12 here */
188+ marker1 (); /* set breakpoint 11 here */
189+ marker2 (43); /* set breakpoint 20 here */
190+ marker3 ("stack", "trace"); /* set breakpoint 21 here */
191+ marker4 (177601976L);
192+ argc = (argc == 12345); /* This is silly, but we can step off of it */ /* set breakpoint 2 here */
193+ return argc; /* set breakpoint 10 here */
194+}
195+
196+#ifdef PROTOTYPES
197+int factorial (int value)
198+#else
199+int factorial (value)
200+int value;
201+#endif
202+{
203+ if (value > 1) { /* set breakpoint 7 here */
204+ value *= factorial (value - 1);
205+ }
206+ return (value); /* set breakpoint 19 here */
207+}
208+
209+#ifdef PROTOTYPES
210+int multi_line_if_conditional (int a, int b, int c)
211+#else
212+int multi_line_if_conditional (a, b, c)
213+ int a, b, c;
214+#endif
215+{
216+ if (a /* set breakpoint 3 here */
217+ && b
218+ && c)
219+ return 0;
220+ else
221+ return 1;
222+}
223+
224+#ifdef PROTOTYPES
225+int multi_line_while_conditional (int a, int b, int c)
226+#else
227+int multi_line_while_conditional (a, b, c)
228+ int a, b, c;
229+#endif
230+{
231+ while (a /* set breakpoint 4 here */
232+ && b
233+ && c)
234+ {
235+ a--, b--, c--;
236+ }
237+ return 0;
238+}
7566401a 239Index: gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/break1.c
3a58abaf
AM
240===================================================================
241--- /dev/null 1970-01-01 00:00:00.000000000 +0000
7566401a 242+++ gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/break1.c 2009-09-09 19:06:01.000000000 +0200
3a58abaf
AM
243@@ -0,0 +1,44 @@
244+/* This testcase is part of GDB, the GNU debugger.
245+
246+ Copyright 1992, 1993, 1994, 1995, 1999, 2002, 2003 Free Software
247+ Foundation, Inc.
248+
249+ This program is free software; you can redistribute it and/or modify
250+ it under the terms of the GNU General Public License as published by
251+ the Free Software Foundation; either version 2 of the License, or
252+ (at your option) any later version.
253+
254+ This program is distributed in the hope that it will be useful,
255+ but WITHOUT ANY WARRANTY; without even the implied warranty of
256+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
257+ GNU General Public License for more details.
258+
259+ You should have received a copy of the GNU General Public License
260+ along with this program; if not, write to the Free Software
261+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
262+
263+ Please email any bugs, comments, and/or additions to this file to:
264+ bug-gdb@prep.ai.mit.edu */
265+
266+/* The code for this file was extracted from the gdb testsuite
267+ testcase "break.c". */
268+
269+/* The following functions do nothing useful. They are included
270+ simply as places to try setting breakpoints at. They are
271+ explicitly "one-line functions" to verify that this case works
272+ (some versions of gcc have or have had problems with this).
273+
274+ These functions are in a separate source file to prevent an
275+ optimizing compiler from inlining them and optimizing them away. */
276+
277+#ifdef PROTOTYPES
278+int marker1 (void) { return (0); } /* set breakpoint 15 here */
279+int marker2 (int a) { return (1); } /* set breakpoint 8 here */
280+void marker3 (char *a, char *b) {} /* set breakpoint 17 here */
281+void marker4 (long d) {} /* set breakpoint 14 here */
282+#else
283+int marker1 () { return (0); } /* set breakpoint 16 here */
284+int marker2 (a) int a; { return (1); } /* set breakpoint 9 here */
285+void marker3 (a, b) char *a, *b; {} /* set breakpoint 18 here */
286+void marker4 (d) long d; {} /* set breakpoint 13 here */
287+#endif
7566401a 288Index: gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/coremaker.c
3a58abaf
AM
289===================================================================
290--- /dev/null 1970-01-01 00:00:00.000000000 +0000
7566401a 291+++ gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/coremaker.c 2009-09-09 19:06:01.000000000 +0200
3a58abaf
AM
292@@ -0,0 +1,142 @@
293+/* Copyright 1992, 1993, 1994, 1995, 1996, 1999
294+ Free Software Foundation, Inc.
295+
296+ This file is part of GDB.
297+
298+ This program is free software; you can redistribute it and/or modify
299+ it under the terms of the GNU General Public License as published by
300+ the Free Software Foundation; either version 2 of the License, or (at
301+ your option) any later version.
302+
303+ This program is distributed in the hope that it will be useful, but
304+ WITHOUT ANY WARRANTY; without even the implied warranty of
305+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
306+ General Public License for more details.
307+
308+ You should have received a copy of the GNU General Public License
309+ along with this program; if not, write to the Free Software
310+ Foundation, Inc., 59 Temple Place - Suite 330,
311+ Boston, MA 02111-1307, USA. */
312+
313+/* Simple little program that just generates a core dump from inside some
314+ nested function calls. */
315+
316+#include <stdio.h>
317+#include <sys/types.h>
318+#include <fcntl.h>
319+#include <sys/mman.h>
320+#include <signal.h>
321+#include <stdlib.h>
322+#include <unistd.h>
323+
324+#ifndef __STDC__
325+#define const /**/
326+#endif
327+
328+#define MAPSIZE (8 * 1024)
329+
330+/* Don't make these automatic vars or we will have to walk back up the
331+ stack to access them. */
332+
333+char *buf1;
334+char *buf2;
335+
336+int coremaker_data = 1; /* In Data section */
337+int coremaker_bss; /* In BSS section */
338+
339+const int coremaker_ro = 201; /* In Read-Only Data section */
340+
341+/* Note that if the mapping fails for any reason, we set buf2
342+ to -1 and the testsuite notices this and reports it as
343+ a failure due to a mapping error. This way we don't have
344+ to test for specific errors when running the core maker. */
345+
346+void
347+mmapdata ()
348+{
349+ int j, fd;
350+
351+ /* Allocate and initialize a buffer that will be used to write
352+ the file that is later mapped in. */
353+
354+ buf1 = (char *) malloc (MAPSIZE);
355+ for (j = 0; j < MAPSIZE; ++j)
356+ {
357+ buf1[j] = j;
358+ }
359+
360+ /* Write the file to map in */
361+
362+ fd = open ("coremmap.data", O_CREAT | O_RDWR, 0666);
363+ if (fd == -1)
364+ {
365+ perror ("coremmap.data open failed");
366+ buf2 = (char *) -1;
367+ return;
368+ }
369+ write (fd, buf1, MAPSIZE);
370+
371+ /* Now map the file into our address space as buf2 */
372+
373+ buf2 = (char *) mmap (0, MAPSIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
374+ if (buf2 == (char *) -1)
375+ {
376+ perror ("mmap failed");
377+ return;
378+ }
379+
380+ /* Verify that the original data and the mapped data are identical.
381+ If not, we'd rather fail now than when trying to access the mapped
382+ data from the core file. */
383+
384+ for (j = 0; j < MAPSIZE; ++j)
385+ {
386+ if (buf1[j] != buf2[j])
387+ {
388+ fprintf (stderr, "mapped data is incorrect");
389+ buf2 = (char *) -1;
390+ return;
391+ }
392+ }
393+}
394+
395+void
396+func2 ()
397+{
398+ int coremaker_local[5];
399+ int i;
400+
401+#ifdef SA_FULLDUMP
402+ /* Force a corefile that includes the data section for AIX. */
403+ {
404+ struct sigaction sa;
405+
406+ sigaction (SIGABRT, (struct sigaction *)0, &sa);
407+ sa.sa_flags |= SA_FULLDUMP;
408+ sigaction (SIGABRT, &sa, (struct sigaction *)0);
409+ }
410+#endif
411+
412+ /* Make sure that coremaker_local doesn't get optimized away. */
413+ for (i = 0; i < 5; i++)
414+ coremaker_local[i] = i;
415+ coremaker_bss = 0;
416+ for (i = 0; i < 5; i++)
417+ coremaker_bss += coremaker_local[i];
418+ coremaker_data = coremaker_ro + 1;
419+ abort ();
420+}
421+
422+void
423+func1 ()
424+{
425+ func2 ();
426+}
427+
428+int main ()
429+{
430+ mmapdata ();
431+ func1 ();
432+ return 0;
433+}
434+
7566401a 435Index: gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/attach.exp
3a58abaf
AM
436===================================================================
437--- /dev/null 1970-01-01 00:00:00.000000000 +0000
7566401a 438+++ gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/attach.exp 2009-09-09 19:06:01.000000000 +0200
ab050a48 439@@ -0,0 +1,433 @@
3a58abaf
AM
440+# Copyright 1997, 1999, 2002 Free Software Foundation, Inc.
441+
442+# This program is free software; you can redistribute it and/or modify
443+# it under the terms of the GNU General Public License as published by
444+# the Free Software Foundation; either version 2 of the License, or
445+# (at your option) any later version.
446+#
447+# This program is distributed in the hope that it will be useful,
448+# but WITHOUT ANY WARRANTY; without even the implied warranty of
449+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
450+# GNU General Public License for more details.
451+#
452+# You should have received a copy of the GNU General Public License
453+# along with this program; if not, write to the Free Software
454+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
455+
456+# Please email any bugs, comments, and/or additions to this file to:
457+# bug-gdb@prep.ai.mit.edu
458+
459+if $tracelevel then {
460+ strace $tracelevel
461+ }
462+
463+set prms_id 0
464+set bug_id 0
465+
466+# On HP-UX 11.0, this test is causing a process running the program
467+# "attach" to be left around spinning. Until we figure out why, I am
468+# commenting out the test to avoid polluting tiamat (our 11.0 nightly
469+# test machine) with these processes. RT
470+#
471+# Setting the magic bit in the target app should work. I added a
472+# "kill", and also a test for the R3 register warning. JB
473+if { [istarget "hppa*-*-hpux*"] } {
474+ return 0
475+}
476+
477+# are we on a target board
478+if [is_remote target] then {
479+ return 0
480+}
481+
482+set testfile "attach"
483+set srcfile ${testfile}.c
484+set srcfile2 ${testfile}2.c
485+set binfile ${objdir}/${subdir}/${testfile}
486+set binfile2 ${objdir}/${subdir}/${testfile}2
487+set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
488+set cleanupfile ${objdir}/${subdir}/${testfile}.awk
489+
490+#execute_anywhere "rm -f ${binfile} ${binfile2}"
491+remote_exec build "rm -f ${binfile} ${binfile2}"
492+# For debugging this test
493+#
494+#log_user 1
495+
496+# Clean out any old files from past runs.
497+#
498+remote_exec build "${cleanupfile}"
499+
500+# build the first test case
501+#
502+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug "additional_flags= -fpie -pie"}] != "" } {
503+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
504+}
505+
506+# Build the in-system-call test
507+
508+if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug "additional_flags= -fpie -pie"}] != "" } {
509+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
510+}
511+
512+if [get_compiler_info ${binfile}] {
513+ return -1
514+}
515+
516+proc do_attach_tests {} {
517+ global gdb_prompt
518+ global binfile
519+ global escapedbinfile
520+ global srcfile
521+ global testfile
522+ global objdir
523+ global subdir
524+ global timeout
525+
526+ # Start the program running and then wait for a bit, to be sure
527+ # that it can be attached to.
528+ #
529+ set testpid [eval exec $binfile &]
530+ exec sleep 2
531+
532+ # Verify that we cannot attach to nonsense.
533+ #
534+ send_gdb "attach abc\n"
535+ gdb_expect {
536+ -re ".*Illegal process-id: abc.*$gdb_prompt $"\
537+ {pass "attach to nonsense is prohibited"}
538+ -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
539+ {
540+ # Response expected from /proc-based systems.
541+ pass "attach to nonsense is prohibited"
542+ }
543+ -re "Attaching to.*$gdb_prompt $"\
544+ {fail "attach to nonsense is prohibited (bogus pid allowed)"}
545+ -re "$gdb_prompt $" {fail "attach to nonsense is prohibited"}
546+ timeout {fail "(timeout) attach to nonsense is prohibited"}
547+ }
548+
549+ # Verify that we cannot attach to what appears to be a valid
550+ # process ID, but is a process that doesn't exist. Traditionally,
551+ # most systems didn't have a process with ID 0, so we take that as
552+ # the default. However, there are a few exceptions.
553+ #
554+ set boguspid 0
555+ if { [istarget "*-*-*bsd*"] } {
556+ # In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead
557+ # (which should have the desired effect on any version of
558+ # FreeBSD, and probably other *BSD's too).
559+ set boguspid -1
560+ }
561+ send_gdb "attach $boguspid\n"
562+ gdb_expect {
563+ -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $"\
564+ {
565+ # Response expected on ptrace-based systems (i.e. HP-UX 10.20).
566+ pass "attach to nonexistent process is prohibited"
567+ }
568+ -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $"\
569+ {
570+ # Response expected on ttrace-based systems (i.e. HP-UX 11.0).
571+ pass "attach to nonexistent process is prohibited"
572+ }
573+ -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $"\
574+ {pass "attach to nonexistent process is prohibited"}
575+ -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $"\
576+ {pass "attach to nonexistent process is prohibited"}
577+ -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
578+ {
579+ # Response expected from /proc-based systems.
580+ pass "attach to nonexistent process is prohibited"
581+ }
582+ -re "$gdb_prompt $" {fail "attach to nonexistent process is prohibited"}
583+ timeout {
584+ fail "(timeout) attach to nonexistent process is prohibited"
585+ }
586+ }
587+
588+ # Verify that we can attach to the process by first giving its
589+ # executable name via the file command, and using attach with
590+ # the process ID.
591+ #
592+ # (Actually, the test system appears to do this automatically
593+ # for us. So, we must also be prepared to be asked if we want
594+ # to discard an existing set of symbols.)
595+ #
596+ send_gdb "file $binfile\n"
597+ gdb_expect {
598+ -re "Load new symbol table from.*y or n.*$" {
599+ send_gdb "y\n"
600+ gdb_expect {
601+ -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
602+ {pass "(re)set file, before attach1"}
603+ -re "$gdb_prompt $" {fail "(re)set file, before attach1"}
604+ timeout {fail "(timeout) (re)set file, before attach1"}
605+ }
606+ }
607+ -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
608+ {pass "set file, before attach1"}
609+ -re "$gdb_prompt $" {fail "set file, before attach1"}
610+ timeout {fail "(timeout) set file, before attach1"}
611+ }
612+
613+ send_gdb "attach $testpid\n"
614+ gdb_expect {
615+ -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $"\
616+ {pass "attach1, after setting file"}
617+ -re "$gdb_prompt $" {fail "attach1, after setting file"}
618+ timeout {fail "(timeout) attach1, after setting file"}
619+ }
620+
621+ # Verify that we can "see" the variable "should_exit" in the
622+ # program, and that it is zero.
623+ #
624+ send_gdb "print should_exit\n"
625+ gdb_expect {
626+ -re ".* = 0.*$gdb_prompt $"\
627+ {pass "after attach1, print should_exit"}
628+ -re "$gdb_prompt $" {fail "after attach1, print should_exit"}
629+ timeout {fail "(timeout) after attach1, print should_exit"}
630+ }
631+
632+ # Detach the process.
633+ #
634+ send_gdb "detach\n"
635+ gdb_expect {
636+ -re "Detaching from program: .*$escapedbinfile.*$gdb_prompt $"\
637+ {pass "attach1 detach"}
638+ -re "$gdb_prompt $" {fail "attach1 detach"}
639+ timeout {fail "(timeout) attach1 detach"}
640+ }
641+
642+ # Wait a bit for gdb to finish detaching
643+ #
644+ exec sleep 5
645+
646+ # Purge the symbols from gdb's brain. (We want to be certain
647+ # the next attach, which won't be preceded by a "file" command,
648+ # is really getting the executable file without our help.)
649+ #
650+ set old_timeout $timeout
651+ set timeout 15
652+ send_gdb "file\n"
653+ gdb_expect {
654+ -re ".*gdb internal error.*$" {
655+ fail "Internal error, prob. Memory corruption"
656+ }
657+ -re "No executable file now.*Discard symbol table.*y or n.*$" {
658+ send_gdb "y\n"
659+ gdb_expect {
660+ -re "No symbol file now.*$gdb_prompt $"\
661+ {pass "attach1, purging symbols after detach"}
662+ -re "$gdb_prompt $" {fail "attach1, purging symbols after detach"}
663+ timeout {fail "(timeout) attach1, purging symbols after detach"}
664+ }
665+ }
666+ -re "$gdb_prompt $" {fail "attach1, purging file after detach"}
667+ timeout {
668+ fail "(timeout) attach1, purging file after detach"
669+ }
670+ }
671+ set timeout $old_timeout
672+
673+ # Verify that we can attach to the process just by giving the
674+ # process ID.
675+ #
676+ send_gdb "attach $testpid\n"
677+ gdb_expect {
678+ -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\
679+ {pass "attach2"}
680+ -re "$gdb_prompt $" {fail "attach2"}
681+ timeout {fail "(timeout) attach2"}
682+ }
683+
684+ # Verify that we can modify the variable "should_exit" in the
685+ # program.
686+ #
687+ send_gdb "set should_exit=1\n"
688+ gdb_expect {
689+ -re "$gdb_prompt $" {pass "after attach2, set should_exit"}
690+ timeout {fail "(timeout) after attach2, set should_exit"}
691+ }
692+
693+ # Verify that the modification really happened.
694+ #
695+ send_gdb "tbreak 19\n"
696+ gdb_expect {
697+ -re "reakpoint .*at.*$srcfile, line 19.*$gdb_prompt $"\
698+ {pass "after attach2, set tbreak postloop"}
699+ -re "$gdb_prompt $" {fail "after attach2, set tbreak postloop"}
700+ timeout {fail "(timeout) after attach2, set tbreak postloop"}
701+ }
702+ send_gdb "continue\n"
703+ gdb_expect {
704+ -re "main.*at.*$srcfile:19.*$gdb_prompt $"\
705+ {pass "after attach2, reach tbreak postloop"}
706+ -re "$gdb_prompt $" {fail "after attach2, reach tbreak postloop"}
707+ timeout {fail "(timeout) after attach2, reach tbreak postloop"}
708+ }
709+
710+ # Allow the test process to exit, to cleanup after ourselves.
711+ #
712+ send_gdb "continue\n"
713+ gdb_expect {
714+ -re "Program exited normally.*$gdb_prompt $"\
715+ {pass "after attach2, exit"}
716+ -re "$gdb_prompt $" {fail "after attach2, exit"}
717+ timeout {fail "(timeout) after attach2, exit"}
718+ }
719+
720+ # Make sure we don't leave a process around to confuse
721+ # the next test run (and prevent the compile by keeping
722+ # the text file busy), in case the "set should_exit" didn't
723+ # work.
724+ #
725+ remote_exec build "kill -9 ${testpid}"
726+ # Start the program running and then wait for a bit, to be sure
727+ # that it can be attached to.
728+ #
729+ set testpid [eval exec $binfile &]
730+ exec sleep 2
731+
732+ # Verify that we can attach to the process, and find its a.out
733+ # when we're cd'd to some directory that doesn't contain the
734+ # a.out. (We use the source path set by the "dir" command.)
735+ #
736+ send_gdb "dir ${objdir}/${subdir}\n"
737+ gdb_expect {
738+ -re ".*Source directories searched: .*$gdb_prompt $"\
739+ {pass "set source path"}
740+ -re "$gdb_prompt $" {fail "set source path"}
741+ timeout {fail "(timeout) set source path"}
742+ }
743+
744+ send_gdb "cd /tmp\n"
745+ gdb_expect {
746+ -re ".*Working directory /tmp.*$gdb_prompt $"\
747+ {pass "cd away from process' a.out"}
748+ -re "$gdb_prompt $" {fail "cd away from process' a.out"}
749+ timeout {fail "(timeout) cd away from process' a.out"}
750+ }
751+
752+ # Explicitly flush out any knowledge of the previous attachment.
753+ send_gdb "symbol\n"
754+ gdb_expect {
755+ -re ".*Discard symbol table from.*y or n. $"\
756+ {send_gdb "y\n"
757+ gdb_expect {
758+ -re ".*No symbol file now.*$gdb_prompt $"\
759+ {pass "before attach3, flush symbols"}
760+ -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
761+ timeout {fail "(timeout) before attach3, flush symbols"}
762+ }
763+ }
764+ -re ".*No symbol file now.*$gdb_prompt $"\
765+ {pass "before attach3, flush symbols"}
766+ -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
767+ timeout {fail "(timeout) before attach3, flush symbols"}
768+ }
769+ send_gdb "exec\n"
770+ gdb_expect {
771+ -re ".*No executable file now.*$gdb_prompt $"\
772+ {pass "before attach3, flush exec"}
773+ -re "$gdb_prompt $" {fail "before attach3, flush exec"}
774+ timeout {fail "(timeout) before attach3, flush exec"}
775+ }
776+
777+ send_gdb "attach $testpid\n"
778+ gdb_expect {
779+ -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\
780+ {pass "attach when process' a.out not in cwd"}
781+ -re "$gdb_prompt $" {fail "attach when process' a.out not in cwd"}
782+ timeout {fail "(timeout) attach when process' a.out not in cwd"}
783+ }
784+
785+ send_gdb "kill\n"
786+ gdb_expect {
787+ -re ".*Kill the program being debugged.*y or n. $"\
788+ {send_gdb "y\n"
789+ gdb_expect {
790+ -re "$gdb_prompt $" {pass "after attach3, exit"}
791+ timeout {fail "(timeout) after attach3, exit"}
792+ }
793+ }
794+ -re "$gdb_prompt $" {fail "after attach3, exit"}
795+ timeout {fail "(timeout) after attach3, exit"}
796+ }
797+
798+ # Another "don't leave a process around"
799+ remote_exec build "kill -9 ${testpid}"
800+}
801+
802+proc do_call_attach_tests {} {
803+ global gdb_prompt
804+ global binfile2
805+
806+ # Start the program running and then wait for a bit, to be sure
807+ # that it can be attached to.
808+ #
809+ set testpid [eval exec $binfile2 &]
810+ exec sleep 2
811+
812+ # Attach
813+ #
814+ gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
815+ send_gdb "attach $testpid\n"
816+ gdb_expect {
817+ -re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
818+ fail "attach call, read register 3 error"
819+ }
ab050a48
BZ
820+ -re "Attaching to.*process $testpid.*$gdb_prompt $" {
821+ # libc is relocated, not relocated, therefore not printed.
3a58abaf
AM
822+ pass "attach call"
823+ }
824+ -re "$gdb_prompt $" {fail "attach call"}
825+ timeout {fail "(timeout) attach call"}
826+ }
827+
828+ # See if other registers are problems
829+ #
830+ send_gdb "i r r3\n"
831+ gdb_expect {
832+ -re ".*warning: reading register.*$gdb_prompt $" {
833+ pass "CHFts23490: known bug"
834+ }
835+ -re ".*r3.*$gdb_prompt $" {
836+ pass "Bug fixed, Yayyy!"
837+ }
838+ timeout { fail "timeout on info reg" }
839+ }
840+
841+ # Get rid of the process
842+ #
843+ gdb_test "p should_exit = 1" ".*"
844+ gdb_test "c" ".*Program exited normally.*"
845+
846+ # Be paranoid
847+ #
848+ remote_exec build "kill -9 ${testpid}"
849+
850+}
851+
852+
853+# Start with a fresh gdb
854+#
855+gdb_exit
856+gdb_start
857+gdb_reinitialize_dir $srcdir/$subdir
858+gdb_load ${binfile}
859+
860+# This is a test of gdb's ability to attach to a running process.
861+#
862+do_attach_tests
863+
864+# Test attaching when the target is inside a system call
865+#
866+gdb_exit
867+gdb_start
868+
869+gdb_reinitialize_dir $srcdir/$subdir
870+do_call_attach_tests
871+
872+return 0
7566401a 873Index: gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/break.exp
3a58abaf
AM
874===================================================================
875--- /dev/null 1970-01-01 00:00:00.000000000 +0000
7566401a
ER
876+++ gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/break.exp 2009-09-09 19:06:01.000000000 +0200
877@@ -0,0 +1,977 @@
3a58abaf
AM
878+# Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
879+# 2000, 2002, 2003, 2004
880+# Free Software Foundation, Inc.
881+
882+# This program is free software; you can redistribute it and/or modify
883+# it under the terms of the GNU General Public License as published by
884+# the Free Software Foundation; either version 2 of the License, or
885+# (at your option) any later version.
886+#
887+# This program is distributed in the hope that it will be useful,
888+# but WITHOUT ANY WARRANTY; without even the implied warranty of
889+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
890+# GNU General Public License for more details.
891+#
892+# You should have received a copy of the GNU General Public License
893+# along with this program; if not, write to the Free Software
894+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
895+
896+# Please email any bugs, comments, and/or additions to this file to:
897+# bug-gdb@prep.ai.mit.edu
898+
899+# This file was written by Rob Savoye. (rob@cygnus.com)
900+
901+# Test the same stuff but with PIE executables
902+
903+if $tracelevel then {
904+ strace $tracelevel
905+}
906+
907+
908+#
909+# test running programs
910+#
911+set prms_id 0
912+set bug_id 0
913+
914+set testfile "break"
915+set srcfile ${testfile}.c
916+set srcfile1 ${testfile}1.c
917+set binfile ${objdir}/${subdir}/${testfile}
918+
919+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug "additional_flags=-w -fpie -pie"}] != "" } {
920+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
921+}
922+
923+if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug "additional_flags=-w -fpie -pie"}] != "" } {
924+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
925+}
926+
927+if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug "additional_flags=-w -fpie -pie"}] != "" } {
928+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
929+}
930+
931+if [get_compiler_info ${binfile}] {
932+ return -1
933+}
934+
935+gdb_exit
936+gdb_start
937+gdb_reinitialize_dir $srcdir/$subdir
938+gdb_load ${binfile}
939+
940+if [target_info exists gdb_stub] {
941+ gdb_step_for_stub;
942+}
943+#
944+# test simple breakpoint setting commands
945+#
946+
947+# Test deleting all breakpoints when there are none installed,
948+# GDB should not prompt for confirmation.
949+# Note that gdb-init.exp provides a "delete_breakpoints" proc
950+# for general use elsewhere.
951+
952+send_gdb "delete breakpoints\n"
953+gdb_expect {
954+ -re "Delete all breakpoints.*$" {
955+ send_gdb "y\n"
956+ gdb_expect {
957+ -re "$gdb_prompt $" {
958+ fail "Delete all breakpoints when none (unexpected prompt)"
959+ }
960+ timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
961+ }
962+ }
963+ -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
964+ timeout { fail "Delete all breakpoints when none (timeout)" }
965+}
966+
967+#
968+# test break at function
969+#
970+gdb_test "break main" \
971+ "Breakpoint.*at.* file .*$srcfile, line.*" \
972+ "breakpoint function"
973+
974+#
975+# test break at quoted function
976+#
977+gdb_test "break \"marker2\"" \
978+ "Breakpoint.*at.* file .*$srcfile1, line.*" \
979+ "breakpoint quoted function"
980+
981+#
982+# test break at function in file
983+#
984+gdb_test "break $srcfile:factorial" \
985+ "Breakpoint.*at.* file .*$srcfile, line.*" \
986+ "breakpoint function in file"
987+
988+set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
989+
990+#
991+# test break at line number
992+#
993+# Note that the default source file is the last one whose source text
994+# was printed. For native debugging, before we've executed the
995+# program, this is the file containing main, but for remote debugging,
996+# it's wherever the processor was stopped when we connected to the
997+# board. So, to be sure, we do a list command.
998+#
999+gdb_test "list main" \
1000+ ".*main \\(argc, argv, envp\\).*" \
1001+ "use `list' to establish default source file"
1002+gdb_test "break $bp_location1" \
1003+ "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
1004+ "breakpoint line number"
1005+
1006+#
1007+# test duplicate breakpoint
1008+#
1009+gdb_test "break $bp_location1" \
1010+ "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
1011+ "breakpoint duplicate"
1012+
1013+set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
1014+
1015+#
1016+# test break at line number in file
1017+#
1018+gdb_test "break $srcfile:$bp_location2" \
1019+ "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
1020+ "breakpoint line number in file"
1021+
1022+set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
1023+set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
1024+
1025+#
1026+# Test putting a break at the start of a multi-line if conditional.
1027+# Verify the breakpoint was put at the start of the conditional.
1028+#
1029+gdb_test "break multi_line_if_conditional" \
1030+ "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
1031+ "breakpoint at start of multi line if conditional"
1032+
1033+gdb_test "break multi_line_while_conditional" \
1034+ "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
1035+ "breakpoint at start of multi line while conditional"
1036+
1037+set bp_location5 [gdb_get_line_number "set breakpoint 5 here"]
1038+set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
1039+
1040+#
1041+# check to see what breakpoints are set
1042+#
1043+if [target_info exists gdb_stub] {
1044+ set main_line $bp_location5
1045+} else {
1046+ set main_line $bp_location6
1047+}
1048+
1049+if {$hp_aCC_compiler} {
1050+ set proto "\\(int\\)"
1051+} else {
1052+ set proto ""
1053+}
1054+
1055+set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
1056+set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
1057+set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
1058+
7566401a
ER
1059+# Test a pending breakpoint in PIE executable does not crash later GDB.
1060+gdb_breakpoint "non_existent_function" allow-pending
1061+
3a58abaf
AM
1062+gdb_test "info break" \
1063+ "Num\[ \]+Type\[ \]+Disp Enb Address\[ \]+What.*
1064+\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
1065+\[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile1:($bp_location8|$bp_location9).*
1066+\[0-9\]+\[\t \]+breakpoint keep y.* in factorial$proto at .*$srcfile:$bp_location7.*
1067+\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
1068+\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
1069+\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location2.*
1070+\[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_if_conditional at .*$srcfile:$bp_location3.*
7566401a
ER
1071+\[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4.*
1072+\[0-9\]+\[\t \]+breakpoint keep y.* <PENDING> *non_existent_function" \
3a58abaf
AM
1073+ "breakpoint info"
1074+
1075+# FIXME: The rest of this test doesn't work with anything that can't
1076+# handle arguments.
1077+# Huh? There doesn't *appear* to be anything that passes arguments
1078+# below.
1079+if [istarget "mips-idt-*"] then {
1080+ return
1081+}
1082+
1083+#
1084+# run until the breakpoint at main is hit. For non-stubs-using targets.
1085+#
1086+if ![target_info exists use_gdb_stub] {
1087+ if [istarget "*-*-vxworks*"] then {
1088+ send_gdb "run vxmain \"2\"\n"
1089+ set timeout 120
1090+ verbose "Timeout is now $timeout seconds" 2
1091+ } else {
1092+ send_gdb "run\n"
1093+ }
1094+ gdb_expect {
1095+ -re "The program .* has been started already.*y or n. $" {
1096+ send_gdb "y\n"
1097+ exp_continue
1098+ }
1099+ -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
1100+ { pass "run until function breakpoint" }
1101+ -re ".*$gdb_prompt $" { fail "run until function breakpoint" }
1102+ timeout { fail "run until function breakpoint (timeout)" }
1103+ }
1104+} else {
1105+ if ![target_info exists gdb_stub] {
1106+ gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue"
1107+ }
1108+}
1109+
1110+#
1111+# run until the breakpoint at a line number
1112+#
1113+gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
1114+ "run until breakpoint set at a line number"
1115+
1116+#
1117+# Run until the breakpoint set in a function in a file
1118+#
1119+for {set i 6} {$i >= 1} {incr i -1} {
1120+ gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
1121+ "run until file:function($i) breakpoint"
1122+}
1123+
1124+#
1125+# Run until the breakpoint set at a quoted function
1126+#
1127+gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*" \
1128+ "run until quoted breakpoint"
1129+#
1130+# run until the file:function breakpoint at a line number in a file
1131+#
1132+gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
1133+ "run until file:linenum breakpoint"
1134+
1135+# Test break at offset +1
1136+set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
1137+
1138+gdb_test "break +1" \
1139+ "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
1140+ "breakpoint offset +1"
1141+
1142+# Check to see if breakpoint is hit when stepped onto
1143+
1144+gdb_test "step" \
1145+ ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
1146+ "step onto breakpoint"
1147+
1148+#
1149+# delete all breakpoints so we can start over, course this can be a test too
1150+#
1151+delete_breakpoints
1152+
1153+#
1154+# test temporary breakpoint at function
1155+#
1156+
1157+gdb_test "tbreak main" "reakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
1158+
1159+#
1160+# test break at function in file
1161+#
1162+
1163+gdb_test "tbreak $srcfile:factorial" "reakpoint.*at.* file .*$srcfile, line.*" \
1164+ "Temporary breakpoint function in file"
1165+
1166+#
1167+# test break at line number
1168+#
1169+send_gdb "tbreak $bp_location1\n"
1170+gdb_expect {
1171+ -re "reakpoint.*at.* file .*$srcfile, line $bp_location1.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
1172+ -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
1173+ timeout { fail "breakpoint line number #1 (timeout)" }
1174+}
1175+
1176+gdb_test "tbreak $bp_location6" "reakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2"
1177+
1178+#
1179+# test break at line number in file
1180+#
1181+send_gdb "tbreak $srcfile:$bp_location2\n"
1182+gdb_expect {
1183+ -re "reakpoint.*at.* file .*$srcfile, line $bp_location2.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
1184+ -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
1185+ timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
1186+}
1187+
1188+set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
1189+gdb_test "tbreak $srcfile:$bp_location11" "reakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
1190+
1191+#
1192+# check to see what breakpoints are set (temporary this time)
1193+#
1194+gdb_test "info break" "Num.*Type.*Disp Enb Address.*What.*\[\r\n\]
1195+\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
1196+\[0-9\]+\[\t \]+breakpoint del.*y.*in factorial$proto at .*$srcfile:$bp_location7.*\[\r\n\]
1197+\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
1198+\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
1199+\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
1200+\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \
1201+ "Temporary breakpoint info"
1202+
1203+
1204+#***********
1205+
1206+# Verify that catchpoints for fork, vfork and exec don't trigger
1207+# inappropriately. (There are no calls to those system functions
1208+# in this test program.)
1209+#
1210+if ![runto_main] then { fail "break tests suppressed" }
1211+
1212+send_gdb "catch\n"
1213+gdb_expect {
1214+ -re "Catch requires an event name.*$gdb_prompt $"\
1215+ {pass "catch requires an event name"}
1216+ -re "$gdb_prompt $"\
1217+ {fail "catch requires an event name"}
1218+ timeout {fail "(timeout) catch requires an event name"}
1219+}
1220+
1221+
1222+set name "set catch fork, never expected to trigger"
1223+send_gdb "catch fork\n"
1224+gdb_expect {
1225+ -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
1226+ {pass $name}
1227+ -re "Catch of fork not yet implemented.*$gdb_prompt $"
1228+ {pass $name}
1229+ -re "$gdb_prompt $"
1230+ {fail $name}
1231+ timeout {fail "(timeout) $name"}
1232+}
1233+
1234+
1235+set name "set catch vfork, never expected to trigger"
1236+send_gdb "catch vfork\n"
1237+
1238+# If we are on HP-UX 10.20, we expect an error message to be
1239+# printed if we type "catch vfork" at the gdb gdb_prompt. This is
1240+# because on HP-UX 10.20, we cannot catch vfork events.
1241+
1242+if [istarget "hppa*-hp-hpux10.20"] then {
1243+ gdb_expect {
1244+ -re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
1245+ {pass $name}
1246+ -re "$gdb_prompt $"
1247+ {fail $name}
1248+ timeout {fail "(timeout) $name"}
1249+ }
1250+} else {
1251+ gdb_expect {
1252+ -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
1253+ {pass $name}
1254+ -re "Catch of vfork not yet implemented.*$gdb_prompt $"
1255+ {pass $name}
1256+ -re "$gdb_prompt $"
1257+ {fail $name}
1258+ timeout {fail "(timeout) $name"}
1259+ }
1260+}
1261+
1262+set name "set catch exec, never expected to trigger"
1263+send_gdb "catch exec\n"
1264+gdb_expect {
1265+ -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
1266+ {pass $name}
1267+ -re "Catch of exec not yet implemented.*$gdb_prompt $"
1268+ {pass $name}
1269+ -re "$gdb_prompt $" {fail $name}
1270+ timeout {fail "(timeout) $name"}
1271+}
1272+
1273+# Verify that GDB responds gracefully when asked to set a breakpoint
1274+# on a nonexistent source line.
1275+#
1276+send_gdb "break 999\n"
1277+gdb_expect {
1278+ -re "No line 999 in file .*$gdb_prompt $"\
1279+ {pass "break on non-existent source line"}
1280+ -re "$gdb_prompt $"\
1281+ {fail "break on non-existent source line"}
1282+ timeout {fail "(timeout) break on non-existent source line"}
1283+}
1284+
1285+# Run to the desired default location. If not positioned here, the
1286+# tests below don't work.
1287+#
1288+gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" "until bp_location1"
1289+
1290+
1291+# Verify that GDB allows one to just say "break", which is treated
1292+# as the "default" breakpoint. Note that GDB gets cute when printing
1293+# the informational message about other breakpoints at the same
1294+# location. We'll hit that bird with this stone too.
1295+#
1296+send_gdb "break\n"
1297+gdb_expect {
1298+ -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
1299+ {pass "break on default location, 1st time"}
1300+ -re "$gdb_prompt $"\
1301+ {fail "break on default location, 1st time"}
1302+ timeout {fail "(timeout) break on default location, 1st time"}
1303+}
1304+
1305+send_gdb "break\n"
1306+gdb_expect {
1307+ -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
1308+ {pass "break on default location, 2nd time"}
1309+ -re "$gdb_prompt $"\
1310+ {fail "break on default location, 2nd time"}
1311+ timeout {fail "(timeout) break on default location, 2nd time"}
1312+}
1313+
1314+send_gdb "break\n"
1315+gdb_expect {
1316+ -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
1317+ {pass "break on default location, 3rd time"}
1318+ -re "$gdb_prompt $"\
1319+ {fail "break on default location, 3rd time"}
1320+ timeout {fail "(timeout) break on default location, 3rd time"}
1321+}
1322+
1323+send_gdb "break\n"
1324+gdb_expect {
1325+ -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
1326+ {pass "break on default location, 4th time"}
1327+ -re "$gdb_prompt $"\
1328+ {fail "break on default location, 4th time"}
1329+ timeout {fail "(timeout) break on default location, 4th time"}
1330+}
1331+
1332+# Verify that a "silent" breakpoint can be set, and that GDB is indeed
1333+# "silent" about its triggering.
1334+#
1335+if ![runto_main] then { fail "break tests suppressed" }
1336+
1337+send_gdb "break $bp_location1\n"
1338+gdb_expect {
1339+ -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $"\
1340+ {pass "set to-be-silent break bp_location1"}
1341+ -re "$gdb_prompt $"\
1342+ {fail "set to-be-silent break bp_location1"}
1343+ timeout {fail "(timeout) set to-be-silent break bp_location1"}
1344+}
1345+
1346+send_gdb "commands $expect_out(1,string)\n"
1347+send_gdb "silent\n"
1348+send_gdb "end\n"
1349+gdb_expect {
1350+ -re ".*$gdb_prompt $"\
1351+ {pass "set silent break bp_location1"}
1352+ timeout {fail "(timeout) set silent break bp_location1"}
1353+}
1354+
1355+send_gdb "info break $expect_out(1,string)\n"
1356+gdb_expect {
1357+ -re "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*$gdb_prompt $"\
1358+ {pass "info silent break bp_location1"}
1359+ -re "$gdb_prompt $"\
1360+ {fail "info silent break bp_location1"}
1361+ timeout {fail "(timeout) info silent break bp_location1"}
1362+}
1363+send_gdb "continue\n"
1364+gdb_expect {
1365+ -re "Continuing.\r\n$gdb_prompt $"\
1366+ {pass "hit silent break bp_location1"}
1367+ -re "$gdb_prompt $"\
1368+ {fail "hit silent break bp_location1"}
1369+ timeout {fail "(timeout) hit silent break bp_location1"}
1370+}
1371+send_gdb "bt\n"
1372+gdb_expect {
1373+ -re "#0 main .* at .*:$bp_location1.*$gdb_prompt $"\
1374+ {pass "stopped for silent break bp_location1"}
1375+ -re "$gdb_prompt $"\
1376+ {fail "stopped for silent break bp_location1"}
1377+ timeout {fail "(timeout) stopped for silent break bp_location1"}
1378+}
1379+
1380+# Verify that GDB can at least parse a breakpoint with the
1381+# "thread" keyword. (We won't attempt to test here that a
1382+# thread-specific breakpoint really triggers appropriately.
1383+# The gdb.threads subdirectory contains tests for that.)
1384+#
1385+set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
1386+send_gdb "break $bp_location12 thread 999\n"
1387+gdb_expect {
1388+ -re "Unknown thread 999.*$gdb_prompt $"\
1389+ {pass "thread-specific breakpoint on non-existent thread disallowed"}
1390+ -re "$gdb_prompt $"\
1391+ {fail "thread-specific breakpoint on non-existent thread disallowed"}
1392+ timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
1393+}
1394+send_gdb "break $bp_location12 thread foo\n"
1395+gdb_expect {
1396+ -re "Junk after thread keyword..*$gdb_prompt $"\
1397+ {pass "thread-specific breakpoint on bogus thread ID disallowed"}
1398+ -re "$gdb_prompt $"\
1399+ {fail "thread-specific breakpoint on bogus thread ID disallowed"}
1400+ timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
1401+}
1402+
1403+# Verify that GDB responds gracefully to a breakpoint command with
1404+# trailing garbage.
1405+#
1406+send_gdb "break $bp_location12 foo\n"
1407+gdb_expect {
1408+ -re "Junk at end of arguments..*$gdb_prompt $"\
1409+ {pass "breakpoint with trailing garbage disallowed"}
1410+ -re "$gdb_prompt $"\
1411+ {fail "breakpoint with trailing garbage disallowed"}
1412+ timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
1413+}
1414+
1415+# Verify that GDB responds gracefully to a "clear" command that has
1416+# no matching breakpoint. (First, get us off the current source line,
1417+# which we know has a breakpoint.)
1418+#
1419+send_gdb "next\n"
1420+gdb_expect {
1421+ -re ".*$gdb_prompt $"\
1422+ {pass "step over breakpoint"}
1423+ timeout {fail "(timeout) step over breakpoint"}
1424+}
1425+send_gdb "clear 81\n"
1426+gdb_expect {
1427+ -re "No breakpoint at 81..*$gdb_prompt $"\
1428+ {pass "clear line has no breakpoint disallowed"}
1429+ -re "$gdb_prompt $"\
1430+ {fail "clear line has no breakpoint disallowed"}
1431+ timeout {fail "(timeout) clear line has no breakpoint disallowed"}
1432+}
1433+send_gdb "clear\n"
1434+gdb_expect {
1435+ -re "No breakpoint at this line..*$gdb_prompt $"\
1436+ {pass "clear current line has no breakpoint disallowed"}
1437+ -re "$gdb_prompt $"\
1438+ {fail "clear current line has no breakpoint disallowed"}
1439+ timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
1440+}
1441+
1442+# Verify that we can set and clear multiple breakpoints.
1443+#
1444+# We don't test that it deletes the correct breakpoints. We do at
1445+# least test that it deletes more than one breakpoint.
1446+#
1447+gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
1448+gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
1449+gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
1450+
1451+# Verify that a breakpoint can be set via a convenience variable.
1452+#
1453+send_gdb "set \$foo=$bp_location11\n"
1454+gdb_expect {
1455+ -re "$gdb_prompt $"\
1456+ {pass "set convenience variable \$foo to bp_location11"}
1457+ timeout {fail "(timeout) set convenience variable \$foo to bp_location11"}
1458+}
1459+send_gdb "break \$foo\n"
1460+gdb_expect {
1461+ -re "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*$gdb_prompt $"\
1462+ {pass "set breakpoint via convenience variable"}
1463+ -re "$gdb_prompt $"\
1464+ {fail "set breakpoint via convenience variable"}
1465+ timeout {fail "(timeout) set breakpoint via convenience variable"}
1466+}
1467+
1468+# Verify that GDB responds gracefully to an attempt to set a
1469+# breakpoint via a convenience variable whose type is not integer.
1470+#
1471+send_gdb "set \$foo=81.5\n"
1472+gdb_expect {
1473+ -re "$gdb_prompt $"\
1474+ {pass "set convenience variable \$foo to 81.5"}
1475+ timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
1476+}
1477+send_gdb "break \$foo\n"
1478+gdb_expect {
1479+ -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
1480+ {pass "set breakpoint via non-integer convenience variable disallowed"}
1481+ -re "$gdb_prompt $"\
1482+ {fail "set breakpoint via non-integer convenience variable disallowed"}
1483+ timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
1484+}
1485+
1486+# Verify that we can set and trigger a breakpoint in a user-called function.
1487+#
1488+send_gdb "break marker2\n"
1489+gdb_expect {
1490+ -re "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*$gdb_prompt $"\
1491+ {pass "set breakpoint on to-be-called function"}
1492+ -re "$gdb_prompt $"\
1493+ {fail "set breakpoint on to-be-called function"}
1494+ timeout {fail "(timeout) set breakpoint on to-be-called function"}
1495+}
1496+send_gdb "print marker2(99)\n"
1497+gdb_expect {
7566401a 1498+ -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 $"\
3a58abaf
AM
1499+ {pass "hit breakpoint on called function"}
1500+ -re "$gdb_prompt $"\
1501+ {fail "hit breakpoint on called function"}
1502+ timeout {fail "(timeout) hit breakpoint on called function"}
1503+}
1504+
1505+# As long as we're stopped (breakpointed) in a called function,
1506+# verify that we can successfully backtrace & such from here.
1507+#
1508+# In this and the following test, the _sr4export check apparently is needed
1509+# for hppa*-*-hpux.
1510+#
1511+send_gdb "bt\n"
1512+gdb_expect {
1513+ -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $"\
1514+ {pass "backtrace while in called function"}
1515+ -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $"\
1516+ {pass "backtrace while in called function"}
1517+ -re "$gdb_prompt $"\
1518+ {fail "backtrace while in called function"}
1519+ timeout {fail "(timeout) backtrace while in called function"}
1520+}
1521+
1522+# Return from the called function. For remote targets, it's important to do
1523+# this before runto_main, which otherwise may silently stop on the dummy
1524+# breakpoint inserted by GDB at the program's entry point.
1525+#
1526+send_gdb "finish\n"
1527+gdb_expect {
1528+ -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $"\
1529+ {pass "finish from called function"}
1530+ -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $"\
1531+ {pass "finish from called function"}
1532+ -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $"\
1533+ {pass "finish from called function"}
1534+ -re "$gdb_prompt $"\
1535+ {fail "finish from called function"}
1536+ timeout {fail "(timeout) finish from called function"}
1537+}
1538+
1539+# Verify that GDB responds gracefully to a "finish" command with
1540+# arguments.
1541+#
1542+if ![runto_main] then { fail "break tests suppressed" }
1543+
1544+send_gdb "finish 123\n"
1545+gdb_expect {
1546+ -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
1547+ {pass "finish with arguments disallowed"}
1548+ -re "$gdb_prompt $"\
1549+ {fail "finish with arguments disallowed"}
1550+ timeout {fail "(timeout) finish with arguments disallowed"}
1551+}
1552+
1553+# Verify that GDB responds gracefully to a request to "finish" from
1554+# the outermost frame. On a stub that never exits, this will just
1555+# run to the stubs routine, so we don't get this error... Thus the
1556+# second condition.
1557+#
1558+
1559+send_gdb "finish\n"
1560+gdb_expect {
1561+ -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
1562+ {pass "finish from outermost frame disallowed"}
1563+ -re "Run till exit from.*\r\n$gdb_prompt $" {
1564+ pass "finish from outermost frame disallowed"
1565+ }
1566+ -re "$gdb_prompt $"\
1567+ {fail "finish from outermost frame disallowed"}
1568+ timeout {fail "(timeout) finish from outermost frame disallowed"}
1569+}
1570+
1571+# Verify that we can explicitly ask GDB to stop on all shared library
1572+# events, and that it does so.
1573+#
1574+if [istarget "hppa*-*-hpux*"] then {
1575+ if ![runto_main] then { fail "break tests suppressed" }
1576+
1577+ send_gdb "set stop-on-solib-events 1\n"
1578+ gdb_expect {
1579+ -re "$gdb_prompt $"\
1580+ {pass "set stop-on-solib-events"}
1581+ timeout {fail "(timeout) set stop-on-solib-events"}
1582+ }
1583+
1584+ send_gdb "run\n"
1585+ gdb_expect {
1586+ -re ".*Start it from the beginning.*y or n. $"\
1587+ {send_gdb "y\n"
1588+ gdb_expect {
1589+ -re ".*Stopped due to shared library event.*$gdb_prompt $"\
1590+ {pass "triggered stop-on-solib-events"}
1591+ -re "$gdb_prompt $"\
1592+ {fail "triggered stop-on-solib-events"}
1593+ timeout {fail "(timeout) triggered stop-on-solib-events"}
1594+ }
1595+ }
1596+ -re "$gdb_prompt $"\
1597+ {fail "rerun for stop-on-solib-events"}
1598+ timeout {fail "(timeout) rerun for stop-on-solib-events"}
1599+ }
1600+
1601+ send_gdb "set stop-on-solib-events 0\n"
1602+ gdb_expect {
1603+ -re "$gdb_prompt $"\
1604+ {pass "reset stop-on-solib-events"}
1605+ timeout {fail "(timeout) reset stop-on-solib-events"}
1606+ }
1607+}
1608+
1609+# Hardware breakpoints are unsupported on HP-UX. Verify that GDB
1610+# gracefully responds to requests to create them.
1611+#
1612+if [istarget "hppa*-*-hpux*"] then {
1613+ if ![runto_main] then { fail "break tests suppressed" }
1614+
1615+ send_gdb "hbreak\n"
1616+ gdb_expect {
1617+ -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
1618+ {pass "hw breaks disallowed"}
1619+ -re "$gdb_prompt $"\
1620+ {fail "hw breaks disallowed"}
1621+ timeout {fail "(timeout) hw breaks disallowed"}
1622+ }
1623+
1624+ send_gdb "thbreak\n"
1625+ gdb_expect {
1626+ -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
1627+ {pass "temporary hw breaks disallowed"}
1628+ -re "$gdb_prompt $"\
1629+ {fail "temporary hw breaks disallowed"}
1630+ timeout {fail "(timeout) temporary hw breaks disallowed"}
1631+ }
1632+}
1633+
1634+#********
1635+
1636+
1637+#
1638+# Test "next" over recursive function call.
1639+#
1640+
1641+proc test_next_with_recursion {} {
1642+ global gdb_prompt
1643+ global decimal
1644+ global binfile
1645+
1646+ if [target_info exists use_gdb_stub] {
1647+ # Reload the program.
1648+ delete_breakpoints
1649+ gdb_load ${binfile};
1650+ } else {
1651+ # FIXME: should be using runto
1652+ gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
1653+
1654+ delete_breakpoints
1655+ }
1656+
1657+ gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
1658+
1659+ # Run until we call factorial with 6
1660+
1661+ if [istarget "*-*-vxworks*"] then {
1662+ send_gdb "run vxmain \"6\"\n"
1663+ } else {
1664+ gdb_run_cmd
1665+ }
1666+ gdb_expect {
1667+ -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
1668+ -re ".*$gdb_prompt $" {
1669+ fail "run to factorial(6)";
1670+ gdb_suppress_tests;
1671+ }
1672+ timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
1673+ }
1674+
1675+ # Continue until we call factorial recursively with 5.
1676+
1677+ if [gdb_test "continue" \
1678+ "Continuing.*Break.* factorial .value=5. .*" \
1679+ "continue to factorial(5)"] then { gdb_suppress_tests }
1680+
1681+ # Do a backtrace just to confirm how many levels deep we are.
1682+
1683+ if [gdb_test "backtrace" \
1684+ "#0\[ \t\]+ factorial .value=5..*" \
1685+ "backtrace from factorial(5)"] then { gdb_suppress_tests }
1686+
1687+ # Now a "next" should position us at the recursive call, which
1688+ # we will be performing with 4.
1689+
1690+ if [gdb_test "next" \
1691+ ".* factorial .value - 1.;.*" \
1692+ "next to recursive call"] then { gdb_suppress_tests }
1693+
1694+ # Disable the breakpoint at the entry to factorial by deleting them all.
1695+ # The "next" should run until we return to the next line from this
1696+ # recursive call to factorial with 4.
1697+ # Buggy versions of gdb will stop instead at the innermost frame on
1698+ # the line where we are trying to "next" to.
1699+
1700+ delete_breakpoints
1701+
1702+ if [istarget "mips*tx39-*"] {
1703+ set timeout 60
1704+ }
1705+ # We used to set timeout here for all other targets as well. This
1706+ # is almost certainly wrong. The proper timeout depends on the
1707+ # target system in use, and how we communicate with it, so there
1708+ # is no single value appropriate for all targets. The timeout
1709+ # should be established by the Dejagnu config file(s) for the
1710+ # board, and respected by the test suite.
1711+ #
1712+ # For example, if I'm running GDB over an SSH tunnel talking to a
1713+ # portmaster in California talking to an ancient 68k board running
1714+ # a crummy ROM monitor (a situation I can only wish were
1715+ # hypothetical), then I need a large timeout. But that's not the
1716+ # kind of knowledge that belongs in this file.
1717+
1718+ gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
1719+ "next over recursive call"
1720+
1721+ # OK, we should be back in the same stack frame we started from.
1722+ # Do a backtrace just to confirm.
1723+
1724+ set result [gdb_test "backtrace" \
1725+ "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
1726+ "backtrace from factorial(5.1)"]
1727+ if { $result != 0 } { gdb_suppress_tests }
1728+
1729+ if [target_info exists gdb,noresults] { gdb_suppress_tests }
1730+ gdb_continue_to_end "recursive next test"
1731+ gdb_stop_suppressing_tests;
1732+}
1733+
1734+test_next_with_recursion
1735+
1736+
1737+#********
1738+
1739+# build a new file with optimization enabled so that we can try breakpoints
1740+# on targets with optimized prologues
1741+
1742+set binfileo2 ${objdir}/${subdir}/${testfile}o2
1743+
1744+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}O0.o" object {debug "additional_flags=-w -O2 -fpie -pie"}] != "" } {
1745+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
1746+}
1747+
1748+if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}O1.o" object {debug "additional_flags=-w -O2 -fpie -pie"}] != "" } {
1749+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
1750+}
1751+
1752+if { [gdb_compile "${binfile}O0.o ${binfile}O1.o" "${binfileo2}" executable {debug "additional_flags=-w -fpie -pie"}] != "" } {
1753+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
1754+}
1755+
1756+if [get_compiler_info ${binfileo2}] {
1757+ return -1
1758+}
1759+
1760+gdb_exit
1761+gdb_start
1762+gdb_reinitialize_dir $srcdir/$subdir
1763+gdb_load ${binfileo2}
1764+
1765+if [target_info exists gdb_stub] {
1766+ gdb_step_for_stub;
1767+}
1768+
1769+#
1770+# test break at function
1771+#
1772+gdb_test "break main" \
1773+ "Breakpoint.*at.* file .*$srcfile, line.*" \
1774+ "breakpoint function, optimized file"
1775+
1776+#
1777+# test break at function
1778+#
1779+gdb_test "break marker4" \
1780+ "Breakpoint.*at.* file .*$srcfile1, line.*" \
1781+ "breakpoint small function, optimized file"
1782+
1783+#
1784+# run until the breakpoint at main is hit. For non-stubs-using targets.
1785+#
1786+if ![target_info exists use_gdb_stub] {
1787+ if [istarget "*-*-vxworks*"] then {
1788+ send_gdb "run vxmain \"2\"\n"
1789+ set timeout 120
1790+ verbose "Timeout is now $timeout seconds" 2
1791+ } else {
1792+ send_gdb "run\n"
1793+ }
1794+ gdb_expect {
1795+ -re "The program .* has been started already.*y or n. $" {
1796+ send_gdb "y\n"
1797+ exp_continue
1798+ }
1799+ -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
1800+ { pass "run until function breakpoint, optimized file" }
1801+ -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $"\
1802+ { pass "run until function breakpoint, optimized file (code motion)" }
1803+ -re ".*$gdb_prompt $" { fail "run until function breakpoint, optimized file" }
1804+ timeout { fail "run until function breakpoint, optimized file (timeout)" }
1805+ }
1806+} else {
1807+ if ![target_info exists gdb_stub] {
1808+ gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue, optimized file"
1809+ }
1810+}
1811+
1812+#
1813+# run until the breakpoint at a small function
1814+#
1815+
1816+#
1817+# Add a second pass pattern. The behavior differs here between stabs
1818+# and dwarf for one-line functions. Stabs preserves two line symbols
1819+# (one before the prologue and one after) with the same line number,
1820+# but dwarf regards these as duplicates and discards one of them.
1821+# Therefore the address after the prologue (where the breakpoint is)
1822+# has no exactly matching line symbol, and GDB reports the breakpoint
1823+# as if it were in the middle of a line rather than at the beginning.
1824+
1825+set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
1826+set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
1827+send_gdb "continue\n"
1828+gdb_expect {
1829+ -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
1830+ pass "run until breakpoint set at small function, optimized file"
1831+ }
1832+ -re "Breakpoint $decimal, $hex in marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
1833+ pass "run until breakpoint set at small function, optimized file"
1834+ }
1835+ -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
1836+ # marker4() is defined at line 46 when compiled with -DPROTOTYPES
1837+ pass "run until breakpoint set at small function, optimized file (line bp_location14)"
1838+ }
1839+ -re ".*$gdb_prompt " {
1840+ fail "run until breakpoint set at small function, optimized file"
1841+ }
1842+ timeout {
1843+ fail "run until breakpoint set at small function, optimized file (timeout)"
1844+ }
1845+}
1846+
1847+
1848+# Reset the default arguments for VxWorks
1849+if [istarget "*-*-vxworks*"] {
1850+ set timeout 10
1851+ verbose "Timeout is now $timeout seconds" 2
1852+ send_gdb "set args main\n"
1853+ gdb_expect -re ".*$gdb_prompt $" {}
1854+}
7566401a 1855Index: gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/corefile.exp
3a58abaf
AM
1856===================================================================
1857--- /dev/null 1970-01-01 00:00:00.000000000 +0000
7566401a 1858+++ gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/corefile.exp 2009-09-09 19:06:01.000000000 +0200
3a58abaf
AM
1859@@ -0,0 +1,243 @@
1860+# Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
1861+# Free Software Foundation, Inc.
1862+
1863+# This program is free software; you can redistribute it and/or modify
1864+# it under the terms of the GNU General Public License as published by
1865+# the Free Software Foundation; either version 2 of the License, or
1866+# (at your option) any later version.
1867+#
1868+# This program is distributed in the hope that it will be useful,
1869+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1870+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1871+# GNU General Public License for more details.
1872+#
1873+# You should have received a copy of the GNU General Public License
1874+# along with this program; if not, write to the Free Software
1875+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1876+
1877+# Please email any bugs, comments, and/or additions to this file to:
1878+# bug-gdb@prep.ai.mit.edu
1879+
1880+# This file was written by Fred Fish. (fnf@cygnus.com)
1881+
1882+if $tracelevel then {
1883+ strace $tracelevel
1884+}
1885+
1886+set prms_id 0
1887+set bug_id 0
1888+
1889+# are we on a target board
1890+if ![isnative] then {
1891+ return
1892+}
1893+
1894+set testfile "coremaker"
1895+set srcfile ${testfile}.c
1896+set binfile ${objdir}/${subdir}/${testfile}
1897+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug "additional_flags=-fpie -pie"}] != "" } {
1898+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
1899+}
1900+
1901+# Create and source the file that provides information about the compiler
1902+# used to compile the test case.
1903+if [get_compiler_info ${binfile}] {
1904+ return -1;
1905+}
1906+
1907+# Create a core file named "corefile" rather than just "core", to
1908+# avoid problems with sys admin types that like to regularly prune all
1909+# files named "core" from the system.
1910+#
1911+# Arbitrarily try setting the core size limit to "unlimited" since
1912+# this does not hurt on systems where the command does not work and
1913+# allows us to generate a core on systems where it does.
1914+#
1915+# Some systems append "core" to the name of the program; others append
1916+# the name of the program to "core"; still others (like Linux, as of
1917+# May 2003) create cores named "core.PID". In the latter case, we
1918+# could have many core files lying around, and it may be difficult to
1919+# tell which one is ours, so let's run the program in a subdirectory.
1920+set found 0
1921+set coredir "${objdir}/${subdir}/coredir.[getpid]"
1922+file mkdir $coredir
1923+catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile}; true) >/dev/null 2>&1\""
1924+# remote_exec host "${binfile}"
1925+foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
1926+ if [remote_file build exists $i] {
1927+ remote_exec build "mv $i ${objdir}/${subdir}/corefile"
1928+ set found 1
1929+ }
1930+}
1931+# Check for "core.PID".
1932+if { $found == 0 } {
1933+ set names [glob -nocomplain -directory $coredir core.*]
1934+ if {[llength $names] == 1} {
1935+ set corefile [file join $coredir [lindex $names 0]]
1936+ remote_exec build "mv $corefile ${objdir}/${subdir}/corefile"
1937+ set found 1
1938+ }
1939+}
1940+if { $found == 0 } {
1941+ # The braindamaged HPUX shell quits after the ulimit -c above
1942+ # without executing ${binfile}. So we try again without the
1943+ # ulimit here if we didn't find a core file above.
1944+ # Oh, I should mention that any "braindamaged" non-Unix system has
1945+ # the same problem. I like the cd bit too, it's really neat'n stuff.
1946+ catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
1947+ foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
1948+ if [remote_file build exists $i] {
1949+ remote_exec build "mv $i ${objdir}/${subdir}/corefile"
1950+ set found 1
1951+ }
1952+ }
1953+}
1954+
1955+# Try to clean up after ourselves.
1956+remote_file build delete [file join $coredir coremmap.data]
1957+remote_exec build "rmdir $coredir"
1958+
1959+if { $found == 0 } {
1960+ warning "can't generate a core file - core tests suppressed - check ulimit -c"
1961+ return 0
1962+}
1963+
1964+#
1965+# Test that we can simply startup with a "-core=corefile" command line arg
1966+# and recognize that the core file is a valid, usable core file.
1967+# To do this, we must shutdown the currently running gdb and restart
1968+# with the -core args. We can't use gdb_start because it looks for
1969+# the first gdb prompt, and the message we are looking for occurs
1970+# before the first prompt. Also, we can't include GDBFLAGS because
1971+# if it is empty, this confuses gdb with an empty argument that it
1972+# grumbles about (said grumbling currently being ignored in gdb_start).
1973+# **FIXME**
1974+#
1975+# Another problem is that on some systems (solaris for example), there
1976+# is apparently a limit on the length of a fully specified path to
1977+# the coremaker executable, at about 80 chars. For this case, consider
1978+# it a pass, but note that the program name is bad.
1979+
1980+gdb_exit
1981+if $verbose>1 then {
1982+ send_user "Spawning $GDB -nw $GDBFLAGS -core=$objdir/$subdir/corefile\n"
1983+}
1984+
1985+set oldtimeout $timeout
1986+set timeout [expr "$timeout + 60"]
1987+verbose "Timeout is now $timeout seconds" 2
1988+eval "spawn $GDB -nw $GDBFLAGS -core=$objdir/$subdir/corefile"
1989+expect {
1990+ -re "Couldn't find .* registers in core file.*$gdb_prompt $" {
1991+ fail "args: -core=corefile (couldn't find regs)"
1992+ }
1993+ -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
1994+ pass "args: -core=corefile"
1995+ }
1996+ -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
1997+ pass "args: -core=corefile (with bad program name)"
1998+ }
1999+ -re ".*registers from core file: File in wrong format.* $" {
2000+ fail "args: -core=corefile (could not read registers from core file)"
2001+ }
2002+ -re ".*$gdb_prompt $" { fail "args: -core=corefile" }
2003+ timeout { fail "(timeout) starting with -core" }
2004+}
2005+
2006+
2007+#
2008+# Test that startup with both an executable file and -core argument.
2009+# See previous comments above, they are still applicable.
2010+#
2011+
2012+close;
2013+
2014+if $verbose>1 then {
2015+ send_user "Spawning $GDB -nw $GDBFLAGS $binfile -core=$objdir/$subdir/corefile\n"
2016+}
2017+
2018+
2019+eval "spawn $GDB -nw $GDBFLAGS $binfile -core=$objdir/$subdir/corefile";
2020+expect {
2021+ -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
2022+ pass "args: execfile -core=corefile"
2023+ }
2024+ -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
2025+ pass "args: execfile -core=corefile (with bad program name)"
2026+ }
2027+ -re ".*registers from core file: File in wrong format.* $" {
2028+ fail "args: execfile -core=corefile (could not read registers from core file)"
2029+ }
2030+ -re ".*$gdb_prompt $" { fail "args: execfile -core=corefile" }
2031+ timeout { fail "(timeout) starting with -core" }
2032+}
2033+set timeout $oldtimeout
2034+verbose "Timeout is now $timeout seconds" 2
2035+
2036+close;
2037+
2038+# Now restart normally.
2039+
2040+gdb_start
2041+gdb_reinitialize_dir $srcdir/$subdir
2042+gdb_load ${binfile}
2043+
2044+# Test basic corefile recognition via core-file command.
2045+
2046+send_gdb "core-file $objdir/$subdir/corefile\n"
2047+gdb_expect {
2048+ -re ".* program is being debugged already.*y or n. $" {
2049+ # gdb_load may connect us to a gdbserver.
2050+ send_gdb "y\n"
2051+ exp_continue;
2052+ }
2053+ -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
2054+ pass "core-file command"
2055+ }
2056+ -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
2057+ pass "core-file command (with bad program name)"
2058+ }
2059+ -re ".*registers from core file: File in wrong format.* $" {
2060+ fail "core-file command (could not read registers from core file)"
2061+ }
2062+ -re ".*$gdb_prompt $" { fail "core-file command" }
2063+ timeout { fail "(timeout) core-file command" }
2064+}
2065+
2066+# Test correct mapping of corefile sections by printing some variables.
2067+
2068+gdb_test "print coremaker_data" "\\\$$decimal = 202"
2069+gdb_test "print coremaker_bss" "\\\$$decimal = 10"
2070+gdb_test "print coremaker_ro" "\\\$$decimal = 201"
2071+
2072+gdb_test "print func2::coremaker_local" "\\\$$decimal = \\{0, 1, 2, 3, 4\\}"
2073+
2074+# Somehow we better test the ability to read the registers out of the core
2075+# file correctly. I don't think the other tests do this.
2076+
2077+gdb_test "bt" "abort.*func2.*func1.*main.*" "backtrace in corefile.exp"
2078+gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp"
2079+
2080+# Test ability to read mmap'd data
2081+
2082+gdb_test "x/8bd buf1" ".*:.*0.*1.*2.*3.*4.*5.*6.*7" "accessing original mmap data in core file"
2083+setup_xfail "*-*-sunos*" "*-*-ultrix*" "*-*-aix*"
2084+set test "accessing mmapped data in core file"
2085+gdb_test_multiple "x/8bd buf2" "$test" {
2086+ -re ".*:.*0.*1.*2.*3.*4.*5.*6.*7.*$gdb_prompt $" {
2087+ pass "$test"
2088+ }
2089+ -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" {
2090+ fail "$test (mapping failed at runtime)"
2091+ }
2092+ -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" {
2093+ fail "$test (mapping address not found in core file)"
2094+ }
2095+}
2096+
2097+# test reinit_frame_cache
2098+
2099+gdb_load ${binfile}
2100+gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(\\).*" "up in corefile.exp (reinit)"
2101+
2102+gdb_test "core" "No core file now."
7566401a 2103Index: gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/Makefile.in
3a58abaf
AM
2104===================================================================
2105--- /dev/null 1970-01-01 00:00:00.000000000 +0000
7566401a 2106+++ gdb-6.8.50.20090909/gdb/testsuite/gdb.pie/Makefile.in 2009-09-09 19:06:01.000000000 +0200
3a58abaf
AM
2107@@ -0,0 +1,19 @@
2108+VPATH = @srcdir@
2109+srcdir = @srcdir@
2110+
2111+EXECUTABLES =
2112+MISCELLANEOUS = arch.inc
2113+
2114+all info install-info dvi install uninstall installcheck check:
2115+ @echo "Nothing to be done for $@..."
2116+
2117+clean mostlyclean:
2118+ -rm -f *~ *.o a.out *.x *.ci *.tmp
2119+ -rm -f core core.coremaker coremaker.core corefile $(EXECUTABLES)
2120+ -rm -f $(MISCELLANEOUS)
2121+
2122+distclean maintainer-clean realclean: clean
2123+ -rm -f *~ core
2124+ -rm -f Makefile config.status config.log
2125+ -rm -f *-init.exp
2126+ -rm -fr *.log summary detail *.plog *.sum *.psum site.*
This page took 0.365999 seconds and 4 git commands to generate.