1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2013-2014 Free Software Foundation, Inc.
5 # Contributed by Intel Corp. <christian.himpel@intel.com>
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.
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.
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/>.
20 # check for btrace support
21 if { [skip_btrace_tests] } { return -1 }
23 # compile and run to main
24 standard_testfile .c .S
25 if [prepare_for_testing $testfile.exp $testfile "$srcfile $srcfile2" {debug}] {
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.*"
38 gdb_test_no_output "record btrace"
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.*"
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.
50 set testname "determine number of recorded instructions"
51 gdb_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)
59 # we have exactly 7 instructions here
60 set message "exactly 7 instructions"
67 # test that we see the expected instructions
68 gdb_test "record instruction-history 1,6" "
69 1\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
70 2\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tdec %eax\r
71 3\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
72 4\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tcmp \\\$0x0,%eax\r
73 5\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r"
75 gdb_test "record instruction-history /f 1,+5" "
76 1\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
77 2\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax\r
78 3\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
79 4\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax\r
80 5\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r"
82 gdb_test "record instruction-history /p 6,-5" "
83 1\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
84 2\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tdec %eax\r
85 3\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
86 4\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tcmp \\\$0x0,%eax\r
87 5\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r"
89 gdb_test "record instruction-history /pf 1,6" "
90 1\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
91 2\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax\r
92 3\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
93 4\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax\r
94 5\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r"
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.
100 # test_lines_output returns the output lines from command as a list.
101 proc test_lines_output { command message } {
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"]
111 # test_lines_length returns the number of lines from command.
112 proc test_lines_length { command message } {
113 return [llength [test_lines_output $command $message]]
116 # show instruction history with unlimited size, we expect to see
117 # all $traced instructions
118 gdb_test_no_output "set record instruction-history-size 0"
119 set message "record instruction-history - unlimited"
120 set lines [test_lines_length "record instruction-history 0" $message]
121 if { $traced != $lines } {
127 gdb_test_no_output "set record instruction-history-size $traced"
128 set message "record instruction-history - traced"
129 set lines [test_lines_length "record instruction-history 0" $message]
130 if { $traced != $lines } {
136 # test that the iterator works
138 gdb_test_no_output "set record instruction-history-size $history_size"
139 set message "browse history forward start"
140 set lines [test_lines_length "record instruction-history 0" $message]
141 if { $lines != $history_size } {
147 set message "browse history forward middle"
148 set lines [test_lines_length "record instruction-history +" $message]
149 if { $lines != $history_size } {
155 set message "browse history forward last"
156 set lines [test_lines_length "record instruction-history +" $message]
163 gdb_test "record instruction-history" "At the end of the branch trace record\\." "browse history forward beyond 1"
165 # make sure we cannot move further
166 gdb_test "record instruction-history" "At the end of the branch trace record\\." "browse history forward beyond 2"
168 set message "browse history backward last"
169 set lines [test_lines_length "record instruction-history -" $message]
170 if { $lines != $history_size } {
176 set message "browse history backward middle"
177 set lines [test_lines_length "record instruction-history -" $message]
178 if { $lines != $history_size } {
184 set message "browse history backward first"
185 set lines [test_lines_length "record instruction-history -" $message]
192 gdb_test "record instruction-history -" "At the start of the branch trace record\\." "browse history backward beyond 1"
194 # make sure we cannot move further back
195 gdb_test "record instruction-history -" "At the start of the branch trace record\\." "browse history backward beyond 2"