aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/infcall-nested-structs.exp
blob: f5fbf44ed165f05cb8dfcd2d99d9397a57e6bec0 (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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# This testcase is part of GDB, the GNU debugger.

# 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/>.


# Some targets can't call functions, so don't even bother with this
# test.

if [target_info exists gdb,cannot_call_functions] {
    unsupported "this target can not call functions"
    continue
}

# Only test C++ if we are able.  Always use C.
if { [skip_cplus_tests] || [get_compiler_info "c++"] } {
    set lang {c}
} else {
    set lang {c c++}
}

foreach l $lang {
    set dir "$l"
    remote_exec host "rm -rf [standard_output_file ${dir}]"
    remote_exec host "mkdir -p [standard_output_file ${dir}]"
}


set int_types { tc ts ti tl tll }
set float_types { tf td tld }
set complex_types { tfc tdc tldc }

set compile_flags {debug}
if [support_complex_tests] {
    lappend compile_flags "additional_flags=-DTEST_COMPLEX"
    lappend compile_flags "additional_flags=-Wno-psabi"
}

# Given N (0..25), return the corresponding alphabetic letter in upper
# case.

proc I2A { n } {
    return [string range "ABCDEFGHIJKLMNOPQRSTUVWXYZ" $n $n]
}

# Compile a variant of nested-structs.c using TYPES to specify the
# types of the struct fields within the source.  Run up to main.
# Also updates the global "testfile" to reflect the most recent build.

proc start_nested_structs_test { lang types } {
    global testfile
    global srcfile
    global binfile
    global subdir
    global srcdir
    global compile_flags

    standard_testfile .c
    set dir "$lang"

    # Create the additional flags
    set flags $compile_flags
    lappend flags $lang

    for {set n 0} {$n<[llength ${types}]} {incr n} {
	set m [I2A ${n}]
	set t [lindex ${types} $n]
	lappend flags "additional_flags=-Dt${m}=${t}"
	append testfile "-" "$t"
    }

    set binfile [standard_output_file ${dir}/${testfile}]
    if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "${flags}"] != "" } {
	unresolved "failed to compile"
	return 0
    }

    # Start with a fresh gdb.
    clean_restart ${binfile}

    # Make certain that the output is consistent
    gdb_test_no_output "set print sevenbit-strings"
    gdb_test_no_output "set print address off"
    gdb_test_no_output "set print pretty off"
    gdb_test_no_output "set width 0"
    gdb_test_no_output "set print elements 300"

    # Advance to main
    if { ![runto_main] } then {
	fail "can't run to main"
	return 0
    }

    # Now continue forward to a suitable location to run the tests.
    # Some targets only enable the FPU on first use, so ensure that we
    # have used the FPU before we make calls from GDB to code that
    # could use the FPU.
    gdb_breakpoint [gdb_get_line_number "Break Here"] temporary
    gdb_continue_to_breakpoint "breakpt" ".* Break Here\\. .*"

    return 1
}

# Assuming GDB is stopped at main within a test binary, run some tests
# passing structures, and reading return value structures.

proc run_tests { lang types } {
    global gdb_prompt

    foreach {name} {struct_01_01 struct_01_02 struct_01_03 struct_01_04
                    struct_02_01 struct_02_02 struct_02_03 struct_02_04
                    struct_04_01 struct_04_02 struct_04_03 struct_04_04
                    struct_05_01 struct_05_02 struct_05_03 struct_05_04
                    struct_static_02_01 struct_static_02_02 struct_static_02_03 struct_static_02_04
                    struct_static_04_01 struct_static_04_02 struct_static_04_03 struct_static_04_04
                    struct_static_06_01 struct_static_06_02 struct_static_06_03 struct_static_06_04} {

	# Only run static member tests on C++
	if { $lang == "c" && [regexp "static" $name match] } {
	    continue
	}

	if { $lang == "c++"
	     && ( ( [regexp "struct_01_0(1|2|3)" $name match] && [regexp "^types-(td($|-)|tl(|l)(|-tf|-td|-tld)$)" $types match] )
		  || ( $name == "struct_01_02" && $types == "types-tfc" )
		  || ( $name == "struct_01_04" && [regexp "^types-(tf($|-)|ti(|-tf|-td|-tld)$)" $types match] )
		  || ( $name == "struct_02_01" && [regexp "^types-tf-t(c|s|i)" $types match] )
		  || ( $name == "struct_static_02_02" && [regexp "^types-(t(f|d|ld)-t(d|l|ll)$|t(d|l|ll)$|t(c|s|i|l|ll)-td)" $types match] )
		  || ( $name == "struct_static_02_03" && [regexp "^types-(ti-t(f|l|d|)|tf(-|$)|ti$)" $types match] )
		  || ( $name == "struct_static_04_02" && [regexp "^types-(t(c|s)-tf|tf-ts)" $types match] )
		  || ( $name == "struct_static_06_04" && ![regexp "^types-(t(c|dc|ldc|ld)$|t.-tld|tl(l|d)-tld|t(f|d|ld)-tc)" $types match] ) ) } {
	    setup_xfail gdb/24104 "x86_64-*-linux*"
	}
	gdb_test "p/d check_arg_${name} (ref_val_${name})" "= 1"

	set refval [ get_valueof "" "ref_val_${name}" "" ]
	verbose -log "Refval: ${refval}"

	set test "check return value ${name}"
	if { ${refval} != "" } {

	    set answer [ get_valueof "" "rtn_str_${name} ()" "XXXX"]
	    verbose -log "Answer: ${answer}"

	    if { ($lang == "c++" && $name == "struct_02_01" && [regexp "^types-(tf-t(c|s|i)|t(c|s|i)-tf)" $types match] ) } {
		setup_xfail gdb/24104 "x86_64-*-linux*"
	    }
	    gdb_assert [string eq ${answer} ${refval}] ${test}
	} else {
	    unresolved $test
	}
    }
}

# Set up a test prefix, compile the test binary, run to main, and then
# run some tests.

proc start_gdb_and_run_tests { lang types } {
    set prefix "types"

    foreach t $types {
	append prefix "-" "${t}"
    }

    foreach_with_prefix l $lang {
	with_test_prefix $prefix {
	    if { [start_nested_structs_test $l $types] } {
		run_tests $l $prefix
	    }
	}
    }
}

foreach ta $int_types {
    start_gdb_and_run_tests $lang $ta
}

if [support_complex_tests] {
    foreach ta $complex_types {
	start_gdb_and_run_tests $lang $ta
    }
}

if ![gdb_skip_float_test] {
    foreach ta $float_types {
	start_gdb_and_run_tests $lang $ta
    }

    foreach ta $int_types {
	foreach tb $float_types {
	    start_gdb_and_run_tests $lang [list $ta $tb]
	}
    }

    foreach ta $float_types {
	foreach tb $int_types {
	    start_gdb_and_run_tests $lang [list $ta $tb]
	}

	foreach tb $float_types {
	    start_gdb_and_run_tests $lang [list $ta $tb]
	}
    }
}