]>
Commit | Line | Data |
---|---|---|
2f1d9bdd MM |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | # | |
b811d2c2 | 3 | # Copyright 2013-2020 Free Software Foundation, Inc. |
2f1d9bdd MM |
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 | ||
b5ac99b0 MM |
20 | if { [skip_btrace_tests] } { |
21 | unsupported "target does not support record-btrace" | |
22 | return -1 | |
23 | } | |
2f1d9bdd | 24 | |
0fe69a94 MM |
25 | # We expect a specific function call history. This gets messed up with |
26 | # PIE on 32-bit. | |
2f1d9bdd | 27 | standard_testfile |
0fe69a94 | 28 | if [prepare_for_testing "failed to prepare" $testfile {} {nopie debug}] { |
2f1d9bdd MM |
29 | return -1 |
30 | } | |
b5ac99b0 | 31 | |
2f1d9bdd | 32 | if ![runto_main] { |
b5ac99b0 | 33 | untested "failed to run to main" |
2f1d9bdd MM |
34 | return -1 |
35 | } | |
36 | ||
37 | # start btrace | |
38 | gdb_test_no_output "record btrace" | |
39 | ||
40 | # set bp after increment loop and continue | |
41 | set bp_location [gdb_get_line_number "bp.1" $testfile.c] | |
42 | gdb_breakpoint $bp_location | |
43 | gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*" | |
44 | ||
724c7dd8 | 45 | proc rec_fun_all {} { |
3c724c8c | 46 | gdb_test "record function-call-history 1" [multi_line \ |
5de9129b MM |
47 | "1\tmain" \ |
48 | "2\tinc" \ | |
49 | "3\tmain" \ | |
50 | "4\tinc" \ | |
51 | "5\tmain" \ | |
52 | "6\tinc" \ | |
53 | "7\tmain" \ | |
54 | "8\tinc" \ | |
55 | "9\tmain" \ | |
56 | "10\tinc" \ | |
57 | "11\tmain" \ | |
58 | "12\tinc" \ | |
59 | "13\tmain" \ | |
60 | "14\tinc" \ | |
61 | "15\tmain" \ | |
62 | "16\tinc" \ | |
63 | "17\tmain" \ | |
64 | "18\tinc" \ | |
65 | "19\tmain" \ | |
66 | "20\tinc" \ | |
3c724c8c | 67 | "21\tmain"] |
724c7dd8 MM |
68 | } |
69 | ||
2f1d9bdd MM |
70 | # show function call history with unlimited size, we expect to see all 21 entries |
71 | gdb_test_no_output "set record function-call-history-size 0" | |
724c7dd8 | 72 | with_test_prefix "size unlimited" rec_fun_all |
2f1d9bdd MM |
73 | |
74 | # show function call history with size of 21, we expect to see all 21 entries | |
75 | gdb_test_no_output "set record function-call-history-size 21" | |
724c7dd8 | 76 | with_test_prefix "size 21" rec_fun_all |
2f1d9bdd MM |
77 | |
78 | # show first 15 entries | |
79 | gdb_test_no_output "set record function-call-history-size 15" | |
3c724c8c | 80 | gdb_test "record function-call-history 1" [multi_line \ |
5de9129b MM |
81 | "1\tmain" \ |
82 | "2\tinc" \ | |
83 | "3\tmain" \ | |
84 | "4\tinc" \ | |
85 | "5\tmain" \ | |
86 | "6\tinc" \ | |
87 | "7\tmain" \ | |
88 | "8\tinc" \ | |
89 | "9\tmain" \ | |
90 | "10\tinc" \ | |
91 | "11\tmain" \ | |
92 | "12\tinc" \ | |
93 | "13\tmain" \ | |
94 | "14\tinc" \ | |
3c724c8c | 95 | "15\tmain"] "forward - 1" |
2f1d9bdd MM |
96 | |
97 | # show last 6 entries | |
3c724c8c | 98 | gdb_test "record function-call-history +" [multi_line \ |
5de9129b MM |
99 | "16\tinc" \ |
100 | "17\tmain" \ | |
101 | "18\tinc" \ | |
102 | "19\tmain" \ | |
103 | "20\tinc" \ | |
3c724c8c | 104 | "21\tmain"] "forward - 2" |
2f1d9bdd MM |
105 | |
106 | # moving further should not work | |
724c7dd8 | 107 | gdb_test "record function-call-history +" "At the end of the branch trace record\\." "forward - 3" |
2f1d9bdd MM |
108 | |
109 | # make sure we cannot move any further a second time | |
724c7dd8 | 110 | gdb_test "record function-call-history +" "At the end of the branch trace record\\." "forward - 4" |
2f1d9bdd MM |
111 | |
112 | # moving back showing the latest 15 function calls | |
3c724c8c | 113 | gdb_test "record function-call-history -" [multi_line \ |
5de9129b MM |
114 | "7\tmain" \ |
115 | "8\tinc" \ | |
116 | "9\tmain" \ | |
117 | "10\tinc" \ | |
118 | "11\tmain" \ | |
119 | "12\tinc" \ | |
120 | "13\tmain" \ | |
121 | "14\tinc" \ | |
122 | "15\tmain" \ | |
123 | "16\tinc" \ | |
124 | "17\tmain" \ | |
125 | "18\tinc" \ | |
126 | "19\tmain" \ | |
127 | "20\tinc" \ | |
3c724c8c | 128 | "21\tmain"] "backward - 1" |
2f1d9bdd MM |
129 | |
130 | # moving further back shows the 6 first function calls | |
3c724c8c | 131 | gdb_test "record function-call-history -" [multi_line \ |
5de9129b MM |
132 | "1\tmain" \ |
133 | "2\tinc" \ | |
134 | "3\tmain" \ | |
135 | "4\tinc" \ | |
136 | "5\tmain" \ | |
3c724c8c | 137 | "6\tinc"] "backward - 2" |
2f1d9bdd MM |
138 | |
139 | # moving further back shouldn't work | |
724c7dd8 | 140 | gdb_test "record function-call-history -" "At the start of the branch trace record\\." "backward - 3" |
2f1d9bdd MM |
141 | |
142 | # make sure we cannot move any further back | |
724c7dd8 | 143 | gdb_test "record function-call-history -" "At the start of the branch trace record\\." "backward - 4" |
2f1d9bdd | 144 | |
8710b709 MM |
145 | # don't mess around with path names |
146 | gdb_test_no_output "set filename-display basename" | |
147 | ||
2f1d9bdd | 148 | # moving forward again, but this time with file and line number, expected to see the first 15 entries |
3c724c8c | 149 | gdb_test "record function-call-history /l +" [multi_line \ |
8710b709 MM |
150 | "\[0-9\]*\tmain\tat $srcfile:40,41" \ |
151 | "\[0-9\]*\tinc\tat $srcfile:22,24" \ | |
152 | "\[0-9\]*\tmain\tat $srcfile:40,41" \ | |
153 | "\[0-9\]*\tinc\tat $srcfile:22,24" \ | |
154 | "\[0-9\]*\tmain\tat $srcfile:40,41" \ | |
155 | "\[0-9\]*\tinc\tat $srcfile:22,24" \ | |
156 | "\[0-9\]*\tmain\tat $srcfile:40,41" \ | |
157 | "\[0-9\]*\tinc\tat $srcfile:22,24" \ | |
158 | "\[0-9\]*\tmain\tat $srcfile:40,41" \ | |
159 | "\[0-9\]*\tinc\tat $srcfile:22,24" \ | |
160 | "\[0-9\]*\tmain\tat $srcfile:40,41" \ | |
161 | "\[0-9\]*\tinc\tat $srcfile:22,24" \ | |
162 | "\[0-9\]*\tmain\tat $srcfile:40,41" \ | |
163 | "\[0-9\]*\tinc\tat $srcfile:22,24" \ | |
164 | "\[0-9\]*\tmain\tat $srcfile:40,41" \ | |
3c724c8c | 165 | ] "forward /l - 1" |
2f1d9bdd MM |
166 | |
167 | # moving forward and expect to see the latest 6 entries | |
3c724c8c | 168 | gdb_test "record function-call-history /l +" [multi_line \ |
8710b709 MM |
169 | "\[0-9\]*\tinc\tat $srcfile:22,24" \ |
170 | "\[0-9\]*\tmain\tat $srcfile:40,41" \ | |
171 | "\[0-9\]*\tinc\tat $srcfile:22,24" \ | |
172 | "\[0-9\]*\tmain\tat $srcfile:40,41" \ | |
173 | "\[0-9\]*\tinc\tat $srcfile:22,24" \ | |
174 | "\[0-9\]*\tmain\tat $srcfile:40,43" \ | |
3c724c8c | 175 | ] "forward /l - 2" |
2f1d9bdd MM |
176 | |
177 | # moving further forward shouldn't work | |
724c7dd8 MM |
178 | gdb_test "record function-call-history /l +" "At the end of the branch trace record\\." "forward /l - 3" |
179 | gdb_test "record function-call-history /l" "At the end of the branch trace record\\." "forward /l - 4" | |
180 | ||
3c724c8c | 181 | set expected_range [multi_line \ |
5de9129b MM |
182 | "4\tinc" \ |
183 | "5\tmain" \ | |
184 | "6\tinc" \ | |
185 | "7\tmain" \ | |
186 | "8\tinc" \ | |
187 | "9\tmain" \ | |
3c724c8c | 188 | "10\tinc"] |
2f1d9bdd MM |
189 | |
190 | # show functions in instruction range | |
0688d04e | 191 | gdb_test "record function-call-history 4,10" $expected_range |
5de9129b | 192 | gdb_test "record function-call-history 4,+7" $expected_range |
0688d04e MM |
193 | gdb_test "record function-call-history 10,-7" $expected_range |
194 | gdb_test "record function-call-history 4,4" "4\tinc\r" | |
2f1d9bdd MM |
195 | |
196 | # set bp after fib recursion and continue | |
197 | set bp_location [gdb_get_line_number "bp.2" $testfile.c] | |
198 | gdb_breakpoint $bp_location | |
199 | gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*" | |
200 | ||
23a7fe75 MM |
201 | # at this point we expect to have main, fib, ..., fib, main, where fib occurs 9 times, |
202 | # so we limit the output to only show the latest 11 function calls | |
203 | gdb_test_no_output "set record function-call-history-size 11" | |
3c724c8c | 204 | gdb_test "record function-call-history" [multi_line \ |
5de9129b | 205 | "21\tmain" \ |
23a7fe75 MM |
206 | "22\tfib" \ |
207 | "23\tfib" \ | |
208 | "24\tfib" \ | |
209 | "25\tfib" \ | |
210 | "26\tfib" \ | |
211 | "27\tfib" \ | |
212 | "28\tfib" \ | |
213 | "29\tfib" \ | |
5de9129b | 214 | "30\tfib" \ |
3c724c8c | 215 | "31\tmain"] "recursive" |
8710b709 MM |
216 | |
217 | # show indented function call history for fib | |
3c724c8c | 218 | gdb_test "record function-call-history /c 21, +11" [multi_line \ |
8710b709 MM |
219 | "21\tmain" \ |
220 | "22\t fib" \ | |
221 | "23\t fib" \ | |
222 | "24\t fib" \ | |
223 | "25\t fib" \ | |
224 | "26\t fib" \ | |
225 | "27\t fib" \ | |
226 | "28\t fib" \ | |
227 | "29\t fib" \ | |
228 | "30\t fib" \ | |
229 | "31\tmain" \ | |
3c724c8c | 230 | ] "indented" |
8710b709 MM |
231 | |
232 | # make sure we can handle incomplete trace with respect to indentation | |
233 | if ![runto_main] { | |
b5ac99b0 | 234 | untested "failed to run to main" |
8710b709 MM |
235 | return -1 |
236 | } | |
237 | # navigate to the fib in line 24 above | |
238 | gdb_breakpoint fib | |
239 | gdb_continue_to_breakpoint "cont to fib.1" | |
240 | gdb_continue_to_breakpoint "cont to fib.2" | |
241 | gdb_continue_to_breakpoint "cont to fib.3" | |
242 | gdb_continue_to_breakpoint "cont to fib.4" | |
243 | ||
244 | # start tracing | |
1a1c0afc | 245 | gdb_test_no_output "record btrace" "start recording after rerun" |
8710b709 MM |
246 | |
247 | # continue until line 30 above | |
248 | delete_breakpoints | |
249 | set bp_location [gdb_get_line_number "bp.2" $testfile.c] | |
250 | gdb_breakpoint $bp_location | |
251 | gdb_continue_to_breakpoint "cont to bp.2" ".*$testfile.c:$bp_location\r\n.*" | |
252 | ||
253 | # let's look at the trace. we expect to see the tail of the above listing. | |
3c724c8c | 254 | gdb_test "record function-call-history /c" [multi_line \ |
8710b709 MM |
255 | "1\t fib" \ |
256 | "2\t fib" \ | |
257 | "3\t fib" \ | |
258 | "4\t fib" \ | |
259 | "5\t fib" \ | |
260 | "6\tmain" \ | |
3c724c8c | 261 | ] "indented tail" |