]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.btrace/instruction_history.exp
Update Copyright year range in all files maintained by GDB.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.btrace / instruction_history.exp
CommitLineData
2f1d9bdd
MM
1# This testcase is part of GDB, the GNU debugger.
2#
ecd75fc8 3# Copyright 2013-2014 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
20# check for btrace support
21if { [skip_btrace_tests] } { return -1 }
22
23# compile and run to main
24standard_testfile .c .S
25if [prepare_for_testing $testfile.exp $testfile "$srcfile $srcfile2" {debug}] {
26 return -1
27}
28if ![runto_main] {
29 return -1
30}
31
32# set bp before loop and continue
33set bp_location [gdb_get_line_number "bp.1" $srcfile2]
34gdb_breakpoint $srcfile2:$bp_location
35gdb_continue_to_breakpoint "cont to $bp_location" ".*$srcfile2:$bp_location.*"
36
37# start btrace
38gdb_test_no_output "record btrace"
39
40# set bp after loop and continue
41set bp_location [gdb_get_line_number "bp.2" $srcfile2]
42gdb_breakpoint $srcfile2:$bp_location
43gdb_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
50set testname "determine number of recorded instructions"
51gdb_test_multiple "info record" $testname {
52 -re "Active record target: record-btrace\r\nRecorded \(\[0-9\]*\) instructions in \(\[0-9\]*\) functions for thread 1 .*\\.\r\n$gdb_prompt $" {
53 set traced $expect_out(1,string)
54 set traced_functions $expect_out(2,string)
55 pass $testname
56 }
57}
58
59# we have exactly 7 instructions here
60set message "exactly 7 instructions"
61if { $traced != 7 } {
62 fail $message
63} else {
64 pass $message
65}
66
67# test that we see the expected instructions
68gdb_test "record instruction-history 1,6" "
691\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
702\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tdec %eax\r
713\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
724\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tcmp \\\$0x0,%eax\r
735\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r"
74
75gdb_test "record instruction-history /f 1,+5" "
761\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
772\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax\r
783\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
794\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax\r
805\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r"
81
82gdb_test "record instruction-history /p 6,-5" "
831\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
842\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tdec %eax\r
853\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
864\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tcmp \\\$0x0,%eax\r
875\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r"
88
89gdb_test "record instruction-history /pf 1,6" "
901\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
912\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax\r
923\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
934\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax\r
945\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r"
95
96# the following tests are checking the iterators
97# to avoid lots of regexps, we just check the number of lines that
98# were printed during command execution.
99
100# test_lines_output returns the output lines from command as a list.
101proc test_lines_output { command message } {
102 global gdb_prompt
103 set message "test_lines_output: $message"
104 gdb_test_multiple $command $message {
105 -re "\n\(.*\)\r\n$gdb_prompt $" {
106 return [split [string trim $expect_out(1,string)] "\n"]
107 }
108 }
109}
110
111# test_lines_length returns the number of lines from command.
112proc test_lines_length { command message } {
113 return [llength [test_lines_output $command $message]]
114}
115
116# show instruction history with unlimited size, we expect to see
117# all $traced instructions
118gdb_test_no_output "set record instruction-history-size 0"
119set message "record instruction-history - unlimited"
120set lines [test_lines_length "record instruction-history 0" $message]
121if { $traced != $lines } {
122 fail $message
123} else {
124 pass $message
125}
126
127gdb_test_no_output "set record instruction-history-size $traced"
128set message "record instruction-history - traced"
129set lines [test_lines_length "record instruction-history 0" $message]
130if { $traced != $lines } {
131 fail $message
132} else {
133 pass $message
134}
135
136# test that the iterator works
137set history_size 3
138gdb_test_no_output "set record instruction-history-size $history_size"
139set message "browse history forward start"
140set lines [test_lines_length "record instruction-history 0" $message]
141if { $lines != $history_size } {
142 fail $message
143} else {
144 pass $message
145}
146
147set message "browse history forward middle"
148set lines [test_lines_length "record instruction-history +" $message]
149if { $lines != $history_size } {
150 fail $message
151} else {
152 pass $message
153}
154
155set message "browse history forward last"
156set lines [test_lines_length "record instruction-history +" $message]
157if { $lines != 1 } {
158 fail $message
159} else {
160 pass $message
161}
162
163gdb_test "record instruction-history" "At the end of the branch trace record\\." "browse history forward beyond 1"
164
165# make sure we cannot move further
166gdb_test "record instruction-history" "At the end of the branch trace record\\." "browse history forward beyond 2"
167
168set message "browse history backward last"
169set lines [test_lines_length "record instruction-history -" $message]
170if { $lines != $history_size } {
171 fail $message
172} else {
173 pass $message
174}
175
176set message "browse history backward middle"
177set lines [test_lines_length "record instruction-history -" $message]
178if { $lines != $history_size } {
179 fail $message
180} else {
181 pass $message
182}
183
184set message "browse history backward first"
185set lines [test_lines_length "record instruction-history -" $message]
186if { $lines != 1 } {
187 fail $message
188} else {
189 pass $message
190}
191
192gdb_test "record instruction-history -" "At the start of the branch trace record\\." "browse history backward beyond 1"
193
194# make sure we cannot move further back
195gdb_test "record instruction-history -" "At the start of the branch trace record\\." "browse history backward beyond 2"