]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.arch/pa-nullify.exp
2005-12-09 Randolph Chung <tausq@debian.org>
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.arch / pa-nullify.exp
1 # Copyright 2004 Free Software Foundation, Inc.
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 #
17 # This file is part of the gdb testsuite.
18
19 if $tracelevel {
20 strace $tracelevel
21 }
22
23 set prms_id 0
24 set bug_id 0
25
26 # Test handling of nullified instructions for the pa target.
27
28 switch -glob -- [istarget] {
29 "hppa-*-*" {
30 set testfile "pa-nullify"
31 }
32 "hppa64-*-*" {
33 set testfile "pa64-nullify"
34 }
35 "*" {
36 verbose "Skipping hppa nullification tests."
37 return
38 }
39 }
40
41 set srcfile ${testfile}.s
42 set binfile ${objdir}/${subdir}/${testfile}
43 set gcorefile ${objdir}/${subdir}/${testfile}.gcore
44
45 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {}] != "" } {
46 unsupported "Testcase compile failed."
47 return -1
48 }
49
50 gdb_exit
51 gdb_start
52 gdb_reinitialize_dir $srcdir/$subdir
53 gdb_load ${binfile}
54
55 # In the first test, we do a "step" on a function whose last instruction
56 # contains a branch-with-nullify. The instruction in the delay slot belongs
57 # to the next function. We verify that when we step off the first function
58 # that we end up back at the caller and not at the second instruction.
59
60 gdb_breakpoint foo
61 gdb_test "run" "Breakpoint 1, .* in foo.*" "Breakpoint at foo"
62
63 set test "stepi till main"
64 gdb_test_multiple "stepi" "${test}" {
65 -re ".*in foo.*$gdb_prompt $" {
66 send_gdb "stepi\n"
67 exp_continue -continue_timer
68 }
69 -re ".*in bar.*$gdb_prompt $" {
70 fail $test
71 }
72 -re ".*in main.*$gdb_prompt $" {
73 pass $test
74 }
75 }
76
77 # In the second test, we verify that we can get a proper backtrace
78 # even when we are in a nullified instruction that belongs to the next function.
79 # We also verify that when stepping over a branch-with-nullify insn that we
80 # stay on the same insn for two steps.
81
82 proc get_addr_of_sym { sym } {
83 set addr 0
84 global gdb_prompt
85 global hex
86
87 set test "get address of $sym"
88 gdb_test_multiple "print $sym" $test {
89 -re ".*($hex) <$sym>.*$gdb_prompt $" {
90 set addr $expect_out(1,string)
91 pass $test
92 }
93 }
94
95 return $addr
96 }
97
98 if { ! [ runto_main ] } then { gdb_suppress_tests; }
99
100 set foo [get_addr_of_sym "foo"]
101 set bar [get_addr_of_sym "bar"]
102 set foo_last "(bar - 4)"
103
104 gdb_breakpoint "*$foo_last"
105
106 gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*"
107 gdb_test "backtrace" "in foo.*in main.*" "Backtrace from last insn in foo"
108 gdb_test "stepi" "in foo.*" "stepi to nullified instruction stays in foo"
109 gdb_test "backtrace" "in foo.*in main.*" "Backtrace from nullified insn"
110 gdb_test "stepi" "in main.*" "stepi to main"
111
112 # In the third test, we verify that backtraces from nullified instructions
113 # work even in coredumps
114
115 proc gen_core { test } {
116 global gcorefile
117 global gdb_prompt
118 set gcore_works 0
119 set escapedfilename [string_to_regexp $gcorefile]
120
121 # gcore is not yet implemented for HPUX
122 setup_xfail hppa*-*-hpux*
123
124 gdb_test_multiple "gcore $gcorefile" "$test: gcore" {
125 -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
126 pass "$test: gcore"
127 set gcore_works 1
128 }
129 -re "Undefined command.*$gdb_prompt $" {
130 fail "$test: gcore (undefined command)"
131 }
132 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
133 fail "$test: gcore (can't create corefile)"
134 }
135 }
136
137 return $gcore_works
138 }
139
140 proc test_core_bt { test } {
141 global gcorefile
142
143 gdb_test "core $gcorefile" "Core was generated by.*" \
144 "$test: load core file" "A program is being debugged already.*" "y"
145
146 gdb_test "backtrace" ".*in foo.*in main.*" "$test: backtrace in gcore"
147 }
148
149 set test "core at last insn in foo"
150 if { ! [ runto_main ] } then { gdb_suppress_tests; }
151 gdb_breakpoint "*$foo_last"
152 gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*" "$test: continue to breakpoint"
153 if [gen_core $test] {
154 test_core_bt $test
155 }
156
157 set test "core at nullified insn"
158 if { ! [ runto_main ] } then { gdb_suppress_tests; }
159 gdb_breakpoint "*$foo_last"
160 gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*" "$test: continue to breakpoint"
161 gdb_test "stepi" ".*in foo.*" "$test: step to nullified instruction"
162 if [gen_core $test] {
163 test_core_bt $test
164 }