xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.arch/i386-mpx.exp (revision f3cfa6f6ce31685c6c4a758bc430e69eb99f50a4)
1# Copyright 2013-2017 Free Software Foundation, Inc.
2#
3# Contributed by Intel Corp. <walfred.tedeschi@intel.com>
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18if { ![istarget i?86-*-*] && ![istarget x86_64-*-* ] } {
19    verbose "Skipping x86 MPX tests."
20    return
21}
22
23standard_testfile
24
25if { ![istarget i?86-*-*] && ![istarget x86_64-*-* ] } {
26    verbose "Skipping x86 MPX tests."
27    return
28}
29
30set comp_flags "-mmpx -fcheck-pointer-bounds -I${srcdir}/../nat/"
31
32if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
33     [list debug nowarnings additional_flags=${comp_flags}]] } {
34    return -1
35}
36
37if ![runto_main] {
38    untested "could not run to main"
39    return -1
40}
41
42set supports_mpx 0
43set test "probe MPX support"
44gdb_test_multiple "print have_mpx()" $test {
45    -re ".. = 1\r\n$gdb_prompt $" {
46        pass $test
47        set supports_mpx 1
48    }
49    -re ".. = 0\r\n$gdb_prompt $" {
50        pass $test
51    }
52}
53
54if { !$supports_mpx } {
55    unsupported "processor does not support MPX"
56    return
57}
58
59# Test bndcfg register and bndstatus at startup
60set test_string "\\\{raw = 0x\[0-9a-f\]+, config = \\\{base = \[0-9\]+,\
61reserved = \[0-9\]+, preserved = \[0-9\]+, enabled = \[0-9\]+\\\}\\\}"
62
63gdb_test "print \$bndcfgu" $test_string "bndcfgu formating"
64gdb_test "print \$bndcfgu.config.enabled" "= 1" "test if bndstatus is enabled"
65gdb_test "print \$bndstatus" "\\\{raw = 0x0, status = \\\{bde = 0, error = 0\\\}\\\}" \
66		"bndstatus formating"
67gdb_test "print \$bndstatus.raw" "= \\\(void \\\*\\\) 0x0" "bndstatus is zero by startup"
68
69# Read values from pseudo registers.
70gdb_breakpoint [ gdb_get_line_number "break here" ]
71gdb_continue_to_breakpoint "break here" ".*break here.*"
72
73set test_string ".*\\\{lbound = 0xa, ubound = 0x13\\\}.*"
74gdb_test "info register bnd0" ".*bnd0$test_string" "pure bnd0 register"
75
76set test_string ".*\\\{lbound = 0x14, ubound = 0x1d\\\}.*"
77gdb_test "info register bnd1" ".*bnd1$test_string" "pure bnd1 register"
78
79set test_string ".*\\\{lbound = 0x1e, ubound = 0x27\\\}.*"
80gdb_test "info register bnd2" ".*bnd2$test_string" "pure bnd2 register"
81
82set test_string ".*\\\{lbound = 0x28, ubound = 0x31\\\}.*"
83gdb_test "info register bnd3" ".*bnd3$test_string" "pure bnd3 register"
84
85# Read value from registers bndrs.
86
87set test_string ".*\\\{lbound = 0xa, ubound_raw = 0x\[f\]+ec\\\}.*"
88gdb_test "info register bnd0raw" ".*bnd0$test_string" "pure bnd0r register"
89
90set test_string ".*\\\{lbound = 0x14, ubound_raw = 0x\[f\]+e2\\\}.*"
91gdb_test "info register bnd1raw" ".*bnd1$test_string" "pure bnd1r register"
92
93set test_string ".*\\\{lbound = 0x1e, ubound_raw = 0x\[f\]+d8\\\}.*"
94gdb_test "info register bnd2raw" ".*bnd2$test_string" "pure bnd2r register"
95
96set test_string ".*\\\{lbound = 0x28, ubound_raw = 0x\[f\]+ce\\\}.*"
97gdb_test "info register bnd3raw" ".*bnd3$test_string" "pure bnd3r register"
98
99# Setting fields on bnds
100set test_string ".*\\\{lbound = 0xa, ubound = 0x400\\\}.*"
101gdb_test "print \$bnd0.ubound = 0x400" "= \\\(void \\\*\\\) 0x400" "set value for bnd0.ubound"
102gdb_test "print  \$bnd0" "$test_string" "after setting bnd0.ubound"
103set test_string ".*\\\{lbound = 0xa, ubound_raw = 0x\[f\]+bff\\\}.*"
104gdb_test "print /x \$bnd0raw" "$test_string" "bnd0raw after set bnd0.ubound"
105
106set test_string ".*\\\{lbound = 0x1, ubound = 0x400\\\}.*"
107gdb_test "print \$bnd0.lbound = 0x1" "= \\\(void \\\*\\\) 0x1" "set value for bnd0.lbound"
108gdb_test "print  \$bnd0" "$test_string" "after setting bnd0.lbound"
109set test_string ".*\\\{lbound = 0x1, ubound_raw = 0x\[f\]+bff\\\}.*"
110gdb_test "print /x \$bnd0raw" "$test_string" "bnd0raw after set bnd0.lbound"
111
112# Setting fields on bnd0raw.
113set test_string ".*\\\{lbound = 0x1, ubound_raw = 0x600\\\}.*"
114gdb_test "print /x \$bnd0raw.ubound_raw = 0x600" "= 0x600" "set value for bnd0raw.ubound"
115gdb_test "print /x \$bnd0raw" "$test_string" "bnd0raw after setting bnd0raw.ubound"
116set test_string ".*\\\{lbound = 0x1, ubound = 0x\[f\]+9ff\\\}.*"
117gdb_test "print /x \$bnd0" "$test_string" "bnd0 after set bnd0raw.ubound"
118
119set test_string ".*\\\{lbound = 0x100, ubound_raw = 0x600\\\}.*"
120gdb_test "print /x \$bnd0raw.lbound = 0x100" "= 0x100" "set value for bnd0raw.lbound"
121gdb_test "print /x \$bnd0raw" "$test_string" "bnd0raw after setting bnd0raw.lbound"
122set test_string ".*\\\{lbound = 0x100, ubound = 0x\[f\]+9ff\\\}.*"
123gdb_test "print /x \$bnd0" "$test_string" "bnd0 after set bnd0raw.lbound"
124
125# Set full value bnd raw
126set test_string ".*\\\{lbound = 0x10, ubound_raw = 0x\[f\]+cff\\\}.*"
127gdb_test "print /x \$bnd0raw = {0x10, ~0x300}" "$test_string" "set full value for bnd0raw"
128set test_string ".*\\\{lbound = 0x10, ubound = 0x300\\\}.*"
129gdb_test "print /x \$bnd0" "$test_string" "bnd0raw after setting full bnd0raw"
130
131# Set full value bnd
132set test_string ".*\\\{lbound = 0x10, ubound = 0x300\\\}.*"
133gdb_test "print /x \$bnd0 = {0x10, 0x300}" "$test_string" "set full value for bnd0"
134set test_string ".*\\\{lbound = 0x10, ubound_raw = 0x\[f\]+cff\\\}.*"
135gdb_test "print /x \$bnd0raw" "$test_string" "bnd0raw after setting full bnd0"
136
137# Test bndcfg register and bndstatus after a failure on bndstr
138gdb_test "print \$bndstatus.status.error" "= 2" "bndstatus error is 2\
139after a failure on allocating an entry"
140
141# Going to test the python extension for lenght.
142if { [skip_python_tests] } { continue }
143# Verify if size is right
144set test_string ".*\\\: size 17.*"
145gdb_test "print /x \$bnd0 = {0x10, 0x20}" "$test_string" "verify size for bnd0"
146
147send_gdb "quit\n"
148