Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.btrace / record_goto.exp
CommitLineData
066ce621
MM
1# This testcase is part of GDB, the GNU debugger.
2#
88b9d363 3# Copyright 2013-2022 Free Software Foundation, Inc.
066ce621
MM
4#
5# Contributed by Intel Corp. <markus.t.metzger@intel.com>
6#
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.
11#
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.
16#
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/>.
19
b5ac99b0
MM
20if { [skip_btrace_tests] } {
21 unsupported "target does not support record-btrace"
22 return -1
23}
066ce621 24
66849923
MM
25# The "record goto" command jumps to a specific instruction in the execution
26# trace. To guarantee that we always get the same execution trace, we use
27# an assembly source file.
28#
29# We use different assembly sources based on the target architecture.
30#
31# Luckily, they are similar enough that a single test script can handle
32# both.
066ce621
MM
33set opts {}
34if [info exists COMPILE] {
35 # make check RUNTESTFLAGS="gdb.btrace/record_goto.exp COMPILE=1"
36 standard_testfile record_goto.c
37 lappend opts debug
e0461dbb
MM
38} elseif {[istarget "i?86-*-*"] || [istarget "x86_64-*-*"]} {
39 if {[is_amd64_regs_target]} {
40 standard_testfile x86_64-record_goto.S
41 } else {
42 standard_testfile i686-record_goto.S
43 }
66849923 44} else {
b5ac99b0 45 unsupported "target architecture not supported"
66849923 46 return -1
066ce621
MM
47}
48
5b362f04 49if [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] {
066ce621
MM
50 return -1
51}
b5ac99b0 52
066ce621 53if ![runto_main] {
b5ac99b0 54 untested "failed to run to main"
066ce621
MM
55 return -1
56}
57
58# we want a small context sizes to simplify the test
59gdb_test_no_output "set record instruction-history-size 3"
60gdb_test_no_output "set record function-call-history-size 3"
61
62# trace the call to the test function
63gdb_test_no_output "record btrace"
64gdb_test "next"
65
66# start by listing all functions
3c724c8c 67gdb_test "record function-call-history /ci 1, +20" [multi_line \
6e07b1d2
MM
68 "1\tmain\tinst 1,1" \
69 "2\t fun4\tinst 2,4" \
70 "3\t fun1\tinst 5,8" \
71 "4\t fun4\tinst 9,9" \
72 "5\t fun2\tinst 10,12" \
73 "6\t fun1\tinst 13,16" \
74 "7\t fun2\tinst 17,18" \
75 "8\t fun4\tinst 19,19" \
76 "9\t fun3\tinst 20,22" \
77 "10\t fun1\tinst 23,26" \
78 "11\t fun3\tinst 27,27" \
79 "12\t fun2\tinst 28,30" \
80 "13\t fun1\tinst 31,34" \
81 "14\t fun2\tinst 35,36" \
82 "15\t fun3\tinst 37,38" \
83 "16\t fun4\tinst 39,40" \
3c724c8c 84 ]
066ce621
MM
85
86# let's see if we can go back in history
6e07b1d2 87gdb_test "record goto 19" ".*fun4 \\(\\) at record_goto.c:43.*"
066ce621
MM
88
89# the function call history should start at the new location
3c724c8c 90gdb_test "record function-call-history /ci" [multi_line \
6e07b1d2
MM
91 "8\t fun4\tinst 19,19" \
92 "9\t fun3\tinst 20,22" \
93 "10\t fun1\tinst 23,26" \
3c724c8c 94 ] "function-call-history from 19 forwards"
066ce621
MM
95
96# the instruction history should start at the new location
3c724c8c 97gdb_test "record instruction-history" [multi_line \
066ce621
MM
98 "19.*" \
99 "20.*" \
6e07b1d2 100 "21.*" \
3c724c8c 101 ] "instruction-history from 19 forwards"
066ce621
MM
102
103# let's go to another place in the history
6e07b1d2 104gdb_test "record goto 27" ".*fun3 \\(\\) at record_goto.c:35.*"
066ce621 105
0b722aec 106# check the back trace at that location
3c724c8c 107gdb_test "backtrace" [multi_line \
0b722aec
MM
108 "#0.*fun3.*at record_goto.c:35.*" \
109 "#1.*fun4.*at record_goto.c:43.*" \
110 "#2.*main.*at record_goto.c:49.*" \
111 "Backtrace stopped: not enough registers or memory available to unwind further" \
3c724c8c 112 ]
0b722aec
MM
113
114# walk the backtrace
115gdb_test "up" ".*fun4.*at record_goto.c:43.*" "up to fun4"
116gdb_test "up" ".*main.*at record_goto.c:49.*" "up to main"
117
066ce621 118# the function call history should start at the new location
3c724c8c 119gdb_test "record function-call-history /ci -" [multi_line \
6e07b1d2
MM
120 "9\t fun3\tinst 20,22" \
121 "10\t fun1\tinst 23,26" \
122 "11\t fun3\tinst 27,27" \
3c724c8c 123 ] "function-call-history from 27 backwards"
066ce621
MM
124
125# the instruction history should start at the new location
3c724c8c 126gdb_test "record instruction-history -" [multi_line \
066ce621 127 "25.*" \
6e07b1d2
MM
128 "26.*" \
129 "27.*" \
3c724c8c 130 ] "instruction-history from 27 backwards"
066ce621
MM
131
132# test that we can go to the begin of the trace
6e07b1d2 133gdb_test "record goto begin" ".*main \\(\\) at record_goto.c:49.*"
066ce621
MM
134
135# check that we're filling up the context correctly
3c724c8c 136gdb_test "record function-call-history /ci -" [multi_line \
6e07b1d2
MM
137 "1\tmain\tinst 1,1" \
138 "2\t fun4\tinst 2,4" \
139 "3\t fun1\tinst 5,8" \
3c724c8c 140 ] "function-call-history from begin backwards"
066ce621
MM
141
142# check that we're filling up the context correctly
3c724c8c 143gdb_test "record instruction-history -" [multi_line \
066ce621
MM
144 "1.*" \
145 "2.*" \
146 "3.*" \
3c724c8c 147 ] "instruction-history from begin backwards"
066ce621
MM
148
149# we should get the exact same history from the first instruction
150gdb_test "record goto 2" ".*fun4 \\(\\) at record_goto.c:40.*"
151
152# check that we're filling up the context correctly
3c724c8c 153gdb_test "record function-call-history /ci -" [multi_line \
6e07b1d2
MM
154 "1\tmain\tinst 1,1" \
155 "2\t fun4\tinst 2,4" \
156 "3\t fun1\tinst 5,8\r" \
3c724c8c 157 ] "function-call-history from 2 backwards"
066ce621
MM
158
159# check that we're filling up the context correctly
3c724c8c 160gdb_test "record instruction-history -" [multi_line \
066ce621
MM
161 "1.*" \
162 "2.*" \
163 "3.*" \
3c724c8c 164 ] "instruction-history from 2 backwards"
066ce621
MM
165
166# check that we can go to the end of the trace
167gdb_test "record goto end" ".*main \\(\\) at record_goto.c:50.*"
168
169# check that we're filling up the context correctly
3c724c8c 170gdb_test "record function-call-history /ci" [multi_line \
6e07b1d2
MM
171 "14\t fun2\tinst 35,36" \
172 "15\t fun3\tinst 37,38" \
173 "16\t fun4\tinst 39,40" \
3c724c8c 174 ] "function-call-history from end forwards"
066ce621
MM
175
176# check that we're filling up the context correctly
3c724c8c 177gdb_test "record instruction-history" [multi_line \
066ce621
MM
178 "38.*" \
179 "39.*" \
6e07b1d2 180 "40.*\r" \
3c724c8c 181 ] "instruction-history from end forwards"
066ce621
MM
182
183# we should get the exact same history from the second to last instruction
6e07b1d2 184gdb_test "record goto 39" ".*fun4 \\(\\) at record_goto.c:44.*"
066ce621
MM
185
186# check that we're filling up the context correctly
3c724c8c 187gdb_test "record function-call-history /ci" [multi_line \
6e07b1d2
MM
188 "14\t fun2\tinst 35,36" \
189 "15\t fun3\tinst 37,38" \
190 "16\t fun4\tinst 39,40\r" \
3c724c8c 191 ] "function-call-history from 39 forwards"
066ce621
MM
192
193# check that we're filling up the context correctly
3c724c8c 194gdb_test "record instruction-history" [multi_line \
066ce621
MM
195 "38.*" \
196 "39.*" \
6e07b1d2 197 "40.*\r" \
3c724c8c 198 ] "instruction-history from 39 forwards"
This page took 1.122799 seconds and 4 git commands to generate.