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