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.*"
41 gdb_test "record function-call-history 0" [join [list \
65 # show function call history with unlimited size, we expect to see all 21 entries
66 gdb_test_no_output "set record function-call-history-size 0"
67 with_test_prefix "size unlimited" rec_fun_all
69 # show function call history with size of 21, we expect to see all 21 entries
70 gdb_test_no_output "set record function-call-history-size 21"
71 with_test_prefix "size 21" rec_fun_all
73 # show first 15 entries
74 gdb_test_no_output "set record function-call-history-size 15"
75 gdb_test "record function-call-history 0" [join [list \
90 "14\tmain"] "\r\n"] "forward - 1"
93 gdb_test "record function-call-history +" [join [list \
99 "20\tmain"] "\r\n"] "forward - 2"
101 # moving further should not work
102 gdb_test "record function-call-history +" "At the end of the branch trace record\\." "forward - 3"
104 # make sure we cannot move any further a second time
105 gdb_test "record function-call-history +" "At the end of the branch trace record\\." "forward - 4"
107 # moving back showing the latest 15 function calls
108 gdb_test "record function-call-history -" [join [list \
123 "20\tmain"] "\r\n"] "backward - 1"
125 # moving further back shows the 6 first function calls
126 gdb_test "record function-call-history -" [join [list \
132 "5\tinc"] "\r\n"] "backward - 2"
134 # moving further back shouldn't work
135 gdb_test "record function-call-history -" "At the start of the branch trace record\\." "backward - 3"
137 # make sure we cannot move any further back
138 gdb_test "record function-call-history -" "At the start of the branch trace record\\." "backward - 4"
140 # moving forward again, but this time with file and line number, expected to see the first 15 entries
141 gdb_test "record function-call-history /l +" [join [list \
142 ".*$srcfile:40-41\tmain" \
143 ".*$srcfile:22-24\tinc" \
144 ".*$srcfile:40-41\tmain" \
145 ".*$srcfile:22-24\tinc" \
146 ".*$srcfile:40-41\tmain" \
147 ".*$srcfile:22-24\tinc" \
148 ".*$srcfile:40-41\tmain" \
149 ".*$srcfile:22-24\tinc" \
150 ".*$srcfile:40-41\tmain" \
151 ".*$srcfile:22-24\tinc" \
152 ".*$srcfile:40-41\tmain" \
153 ".*$srcfile:22-24\tinc" \
154 ".*$srcfile:40-41\tmain" \
155 ".*$srcfile:22-24\tinc" \
156 ".*$srcfile:40-41\tmain"] "\r\n"] "forward /l - 1"
158 # moving forward and expect to see the latest 6 entries
159 gdb_test "record function-call-history /l +" [join [list \
160 ".*$srcfile:22-24\tinc" \
161 ".*$srcfile:40-41\tmain" \
162 ".*$srcfile:22-24\tinc" \
163 ".*$srcfile:40-41\tmain" \
164 ".*$srcfile:22-24\tinc" \
165 ".*$srcfile:40-43\tmain"] "\r\n"] "forward /l - 2"
167 # moving further forward shouldn't work
168 gdb_test "record function-call-history /l +" "At the end of the branch trace record\\." "forward /l - 3"
169 gdb_test "record function-call-history /l" "At the end of the branch trace record\\." "forward /l - 4"
171 set expected_range [join [list \
180 # show functions in instruction range
181 gdb_test "record function-call-history 3,10" $expected_range
182 gdb_test "record function-call-history 3,+7" $expected_range
183 gdb_test "record function-call-history 10,-7" $expected_range
185 # set bp after fib recursion and continue
186 set bp_location [gdb_get_line_number "bp.2" $testfile.c]
187 gdb_breakpoint $bp_location
188 gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*"
190 # at this point we expect to have main, fib, ..., fib, main, where fib occurs 9 times,
191 # so we limit the output to only show the latest 11 function calls
192 gdb_test_no_output "set record function-call-history-size 11"
193 gdb_test "record function-call-history" [join [list \
204 "30\tmain"] "\r\n"] "recursive"