record-btrace: start counting at one
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.btrace / instruction_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 # compile and run to main
24 standard_testfile .c .S
25 if [prepare_for_testing $testfile.exp $testfile "$srcfile $srcfile2" {debug}] {
26 return -1
27 }
28 if ![runto_main] {
29 return -1
30 }
31
32 # set bp before loop and continue
33 set bp_location [gdb_get_line_number "bp.1" $srcfile2]
34 gdb_breakpoint $srcfile2:$bp_location
35 gdb_continue_to_breakpoint "cont to $bp_location" ".*$srcfile2:$bp_location.*"
36
37 # start btrace
38 gdb_test_no_output "record btrace"
39
40 # set bp after loop and continue
41 set bp_location [gdb_get_line_number "bp.2" $srcfile2]
42 gdb_breakpoint $srcfile2:$bp_location
43 gdb_continue_to_breakpoint "cont to $bp_location" ".*$srcfile2:$bp_location.*"
44
45 # The following test cases test if "browsing" through the
46 # instruction history works as expected. So for the tests
47 # it is necessary to count the number of lines that are
48 # shown by the "record instruction-history" command.
49
50 set traced {}
51 set testname "determine number of recorded instructions"
52 gdb_test_multiple "info record" $testname {
53 -re "Active record target: record-btrace\r\nRecorded \(\[0-9\]*\) instructions in \(\[0-9\]*\) functions for thread 1 .*\\.\r\n$gdb_prompt $" {
54 set traced $expect_out(1,string)
55 pass $testname
56 }
57 }
58
59 # we have exactly 6 instructions here
60 set message "exactly 6 instructions"
61 if { $traced != 6 } {
62 fail $message
63 } else {
64 pass $message
65 }
66
67 # test that we see the expected instructions
68 gdb_test "record instruction-history 2,7" [join [list \
69 "2\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
70 "3\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tdec %eax" \
71 "4\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
72 "5\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
73 "6\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r" \
74 ] "\r\n"]
75
76 gdb_test "record instruction-history /f 2,+5" [join [list \
77 "2\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
78 "3\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax" \
79 "4\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
80 "5\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
81 "6\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r" \
82 ] "\r\n"]
83
84 gdb_test "record instruction-history /p 7,-5" [join [list \
85 "2\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
86 "3\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tdec %eax" \
87 "4\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
88 "5\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
89 "6\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r" \
90 ] "\r\n"]
91
92 gdb_test "record instruction-history /pf 2,7" [join [list \
93 "2\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
94 "3\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax" \
95 "4\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
96 "5\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
97 "6\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r" \
98 ] "\r\n"]
99
100 # the following tests are checking the iterators
101 # to avoid lots of regexps, we just check the number of lines that
102 # were printed during command execution.
103
104 # test_lines_output returns the output lines from command as a list.
105 proc test_lines_output { command message } {
106 global gdb_prompt
107 set message "test_lines_output: $message"
108 gdb_test_multiple $command $message {
109 -re "\n\(.*\)\r\n$gdb_prompt $" {
110 return [split [string trim $expect_out(1,string)] "\n"]
111 }
112 }
113 }
114
115 # test_lines_length returns the number of lines from command.
116 proc test_lines_length { command message } {
117 return [llength [test_lines_output $command $message]]
118 }
119
120 # show instruction history with unlimited size, we expect to see
121 # all $traced instructions
122 gdb_test_no_output "set record instruction-history-size 0"
123 set message "record instruction-history - unlimited"
124 set lines [test_lines_length "record instruction-history 1" $message]
125 if { $traced != $lines } {
126 fail $message
127 } else {
128 pass $message
129 }
130
131 gdb_test_no_output "set record instruction-history-size $traced"
132 set message "record instruction-history - traced"
133 set lines [test_lines_length "record instruction-history 1" $message]
134 if { $traced != $lines } {
135 fail $message
136 } else {
137 pass $message
138 }
139
140 # test that the iterator works
141 set history_size 3
142 gdb_test_no_output "set record instruction-history-size $history_size"
143 set message "browse history forward start"
144 set lines [test_lines_length "record instruction-history 1" $message]
145 if { $lines != $history_size } {
146 fail $message
147 } else {
148 pass $message
149 }
150
151 set history_size 2
152 gdb_test_no_output "set record instruction-history-size $history_size"
153 set message "browse history forward middle"
154 set lines [test_lines_length "record instruction-history +" $message]
155 if { $lines != $history_size } {
156 fail $message
157 } else {
158 pass $message
159 }
160
161 set message "browse history forward last"
162 set lines [test_lines_length "record instruction-history +" $message]
163 if { $lines != 1 } {
164 fail $message
165 } else {
166 pass $message
167 }
168
169 gdb_test "record instruction-history" "At the end of the branch trace record\\." "browse history forward beyond 1"
170
171 # make sure we cannot move further
172 gdb_test "record instruction-history" "At the end of the branch trace record\\." "browse history forward beyond 2"
173
174 set history_size 3
175 gdb_test_no_output "set record instruction-history-size $history_size"
176 set message "browse history backward last"
177 set lines [test_lines_length "record instruction-history -" $message]
178 if { $lines != $history_size } {
179 fail $message
180 } else {
181 pass $message
182 }
183
184 set history_size 2
185 gdb_test_no_output "set record instruction-history-size $history_size"
186 set message "browse history backward middle"
187 set lines [test_lines_length "record instruction-history -" $message]
188 if { $lines != $history_size } {
189 fail $message
190 } else {
191 pass $message
192 }
193
194 set message "browse history backward first"
195 set lines [test_lines_length "record instruction-history -" $message]
196 if { $lines != 1 } {
197 fail $message
198 } else {
199 pass $message
200 }
201
202 gdb_test "record instruction-history -" "At the start of the branch trace record\\." "browse history backward beyond 1"
203
204 # make sure we cannot move further back
205 gdb_test "record instruction-history -" "At the start of the branch trace record\\." "browse history backward beyond 2"
This page took 0.034827 seconds and 4 git commands to generate.