daily update
[deliverable/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 if ![istarget "hppa*-*-*"] then {
29 verbose "Skipping hppa nullification tests."
30 return
31 }
32
33 set testfile "pa-nullify"
34 set srcfile ${testfile}.s
35 set binfile ${objdir}/${subdir}/${testfile}
36 set gcorefile ${objdir}/${subdir}/${testfile}.gcore
37
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {}] != "" } {
39 unsupported "Testcase compile failed."
40 return -1
41 }
42
43 gdb_exit
44 gdb_start
45 gdb_reinitialize_dir $srcdir/$subdir
46 gdb_load ${binfile}
47
48 # In the first test, we do a "step" on a function whose last instruction
49 # contains a branch-with-nullify. The instruction in the delay slot belongs
50 # to the next function. We verify that when we step off the first function
51 # that we end up back at the caller and not at the second instruction.
52
53 gdb_breakpoint foo
54 gdb_test "run" "Breakpoint 1, .* in foo.*" "Breakpoint at foo"
55
56 set test "stepi till main"
57 gdb_test_multiple "stepi" "${test}" {
58 -re ".*in foo.*$gdb_prompt $" {
59 send_gdb "stepi\n"
60 exp_continue -continue_timer
61 }
62 -re ".*in bar.*$gdb_prompt $" {
63 fail $test
64 }
65 -re ".*in main.*$gdb_prompt $" {
66 pass $test
67 }
68 }
69
70 # In the second test, we verify that we can get a proper backtrace
71 # even when we are in a nullified instruction that belongs to the next function.
72 # We also verify that when stepping over a branch-with-nullify insn that we
73 # stay on the same insn for two steps.
74
75 proc get_addr_of_sym { sym } {
76 set addr 0
77 global gdb_prompt
78 global hex
79
80 set test "get address of $sym"
81 send_gdb "print $sym\n"
82 gdb_test_multiple "print $sym" $test {
83 -re ".*($hex) <$sym>.*$gdb_prompt $" {
84 set addr $expect_out(1,string)
85 pass $test
86 }
87 }
88
89 return $addr
90 }
91
92 if { ! [ runto_main ] } then { gdb_suppress_tests; }
93
94 set foo [get_addr_of_sym "foo"]
95 set bar [get_addr_of_sym "bar"]
96 set foo_last [expr $bar - 4]
97
98 gdb_breakpoint "*$foo_last"
99
100 gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*"
101 gdb_test "backtrace" "in foo.*in main.*" "Backtrace from last insn in foo"
102 gdb_test "stepi" "in foo.*" "stepi to nullified instruction stays in foo"
103 gdb_test "backtrace" "in foo.*in main.*" "Backtrace from nullified insn"
104 gdb_test "stepi" "in main.*" "stepi to main"
105
106 # In the third test, we verify that backtraces from nullified instructions
107 # work even in coredumps
108
109 proc gen_core { test } {
110 global gcorefile
111 global gdb_prompt
112 set gcore_works 0
113 set escapedfilename [string_to_regexp $gcorefile]
114
115 gdb_test_multiple "gcore $gcorefile" "$test: gcore" {
116 -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
117 pass "$test: gcore"
118 set gcore_works 1
119 }
120 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
121 fail "$test: gcore"
122 }
123 }
124
125 return $gcore_works
126 }
127
128 proc test_core_bt { test } {
129 global gcorefile
130
131 gdb_test "core $gcorefile" "Core was generated by.*" \
132 "$test: load core file" "A program is being debugged already.*" "y"
133
134 gdb_test "backtrace" ".*in foo.*in main.*" "$test: backtrace in gcore"
135 }
136
137 set test "core at last insn in foo"
138 if { ! [ runto_main ] } then { gdb_suppress_tests; }
139 gdb_breakpoint "*$foo_last"
140 gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*" "$test: continue to breakpoint"
141 if [gen_core $test] {
142 test_core_bt $test
143 }
144
145 set test "core at nullified insn"
146 if { ! [ runto_main ] } then { gdb_suppress_tests; }
147 gdb_breakpoint "*$foo_last"
148 gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*" "$test: continue to breakpoint"
149 gdb_test "stepi" ".*in foo.*" "$test: step to nullified instruction"
150 if [gen_core $test] {
151 test_core_bt $test
152 }
This page took 0.035959 seconds and 4 git commands to generate.