1# This testcase is part of GDB, the GNU debugger. 2# 3# Copyright 2013-2023 Free Software Foundation, Inc. 4# 5# Contributed by Intel Corp. <markus.t.metzger@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 25# The "record goto" command jumps to a specific instruction in the execution 26# trace. To guarantee that we always get the same execution trace, we use 27# an assembly source file. 28# 29# We use different assembly sources based on the target architecture. 30# 31# Luckily, they are similar enough that a single test script can handle 32# both. 33set opts {} 34if [info exists COMPILE] { 35 # make check RUNTESTFLAGS="gdb.btrace/record_goto.exp COMPILE=1" 36 standard_testfile record_goto.c 37 lappend opts debug 38} elseif {[istarget "i?86-*-*"] || [istarget "x86_64-*-*"]} { 39 if {[is_amd64_regs_target]} { 40 standard_testfile x86_64-record_goto.S 41 } else { 42 standard_testfile i686-record_goto.S 43 } 44} else { 45 unsupported "target architecture not supported" 46 return -1 47} 48 49if [prepare_for_testing "failed to prepare" $testfile $srcfile $opts] { 50 return -1 51} 52 53if ![runto_main] { 54 return -1 55} 56 57# we want a small context sizes to simplify the test 58gdb_test_no_output "set record instruction-history-size 3" 59gdb_test_no_output "set record function-call-history-size 3" 60 61# trace the call to the test function 62gdb_test_no_output "record btrace" 63gdb_test "next" 64 65# start by listing all functions 66gdb_test "record function-call-history /ci 1, +20" [multi_line \ 67 "1\tmain\tinst 1,1" \ 68 "2\t fun4\tinst 2,4" \ 69 "3\t fun1\tinst 5,8" \ 70 "4\t fun4\tinst 9,9" \ 71 "5\t fun2\tinst 10,12" \ 72 "6\t fun1\tinst 13,16" \ 73 "7\t fun2\tinst 17,18" \ 74 "8\t fun4\tinst 19,19" \ 75 "9\t fun3\tinst 20,22" \ 76 "10\t fun1\tinst 23,26" \ 77 "11\t fun3\tinst 27,27" \ 78 "12\t fun2\tinst 28,30" \ 79 "13\t fun1\tinst 31,34" \ 80 "14\t fun2\tinst 35,36" \ 81 "15\t fun3\tinst 37,38" \ 82 "16\t fun4\tinst 39,40" \ 83 ] 84 85# let's see if we can go back in history 86gdb_test "record goto 19" ".*fun4 \\(\\) at record_goto.c:43.*" 87 88# the function call history should start at the new location 89gdb_test "record function-call-history /ci" [multi_line \ 90 "8\t fun4\tinst 19,19" \ 91 "9\t fun3\tinst 20,22" \ 92 "10\t fun1\tinst 23,26" \ 93 ] "function-call-history from 19 forwards" 94 95# the instruction history should start at the new location 96gdb_test "record instruction-history" [multi_line \ 97 "19.*" \ 98 "20.*" \ 99 "21.*" \ 100 ] "instruction-history from 19 forwards" 101 102# let's go to another place in the history 103gdb_test "record goto 27" ".*fun3 \\(\\) at record_goto.c:35.*" 104 105# check the back trace at that location 106gdb_test "backtrace" [multi_line \ 107 "#0.*fun3.*at record_goto.c:35.*" \ 108 "#1.*fun4.*at record_goto.c:43.*" \ 109 "#2.*main.*at record_goto.c:49.*" \ 110 "Backtrace stopped: not enough registers or memory available to unwind further" \ 111 ] 112 113# walk the backtrace 114gdb_test "up" ".*fun4.*at record_goto.c:43.*" "up to fun4" 115gdb_test "up" ".*main.*at record_goto.c:49.*" "up to main" 116 117# the function call history should start at the new location 118gdb_test "record function-call-history /ci -" [multi_line \ 119 "9\t fun3\tinst 20,22" \ 120 "10\t fun1\tinst 23,26" \ 121 "11\t fun3\tinst 27,27" \ 122 ] "function-call-history from 27 backwards" 123 124# the instruction history should start at the new location 125gdb_test "record instruction-history -" [multi_line \ 126 "25.*" \ 127 "26.*" \ 128 "27.*" \ 129 ] "instruction-history from 27 backwards" 130 131# test that we can go to the begin of the trace 132gdb_test "record goto begin" ".*main \\(\\) at record_goto.c:49.*" 133 134# check that we're filling up the context correctly 135gdb_test "record function-call-history /ci -" [multi_line \ 136 "1\tmain\tinst 1,1" \ 137 "2\t fun4\tinst 2,4" \ 138 "3\t fun1\tinst 5,8" \ 139 ] "function-call-history from begin backwards" 140 141# check that we're filling up the context correctly 142gdb_test "record instruction-history -" [multi_line \ 143 "1.*" \ 144 "2.*" \ 145 "3.*" \ 146 ] "instruction-history from begin backwards" 147 148# we should get the exact same history from the first instruction 149gdb_test "record goto 2" ".*fun4 \\(\\) at record_goto.c:40.*" 150 151# check that we're filling up the context correctly 152gdb_test "record function-call-history /ci -" [multi_line \ 153 "1\tmain\tinst 1,1" \ 154 "2\t fun4\tinst 2,4" \ 155 "3\t fun1\tinst 5,8\r" \ 156 ] "function-call-history from 2 backwards" 157 158# check that we're filling up the context correctly 159gdb_test "record instruction-history -" [multi_line \ 160 "1.*" \ 161 "2.*" \ 162 "3.*" \ 163 ] "instruction-history from 2 backwards" 164 165# check that we can go to the end of the trace 166gdb_test "record goto end" ".*main \\(\\) at record_goto.c:50.*" 167 168# check that we're filling up the context correctly 169gdb_test "record function-call-history /ci" [multi_line \ 170 "14\t fun2\tinst 35,36" \ 171 "15\t fun3\tinst 37,38" \ 172 "16\t fun4\tinst 39,40" \ 173 ] "function-call-history from end forwards" 174 175# check that we're filling up the context correctly 176gdb_test "record instruction-history" [multi_line \ 177 "38.*" \ 178 "39.*" \ 179 "40.*\r" \ 180 ] "instruction-history from end forwards" 181 182# we should get the exact same history from the second to last instruction 183gdb_test "record goto 39" ".*fun4 \\(\\) at record_goto.c:44.*" 184 185# check that we're filling up the context correctly 186gdb_test "record function-call-history /ci" [multi_line \ 187 "14\t fun2\tinst 35,36" \ 188 "15\t fun3\tinst 37,38" \ 189 "16\t fun4\tinst 39,40\r" \ 190 ] "function-call-history from 39 forwards" 191 192# check that we're filling up the context correctly 193gdb_test "record instruction-history" [multi_line \ 194 "38.*" \ 195 "39.*" \ 196 "40.*\r" \ 197 ] "instruction-history from 39 forwards" 198