aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.arch/mips-octeon-bbit.exp
blob: 58322119976c20e150a9341bfec1a9859334fd0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Copyright (C) 2012-2016 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

# Test single-step on bbit.  

if ![istarget "*octeon*"] {
  return -1
}

proc current_insn {} {
    global gdb_prompt

    send_gdb "x/i \$pc\n"
    gdb_expect {
	-re ".*?:\\s+\(.*?\)\\s*$gdb_prompt $" {
	    set insn $expect_out(1,string)
	    return $insn
	}
    }
    return ""
}

proc single_step {} {
    global gdb_prompt

    send_gdb "si\n"
    gdb_expect {
	-re "$gdb_prompt \$" {
	    return 1
	}
    }
    return 0
}

proc single_step_until { match } {
    global timeout

    set insn [current_insn]
    set start [timestamp]
    while { $insn != "" && [timestamp] - $start < 3*$timeout } {
	if [regexp $match $insn] {
	    return 1
	}
	if {![single_step]} {
	    return 0
	}
	set insn [current_insn]
    }
    return 0
}

proc test_bbit { name taken } {
    if {![single_step_until "bbit"]} {
	fail "$name single-step until bbit"
	return
    }
    pass "$name single-step until bbit"
    gdb_test "si" "" "$name single-step on bbit"
    if [regexp "li\\s+\[sv\]0,$taken" [current_insn]] {
	pass "$name check insn after bbit"
    } else {
	send_log "expected: li\\s+\[sv\]0,$taken found [current_insn]\n"
	fail "$name check insn after bbit"
    }
}

set testfile "mips-octeon-bbit"
set srcfile ${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}

if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
       {debug nowarnings}] != "" } {
     fail "compilation"
     return
}

pass "compilation"

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
# Native needs run.
runto_main

set tests ""
foreach n [list "0_10" "0_36" "1_20" "1_49"] {
    lappend tests "bbit_is_taken_$n"
}
foreach func $tests {
    gdb_test "break $func" "Breakpoint.*at.*" "set breakpoint on $func"
}

foreach func $tests {
    gdb_test "continue" "Continuing.*Breakpoint.*$func.*" "hit $func first"
    test_bbit "$func branch taken" 1
    gdb_test "continue" "Continuing.*Breakpoint.*$func.*" "hit $func second"
    test_bbit "$func branch not taken" 0
}