File: function_call_history.exp

package info (click to toggle)
gdb 10.1-1.7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 310,484 kB
  • sloc: ansic: 1,939,704; asm: 342,615; exp: 164,493; cpp: 69,350; makefile: 59,036; sh: 25,131; yacc: 13,167; ada: 5,758; xml: 5,461; perl: 5,334; python: 4,761; pascal: 3,220; lisp: 1,575; tcl: 1,541; f90: 1,395; cs: 879; lex: 620; sed: 234; awk: 141; objc: 137; fortran: 62
file content (259 lines) | stat: -rw-r--r-- 7,541 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# This testcase is part of GDB, the GNU debugger.
#
# Copyright 2013-2021 Free Software Foundation, Inc.
#
# Contributed by Intel Corp. <christian.himpel@intel.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

if { [skip_btrace_tests] } {
    unsupported "target does not support record-btrace"
    return -1
}

standard_testfile
if [prepare_for_testing "failed to prepare" $testfile {} {debug}] {
    return -1
}

if ![runto_main] {
    untested "failed to run to main"
    return -1
}

# start btrace
gdb_test_no_output "record btrace"

# set bp after increment loop and continue
set bp_location [gdb_get_line_number "bp.1" $testfile.c]
gdb_breakpoint $bp_location
gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*"

proc rec_fun_all {} {
  gdb_test "record function-call-history 1" [multi_line \
    "1\tmain" \
    "2\tinc" \
    "3\tmain" \
    "4\tinc" \
    "5\tmain" \
    "6\tinc" \
    "7\tmain" \
    "8\tinc" \
    "9\tmain" \
    "10\tinc" \
    "11\tmain" \
    "12\tinc" \
    "13\tmain" \
    "14\tinc" \
    "15\tmain" \
    "16\tinc" \
    "17\tmain" \
    "18\tinc" \
    "19\tmain" \
    "20\tinc" \
    "21\tmain"]
}

# show function call history with unlimited size, we expect to see all 21 entries
gdb_test_no_output "set record function-call-history-size 0"
with_test_prefix "size unlimited" rec_fun_all

# show function call history with size of 21, we expect to see all 21 entries
gdb_test_no_output "set record function-call-history-size 21"
with_test_prefix "size 21" rec_fun_all

# show first 15 entries
gdb_test_no_output "set record function-call-history-size 15"
gdb_test "record function-call-history 1" [multi_line \
  "1\tmain" \
  "2\tinc" \
  "3\tmain" \
  "4\tinc" \
  "5\tmain" \
  "6\tinc" \
  "7\tmain" \
  "8\tinc" \
  "9\tmain" \
  "10\tinc" \
  "11\tmain" \
  "12\tinc" \
  "13\tmain" \
  "14\tinc" \
  "15\tmain"] "forward - 1"

# show last 6 entries
gdb_test "record function-call-history +" [multi_line \
  "16\tinc" \
  "17\tmain" \
  "18\tinc" \
  "19\tmain" \
  "20\tinc" \
  "21\tmain"] "forward - 2"

# moving further should not work
gdb_test "record function-call-history +" "At the end of the branch trace record\\." "forward - 3"

# make sure we cannot move any further a second time
gdb_test "record function-call-history +" "At the end of the branch trace record\\." "forward - 4"

# moving back showing the latest 15 function calls
gdb_test "record function-call-history -" [multi_line \
  "7\tmain" \
  "8\tinc" \
  "9\tmain" \
  "10\tinc" \
  "11\tmain" \
  "12\tinc" \
  "13\tmain" \
  "14\tinc" \
  "15\tmain" \
  "16\tinc" \
  "17\tmain" \
  "18\tinc" \
  "19\tmain" \
  "20\tinc" \
  "21\tmain"] "backward - 1"

# moving further back shows the 6 first function calls
gdb_test "record function-call-history -" [multi_line \
  "1\tmain" \
  "2\tinc" \
  "3\tmain" \
  "4\tinc" \
  "5\tmain" \
  "6\tinc"] "backward - 2"

# moving further back shouldn't work
gdb_test "record function-call-history -" "At the start of the branch trace record\\." "backward - 3"

# make sure we cannot move any further back
gdb_test "record function-call-history -" "At the start of the branch trace record\\." "backward - 4"

# don't mess around with path names
gdb_test_no_output "set filename-display basename"

