1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2013-2023 Free Software Foundation, Inc.
5 # Contributed by Intel Corp. <christian.himpel@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 if { [skip_btrace_tests] } {
21 unsupported "target does not support record-btrace"
25 # We expect a specific function call history. This gets messed up with
28 if [prepare_for_testing "failed to prepare" $testfile {} {nopie debug}] {
37 gdb_test_no_output "record btrace"
39 # set bp after increment loop and continue
40 set bp_location [gdb_get_line_number "bp.1" $testfile.c]
41 gdb_breakpoint $bp_location
42 gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*"
45 gdb_test "record function-call-history 1" [multi_line \
69 # show function call history with unlimited size, we expect to see all 21 entries
70 gdb_test_no_output "set record function-call-history-size 0"
71 with_test_prefix "size unlimited" rec_fun_all
73 # show function call history with size of 21, we expect to see all 21 entries
74 gdb_test_no_output "set record function-call-history-size 21"
75 with_test_prefix "size 21" rec_fun_all
77 # show first 15 entries
78 gdb_test_no_output "set record function-call-history-size 15"
79 gdb_test "record function-call-history 1" [multi_line \
94 "15\tmain"] "forward - 1"
97 gdb_test "record function-call-history +" [multi_line \
103 "21\tmain"] "forward - 2"
105 # moving further should not work
106 gdb_test "record function-call-history +" "At the end of the branch trace record\\." "forward - 3"
108 # make sure we cannot move any further a second time
109 gdb_test "record function-call-history +" "At the end of the branch trace record\\." "forward - 4"
111 # moving back showing the latest 15 function calls
112 gdb_test "record function-call-history -" [multi_line \
127 "21\tmain"] "backward - 1"
129 # moving further back shows the 6 first function calls
130 gdb_test "record function-call-history -" [multi_line \
136 "6\tinc"] "backward - 2"
138 # moving further back shouldn't work
139 gdb_test "record function-call-history -" "At the start of the branch trace record\\." "backward - 3"
141 # make sure we cannot move any further back
142 gdb_test "record function-call-history -" "At the start of the branch trace record\\." "backward - 4"
144 # don't mess around with path names
145 gdb_test_no_output "set filename-display basename"
147 # moving forward again, but this time with file and line number, expected to see the first 15 entries
148 gdb_test "record function-call-history /l +" [multi_line \
149 "\[0-9\]*\tmain\tat $srcfile:40,41" \
150 "\[0-9\]*\tinc\tat $srcfile:22,2\[34\]" \
151 "\[0-9\]*\tmain\tat $srcfile:40,41" \
152 "\[0-9\]*\tinc\tat $srcfile:22,2\[34\]" \
153 "\[0-9\]*\tmain\tat $srcfile:40,41" \
154 "\[0-9\]*\tinc\tat $srcfile:22,2\[34\]" \
155 "\[0-9\]*\tmain\tat $srcfile:40,41" \
156 "\[0-9\]*\tinc\tat $srcfile:22,2\[34\]" \
157 "\[0-9\]*\tmain\tat $srcfile:40,41" \
158 "\[0-9\]*\tinc\tat $srcfile:22,2\[34\]" \
159 "\[0-9\]*\tmain\tat $srcfile:40,41" \
160 "\[0-9\]*\tinc\tat $srcfile:22,2\[34\]" \
161 "\[0-9\]*\tmain\tat $srcfile:40,41" \
162 "\[0-9\]*\tinc\tat $srcfile:22,2\[34\]" \
163 "\[0-9\]*\tmain\tat $srcfile:40,41" \
166 # moving forward and expect to see the latest 6 entries
167 gdb_test "record function-call-history /l +" [multi_line \
168 "\[0-9\]*\tinc\tat $srcfile:22,2\[34\]" \
169 "\[0-9\]*\tmain\tat $srcfile:40,41" \
170 "\[0-9\]*\tinc\tat $srcfile:22,2\[34\]" \
171 "\[0-9\]*\tmain\tat $srcfile:40,41" \
172 "\[0-9\]*\tinc\tat $srcfile:22,2\[34\]" \
173 "\[0-9\]*\tmain\tat $srcfile:40,43" \
176 # moving further forward shouldn't work
177 gdb_test "record function-call-history /l +" "At the end of the branch trace record\\." "forward /l - 3"
178 gdb_test "record function-call-history /l" "At the end of the branch trace record\\." "forward /l - 4"
180 set expected_range [multi_line \
189 # show functions in instruction range
190 gdb_test "record function-call-history 4,10" $expected_range
191 gdb_test "record function-call-history 4,+7" $expected_range
192 gdb_test "record function-call-history 10,-7" $expected_range
193 gdb_test "record function-call-history 4,4" "4\tinc\r"
195 # set bp after fib recursion and continue
196 set bp_location [gdb_get_line_number "bp.2" $testfile.c]
197 gdb_breakpoint $bp_location
198 gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*"
200 # at this point we expect to have main, fib, ..., fib, main, where fib occurs 9 times,
201 # so we limit the output to only show the latest 11 function calls
202 gdb_test_no_output "set record function-call-history-size 11"
203 gdb_test "record function-call-history" [multi_line \
214 "31\tmain"] "recursive"
216 # show indented function call history for fib
217 gdb_test "record function-call-history /c 21, +11" [multi_line \
231 # make sure we can handle incomplete trace with respect to indentation
235 # navigate to the fib in line 24 above
237 gdb_continue_to_breakpoint "cont to fib.1"
238 gdb_continue_to_breakpoint "cont to fib.2"
239 gdb_continue_to_breakpoint "cont to fib.3"
240 gdb_continue_to_breakpoint "cont to fib.4"
243 gdb_test_no_output "record btrace" "start recording after rerun"
245 # continue until line 30 above
247 set bp_location [gdb_get_line_number "bp.2" $testfile.c]
248 gdb_breakpoint $bp_location
249 gdb_continue_to_breakpoint "cont to bp.2" ".*$testfile.c:$bp_location\r\n.*"
251 # let's look at the trace. we expect to see the tail of the above listing.
252 gdb_test "record function-call-history /c" [multi_line \