1 # Copyright 2018-2024 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 3 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, see <http://www.gnu.org/licenses/>. 15 16 require supports_reverse 17 18 require {istarget "x86*"} 19 20 standard_testfile 21 22 set cflags {} 23 lappend cflags debug 24 lappend cflags additional_flags=-mindirect-branch=thunk 25 lappend cflags additional_flags=-mfunction-return=thunk 26 27 set fcf_protection_none additional_flags=-fcf-protection=none 28 if { [gdb_can_simple_compile fcf-protection-none {int main () { return 0; }} \ 29 executable $fcf_protection_none] } { 30 lappend cflags $fcf_protection_none 31 } 32 33 if { [prepare_for_testing "failed to prepare" $testfile $srcfile $cflags] } { 34 return -1 35 } 36 37 if { ![runto_main] } { 38 return -1 39 } 40 41 gdb_test_no_output "record" 42 gdb_test "next" ".*" "record trace" 43 44 # Normal stepping steps through all thunks. 45 gdb_test "reverse-step" "apply\.3.*" "reverse-step into apply" 46 gdb_test "reverse-step" "inc\.3.*" "reverse-step into inc" 47 gdb_test "reverse-step" "inc\.2.*" "reverse-step inside inc" 48 gdb_test "reverse-step" "apply\.2.*" \ 49 "reverse-step through call thunk into apply, first time" 50 gdb_test "reverse-step" "main\.2.*" "reverse-step into main" 51 gdb_test "step" "apply\.2.*" "step into apply" 52 gdb_test "step" "inc\.2.*" "step through call thunk into inc" 53 gdb_test "reverse-step" "apply\.2.*" \ 54 "reverse-step through call thunk into apply, second time" 55 gdb_test "next" "apply\.3.*" "step through thunks and over inc" 56 gdb_test "reverse-next" "apply\.2.*" \ 57 "reverse-step through thunks and over inc" 58 59 # We can use instruction stepping to step into thunks. 60 repeat_cmd_until "stepi" "apply\.2" "indirect_thunk" "stepi into call thunk" 61 repeat_cmd_until "stepi" "indirect_thunk" "inc" \ 62 "stepi out of call thunk into inc" 63 set alphanum_re "\[a-zA-Z0-9\]" 64 set pic_thunk_re "__$alphanum_re*\\.get_pc_thunk\\.$alphanum_re* \\(\\)" 65 repeat_cmd_until "stepi" "(inc|$pic_thunk_re)" "return_thunk" "stepi into return thunk" 66 repeat_cmd_until "stepi" "return_thunk" "apply" \ 67 "stepi out of return thunk back into apply" 68 69 repeat_cmd_until "reverse-stepi" "apply" "return_thunk" \ 70 "reverse-stepi into return thunk" 71 repeat_cmd_until "reverse-stepi" "return_thunk" "inc" \ 72 "reverse-stepi out of return thunk into inc" 73 repeat_cmd_until "reverse-stepi" "(inc|$pic_thunk_re)" "indirect_thunk" \ 74 "reverse-stepi into call thunk" 75 repeat_cmd_until "reverse-stepi" "indirect_thunk" "apply" \ 76 "reverse-stepi out of call thunk into apply" 77