# moving forward again, but this time with file and line number, expected to see the first 15 entries
gdb_test "record function-call-history /l +" [multi_line \
  "\[0-9\]*\tmain\tat $srcfile:40,41" \
  "\[0-9\]*\tinc\tat $srcfile:22,24" \
  "\[0-9\]*\tmain\tat $srcfile:40,41" \
  "\[0-9\]*\tinc\tat $srcfile:22,24" \
  "\[0-9\]*\tmain\tat $srcfile:40,41" \
  "\[0-9\]*\tinc\tat $srcfile:22,24" \
  "\[0-9\]*\tmain\tat $srcfile:40,41" \
  "\[0-9\]*\tinc\tat $srcfile:22,24" \
  "\[0-9\]*\tmain\tat $srcfile:40,41" \
  "\[0-9\]*\tinc\tat $srcfile:22,24" \
  "\[0-9\]*\tmain\tat $srcfile:40,41" \
  "\[0-9\]*\tinc\tat $srcfile:22,24" \
  "\[0-9\]*\tmain\tat $srcfile:40,41" \
  "\[0-9\]*\tinc\tat $srcfile:22,24" \
  "\[0-9\]*\tmain\tat $srcfile:40,41" \
  ] "forward /l - 1"

# moving forward and expect to see the latest 6 entries
gdb_test "record function-call-history /l +" [multi_line \
  "\[0-9\]*\tinc\tat $srcfile:22,24" \
  "\[0-9\]*\tmain\tat $srcfile:40,41" \
  "\[0-9\]*\tinc\tat $srcfile:22,24" \
  "\[0-9\]*\tmain\tat $srcfile:40,41" \
  "\[0-9\]*\tinc\tat $srcfile:22,24" \
  "\[0-9\]*\tmain\tat $srcfile:40,43" \
  ] "forward /l - 2"

# moving further forward shouldn't work
gdb_test "record function-call-history /l +" "At the end of the branch trace record\\." "forward /l - 3"
gdb_test "record function-call-history /l" "At the end of the branch trace record\\." "forward /l - 4"

set expected_range [multi_line \
  "4\tinc" \
  "5\tmain" \
  "6\tinc" \
  "7\tmain" \
  "8\tinc" \
  "9\tmain" \
  "10\tinc"]

# show functions in instruction range
gdb_test "record function-call-history 4,10" $expected_range
gdb_test "record function-call-history 4,+7" $expected_range
gdb_test "record function-call-history 10,-7" $expected_range
gdb_test "record function-call-history 4,4" "4\tinc\r"

# set bp after fib recursion and continue
set bp_location [gdb_get_line_number "bp.2" $testfile.c]
gdb_breakpoint $bp_location
gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*"

# at this point we expect to have main, fib, ..., fib, main, where fib occurs 9 times,
# so we limit the output to only show the latest 11 function calls
gdb_test_no_output "set record function-call-history-size 11"
gdb_test "record function-call-history" [multi_line \
  "21\tmain" \
  "22\tfib" \
  "23\tfib" \
  "24\tfib" \
  "25\tfib" \
  "26\tfib" \
  "27\tfib" \
  "28\tfib" \
  "29\tfib" \
  "30\tfib" \
  "31\tmain"] "recursive"

# show indented function call history for fib
gdb_test "record function-call-history /c 21, +11" [multi_line \
  "21\tmain" \
  "22\t  fib" \
  "23\t    fib" \
  "24\t  fib" \
  "25\t    fib" \
  "26\t      fib" \
  "27\t    fib" \
  "28\t      fib" \
  "29\t    fib" \
  "30\t  fib" \
  "31\tmain" \
  ] "indented"

# make sure we can handle incomplete trace with respect to indentation
if ![runto_main] {
    untested "failed to run to main"
    return -1
}
# navigate to the fib in line 24 above
gdb_breakpoint fib
gdb_continue_to_breakpoint "cont to fib.1"
gdb_continue_to_breakpoint "cont to fib.2"
gdb_continue_to_breakpoint "cont to fib.3"
gdb_continue_to_breakpoint "cont to fib.4"

# start tracing
gdb_test_no_output "record btrace"

# continue until line 30 above
delete_breakpoints
set bp_location [gdb_get_line_number "bp.2" $testfile.c]
gdb_breakpoint $bp_location
gdb_continue_to_breakpoint "cont to bp.2" ".*$testfile.c:$bp_location\r\n.*"

# let's look at the trace. we expect to see the tail of the above listing.
gdb_test "record function-call-history /c" [multi_line \
  "1\t      fib" \
  "2\t    fib" \
  "3\t      fib" \
  "4\t    fib" \
  "5\t  fib" \
  "6\tmain" \
  ] "indented tail"