aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/step-indirect-call-thunk.exp
blob: d84a02322652fe460d8eb60ea3f8e2e1188a13a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Copyright 2018-2021 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

standard_testfile

set cflags "-mindirect-branch=thunk -mfunction-return=thunk"
if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
        [list debug "additional_flags=$cflags"]] } {
    return -1
}

if { ![runto_main] } {
    untested "failed to run to main"
    return -1
}

# Do repeated instruction steps in order to reach TARGET from CURRENT
#
#  CURRENT is a string matching the current location
#  TARGET  is a string matching the target location
#  TEST    is the test name
#
# The function issues repeated "stepi" commands as long as the location
# matches CURRENT up to a maximum of 100 steps.
#
# TEST passes if the resulting location matches TARGET and fails
# otherwise.
#
proc stepi_until { current target test } {
    global gdb_prompt

    set count 0
    gdb_test_multiple "stepi" "$test" {
        -re "$current.*$gdb_prompt $" {
            incr count
            if { $count < 100 } {
                send_gdb "stepi\n"
                exp_continue
            } else {
                fail "$test"
            }
        }
        -re "$target.*$gdb_prompt $" {
            pass "$test"
        }
    }
}

# Normal stepping steps through all thunks.
gdb_test "step" "thrice\.2.*" "step into thrice"
gdb_test "next" "thrice\.3.*" "step through thunks and over inc"
gdb_test "step" "inc\.2.*" "step through call thunk into inc"
gdb_test "step" "inc\.3.*" "step inside inc"
gdb_test "step" "thrice\.4.*" "step through return thunk back into thrice"

# We can use instruction stepping to step into thunks.
stepi_until "thrice" "indirect_thunk" "stepi into call thunk"
stepi_until "indirect_thunk" "inc." "stepi out of call thunk into inc"
stepi_until "inc" "return_thunk" "stepi into return thunk"
stepi_until "return_thunk" "thrice" \
    "stepi out of return thunk back into thrice"