summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.arch/s390-multiarch.exp
blob: 41eee3c4582dd0b7b11455f93a5a002ebf9be764 (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
150
151
152
153
154
155
156
157
158
159
160
161
# Copyright 2013-2014 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/>.

# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@gnu.org

# This file is part of the gdb testsuite.


# This test is supported on 64-bit s390 targets only, and only when
# running native.  It should be executed on a sufficiently new Linux
# kernel that provides the 'system_call' regset.

if { ![isnative] || ![istarget s390x-*-* ] } {
    verbose "Skipping s390 multi-arch tests."
    return
}

set testfile "s390-multiarch"
set srcfile "${srcdir}/${subdir}/${testfile}.c"
set binprefix "${objdir}/${subdir}/${testfile}"

gdb_exit

if { [get_compiler_info] } {
    return -1
}

proc compile_and_dump {variant ccopts binfile} {
    global srcfile
    set compile_flags {debug}
    foreach opt $ccopts {
	lappend compile_flags "additional_flags=$opt"
    }
    set test "compile ($variant)"
    if { [gdb_compile $srcfile $binfile executable $compile_flags] != "" } {
	fail $test
	return {}
    }
    pass $test

    set test "create core file ($variant)"
    set corefile [core_find $binfile]
    if {$corefile == ""} {
	fail $test
	return {}
    }
    pass $test
    return $corefile
}

proc test_linux_v2 {} {
    global gdb_prompt

    set test "Linux v2"
    gdb_test_multiple "info reg system_call" "$test" {
	-re "system_call\[ \t\]+0x\[0-9a-z\]+\t.*\r\n$gdb_prompt $" {
	    pass "$test"
	    return 1
	}
	-re "Invalid register `system_call'.*\r\n$gdb_prompt $" {
	    unsupported "$test (no system_call reg)"
	    return 0
	}
    }
    return 0
}

proc test_register_valid {reg variant} {
    gdb_test "info reg $reg" \
	"$reg\[ \t\]+0x\[0-9a-z\]+\t.*" \
	"'$reg' exists ($variant)"
}

proc test_register_invalid {reg variant} {
    gdb_test "info reg $reg" \
	"Invalid register `$reg'.*" \
	"'$reg' must not exist ($variant)"
}

proc test_all_core64 {core type} {
    set variant "64-bit $type"
    gdb_core_cmd $core "core-file ($variant)"
    if { ! [test_linux_v2] } {
	return
    }
    test_register_valid "last_break" $variant
    gdb_core_cmd "${core}.2" "core-file #2 ($variant)"
    test_register_invalid "system_call" $variant
    gdb_core_cmd "${core}.3" "core-file #3 ($variant)"
    test_register_invalid "last_break" $variant
}

proc test_all_core31 {core type} {
    set variant "31-bit $type"
    gdb_core_cmd $core "core-file ($variant)"
    if { ! [test_linux_v2] } {
	return
    }
    test_register_valid "r0h" $variant
    test_register_valid "last_break" $variant
    gdb_core_cmd "${core}.1" "core-file #1 ($variant)"
    test_register_invalid "r0h" $variant
    gdb_core_cmd "${core}.2" "core-file #2 ($variant)"
    test_register_invalid "system_call" $variant
    gdb_core_cmd "${core}.3" "core-file #3 ($variant)"
    test_register_invalid "last_break" $variant
}

set binfile "${binprefix}-64"
set core64 [compile_and_dump 64 {-m64} $binfile]
if { $core64 != "" } {
    # Remove 'system_call' and mask hwcap
    remote_exec host "$binfile $core64 ${core64}.2 775 1023"
    # Remove 'last_break'
    remote_exec host "$binfile ${core64}.2 ${core64}.3 774"
}

set binfile "${binprefix}-31"
set core31 [compile_and_dump 31 {-m31 -mesa} $binfile]
if { $core31 != "" } {
    # Create "patched" core file by removing 'high_gprs' notes
    remote_exec host "$binfile $core31 ${core31}.1 768"
    # Remove 'system_call' and mask off TE and any newer capabilities
    # from hwcap
    remote_exec host "$binfile $core31 ${core31}.2 775 1023"
    # Remove 'last_break'
    remote_exec host "$binfile ${core31}.2 ${core31}.3 774"
}

gdb_start
gdb_reinitialize_dir $srcdir/$subdir

if { $core64 != "" } {
    test_all_core64 $core64 "no exec"
    gdb_load "${binprefix}-64"
    test_all_core64 $core64 "with exec"
}

gdb_test "file" ".*" "discard symbol table" \
    {Discard symbol table from `.*'\? \(y or n\) } "y"

if { $core31 != "" } {
    test_all_core31 $core31 "no exec"
    gdb_load "${binprefix}-31"
    test_all_core31 $core31 "with exec"
}

gdb_exit