1 # Copyright 2018-2023 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 require supports_reverse
22 lappend cflags additional_flags=-mindirect-branch=thunk
23 lappend cflags additional_flags=-mfunction-return=thunk
25 set fcf_protection_none additional_flags=-fcf-protection=none
26 if { [gdb_can_simple_compile fcf-protection-none {int main () { return 0; }} \
27 executable $fcf_protection_none] } {
28 lappend cflags $fcf_protection_none
31 if { [prepare_for_testing "failed to prepare" $testfile $srcfile $cflags] } {
35 if { ![runto_main] } {
39 # Do repeated stepping COMMANDs in order to reach TARGET from CURRENT
41 # COMMAND is a stepping command
42 # CURRENT is a string matching the current location
43 # TARGET is a string matching the target location
44 # TEST is the test name
46 # The function issues repeated COMMANDs as long as the location matches
47 # CURRENT up to a maximum of 100 steps.
49 # TEST passes if the resulting location matches TARGET and fails
52 proc step_until { command current target test } {
56 gdb_test_multiple "$command" "$test" {
57 -re "$current.*$gdb_prompt $" {
66 -re "$target.*$gdb_prompt $" {
72 gdb_test_no_output "record"
73 gdb_test "next" ".*" "record trace"
75 # Normal stepping steps through all thunks.
76 gdb_test "reverse-step" "apply\.3.*" "reverse-step into apply"
77 gdb_test "reverse-step" "inc\.3.*" "reverse-step into inc"
78 gdb_test "reverse-step" "inc\.2.*" "reverse-step inside inc"
79 gdb_test "reverse-step" "apply\.2.*" \
80 "reverse-step through call thunk into apply, first time"
81 gdb_test "reverse-step" "main\.2.*" "reverse-step into main"
82 gdb_test "step" "apply\.2.*" "step into apply"
83 gdb_test "step" "inc\.2.*" "step through call thunk into inc"
84 gdb_test "reverse-step" "apply\.2.*" \
85 "reverse-step through call thunk into apply, second time"
86 gdb_test "next" "apply\.3.*" "step through thunks and over inc"
87 gdb_test "reverse-next" "apply\.2.*" \
88 "reverse-step through thunks and over inc"
90 # We can use instruction stepping to step into thunks.
91 step_until "stepi" "apply\.2" "indirect_thunk" "stepi into call thunk"
92 step_until "stepi" "indirect_thunk" "inc" \
93 "stepi out of call thunk into inc"
94 set alphanum_re "\[a-zA-Z0-9\]"
95 set pic_thunk_re "__$alphanum_re*\\.get_pc_thunk\\.$alphanum_re* \\(\\)"
96 step_until "stepi" "(inc|$pic_thunk_re)" "return_thunk" "stepi into return thunk"
97 step_until "stepi" "return_thunk" "apply" \
98 "stepi out of return thunk back into apply"
100 step_until "reverse-stepi" "apply" "return_thunk" \
101 "reverse-stepi into return thunk"
102 step_until "reverse-stepi" "return_thunk" "inc" \
103 "reverse-stepi out of return thunk into inc"
104 step_until "reverse-stepi" "(inc|$pic_thunk_re)" "indirect_thunk" \
105 "reverse-stepi into call thunk"
106 step_until "reverse-stepi" "indirect_thunk" "apply" \
107 "reverse-stepi out of call thunk into apply"