Add translations for various sub-directories
[binutils-gdb.git] / gdb / testsuite / gdb.btrace / stepi.exp
blob689bc792b24a6ac2ea438d152c44616cf596ed04
1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2013-2024 Free Software Foundation, Inc.
5 # Contributed by Intel Corp. <markus.t.metzger@intel.com>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 require allow_btrace_tests
22 # This test is stepping on instruction level.  To guarantee that we always
23 # get the same execution trace, we use an assembly source file.
25 # We use different assembly sources based on the target architecture.
27 # Luckily, they are similar enough that a single test script can handle
28 # both.
29 if [info exists COMPILE] {
30     # make check RUNTESTFLAGS="gdb.btrace/stepi.exp COMPILE=1"
31     standard_testfile record_goto.c
32     lappend opts debug
33 } elseif {[istarget "i?86-*-*"] || [istarget "x86_64-*-*"]} {
34         if {[is_amd64_regs_target]} {
35                 standard_testfile x86_64-record_goto.S
36         } else {
37                 standard_testfile i686-record_goto.S
38         }
39 } else {
40     unsupported "target architecture not supported"
41     return -1
44 if [prepare_for_testing "failed to prepare" $testfile $srcfile {}] {
45     return -1
48 if ![runto_main] {
49     return -1
52 global gdb_prompt
54 proc check_replay_at { insn } {
55   gdb_test "info record" [multi_line \
56     "Active record target: record-btrace" \
57     ".*" \
58     "Recorded 40 instructions in 16 functions \\\(0 gaps\\\) for .*" \
59     "Replay in progress\.  At instruction $insn\." \
60     ] "check replay at $insn"
63 # trace the call to the test function
64 with_test_prefix "record" {
65     gdb_test_no_output "record btrace"
66     gdb_test "next" ".*" "next.1"
69 # we start with stepping to make sure that the trace is fetched automatically
70 with_test_prefix "fetch" {
71     gdb_test "reverse-stepi" ".*fun4\.5.*" "reverse-stepi.1"
72     gdb_test "reverse-stepi" ".*fun4\.5.*" "reverse-stepi.2"
74     # let's check where we are in the trace
75     check_replay_at 39
78 # let's step forward and check again
79 with_test_prefix "stepi" {
80     gdb_test "stepi" ".*fun4\.5.*"
81     check_replay_at 40
84 # with the next step, we stop replaying
85 with_test_prefix "end" {
86     gdb_test "stepi" ".*main\.3.*"
87     gdb_test "info record" [multi_line \
88       "Active record target: record-btrace" \
89       ".*" \
90       "Recorded 40 instructions in 16 functions \\\(0 gaps\\\) for \[^\\\r\\\n\]*" \
91                                ]
94 # let's try nexti
95 with_test_prefix "reverse-nexti.1" {
96     gdb_test "reverse-nexti" ".*main\.2.*"
97     check_replay_at 1
100 # we can't reverse-nexti any further
101 with_test_prefix "reverse-nexti.2" {
102     gdb_test "reverse-nexti" \
103         "Reached end of recorded history; stopping\.\r\n.*main\.2.*" \
104         "reverse-nexti.2"
105     check_replay_at 1
108 # but we can step back again
109 with_test_prefix "nexti" {
110     gdb_test "nexti" ".*main\.3.*"
111     gdb_test "info record" [multi_line \
112       "Active record target: record-btrace" \
113       ".*" \
114       "Recorded 40 instructions in 16 functions \\\(0 gaps\\\) for \[^\\\r\\\n\]*" \
115                                ]
118 # let's step from a goto position somewhere in the middle
119 with_test_prefix "goto" {
120     gdb_test "record goto 22" ".*fun3\.2.*"
121     with_test_prefix "goto 22" { check_replay_at 22 }
123     gdb_test "stepi" ".*fun1\.1.*" "stepi.3"
124     with_test_prefix "stepi to 23" { check_replay_at 23 }
126     gdb_test "reverse-stepi" ".*fun3\.2.*" "reverse-stepi.3"
127     with_test_prefix "reverse-stepi to 22" { check_replay_at 22 }
129     gdb_test "nexti" ".*fun3\.3.*"
130     with_test_prefix "nexti to 27" { check_replay_at 27 }
132     gdb_test "reverse-nexti" ".*fun3\.2.*" "reverse-nexti.3"
133     with_test_prefix "reverse-nexti to 22" { check_replay_at 22 }
136 # let's try to step off the left end
137 with_test_prefix "goto begin" {
138     gdb_test "record goto begin" ".*main\.2.*"
139     check_replay_at 1
141     with_test_prefix "reverse-stepi" {
142         gdb_test "reverse-stepi" \
143             "Reached end of recorded history; stopping\.\r\n.*main\.2.*" \
144             "reverse-stepi.1"
145         gdb_test "reverse-stepi" \
146             "Reached end of recorded history; stopping\.\r\n.*main\.2.*" \
147             "reverse-stepi.2"
148         check_replay_at 1
149     }
151     with_test_prefix "reverse-nexti" {
152         gdb_test "reverse-nexti" \
153             "Reached end of recorded history; stopping\.\r\n.*main\.2.*" \
154             "reverse-nexti.1"
155         gdb_test "reverse-nexti" \
156             "Reached end of recorded history; stopping\.\r\n.*main\.2.*" \
157             "reverse-nexti.2"
158         check_replay_at 1
159     }
161     # we can step forward, though
162     with_test_prefix "stepi" {
163         gdb_test "stepi" ".*fun4\.1.*"
164         check_replay_at 2
165     }
168 # let's try to step off the left end again
169 with_test_prefix "reverse-stepi" {
170     gdb_test "reverse-stepi" ".*main\.2.*" "reverse-stepi.1"
171     gdb_test "reverse-stepi" \
172         "Reached end of recorded history; stopping\.\r\n.*main\.2.*" \
173         "reverse-stepi.2"
174     gdb_test "reverse-stepi" \
175         "Reached end of recorded history; stopping\.\r\n.*main\.2.*" \
176         "reverse-stepi.3"
177     check_replay_at 1