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 # The "record goto" command jumps to a specific instruction in the execution
23 # trace. To guarantee that we always get the same execution trace, we use
24 # an assembly source file.
26 # We use different assembly sources based on the target architecture.
28 # Luckily, they are similar enough that a single test script can handle
31 if [info exists COMPILE] {
32 # make check RUNTESTFLAGS="gdb.btrace/record_goto.exp COMPILE=1"
33 standard_testfile record_goto.c
35 } elseif {[istarget "i?86-*-*"] || [istarget "x86_64-*-*"]} {
36 if {[is_amd64_regs_target]} {
37 standard_testfile x86_64-record_goto.S
39 standard_testfile i686-record_goto.S
42 unsupported "target architecture not supported"
46 if [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] {
54 # When GDB prints the file for a stop location, it may print the full path
55 # depending on what information the compiler added. This regexp allows for
56 # that path to be present, but does not require it.
57 set optional_filepath {[^\n]*}
59 # we want a small context sizes to simplify the test
60 gdb_test_no_output "set record instruction-history-size 3"
61 gdb_test_no_output "set record function-call-history-size 3"
63 # trace the call to the test function
64 gdb_test_no_output "record btrace"
67 # start by listing all functions
68 gdb_test "record function-call-history /ci 1, +20" [multi_line \
70 "2\t fun4\tinst 2,4" \
71 "3\t fun1\tinst 5,8" \
72 "4\t fun4\tinst 9,9" \
73 "5\t fun2\tinst 10,12" \
74 "6\t fun1\tinst 13,16" \
75 "7\t fun2\tinst 17,18" \
76 "8\t fun4\tinst 19,19" \
77 "9\t fun3\tinst 20,22" \
78 "10\t fun1\tinst 23,26" \
79 "11\t fun3\tinst 27,27" \
80 "12\t fun2\tinst 28,30" \
81 "13\t fun1\tinst 31,34" \
82 "14\t fun2\tinst 35,36" \
83 "15\t fun3\tinst 37,38" \
84 "16\t fun4\tinst 39,40" \
87 # let's see if we can go back in history
88 gdb_test "record goto 19" ".*fun4 \\(\\) at ${optional_filepath}record_goto.c:43.*"
90 # the function call history should start at the new location
91 gdb_test "record function-call-history /ci" [multi_line \
92 "8\t fun4\tinst 19,19" \
93 "9\t fun3\tinst 20,22" \
94 "10\t fun1\tinst 23,26" \
95 ] "function-call-history from 19 forwards"
97 # the instruction history should start at the new location
98 gdb_test "record instruction-history" [multi_line \
102 ] "instruction-history from 19 forwards"
104 # let's go to another place in the history
105 gdb_test "record goto 27" ".*fun3 \\(\\) at ${optional_filepath}record_goto.c:35.*"
107 # check the back trace at that location
108 gdb_test "backtrace" [multi_line \
109 "#0.*fun3.*at ${optional_filepath}record_goto.c:35.*" \
110 "#1.*fun4.*at ${optional_filepath}record_goto.c:43.*" \
111 "#2.*main.*at ${optional_filepath}record_goto.c:49.*" \
112 "Backtrace stopped: not enough registers or memory available to unwind further" \
116 gdb_test "up" ".*fun4.*at ${optional_filepath}record_goto.c:43.*" "up to fun4"
117 gdb_test "up" ".*main.*at ${optional_filepath}record_goto.c:49.*" "up to main"
119 # the function call history should start at the new location
120 gdb_test "record function-call-history /ci -" [multi_line \
121 "9\t fun3\tinst 20,22" \
122 "10\t fun1\tinst 23,26" \
123 "11\t fun3\tinst 27,27" \
124 ] "function-call-history from 27 backwards"
126 # the instruction history should start at the new location
127 gdb_test "record instruction-history -" [multi_line \
131 ] "instruction-history from 27 backwards"
133 # test that we can go to the begin of the trace
134 gdb_test "record goto begin" ".*main \\(\\) at ${optional_filepath}record_goto.c:49.*"
136 # check that we're filling up the context correctly
137 gdb_test "record function-call-history /ci -" [multi_line \
138 "1\tmain\tinst 1,1" \
139 "2\t fun4\tinst 2,4" \
140 "3\t fun1\tinst 5,8" \
141 ] "function-call-history from begin backwards"
143 # check that we're filling up the context correctly
144 gdb_test "record instruction-history -" [multi_line \
148 ] "instruction-history from begin backwards"
150 # we should get the exact same history from the first instruction
151 gdb_test "record goto 2" ".*fun4 \\(\\) at ${optional_filepath}record_goto.c:40.*"
153 # check that we're filling up the context correctly
154 gdb_test "record function-call-history /ci -" [multi_line \
155 "1\tmain\tinst 1,1" \
156 "2\t fun4\tinst 2,4" \
157 "3\t fun1\tinst 5,8" \
158 ] "function-call-history from 2 backwards"
160 # check that we're filling up the context correctly
161 gdb_test "record instruction-history -" [multi_line \
165 ] "instruction-history from 2 backwards"
167 # check that we can go to the end of the trace
168 gdb_test "record goto end" ".*main \\(\\) at ${optional_filepath}record_goto.c:50.*"
170 # check that we're filling up the context correctly
171 gdb_test "record function-call-history /ci" [multi_line \
172 "14\t fun2\tinst 35,36" \
173 "15\t fun3\tinst 37,38" \
174 "16\t fun4\tinst 39,40" \
175 ] "function-call-history from end forwards"
177 # check that we're filling up the context correctly
178 gdb_test "record instruction-history" [multi_line \
182 ] "instruction-history from end forwards"
184 # we should get the exact same history from the second to last instruction
185 gdb_test "record goto 39" ".*fun4 \\(\\) at ${optional_filepath}record_goto.c:44.*"
187 # check that we're filling up the context correctly
188 gdb_test "record function-call-history /ci" [multi_line \
189 "14\t fun2\tinst 35,36" \
190 "15\t fun3\tinst 37,38" \
191 "16\t fun4\tinst 39,40" \
192 ] "function-call-history from 39 forwards"
194 # check that we're filling up the context correctly
195 gdb_test "record instruction-history" [multi_line \
199 ] "instruction-history from 39 forwards"