| 1 | # Copyright 2010-2016 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 | # Test single stepping over Thumb-2 IT blocks. |
| 17 | |
| 18 | if {![istarget arm*-*eabi*]} then { |
| 19 | verbose "Skipping Thumb-2 tests." |
| 20 | return |
| 21 | } |
| 22 | |
| 23 | standard_testfile .S |
| 24 | |
| 25 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != "" } { |
| 26 | untested "failed to compile" |
| 27 | return -1 |
| 28 | } |
| 29 | |
| 30 | gdb_exit |
| 31 | gdb_start |
| 32 | gdb_reinitialize_dir $srcdir/$subdir |
| 33 | gdb_load ${binfile} |
| 34 | |
| 35 | if ![runto_main] then { |
| 36 | untested "could not run to main" |
| 37 | return -1 |
| 38 | } |
| 39 | |
| 40 | # Make sure that the compiler options allow Thumb-2. |
| 41 | gdb_test_multiple "list" "list main" { |
| 42 | -re ".*@ No Thumb-2.*$gdb_prompt $" { |
| 43 | pass "list main" |
| 44 | untested "skipping tests due to lack of Thumb-2" |
| 45 | return -1 |
| 46 | } |
| 47 | -re ".*@ Thumb-2 OK.*$gdb_prompt $" { |
| 48 | pass "list main" |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | proc test_it_block { func } { |
| 53 | global gdb_prompt |
| 54 | global software_step |
| 55 | |
| 56 | if { ! [gdb_breakpoint "*${func}"] } { |
| 57 | unresolved "$func, IT block tests" |
| 58 | return |
| 59 | } |
| 60 | |
| 61 | gdb_test "call ${func}()" "Breakpoint.*@ Setup.*" "$func, call" |
| 62 | |
| 63 | set expected 0 |
| 64 | set reached 0 |
| 65 | set steps 0 |
| 66 | set ok 1 |
| 67 | while { $ok } { |
| 68 | set ok 0 |
| 69 | set msg "$func, stepi $steps" |
| 70 | gdb_test_multiple "stepi" "$msg" { |
| 71 | -re ".*@ Setup.*$gdb_prompt $" { |
| 72 | pass "$msg" |
| 73 | set ok 1 |
| 74 | } |
| 75 | -re ".*@ IT instruction, Expected == (\[0-9\]*)\r\n$gdb_prompt $" { |
| 76 | set expected $expect_out(1,string) |
| 77 | pass "$msg" |
| 78 | set ok 1 |
| 79 | } |
| 80 | -re ".*@ Reached.*$gdb_prompt $" { |
| 81 | incr reached |
| 82 | pass "$msg" |
| 83 | set ok 1 |
| 84 | if { [regexp {@ Reached, Set ([^\r\n]*)\r\n} $expect_out(0,string) dummy change] } { |
| 85 | gdb_test "set $change" "" "$func, set $change" |
| 86 | } |
| 87 | } |
| 88 | -re ".*@ Not reached.*$gdb_prompt $" { |
| 89 | # An instruction in an IT block whose predicate is false when |
| 90 | # we reach it. If using software single step, we should not |
| 91 | # stop here. |
| 92 | if { $software_step } { |
| 93 | fail "$msg" |
| 94 | } else { |
| 95 | pass "$msg" |
| 96 | set ok 1 |
| 97 | } |
| 98 | } |
| 99 | -re ".*@ Never reached.*$gdb_prompt $" { |
| 100 | # An instruction that should be branched over. |
| 101 | fail "$msg" |
| 102 | } |
| 103 | -re ".*@ Done.*$gdb_prompt $" { |
| 104 | pass "$msg" |
| 105 | if { $reached == $expected } { |
| 106 | pass "$func, correct instructions reached" |
| 107 | } else { |
| 108 | fail "$func, correct instructions reached" |
| 109 | } |
| 110 | if { [regexp {@ Done, Check ([^\r\n]*)\r\n} $expect_out(0,string) dummy check] } { |
| 111 | gdb_test "print $check" ".* = 1" "$func, $check" |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | if { ! $ok } { |
| 116 | break |
| 117 | } |
| 118 | incr steps |
| 119 | continue |
| 120 | } |
| 121 | |
| 122 | gdb_test "continue" "" "$func, continue" |
| 123 | return |
| 124 | } |
| 125 | |
| 126 | proc test_it_break { ndx } { |
| 127 | global software_step |
| 128 | |
| 129 | set line [gdb_get_line_number "@ Break ${ndx}"] |
| 130 | |
| 131 | if { ! [gdb_breakpoint "${line}"] } { |
| 132 | unresolved "continue to breakpoint: test ${ndx}" |
| 133 | return |
| 134 | } |
| 135 | |
| 136 | if { $software_step } { |
| 137 | gdb_continue_to_breakpoint "test ${ndx}" ".*@ Location ${ndx}.*" |
| 138 | } else { |
| 139 | gdb_continue_to_breakpoint "test ${ndx}" ".*@ Break ${ndx}.*" |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | # If we are using software single-stepping in GDB, then GDB will not |
| 144 | # stop at conditional instructions with a false predicate during stepi. |
| 145 | # If we are using a simulator or debug interface with hardware single |
| 146 | # step, then GDB will stop at such instructions. |
| 147 | if { [istarget arm*-linux*] } { |
| 148 | set software_step 1 |
| 149 | } else { |
| 150 | set software_step 0 |
| 151 | } |
| 152 | |
| 153 | for { set i 1 } { $i <= 8 } { incr i } { |
| 154 | test_it_block it_${i} |
| 155 | } |
| 156 | |
| 157 | gdb_breakpoint "*it_breakpoints" |
| 158 | gdb_test "call it_breakpoints()" "Breakpoint.*" |
| 159 | for { set i 1 } { $i <= 7 } { incr i } { |
| 160 | test_it_break ${i} |
| 161 | } |