2011-02-21 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.arch / pa-nullify.exp
CommitLineData
7b6bb8da 1# Copyright 2004, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
fe46cd3a
RC
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
fe46cd3a
RC
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
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
fe46cd3a
RC
15#
16# This file is part of the gdb testsuite.
17
18if $tracelevel {
19 strace $tracelevel
20}
21
fe46cd3a
RC
22
23# Test handling of nullified instructions for the pa target.
24
8117349c
RC
25switch -glob -- [istarget] {
26 "hppa-*-*" {
27 set testfile "pa-nullify"
28 }
29 "hppa64-*-*" {
30 set testfile "pa64-nullify"
31 }
32 "*" {
33 verbose "Skipping hppa nullification tests."
34 return
35 }
fe46cd3a
RC
36}
37
fe46cd3a
RC
38set srcfile ${testfile}.s
39set binfile ${objdir}/${subdir}/${testfile}
40set gcorefile ${objdir}/${subdir}/${testfile}.gcore
41
42if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {}] != "" } {
43 unsupported "Testcase compile failed."
44 return -1
45}
46
47gdb_exit
48gdb_start
49gdb_reinitialize_dir $srcdir/$subdir
50gdb_load ${binfile}
51
52# In the first test, we do a "step" on a function whose last instruction
53# contains a branch-with-nullify. The instruction in the delay slot belongs
54# to the next function. We verify that when we step off the first function
55# that we end up back at the caller and not at the second instruction.
56
57gdb_breakpoint foo
58gdb_test "run" "Breakpoint 1, .* in foo.*" "Breakpoint at foo"
59
60set test "stepi till main"
61gdb_test_multiple "stepi" "${test}" {
62 -re ".*in foo.*$gdb_prompt $" {
63 send_gdb "stepi\n"
64 exp_continue -continue_timer
65 }
66 -re ".*in bar.*$gdb_prompt $" {
67 fail $test
68 }
69 -re ".*in main.*$gdb_prompt $" {
70 pass $test
71 }
72}
73
74# In the second test, we verify that we can get a proper backtrace
75# even when we are in a nullified instruction that belongs to the next function.
76# We also verify that when stepping over a branch-with-nullify insn that we
77# stay on the same insn for two steps.
78
79proc get_addr_of_sym { sym } {
80 set addr 0
81 global gdb_prompt
82 global hex
83
84 set test "get address of $sym"
fe46cd3a
RC
85 gdb_test_multiple "print $sym" $test {
86 -re ".*($hex) <$sym>.*$gdb_prompt $" {
87 set addr $expect_out(1,string)
88 pass $test
89 }
90 }
91
92 return $addr
93}
94
95if { ! [ runto_main ] } then { gdb_suppress_tests; }
96
97set foo [get_addr_of_sym "foo"]
98set bar [get_addr_of_sym "bar"]
8117349c 99set foo_last "(bar - 4)"
fe46cd3a
RC
100
101gdb_breakpoint "*$foo_last"
102
103gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*"
104gdb_test "backtrace" "in foo.*in main.*" "Backtrace from last insn in foo"
105gdb_test "stepi" "in foo.*" "stepi to nullified instruction stays in foo"
106gdb_test "backtrace" "in foo.*in main.*" "Backtrace from nullified insn"
107gdb_test "stepi" "in main.*" "stepi to main"
108
109# In the third test, we verify that backtraces from nullified instructions
110# work even in coredumps
111
112proc gen_core { test } {
113 global gcorefile
114 global gdb_prompt
115 set gcore_works 0
116 set escapedfilename [string_to_regexp $gcorefile]
117
8117349c
RC
118 # gcore is not yet implemented for HPUX
119 setup_xfail hppa*-*-hpux*
120
fe46cd3a
RC
121 gdb_test_multiple "gcore $gcorefile" "$test: gcore" {
122 -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
123 pass "$test: gcore"
124 set gcore_works 1
125 }
8117349c
RC
126 -re "Undefined command.*$gdb_prompt $" {
127 fail "$test: gcore (undefined command)"
128 }
fe46cd3a 129 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
8117349c 130 fail "$test: gcore (can't create corefile)"
fe46cd3a
RC
131 }
132 }
133
134 return $gcore_works
135}
136
137proc test_core_bt { test } {
138 global gcorefile
139
140 gdb_test "core $gcorefile" "Core was generated by.*" \
141 "$test: load core file" "A program is being debugged already.*" "y"
142
143 gdb_test "backtrace" ".*in foo.*in main.*" "$test: backtrace in gcore"
144}
145
146set test "core at last insn in foo"
147if { ! [ runto_main ] } then { gdb_suppress_tests; }
148gdb_breakpoint "*$foo_last"
149gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*" "$test: continue to breakpoint"
150if [gen_core $test] {
151 test_core_bt $test
152}
153
154set test "core at nullified insn"
155if { ! [ runto_main ] } then { gdb_suppress_tests; }
156gdb_breakpoint "*$foo_last"
157gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*" "$test: continue to breakpoint"
158gdb_test "stepi" ".*in foo.*" "$test: step to nullified instruction"
159if [gen_core $test] {
160 test_core_bt $test
161}
This page took 0.576339 seconds and 4 git commands to generate.