]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.btrace/function_call_history.exp
Update copyright year range in all GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.btrace / function_call_history.exp
CommitLineData
2f1d9bdd
MM
1# This testcase is part of GDB, the GNU debugger.
2#
42a4f53d 3# Copyright 2013-2019 Free Software Foundation, Inc.
2f1d9bdd
MM
4#
5# Contributed by Intel Corp. <christian.himpel@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}
2f1d9bdd 24
2f1d9bdd 25standard_testfile
5b362f04 26if [prepare_for_testing "failed to prepare" $testfile {} {debug}] {
2f1d9bdd
MM
27 return -1
28}
b5ac99b0 29
2f1d9bdd 30if ![runto_main] {
b5ac99b0 31 untested "failed to run to main"
2f1d9bdd
MM
32 return -1
33}
34
35# start btrace
36gdb_test_no_output "record btrace"
37
38# set bp after increment loop and continue
39set bp_location [gdb_get_line_number "bp.1" $testfile.c]
40gdb_breakpoint $bp_location
41gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*"
42
724c7dd8 43proc rec_fun_all {} {
3c724c8c 44 gdb_test "record function-call-history 1" [multi_line \
5de9129b
MM
45 "1\tmain" \
46 "2\tinc" \
47 "3\tmain" \
48 "4\tinc" \
49 "5\tmain" \
50 "6\tinc" \
51 "7\tmain" \
52 "8\tinc" \
53 "9\tmain" \
54 "10\tinc" \
55 "11\tmain" \
56 "12\tinc" \
57 "13\tmain" \
58 "14\tinc" \
59 "15\tmain" \
60 "16\tinc" \
61 "17\tmain" \
62 "18\tinc" \
63 "19\tmain" \
64 "20\tinc" \
3c724c8c 65 "21\tmain"]
724c7dd8
MM
66}
67
2f1d9bdd
MM
68# show function call history with unlimited size, we expect to see all 21 entries
69gdb_test_no_output "set record function-call-history-size 0"
724c7dd8 70with_test_prefix "size unlimited" rec_fun_all
2f1d9bdd
MM
71
72# show function call history with size of 21, we expect to see all 21 entries
73gdb_test_no_output "set record function-call-history-size 21"
724c7dd8 74with_test_prefix "size 21" rec_fun_all
2f1d9bdd
MM
75
76# show first 15 entries
77gdb_test_no_output "set record function-call-history-size 15"
3c724c8c 78gdb_test "record function-call-history 1" [multi_line \
5de9129b
MM
79 "1\tmain" \
80 "2\tinc" \
81 "3\tmain" \
82 "4\tinc" \
83 "5\tmain" \
84 "6\tinc" \
85 "7\tmain" \
86 "8\tinc" \
87 "9\tmain" \
88 "10\tinc" \
89 "11\tmain" \
90 "12\tinc" \
91 "13\tmain" \
92 "14\tinc" \
3c724c8c 93 "15\tmain"] "forward - 1"
2f1d9bdd
MM
94
95# show last 6 entries
3c724c8c 96gdb_test "record function-call-history +" [multi_line \
5de9129b
MM
97 "16\tinc" \
98 "17\tmain" \
99 "18\tinc" \
100 "19\tmain" \
101 "20\tinc" \
3c724c8c 102 "21\tmain"] "forward - 2"
2f1d9bdd
MM
103
104# moving further should not work
724c7dd8 105gdb_test "record function-call-history +" "At the end of the branch trace record\\." "forward - 3"
2f1d9bdd
MM
106
107# make sure we cannot move any further a second time
724c7dd8 108gdb_test "record function-call-history +" "At the end of the branch trace record\\." "forward - 4"
2f1d9bdd
MM
109
110# moving back showing the latest 15 function calls
3c724c8c 111gdb_test "record function-call-history -" [multi_line \
5de9129b
MM
112 "7\tmain" \
113 "8\tinc" \
114 "9\tmain" \
115 "10\tinc" \
116 "11\tmain" \
117 "12\tinc" \
118 "13\tmain" \
119 "14\tinc" \
120 "15\tmain" \
121 "16\tinc" \
122 "17\tmain" \
123 "18\tinc" \
124 "19\tmain" \
125 "20\tinc" \
3c724c8c 126 "21\tmain"] "backward - 1"
2f1d9bdd
MM
127
128# moving further back shows the 6 first function calls
3c724c8c 129gdb_test "record function-call-history -" [multi_line \
5de9129b
MM
130 "1\tmain" \
131 "2\tinc" \
132 "3\tmain" \
133 "4\tinc" \
134 "5\tmain" \
3c724c8c 135 "6\tinc"] "backward - 2"
2f1d9bdd
MM
136
137# moving further back shouldn't work
724c7dd8 138gdb_test "record function-call-history -" "At the start of the branch trace record\\." "backward - 3"
2f1d9bdd
MM
139
140# make sure we cannot move any further back
724c7dd8 141gdb_test "record function-call-history -" "At the start of the branch trace record\\." "backward - 4"
2f1d9bdd 142
8710b709
MM
143# don't mess around with path names
144gdb_test_no_output "set filename-display basename"
145
2f1d9bdd 146# moving forward again, but this time with file and line number, expected to see the first 15 entries
3c724c8c 147gdb_test "record function-call-history /l +" [multi_line \
8710b709
MM
148 "\[0-9\]*\tmain\tat $srcfile:40,41" \
149 "\[0-9\]*\tinc\tat $srcfile:22,24" \
150 "\[0-9\]*\tmain\tat $srcfile:40,41" \
151 "\[0-9\]*\tinc\tat $srcfile:22,24" \
152 "\[0-9\]*\tmain\tat $srcfile:40,41" \
153 "\[0-9\]*\tinc\tat $srcfile:22,24" \
154 "\[0-9\]*\tmain\tat $srcfile:40,41" \
155 "\[0-9\]*\tinc\tat $srcfile:22,24" \
156 "\[0-9\]*\tmain\tat $srcfile:40,41" \
157 "\[0-9\]*\tinc\tat $srcfile:22,24" \
158 "\[0-9\]*\tmain\tat $srcfile:40,41" \
159 "\[0-9\]*\tinc\tat $srcfile:22,24" \
160 "\[0-9\]*\tmain\tat $srcfile:40,41" \
161 "\[0-9\]*\tinc\tat $srcfile:22,24" \
162 "\[0-9\]*\tmain\tat $srcfile:40,41" \
3c724c8c 163 ] "forward /l - 1"
2f1d9bdd
MM
164
165# moving forward and expect to see the latest 6 entries
3c724c8c 166gdb_test "record function-call-history /l +" [multi_line \
8710b709
MM
167 "\[0-9\]*\tinc\tat $srcfile:22,24" \
168 "\[0-9\]*\tmain\tat $srcfile:40,41" \
169 "\[0-9\]*\tinc\tat $srcfile:22,24" \
170 "\[0-9\]*\tmain\tat $srcfile:40,41" \
171 "\[0-9\]*\tinc\tat $srcfile:22,24" \
172 "\[0-9\]*\tmain\tat $srcfile:40,43" \
3c724c8c 173 ] "forward /l - 2"
2f1d9bdd
MM
174
175# moving further forward shouldn't work
724c7dd8
MM
176gdb_test "record function-call-history /l +" "At the end of the branch trace record\\." "forward /l - 3"
177gdb_test "record function-call-history /l" "At the end of the branch trace record\\." "forward /l - 4"
178
3c724c8c 179set expected_range [multi_line \
5de9129b
MM
180 "4\tinc" \
181 "5\tmain" \
182 "6\tinc" \
183 "7\tmain" \
184 "8\tinc" \
185 "9\tmain" \
3c724c8c 186 "10\tinc"]
2f1d9bdd
MM
187
188# show functions in instruction range
0688d04e 189gdb_test "record function-call-history 4,10" $expected_range
5de9129b 190gdb_test "record function-call-history 4,+7" $expected_range
0688d04e
MM
191gdb_test "record function-call-history 10,-7" $expected_range
192gdb_test "record function-call-history 4,4" "4\tinc\r"
2f1d9bdd
MM
193
194# set bp after fib recursion and continue
195set bp_location [gdb_get_line_number "bp.2" $testfile.c]
196gdb_breakpoint $bp_location
197gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*"
198
23a7fe75
MM
199# at this point we expect to have main, fib, ..., fib, main, where fib occurs 9 times,
200# so we limit the output to only show the latest 11 function calls
201gdb_test_no_output "set record function-call-history-size 11"
3c724c8c 202gdb_test "record function-call-history" [multi_line \
5de9129b 203 "21\tmain" \
23a7fe75
MM
204 "22\tfib" \
205 "23\tfib" \
206 "24\tfib" \
207 "25\tfib" \
208 "26\tfib" \
209 "27\tfib" \
210 "28\tfib" \
211 "29\tfib" \
5de9129b 212 "30\tfib" \
3c724c8c 213 "31\tmain"] "recursive"
8710b709
MM
214
215# show indented function call history for fib
3c724c8c 216gdb_test "record function-call-history /c 21, +11" [multi_line \
8710b709
MM
217 "21\tmain" \
218 "22\t fib" \
219 "23\t fib" \
220 "24\t fib" \
221 "25\t fib" \
222 "26\t fib" \
223 "27\t fib" \
224 "28\t fib" \
225 "29\t fib" \
226 "30\t fib" \
227 "31\tmain" \
3c724c8c 228 ] "indented"
8710b709
MM
229
230# make sure we can handle incomplete trace with respect to indentation
231if ![runto_main] {
b5ac99b0 232 untested "failed to run to main"
8710b709
MM
233 return -1
234}
235# navigate to the fib in line 24 above
236gdb_breakpoint fib
237gdb_continue_to_breakpoint "cont to fib.1"
238gdb_continue_to_breakpoint "cont to fib.2"
239gdb_continue_to_breakpoint "cont to fib.3"
240gdb_continue_to_breakpoint "cont to fib.4"
241
242# start tracing
243gdb_test_no_output "record btrace"
244
245# continue until line 30 above
246delete_breakpoints
247set bp_location [gdb_get_line_number "bp.2" $testfile.c]
248gdb_breakpoint $bp_location
249gdb_continue_to_breakpoint "cont to bp.2" ".*$testfile.c:$bp_location\r\n.*"
250
251# let's look at the trace. we expect to see the tail of the above listing.
3c724c8c 252gdb_test "record function-call-history /c" [multi_line \
8710b709
MM
253 "1\t fib" \
254 "2\t fib" \
255 "3\t fib" \
256 "4\t fib" \
257 "5\t fib" \
258 "6\tmain" \
3c724c8c 259 ] "indented tail"