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