bf2458b5d9ead27c40576effbc57d7ce0e7c6b65
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.btrace / function_call_history.exp
1 # This testcase is part of GDB, the GNU debugger.
2 #
3 # Copyright 2013-2014 Free Software Foundation, Inc.
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
20 # check for btrace support
21 if { [skip_btrace_tests] } { return -1 }
22
23 # start inferior
24 standard_testfile
25 if [prepare_for_testing function_call_history.exp $testfile {} {debug}] {
26 return -1
27 }
28 if ![runto_main] {
29 return -1
30 }
31
32 # start btrace
33 gdb_test_no_output "record btrace"
34
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.*"
39
40 proc rec_fun_all {} {
41 gdb_test "record function-call-history 0" [join [list \
42 "0\tmain" \
43 "1\tinc" \
44 "2\tmain" \
45 "3\tinc" \
46 "4\tmain" \
47 "5\tinc" \
48 "6\tmain" \
49 "7\tinc" \
50 "8\tmain" \
51 "9\tinc" \
52 "10\tmain" \
53 "11\tinc" \
54 "12\tmain" \
55 "13\tinc" \
56 "14\tmain" \
57 "15\tinc" \
58 "16\tmain" \
59 "17\tinc" \
60 "18\tmain" \
61 "19\tinc" \
62 "20\tmain"] "\r\n"]
63 }
64
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
68
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
72
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 \
76 "0\tmain" \
77 "1\tinc" \
78 "2\tmain" \
79 "3\tinc" \
80 "4\tmain" \
81 "5\tinc" \
82 "6\tmain" \
83 "7\tinc" \
84 "8\tmain" \
85 "9\tinc" \
86 "10\tmain" \
87 "11\tinc" \
88 "12\tmain" \
89 "13\tinc" \
90 "14\tmain"] "\r\n"] "forward - 1"
91
92 # show last 6 entries
93 gdb_test "record function-call-history +" [join [list \
94 "15\tinc" \
95 "16\tmain" \
96 "17\tinc" \
97 "18\tmain" \
98 "19\tinc" \
99 "20\tmain"] "\r\n"] "forward - 2"
100
101 # moving further should not work
102 gdb_test "record function-call-history +" "At the end of the branch trace record\\." "forward - 3"
103
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"
106
107 # moving back showing the latest 15 function calls
108 gdb_test "record function-call-history -" [join [list \
109 "6\tmain" \
110 "7\tinc" \
111 "8\tmain" \
112 "9\tinc" \
113 "10\tmain" \
114 "11\tinc" \
115 "12\tmain" \
116 "13\tinc" \
117 "14\tmain" \
118 "15\tinc" \
119 "16\tmain" \
120 "17\tinc" \
121 "18\tmain" \
122 "19\tinc" \
123 "20\tmain"] "\r\n"] "backward - 1"
124
125 # moving further back shows the 6 first function calls
126 gdb_test "record function-call-history -" [join [list \
127 "0\tmain" \
128 "1\tinc" \
129 "2\tmain" \
130 "3\tinc" \
131 "4\tmain" \
132 "5\tinc"] "\r\n"] "backward - 2"
133
134 # moving further back shouldn't work
135 gdb_test "record function-call-history -" "At the start of the branch trace record\\." "backward - 3"
136
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"
139
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"
157
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"
166
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"
170
171 set expected_range [join [list \
172 "3\tinc" \
173 "4\tmain" \
174 "5\tinc" \
175 "6\tmain" \
176 "7\tinc" \
177 "8\tmain" \
178 "9\tinc"] "\r\n"]
179
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
184
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.*"
189
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 \
194 "20\tmain" \
195 "21\tfib" \
196 "22\tfib" \
197 "23\tfib" \
198 "24\tfib" \
199 "25\tfib" \
200 "26\tfib" \
201 "27\tfib" \
202 "28\tfib" \
203 "29\tfib" \
204 "30\tmain"] "\r\n"] "recursive"
This page took 0.0405 seconds and 4 git commands to generate.