]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.btrace/instruction_history.exp
Fix more cases of improper test names
[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#
618f726f 3# Copyright 2013-2016 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
5b362f04 25if [prepare_for_testing "failed to prepare" $testfile "$srcfile $srcfile2" {debug}] {
2f1d9bdd
MM
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
23a7fe75 50set traced {}
2f1d9bdd
MM
51set testname "determine number of recorded instructions"
52gdb_test_multiple "info record" $testname {
31fd9caa 53 -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 54 set traced $expect_out(1,string)
2f1d9bdd
MM
55 pass $testname
56 }
57}
58
6e07b1d2
MM
59# we have exactly 11 instructions here
60set message "exactly 11 instructions"
61if { $traced != 11 } {
2f1d9bdd
MM
62 fail $message
63} else {
64 pass $message
65}
66
67# test that we see the expected instructions
3c724c8c 68gdb_test "record instruction-history 3,7" [multi_line \
6e07b1d2
MM
69 "3\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
70 "4\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tdec %eax" \
71 "5\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
72 "6\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
73 "7\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r" \
3c724c8c 74 ]
5de9129b 75
3c724c8c 76gdb_test "record instruction-history /f 3,+5" [multi_line \
6e07b1d2
MM
77 "3\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
78 "4\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax" \
79 "5\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
80 "6\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
81 "7\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r" \
3c724c8c 82 ]
5de9129b 83
3c724c8c 84gdb_test "record instruction-history /p 7,-5" [multi_line \
da8c46d2
MM
85 "3\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
86 "4\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tdec %eax" \
87 "5\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
88 "6\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
89 "7\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r" \
3c724c8c 90 ]
5de9129b 91
3c724c8c 92gdb_test "record instruction-history /pf 3,7" [multi_line \
da8c46d2
MM
93 "3\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
94 "4\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax" \
95 "5\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
96 "6\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
97 "7\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r" \
3c724c8c 98 ]
2f1d9bdd 99
6e07b1d2 100gdb_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 101
2f1d9bdd
MM
102# the following tests are checking the iterators
103# to avoid lots of regexps, we just check the number of lines that
104# were printed during command execution.
105
106# test_lines_output returns the output lines from command as a list.
107proc test_lines_output { command message } {
108 global gdb_prompt
109 set message "test_lines_output: $message"
110 gdb_test_multiple $command $message {
111 -re "\n\(.*\)\r\n$gdb_prompt $" {
112 return [split [string trim $expect_out(1,string)] "\n"]
113 }
114 }
115}
116
117# test_lines_length returns the number of lines from command.
118proc test_lines_length { command message } {
119 return [llength [test_lines_output $command $message]]
120}
121
122# show instruction history with unlimited size, we expect to see
123# all $traced instructions
124gdb_test_no_output "set record instruction-history-size 0"
125set message "record instruction-history - unlimited"
5de9129b 126set lines [test_lines_length "record instruction-history 1" $message]
2f1d9bdd
MM
127if { $traced != $lines } {
128 fail $message
129} else {
130 pass $message
131}
132
133gdb_test_no_output "set record instruction-history-size $traced"
134set message "record instruction-history - traced"
5de9129b 135set lines [test_lines_length "record instruction-history 1" $message]
2f1d9bdd
MM
136if { $traced != $lines } {
137 fail $message
138} else {
139 pass $message
140}
141
142# test that the iterator works
6e07b1d2 143set history_size 4
2f1d9bdd
MM
144gdb_test_no_output "set record instruction-history-size $history_size"
145set message "browse history forward start"
5de9129b 146set lines [test_lines_length "record instruction-history 1" $message]
2f1d9bdd
MM
147if { $lines != $history_size } {
148 fail $message
149} else {
150 pass $message
151}
152
153set message "browse history forward middle"
154set lines [test_lines_length "record instruction-history +" $message]
155if { $lines != $history_size } {
156 fail $message
157} else {
158 pass $message
159}
160
161set message "browse history forward last"
162set lines [test_lines_length "record instruction-history +" $message]
6e07b1d2 163if { $lines != 3 } {
2f1d9bdd
MM
164 fail $message
165} else {
166 pass $message
167}
168
169gdb_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
172gdb_test "record instruction-history" "At the end of the branch trace record\\." "browse history forward beyond 2"
173
174set message "browse history backward last"
175set lines [test_lines_length "record instruction-history -" $message]
176if { $lines != $history_size } {
177 fail $message
178} else {
179 pass $message
180}
181
182set message "browse history backward middle"
183set lines [test_lines_length "record instruction-history -" $message]
184if { $lines != $history_size } {
185 fail $message
186} else {
187 pass $message
188}
189
190set message "browse history backward first"
191set lines [test_lines_length "record instruction-history -" $message]
6e07b1d2 192if { $lines != 3 } {
2f1d9bdd
MM
193 fail $message
194} else {
195 pass $message
196}
197
198gdb_test "record instruction-history -" "At the start of the branch trace record\\." "browse history backward beyond 1"
199
200# make sure we cannot move further back
201gdb_test "record instruction-history -" "At the start of the branch trace record\\." "browse history backward beyond 2"