1# Copyright 2019-2020 Free Software Foundation, Inc. 2# 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16# This tests GDB's ability to handle 6 and 8 byte instructions in the 17# RISC-V prologue scanner. These instruction should be ignored, but 18# should not result in an error that interrupts the debug session. 19# 20# Each of the files riscv-unwind-long-insn-*.s include a function 21# (func) that contains a fake long instruction (6 or 8 bytes) in the 22# prologue. We trick GDB into parsing the fake instruction by tail 23# calling from a different function, 'bar' to the middle of 'func'. 24 25if {![istarget "riscv*-*-*"]} { 26 verbose "Skipping ${gdb_test_file_name}." 27 return 28} 29 30foreach_with_prefix {insn_size} {6 8} { 31 standard_testfile riscv-unwind-long-insn.c \ 32 riscv-unwind-long-insn-${insn_size}.s 33 34 set testfile "${testfile}-${insn_size}" 35 if {[prepare_for_testing "failed to prepare" $testfile \ 36 "$srcfile $srcfile2" debug]} { 37 return -1 38 } 39 40 if ![runto_main] then { 41 fail "can't run to main" 42 return 0 43 } 44 45 gdb_breakpoint "bar" 46 gdb_continue_to_breakpoint "bar" 47 48 # This next single instruction step takes us through a tail-call 49 # from 'bar' into 'func'. 50 gdb_test "si" "func \(\).*" 51 52 # Now check that we have a sane backtrace. 53 gdb_test "bt" \ 54 [multi_line \ 55 "#0\[ \t\]*func \\\(\\\) at .*$srcfile2:\[0-9\]+" \ 56 "#1\[ \t\]*$hex in main \\\(\\\) at .*$srcfile:\[0-9\]+"] \ 57 "Backtrace to the main frame" 58 59 # Finally finish, and we should end up back in main. 60 gdb_test "finish" "main \\\(\\\) at .*$srcfile:.*" 61} 62