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