1# This testcase is part of GDB, the GNU debugger. 2# 3# Copyright 2013-2019 Free Software Foundation, Inc. 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 20if { [skip_btrace_tests] } { 21 unsupported "target does not support record-btrace" 22 return -1 23} 24 25standard_testfile .c .S 26if [prepare_for_testing "failed to prepare" $testfile "$srcfile $srcfile2" {debug}] { 27 return -1 28} 29 30if ![runto_main] { 31 untested "failed to run to main" 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 53set traced {} 54set testname "determine number of recorded instructions" 55gdb_test_multiple "info record" $testname { 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 $" { 57 set traced $expect_out(1,string) 58 pass $testname 59 } 60} 61 62# we have exactly 11 instructions here 63set message "exactly 11 instructions" 64if { $traced != 11 } { 65 fail $message 66} else { 67 pass $message 68} 69 70# test that we see the expected instructions 71gdb_test "record instruction-history 3,7" [multi_line \ 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" \ 77 ] 78 79gdb_test "record instruction-history /f 3,+5" [multi_line \ 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" \ 85 ] 86 87gdb_test "record instruction-history /p 7,-5" [multi_line \ 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" \ 93 ] 94 95gdb_test "record instruction-history /pf 3,7" [multi_line \ 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" \ 101 ] 102 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" 104 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" 129set lines [test_lines_length "record instruction-history 1" $message] 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" 138set lines [test_lines_length "record instruction-history 1" $message] 139if { $traced != $lines } { 140 fail $message 141} else { 142 pass $message 143} 144 145# test that the iterator works 146set history_size 4 147gdb_test_no_output "set record instruction-history-size $history_size" 148set message "browse history forward start" 149set lines [test_lines_length "record instruction-history 1" $message] 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] 166if { $lines != 3 } { 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] 195if { $lines != 3 } { 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" 205