1 # Copyright 2004-2016 Free Software Foundation, Inc.
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 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This file is part of the gdb testsuite.
19 # Test handling of nullified instructions for the pa target.
21 switch -glob -- [istarget] {
23 set testfile "pa-nullify"
26 set testfile "pa64-nullify"
29 verbose "Skipping hppa nullification tests."
34 set srcfile ${testfile}.s
35 set binfile ${objdir}/${subdir}/${testfile}
36 set gcorefile ${objdir}/${subdir}/${testfile}.gcore
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {}] != "" } {
39 unsupported "Testcase compile failed."
45 gdb_reinitialize_dir $srcdir/$subdir
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.
54 gdb_test "run" "Breakpoint 1, .* in foo.*" "Breakpoint at foo"
56 set test "stepi till main"
57 gdb_test_multiple "stepi" "${test}" {
58 -re ".*in foo.*$gdb_prompt $" {
60 exp_continue -continue_timer
62 -re ".*in bar.*$gdb_prompt $" {
65 -re ".*in main.*$gdb_prompt $" {
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.
75 proc get_addr_of_sym { sym } {
80 set test "get address of $sym"
81 gdb_test_multiple "print $sym" $test {
82 -re ".*($hex) <$sym>.*$gdb_prompt $" {
83 set addr $expect_out(1,string)
91 if { ! [ runto_main ] } then { gdb_suppress_tests; }
93 set foo [get_addr_of_sym "foo"]
94 set bar [get_addr_of_sym "bar"]
95 set foo_last "(bar - 4)"
97 gdb_breakpoint "*$foo_last"
99 gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*"
100 gdb_test "backtrace" "in foo.*in main.*" "Backtrace from last insn in foo"
101 gdb_test "stepi" "in foo.*" "stepi to nullified instruction stays in foo"
102 gdb_test "backtrace" "in foo.*in main.*" "Backtrace from nullified insn"
103 gdb_test "stepi" "in main.*" "stepi to main"
105 # In the third test, we verify that backtraces from nullified instructions
106 # work even in coredumps
108 proc gen_core { test } {
111 set gcore_works [gdb_gcore_cmd $gcorefile "$test: gcore"]
115 proc test_core_bt { test } {
118 gdb_test "core $gcorefile" "Core was generated by.*" \
119 "$test: load core file" "A program is being debugged already.*" "y"
121 gdb_test "backtrace" ".*in foo.*in main.*" "$test: backtrace in gcore"
124 set test "core at last insn in foo"
125 if { ! [ runto_main ] } then { gdb_suppress_tests; }
126 gdb_breakpoint "*$foo_last"
127 gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*" "$test: continue to breakpoint"
128 if [gen_core $test] {
132 set test "core at nullified insn"
133 if { ! [ runto_main ] } then { gdb_suppress_tests; }
134 gdb_breakpoint "*$foo_last"
135 gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*" "$test: continue to breakpoint"
136 gdb_test "stepi" ".*in foo.*" "$test: step to nullified instruction"
137 if [gen_core $test] {