btrace: change branch trace data structure
[deliverable/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
23a7fe75 50set traced {}
2f1d9bdd
MM
51set testname "determine number of recorded instructions"
52gdb_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)
2f1d9bdd
MM
55 pass $testname
56 }
57}
58
23a7fe75
MM
59# we have exactly 6 instructions here
60set message "exactly 6 instructions"
61if { $traced != 6 } {
2f1d9bdd
MM
62 fail $message
63} else {
64 pass $message
65}
66
67# test that we see the expected instructions
724c7dd8
MM
68gdb_test "record instruction-history 1,6" [join [list \
69 "1\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
70 "2\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tdec %eax" \
71 "3\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
72 "4\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
73 "5\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>"] "\r\n"]
2f1d9bdd 74
724c7dd8
MM
75gdb_test "record instruction-history /f 1,+5" [join [list \
76 "1\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
77 "2\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax" \
78 "3\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
79 "4\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
80 "5\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r" \
81] "\r\n"]
2f1d9bdd 82
724c7dd8
MM
83gdb_test "record instruction-history /p 6,-5" [join [list \
84 "1\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
85 "2\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tdec %eax" \
86 "3\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
87 "4\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
88 "5\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r" \
89] "\r\n"]
2f1d9bdd 90
724c7dd8
MM
91gdb_test "record instruction-history /pf 1,6" [join [list \
92 "1\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
93 "2\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax" \
94 "3\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>" \
95 "4\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
96 "5\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r" \
97] "\r\n"]
2f1d9bdd
MM
98
99# the following tests are checking the iterators
100# to avoid lots of regexps, we just check the number of lines that
101# were printed during command execution.
102
103# test_lines_output returns the output lines from command as a list.
104proc test_lines_output { command message } {
105 global gdb_prompt
106 set message "test_lines_output: $message"
107 gdb_test_multiple $command $message {
108 -re "\n\(.*\)\r\n$gdb_prompt $" {
109 return [split [string trim $expect_out(1,string)] "\n"]
110 }
111 }
112}
113
114# test_lines_length returns the number of lines from command.
115proc test_lines_length { command message } {
116 return [llength [test_lines_output $command $message]]
117}
118
119# show instruction history with unlimited size, we expect to see
120# all $traced instructions
121gdb_test_no_output "set record instruction-history-size 0"
122set message "record instruction-history - unlimited"
123set lines [test_lines_length "record instruction-history 0" $message]
124if { $traced != $lines } {
125 fail $message
126} else {
127 pass $message
128}
129
130gdb_test_no_output "set record instruction-history-size $traced"
131set message "record instruction-history - traced"
132set lines [test_lines_length "record instruction-history 0" $message]
133if { $traced != $lines } {
134 fail $message
135} else {
136 pass $message
137}
138
139# test that the iterator works
140set history_size 3
141gdb_test_no_output "set record instruction-history-size $history_size"
142set message "browse history forward start"
143set lines [test_lines_length "record instruction-history 0" $message]
144if { $lines != $history_size } {
145 fail $message
146} else {
147 pass $message
148}
149
23a7fe75
MM
150set history_size 2
151gdb_test_no_output "set record instruction-history-size $history_size"
2f1d9bdd
MM
152set message "browse history forward middle"
153set lines [test_lines_length "record instruction-history +" $message]
154if { $lines != $history_size } {
155 fail $message
156} else {
157 pass $message
158}
159
160set message "browse history forward last"
161set lines [test_lines_length "record instruction-history +" $message]
162if { $lines != 1 } {
163 fail $message
164} else {
165 pass $message
166}
167
168gdb_test "record instruction-history" "At the end of the branch trace record\\." "browse history forward beyond 1"
169
170# make sure we cannot move further
171gdb_test "record instruction-history" "At the end of the branch trace record\\." "browse history forward beyond 2"
172
23a7fe75
MM
173set history_size 3
174gdb_test_no_output "set record instruction-history-size $history_size"
2f1d9bdd
MM
175set message "browse history backward last"
176set lines [test_lines_length "record instruction-history -" $message]
177if { $lines != $history_size } {
178 fail $message
179} else {
180 pass $message
181}
182
23a7fe75
MM
183set history_size 2
184gdb_test_no_output "set record instruction-history-size $history_size"
2f1d9bdd
MM
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]
195if { $lines != 1 } {
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"
This page took 0.135189 seconds and 4 git commands to generate.