btrace, test: fix multi-line btrace tests
[platform/upstream/binutils.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 8 times,
191 # so we limit the output to only show the latest 10 function calls
192 gdb_test_no_output "set record function-call-history-size 10"
193 set message "recursive"
194 gdb_test_multiple "record function-call-history" $message {
195     -re "13\tmain\r\n14\tfib\r\n15\tfib\r\n16\tfib\r\n17\tfib\r\n18\tfib\r\n19\tfib\r\n20\tfib\r\n21\tfib\r\n22  main\r\n$gdb_prompt $" {
196         pass $message
197     }
198     -re "13\tinc\r\n14\tmain\r\n15\tinc\r\n16\tmain\r\n17\tinc\r\n18\tmain\r\n19\tinc\r\n20\tmain\r\n21\tfib\r\n22\tmain\r\n$gdb_prompt $" {
199         # recursive function calls appear only as 1 call
200         kfail "gdb/15240" $message
201     }
202 }