7d1e40491d8d5441a2b3f9a47188eba6a2c24070
[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-2016 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 1" [multi_line \
42 "1\tmain" \
43 "2\tinc" \
44 "3\tmain" \
45 "4\tinc" \
46 "5\tmain" \
47 "6\tinc" \
48 "7\tmain" \
49 "8\tinc" \
50 "9\tmain" \
51 "10\tinc" \
52 "11\tmain" \
53 "12\tinc" \
54 "13\tmain" \
55 "14\tinc" \
56 "15\tmain" \
57 "16\tinc" \
58 "17\tmain" \
59 "18\tinc" \
60 "19\tmain" \
61 "20\tinc" \
62 "21\tmain"]
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 1" [multi_line \
76 "1\tmain" \
77 "2\tinc" \
78 "3\tmain" \
79 "4\tinc" \
80 "5\tmain" \
81 "6\tinc" \
82 "7\tmain" \
83 "8\tinc" \
84 "9\tmain" \
85 "10\tinc" \
86 "11\tmain" \
87 "12\tinc" \
88 "13\tmain" \
89 "14\tinc" \
90 "15\tmain"] "forward - 1"
91
92 # show last 6 entries
93 gdb_test "record function-call-history +" [multi_line \
94 "16\tinc" \
95 "17\tmain" \
96 "18\tinc" \
97 "19\tmain" \
98 "20\tinc" \
99 "21\tmain"] "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 -" [multi_line \
109 "7\tmain" \
110 "8\tinc" \
111 "9\tmain" \
112 "10\tinc" \
113 "11\tmain" \
114 "12\tinc" \
115 "13\tmain" \
116 "14\tinc" \
117 "15\tmain" \
118 "16\tinc" \
119 "17\tmain" \
120 "18\tinc" \
121 "19\tmain" \
122 "20\tinc" \
123 "21\tmain"] "backward - 1"
124
125 # moving further back shows the 6 first function calls
126 gdb_test "record function-call-history -" [multi_line \
127 "1\tmain" \
128 "2\tinc" \
129 "3\tmain" \
130 "4\tinc" \
131 "5\tmain" \
132 "6\tinc"] "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 # don't mess around with path names
141 gdb_test_no_output "set filename-display basename"
142
143 # moving forward again, but this time with file and line number, expected to see the first 15 entries
144 gdb_test "record function-call-history /l +" [multi_line \
145 "\[0-9\]*\tmain\tat $srcfile:40,41" \
146 "\[0-9\]*\tinc\tat $srcfile:22,24" \
147 "\[0-9\]*\tmain\tat $srcfile:40,41" \
148 "\[0-9\]*\tinc\tat $srcfile:22,24" \
149 "\[0-9\]*\tmain\tat $srcfile:40,41" \
150 "\[0-9\]*\tinc\tat $srcfile:22,24" \
151 "\[0-9\]*\tmain\tat $srcfile:40,41" \
152 "\[0-9\]*\tinc\tat $srcfile:22,24" \
153 "\[0-9\]*\tmain\tat $srcfile:40,41" \
154 "\[0-9\]*\tinc\tat $srcfile:22,24" \
155 "\[0-9\]*\tmain\tat $srcfile:40,41" \
156 "\[0-9\]*\tinc\tat $srcfile:22,24" \
157 "\[0-9\]*\tmain\tat $srcfile:40,41" \
158 "\[0-9\]*\tinc\tat $srcfile:22,24" \
159 "\[0-9\]*\tmain\tat $srcfile:40,41" \
160 ] "forward /l - 1"
161
162 # moving forward and expect to see the latest 6 entries
163 gdb_test "record function-call-history /l +" [multi_line \
164 "\[0-9\]*\tinc\tat $srcfile:22,24" \
165 "\[0-9\]*\tmain\tat $srcfile:40,41" \
166 "\[0-9\]*\tinc\tat $srcfile:22,24" \
167 "\[0-9\]*\tmain\tat $srcfile:40,41" \
168 "\[0-9\]*\tinc\tat $srcfile:22,24" \
169 "\[0-9\]*\tmain\tat $srcfile:40,43" \
170 ] "forward /l - 2"
171
172 # moving further forward shouldn't work
173 gdb_test "record function-call-history /l +" "At the end of the branch trace record\\." "forward /l - 3"
174 gdb_test "record function-call-history /l" "At the end of the branch trace record\\." "forward /l - 4"
175
176 set expected_range [multi_line \
177 "4\tinc" \
178 "5\tmain" \
179 "6\tinc" \
180 "7\tmain" \
181 "8\tinc" \
182 "9\tmain" \
183 "10\tinc"]
184
185 # show functions in instruction range
186 gdb_test "record function-call-history 4,10" $expected_range
187 gdb_test "record function-call-history 4,+7" $expected_range
188 gdb_test "record function-call-history 10,-7" $expected_range
189 gdb_test "record function-call-history 4,4" "4\tinc\r"
190
191 # set bp after fib recursion and continue
192 set bp_location [gdb_get_line_number "bp.2" $testfile.c]
193 gdb_breakpoint $bp_location
194 gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*"
195
196 # at this point we expect to have main, fib, ..., fib, main, where fib occurs 9 times,
197 # so we limit the output to only show the latest 11 function calls
198 gdb_test_no_output "set record function-call-history-size 11"
199 gdb_test "record function-call-history" [multi_line \
200 "21\tmain" \
201 "22\tfib" \
202 "23\tfib" \
203 "24\tfib" \
204 "25\tfib" \
205 "26\tfib" \
206 "27\tfib" \
207 "28\tfib" \
208 "29\tfib" \
209 "30\tfib" \
210 "31\tmain"] "recursive"
211
212 # show indented function call history for fib
213 gdb_test "record function-call-history /c 21, +11" [multi_line \
214 "21\tmain" \
215 "22\t fib" \
216 "23\t fib" \
217 "24\t fib" \
218 "25\t fib" \
219 "26\t fib" \
220 "27\t fib" \
221 "28\t fib" \
222 "29\t fib" \
223 "30\t fib" \
224 "31\tmain" \
225 ] "indented"
226
227 # make sure we can handle incomplete trace with respect to indentation
228 if ![runto_main] {
229 return -1
230 }
231 # navigate to the fib in line 24 above
232 gdb_breakpoint fib
233 gdb_continue_to_breakpoint "cont to fib.1"
234 gdb_continue_to_breakpoint "cont to fib.2"
235 gdb_continue_to_breakpoint "cont to fib.3"
236 gdb_continue_to_breakpoint "cont to fib.4"
237
238 # start tracing
239 gdb_test_no_output "record btrace"
240
241 # continue until line 30 above
242 delete_breakpoints
243 set bp_location [gdb_get_line_number "bp.2" $testfile.c]
244 gdb_breakpoint $bp_location
245 gdb_continue_to_breakpoint "cont to bp.2" ".*$testfile.c:$bp_location\r\n.*"
246
247 # let's look at the trace. we expect to see the tail of the above listing.
248 gdb_test "record function-call-history /c" [multi_line \
249 "1\t fib" \
250 "2\t fib" \
251 "3\t fib" \
252 "4\t fib" \
253 "5\t fib" \
254 "6\tmain" \
255 ] "indented tail"
This page took 0.034696 seconds and 3 git commands to generate.