aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.arch/aarch64-sighandler-regs.exp
blob: 3d683f21189d116542d5c92d5bfac457d9de38de (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Copyright 2018-2019 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/>.
#
# This file is part of the gdb testsuite.

if {![is_aarch64_target]} {
    verbose "Skipping ${gdb_test_file_name}."
    return -1
}

set compile_flags {debug}

if { [skip_aarch64_sve_tests] } {
    unsupported "target does not support SVE"
    set sve_hw 0
} else {
    set sve_hw 1
    lappend compile_flags "additional_flags=-DSVE"
}

standard_testfile
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} ${compile_flags}] } {
    return -1
}

if ![runto_main] {
    untested "could not run to main"
    return -1
}

set endianness [get_endianness]

if {$endianness == "little"} {
    set reg_handler_value_128 "0x5f5e5d5c5b5a59585756555453525150"
    set reg_handler_value_64 "0x5756555453525150"
    set reg_handler_value_32 "0x53525150"
    set reg_handler_value_16 "0x5150"
    set reg_handler_value_8 "0x50"
    set reg_main_value_128 "0x1f1e1d1c1b1a19181716151413121110"
    set reg_main_value_64 "0x1716151413121110"
    set reg_main_value_32 "0x13121110"
    set reg_main_value_16 "0x1110"
    set reg_main_value_8 "0x10"
} else {
    set reg_handler_value_128 "0x505152535455565758595a5b5c5d5e5f"
    set reg_handler_value_64 "0x5051525354555657"
    set reg_handler_value_32 "0x50515253"
    set reg_handler_value_16 "0x5051"
    set reg_handler_value_8 "0x50"
    set reg_main_value_128 "0x101112131415161718191a1b1c1d1e1f"
    set reg_main_value_64 "0x1011121314151617"
    set reg_main_value_32 "0x10111213"
    set reg_main_value_16 "0x1011"
    set reg_main_value_8 "0x10"
}
set zreg_handler_value "\\{0x5756555453525150, .*"
set zreg_main_value "\\{0x1716151413121110, .*"
set preg_handler_value "\\{0x11, .*"
set preg_main_value "\\{0x1, 0x0, .*"

#Ignore x0, and x29 to x31
set xreg_nums [list 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 21 22 23 24 \
		    25 26 27 28 ]
set vreg_nums [list 0 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 21 22 23 \
		    24 25 26 27 28 29 30 31]
set preg_nums [list 0 1 2 3 4 5 6 7 8 9 11 12 13 14 15]

proc check_regs {regtype regnums value postfix} {
  foreach regnum $regnums {
    gdb_test "print /x \$$regtype$regnum$postfix" \
      ".* = {?$value}?" \
      "check register \$$regtype$regnum has value $value"
  }
}

# Run until end of signal handler

gdb_test "continue" \
    "Continuing.*Program received signal SIGILL.*" \
    "continue until signal"

gdb_breakpoint [gdb_get_line_number "exit(0)"]
gdb_continue_to_breakpoint "exit" ".*exit.*"

set handlerframe [get_current_frame_number]
set mainframe [expr $handlerframe + 2]


# Check register values

check_regs x $xreg_nums $reg_handler_value_64 ""
check_regs v $vreg_nums $reg_handler_value_128 ".q.u"
check_regs q $vreg_nums $reg_handler_value_128 ".u"
check_regs d $vreg_nums $reg_handler_value_64 ".u"
check_regs s $vreg_nums $reg_handler_value_32 ".u"
check_regs h $vreg_nums $reg_handler_value_16 ".u"
check_regs b $vreg_nums $reg_handler_value_8 ".u"
if { $sve_hw } {
  check_regs z $vreg_nums $zreg_handler_value ".d.u"
  check_regs p $preg_nums $preg_handler_value ""
}

# Switch to the frame for main(), and check register values

gdb_test "frame $mainframe" \
      "#$mainframe.*in main ().*" \
      "set to main frame"

check_regs x $xreg_nums $reg_main_value_64 ""
check_regs v $vreg_nums $reg_main_value_128 ".q.u"
check_regs q $vreg_nums $reg_main_value_128 ".u"
check_regs d $vreg_nums $reg_main_value_64 ".u"
check_regs s $vreg_nums $reg_main_value_32 ".u"
check_regs h $vreg_nums $reg_main_value_16 ".u"
check_regs b $vreg_nums $reg_main_value_8 ".u"
if { $sve_hw } {
  check_regs z $vreg_nums $zreg_main_value ".d.u"
  check_regs p $preg_nums $preg_main_value ""
}

# Switch back to the signal handler frame, and check register values

gdb_test "frame $handlerframe" \
      "#$handlerframe.*handler \\\(sig=4\\\).*" \
      "set to signal handler frame"

check_regs x $xreg_nums $reg_handler_value_64 ""
check_regs v $vreg_nums $reg_handler_value_128 ".q.u"
check_regs q $vreg_nums $reg_handler_value_128 ".u"
check_regs d $vreg_nums $reg_handler_value_64 ".u"
check_regs s $vreg_nums $reg_handler_value_32 ".u"
check_regs h $vreg_nums $reg_handler_value_16 ".u"
check_regs b $vreg_nums $reg_handler_value_8 ".u"
if { $sve_hw } {
  check_regs z $vreg_nums $zreg_handler_value ".d.u"
  check_regs p $preg_nums $preg_handler_value ""
}