1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2013-2014 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 # check for btrace support
21 if { [skip_btrace_tests] } { return -1 }
25 if [prepare_for_testing function_call_history.exp $testfile {} {debug}] {
33 gdb_test_no_output "record btrace"
35 # set bp after increment loop and continue
36 set bp_location [gdb_get_line_number "bp.1" $testfile.c]
37 gdb_breakpoint $bp_location
38 gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*"
40 # show function call history with unlimited size, we expect to see all 21 entries
41 gdb_test_no_output "set record function-call-history-size 0"
42 gdb_test "record function-call-history" "
63 20\tmain\r" "record function-call-history - with size unlimited"
65 # show function call history with size of 21, we expect to see all 21 entries
66 gdb_test_no_output "set record function-call-history-size 21"
67 # show function call history
68 gdb_test "record function-call-history 0" "
89 20\tmain\r" "record function-call-history - show all 21 entries"
91 # show first 15 entries
92 gdb_test_no_output "set record function-call-history-size 15"
93 gdb_test "record function-call-history 0" "
108 14\tmain\r" "record function-call-history - show first 15 entries"
110 # show last 6 entries
111 gdb_test "record function-call-history +" "
117 20\tmain\r" "record function-call-history - show last 6 entries"
119 # moving further should not work
120 gdb_test "record function-call-history +" "At the end of the branch trace record\\." "record function-call-history - at the end (1)"
122 # make sure we cannot move any further a second time
123 gdb_test "record function-call-history +" "At the end of the branch trace record\\." "record function-call-history - at the end (2)"
125 # moving back showing the latest 15 function calls
126 gdb_test "record function-call-history -" "
141 20\tmain\r" "record function-call-history - show last 15 entries"
143 # moving further back shows the 6 first function calls
144 gdb_test "record function-call-history -" "
150 5\tinc\r" "record function-call-history - show first 6 entries"
152 # moving further back shouldn't work
153 gdb_test "record function-call-history -" "At the start of the branch trace record\\." "record function-call-history - at the start (1)"
155 # make sure we cannot move any further back
156 gdb_test "record function-call-history -" "At the start of the branch trace record\\." "record function-call-history - at the start (2)"
158 # moving forward again, but this time with file and line number, expected to see the first 15 entries
159 gdb_test "record function-call-history /l +" "
160 .*$srcfile:40-41\tmain\r
161 .*$srcfile:22-24\tinc\r
162 .*$srcfile:40-41\tmain\r
163 .*$srcfile:22-24\tinc\r
164 .*$srcfile:40-41\tmain\r
165 .*$srcfile:22-24\tinc\r
166 .*$srcfile:40-41\tmain\r
167 .*$srcfile:22-24\tinc\r
168 .*$srcfile:40-41\tmain\r
169 .*$srcfile:22-24\tinc\r
170 .*$srcfile:40-41\tmain\r
171 .*$srcfile:22-24\tinc\r
172 .*$srcfile:40-41\tmain\r
173 .*$srcfile:22-24\tinc\r
174 .*$srcfile:40-41\tmain\r" "record function-call-history /l - show first 15 entries"
176 # moving forward and expect to see the latest 6 entries
177 gdb_test "record function-call-history /l +" "
178 .*$srcfile:22-24\tinc\r
179 .*$srcfile:40-41\tmain\r
180 .*$srcfile:22-24\tinc\r
181 .*$srcfile:40-41\tmain\r
182 .*$srcfile:22-24\tinc\r
183 .*$srcfile:40-43\tmain\r" "record function-call-history /l - show last 6 entries"
185 # moving further forward shouldn't work
186 gdb_test "record function-call-history /l +" "At the end of the branch trace record\\." "record function-call-history /l - at the end (1)"
187 gdb_test "record function-call-history /l" "At the end of the branch trace record\\." "record function-call-history /l - at the end (2)"
189 set expected_range "3\tinc\r
197 # show functions in instruction range
198 gdb_test "record function-call-history 3,10" $expected_range "absolute instruction range"
199 gdb_test "record function-call-history 3,+7" $expected_range "relative positive instruction range"
200 gdb_test "record function-call-history 10,-7" $expected_range "relative negative instruction range"
202 # set bp after fib recursion and continue
203 set bp_location [gdb_get_line_number "bp.2" $testfile.c]
204 gdb_breakpoint $bp_location
205 gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*"
207 # at this point we expect to have main, fib, ..., fib, main, where fib occurs 8 times,
208 # so we limit the output to only show the latest 10 function calls
209 gdb_test_no_output "set record function-call-history-size 10"
210 set message "show recursive function call history"
211 gdb_test_multiple "record function-call-history" $message {
212 -re "13\tmain\r\n14\tfib\r\n15\tfib\r\n16\tfib\r\n17\tfib\r\n18\tfib\r\n19\tfib\r\n20\tfib\r\n21\tfib\r\n22 main\r\n$gdb_prompt $" {
215 -re "13\tinc\r\n14\tmain\r\n15\tinc\r\n16\tmain\r\n17\tinc\r\n18\tmain\r\n19\tinc\r\n20\tmain\r\n21\tfib\r\n22\tmain\r\n$gdb_prompt $" {
216 # recursive function calls appear only as 1 call
217 kfail "gdb/15240" $message