Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2004-2020 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 | ||
fe46cd3a RC |
18 | |
19 | # Test handling of nullified instructions for the pa target. | |
20 | ||
8117349c RC |
21 | switch -glob -- [istarget] { |
22 | "hppa-*-*" { | |
23 | set testfile "pa-nullify" | |
24 | } | |
25 | "hppa64-*-*" { | |
26 | set testfile "pa64-nullify" | |
27 | } | |
28 | "*" { | |
29 | verbose "Skipping hppa nullification tests." | |
30 | return | |
31 | } | |
fe46cd3a RC |
32 | } |
33 | ||
fe46cd3a RC |
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 {}] != "" } { | |
84c93cd5 | 39 | unsupported "failed to compile" |
fe46cd3a RC |
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 | |
cdc7edd7 | 54 | gdb_test "run" "Breakpoint 1, .* in foo.*" "breakpoint at foo" |
fe46cd3a RC |
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" | |
fe46cd3a RC |
81 | gdb_test_multiple "print $sym" $test { |
82 | -re ".*($hex) <$sym>.*$gdb_prompt $" { | |
83 | set addr $expect_out(1,string) | |
84 | pass $test | |
85 | } | |
86 | } | |
87 | ||
88 | return $addr | |
89 | } | |
90 | ||
c8ee3f04 PW |
91 | if ![runto_main] then { |
92 | fail "can't run to main" | |
93 | return 0 | |
94 | } | |
fe46cd3a RC |
95 | |
96 | set foo [get_addr_of_sym "foo"] | |
97 | set bar [get_addr_of_sym "bar"] | |
8117349c | 98 | set foo_last "(bar - 4)" |
fe46cd3a RC |
99 | |
100 | gdb_breakpoint "*$foo_last" | |
101 | ||
102 | gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*" | |
cdc7edd7 | 103 | gdb_test "backtrace" "in foo.*in main.*" "backtrace from last insn in foo" |
fe46cd3a | 104 | gdb_test "stepi" "in foo.*" "stepi to nullified instruction stays in foo" |
cdc7edd7 | 105 | gdb_test "backtrace" "in foo.*in main.*" "backtrace from nullified insn" |
fe46cd3a RC |
106 | gdb_test "stepi" "in main.*" "stepi to main" |
107 | ||
108 | # In the third test, we verify that backtraces from nullified instructions | |
109 | # work even in coredumps | |
110 | ||
111 | proc gen_core { test } { | |
112 | global gcorefile | |
fe46cd3a | 113 | |
2d338fa9 | 114 | set gcore_works [gdb_gcore_cmd $gcorefile "$test: gcore"] |
fe46cd3a RC |
115 | return $gcore_works |
116 | } | |
117 | ||
118 | proc test_core_bt { test } { | |
119 | global gcorefile | |
120 | ||
121 | gdb_test "core $gcorefile" "Core was generated by.*" \ | |
122 | "$test: load core file" "A program is being debugged already.*" "y" | |
123 | ||
124 | gdb_test "backtrace" ".*in foo.*in main.*" "$test: backtrace in gcore" | |
125 | } | |
126 | ||
127 | set test "core at last insn in foo" | |
c8ee3f04 PW |
128 | if ![runto_main] then { |
129 | fail "can't run to main" | |
130 | return 0 | |
131 | } | |
fe46cd3a RC |
132 | gdb_breakpoint "*$foo_last" |
133 | gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*" "$test: continue to breakpoint" | |
134 | if [gen_core $test] { | |
135 | test_core_bt $test | |
136 | } | |
137 | ||
138 | set test "core at nullified insn" | |
c8ee3f04 PW |
139 | if ![runto_main] then { |
140 | fail "can't run to main" | |
141 | return 0 | |
142 | } | |
fe46cd3a RC |
143 | gdb_breakpoint "*$foo_last" |
144 | gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*" "$test: continue to breakpoint" | |
145 | gdb_test "stepi" ".*in foo.*" "$test: step to nullified instruction" | |
146 | if [gen_core $test] { | |
147 | test_core_bt $test | |
148 | } |