Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.base / step-indirect-call-thunk.exp
blob94da7e7ce970079786a440afd3f6446295741e1a
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 standard_testfile
18 if { ![istarget "x86*"] } {
19     return
22 set cflags "-mindirect-branch=thunk -mfunction-return=thunk"
24 if { [gcc_major_version] >= 8 } {
25     append cflags " -fcf-protection=none"
27 if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
28         [list debug "additional_flags=$cflags"]] } {
29     return -1
32 if { ![runto_main] } {
33     return -1
36 # Do repeated instruction steps in order to reach TARGET from CURRENT
38 #  CURRENT is a string matching the current location
39 #  TARGET  is a string matching the target location
40 #  TEST    is the test name
42 # The function issues repeated "stepi" commands as long as the location
43 # matches CURRENT up to a maximum of 100 steps.
45 # TEST passes if the resulting location matches TARGET and fails
46 # otherwise.
48 proc stepi_until { current target test } {
49     global gdb_prompt
51     set count 0
52     gdb_test_multiple "stepi" "$test" {
53         -re "$current.*$gdb_prompt $" {
54             incr count
55             if { $count < 100 } {
56                 send_gdb "stepi\n"
57                 exp_continue
58             } else {
59                 fail "$test"
60             }
61         }
62         -re "$target.*$gdb_prompt $" {
63             pass "$test"
64         }
65     }
68 # Normal stepping steps through all thunks.
69 gdb_test "step" "thrice\.2.*" "step into thrice"
70 gdb_test "next" "thrice\.3.*" "step through thunks and over inc"
71 gdb_test "step" "inc\.2.*" "step through call thunk into inc"
72 gdb_test "step" "inc\.3.*" "step inside inc"
73 gdb_test "step" "thrice\.4.*" "step through return thunk back into thrice"
75 set alphanum_re "\[a-zA-Z0-9\]"
76 set pic_thunk_re  "__$alphanum_re*\\.get_pc_thunk\\.$alphanum_re* \\(\\)"
78 # We can use instruction stepping to step into thunks.
79 stepi_until "thrice" "indirect_thunk" "stepi into call thunk"
80 stepi_until "indirect_thunk" "inc." "stepi out of call thunk into inc"
81 stepi_until "(inc|$pic_thunk_re)" "return_thunk" "stepi into return thunk"
82 stepi_until "return_thunk" "thrice" \
83     "stepi out of return thunk back into thrice"