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