OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.1/] [gdb/] [testsuite/] [gdb.hp/] [gdb.base-hp/] [callfwmall.exp] - Blame information for rev 237

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 227 jeremybenn
# Copyright 1997, 1998, 1999, 2007, 2008, 2009, 2010
2
# Free Software Foundation, Inc.
3
 
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program.  If not, see .  */
16
 
17
# This file was written by Fred Fish. (fnf@cygnus.com)
18
 
19
# These tests are the same as those in callfuncs.exp, except that the
20
# test program here does not call malloc.
21
#
22
# "What in the world does malloc have to do with calling functions in
23
# the inferior?"  Well, nothing.  GDB's ability to invoke a function
24
# in the inferior program works just fine in programs that have no
25
# malloc function available.  It doesn't rely on the inferior's
26
# malloc, directly or indirectly.  It just uses the inferior's stack
27
# space.
28
#
29
# "Then what's the point of this test file?"  Well, it just so happens
30
# that this file, in addition to testing inferior function calls, also
31
# tests GDB's ability to evaluate string literals (like "string 1" and
32
# "string 2" in the tests below).  Evaluating *those* sorts of
33
# expressions does require malloc.
34
#
35
# (As an extension to C, GDB also has a syntax for literal arrays of
36
# anything, not just characters.  For example, the expression
37
# {2,3,4,5} (which appears in the tests below) evaluates to an array
38
# of four ints.  So rather than talking just about string literals,
39
# we'll use the broader term "array literals".)
40
#
41
# Now, in this file, we only evaluate array literals when we're about
42
# to pass them to a function, but don't be confused --- this is a red
43
# herring.  You can evaluate "abcdef" even if you're not about to pass
44
# that to a function, and doing so requires malloc even if you're just
45
# going to store a pointer to it in a variable, like this:
46
#
47
#    (gdb) ptype s
48
#    type = char *
49
#    (gdb) set variable s = "abcdef"
50
#
51
# According to C's rules for evaluating expressions, arrays are
52
# converted into pointers to their first element.  This means that, in
53
# order to evaluate an expression like "abcdef", GDB needs to actually
54
# find some memory in the inferior we can plop the characters into;
55
# then we use that memory's address as the address of our array
56
# literal.  GDB finds this memory by calling the inferior's malloc
57
# function, if it has one.  So, evaluating an array literal depends on
58
# performing an inferior function call, but not vice versa.  (GDB
59
# can't just allocate the space on the stack; the pointer may remain
60
# live long after the current frame has been popped.)
61
#
62
# "But, if evaluating array literals requires malloc, what's the point
63
# of testing that GDB can do so in a program that doesn't have malloc?
64
# It can't work!"  On most systems, that's right, but HP-UX has some
65
# sort of dynamic linking magic that ensures that *every* program has
66
# malloc.  So on HP-UX, GDB can evaluate array literals even in
67
# inferior programs that don't use malloc.  That's why this test is in
68
# gdb.hp.
69
#
70
# This file has, for some reason, led to well more than its fair share
71
# of misunderstandings about the relationship between array literal
72
# expressions and inferior function calls.  Folks talk as if you can
73
# only evaluate array literals when you're about to pass them to a
74
# function.  I think they're assuming that, since GDB is constructing
75
# a new frame on the inferior's stack (correct), it's going to use
76
# that space for the array literals (incorrect).  Remember that those
77
# array literals may need to be live long after the inferior function
78
# call returns; GDB can't tell.
79
#
80
# What makes the confusion worse is that there *is* a relationship
81
# between array literals and inferior function calls --- GDB uses
82
# inferior function calls to evaluate array literals.  But many people
83
# jump to other, incorrect conclusions about this.
84
 
85
if $tracelevel then {
86
        strace $tracelevel
87
}
88
 
89
set prms_id 0
90
set bug_id 0
91
 
92
if { [skip_hp_tests] } then { continue }
93
 
94
set testfile "callfwmall"
95
set srcfile ${testfile}.c
96
set binfile ${objdir}/${subdir}/${testfile}
97
 
98
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
99
     untested callfwmall.exp
100
     return -1
101
}
102
 
103
# Create and source the file that provides information about the compiler
104
# used to compile the test case.
105
 
106
if [get_compiler_info ${binfile}] {
107
    return -1;
108
}
109
 
110
if {$hp_aCC_compiler} {
111
    set prototypes 1
112
} else {
113
    set prototypes 0
114
}
115
 
116
 
117
# Some targets can't call functions, so don't even bother with this
118
# test.
119
if [target_info exists gdb,cannot_call_functions] {
120
    setup_xfail "*-*-*" 2416
121
    fail "This target can not call functions"
122
    continue
123
}
124
 
125
# Set the current language to C.  This counts as a test.  If it
126
# fails, then we skip the other tests.
127
 
128
proc set_lang_c {} {
129
    global gdb_prompt
130
 
131
    send_gdb "set language c\n"
132
    gdb_expect {
133
        -re ".*$gdb_prompt $" {}
134
        timeout { fail "set language c (timeout)" ; return 0 }
135
    }
136
 
137
    send_gdb "show language\n"
138
    gdb_expect {
139
        -re ".* source language is \"c\".*$gdb_prompt $" {
140
            pass "set language to \"c\""
141
            return 1
142
        }
143
        -re ".*$gdb_prompt $" {
144
            fail "setting language to \"c\""
145
            return 0
146
        }
147
        timeout {
148
            fail "can't show language (timeout)"
149
            return 0
150
        }
151
    }
152
}
153
 
154
# FIXME:  Before calling this proc, we should probably verify that
155
# we can call inferior functions and get a valid integral value
156
# returned.
157
# Note that it is OK to check for 0 or 1 as the returned values, because C
158
# specifies that the numeric value of a relational or logical expression
159
# (computed in the inferior) is 1 for true and 0 for false.
160
 
161
proc do_function_calls {} {
162
    global prototypes
163
    global gcc_compiled
164
    global gdb_prompt
165
 
166
    # We need to up this because this can be really slow on some boards.
167
    set timeout 60;
168
 
169
    gdb_test "p t_char_values(0,0)" " = 0"
170
    gdb_test "p t_char_values('a','b')" " = 1"
171
    gdb_test "p t_char_values(char_val1,char_val2)" " = 1"
172
    gdb_test "p t_char_values('a',char_val2)" " = 1"
173
    gdb_test "p t_char_values(char_val1,'b')" " = 1"
174
 
175
    gdb_test "p t_short_values(0,0)" " = 0"
176
    gdb_test "p t_short_values(10,-23)" " = 1"
177
    gdb_test "p t_short_values(short_val1,short_val2)" " = 1"
178
    gdb_test "p t_short_values(10,short_val2)" " = 1"
179
    gdb_test "p t_short_values(short_val1,-23)" " = 1"
180
 
181
    gdb_test "p t_int_values(0,0)" " = 0"
182
    gdb_test "p t_int_values(87,-26)" " = 1"
183
    gdb_test "p t_int_values(int_val1,int_val2)" " = 1"
184
    gdb_test "p t_int_values(87,int_val2)" " = 1"
185
    gdb_test "p t_int_values(int_val1,-26)" " = 1"
186
 
187
    gdb_test "p t_long_values(0,0)" " = 0"
188
    gdb_test "p t_long_values(789,-321)" " = 1"
189
    gdb_test "p t_long_values(long_val1,long_val2)" " = 1"
190
    gdb_test "p t_long_values(789,long_val2)" " = 1"
191
    gdb_test "p t_long_values(long_val1,-321)" " = 1"
192
 
193
    if ![target_info exists gdb,skip_float_tests] {
194
        gdb_test "p t_float_values(0.0,0.0)" " = 0"
195
 
196
        # These next four tests fail on the mn10300.
197
        # The first value is passed in regs, the other in memory.
198
        # Gcc emits different stabs for the two parameters; the first is
199
        # claimed to be a float, the second a double.
200
        # dbxout.c in gcc claims this is the desired behavior.
201
        setup_xfail "mn10300-*-*"
202
        gdb_test "p t_float_values(3.14159,-2.3765)" " = 1"
203
        setup_xfail "mn10300-*-*"
204
        gdb_test "p t_float_values(float_val1,float_val2)" " = 1"
205
        setup_xfail "mn10300-*-*"
206
        gdb_test "p t_float_values(3.14159,float_val2)" " = 1"
207
        setup_xfail "mn10300-*-*"
208
        gdb_test "p t_float_values(float_val1,-2.3765)" " = 1"
209
 
210
        # Test passing of arguments which might not be widened.
211
        gdb_test "p t_float_values2(0.0,0.0)" " = 0"
212
 
213
        # Although PR 5318 mentions SunOS specifically, this seems
214
        # to be a generic problem on quite a few platforms.
215
        if $prototypes then {
216
            setup_xfail "sparc-*-*" "mips*-*-*" 5318
217
            if {!$gcc_compiled} then {
218
                setup_xfail "alpha-dec-osf2*" "i*86-*-sysv4*" 5318
219
            }
220
        }
221
        gdb_test "p t_float_values2(3.14159,float_val2)" " = 1"
222
        gdb_test "p t_small_values(1,2,3,4,5,6,7,8,9,10)" " = 55"
223
 
224
        gdb_test "p t_double_values(0.0,0.0)" " = 0"
225
        gdb_test "p t_double_values(45.654,-67.66)" " = 1"
226
        gdb_test "p t_double_values(double_val1,double_val2)" " = 1"
227
        gdb_test "p t_double_values(45.654,double_val2)" " = 1"
228
        gdb_test "p t_double_values(double_val1,-67.66)" " = 1"
229
 
230
    }
231
 
232
    gdb_test "p t_string_values(string_val2,string_val1)" " = 0"
233
    gdb_test "p t_string_values(string_val1,string_val2)" " = 1"
234
    gdb_test "p t_string_values(\"string 1\",\"string 2\")" " = 1"
235
    gdb_test "p t_string_values(\"string 1\",string_val2)" " = 1"
236
    gdb_test "p t_string_values(string_val1,\"string 2\")" " = 1"
237
 
238
    gdb_test "p t_char_array_values(char_array_val2,char_array_val1)" " = 0"
239
    gdb_test "p t_char_array_values(char_array_val1,char_array_val2)" " = 1"
240
    gdb_test "p t_char_array_values(\"carray 1\",\"carray 2\")" " = 1"
241
    gdb_test "p t_char_array_values(\"carray 1\",char_array_val2)" " = 1"
242
    gdb_test "p t_char_array_values(char_array_val1,\"carray 2\")" " = 1"
243
 
244
    gdb_test "p doubleit(4)" " = 8"
245
    gdb_test "p add(4,5)" " = 9"
246
    gdb_test "p t_func_values(func_val2,func_val1)" " = 0"
247
    gdb_test "p t_func_values(func_val1,func_val2)" " = 1"
248
 
249
    # On the rs6000, we need to pass the address of the trampoline routine,
250
    # not the address of add itself.  I don't know how to go from add to
251
    # the address of the trampoline.  Similar problems exist on the HPPA,
252
    # and in fact can present an unsolvable problem as the stubs may not
253
    # even exist in the user's program.  We've slightly recoded t_func_values
254
    # to avoid such problems in the common case.  This may or may not help
255
    # the RS6000.
256
    setup_xfail "rs6000*-*-*"
257
 
258
    if {![istarget hppa*-*-hpux*]} then {
259
        gdb_test "p t_func_values(add,func_val2)" " = 1"
260
    }
261
 
262
    setup_xfail "rs6000*-*-*"
263
 
264
    if {![istarget hppa*-*-hpux*]} then {
265
        gdb_test "p t_func_values(func_val1,doubleit)" " = 1"
266
    }
267
 
268
    gdb_test "p t_call_add(func_val1,3,4)" " = 7"
269
 
270
    setup_xfail "rs6000*-*-*"
271
 
272
    if {![istarget hppa*-*-hpux*]} then {
273
        gdb_test "p t_call_add(add,3,4)" " = 7"
274
    }
275
 
276
    gdb_test "p t_enum_value1(enumval1)" " = 1"
277
    gdb_test "p t_enum_value1(enum_val1)" " = 1"
278
    gdb_test "p t_enum_value1(enum_val2)" " = 0"
279
 
280
    gdb_test "p t_enum_value2(enumval2)" " = 1"
281
    gdb_test "p t_enum_value2(enum_val2)" " = 1"
282
    gdb_test "p t_enum_value2(enum_val1)" " = 0"
283
 
284
    gdb_test "p sum_args(1,{2})" " = 2"
285
    gdb_test "p sum_args(2,{2,3})" " = 5"
286
    gdb_test "p sum_args(3,{2,3,4})" " = 9"
287
    gdb_test "p sum_args(4,{2,3,4,5})" " = 14"
288
    gdb_test "p sum10 (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)" " = 55"
289
 
290
    gdb_test "p t_structs_c(struct_val1)" "= 120 'x'" \
291
        "call inferior func with struct - returns char"
292
    gdb_test "p t_structs_s(struct_val1)" "= 87" \
293
        "call inferior func with struct -  returns short"
294
    gdb_test "p t_structs_i(struct_val1)" "= 76" \
295
        "call inferior func with struct - returns int"
296
    gdb_test "p t_structs_l(struct_val1)" "= 51" \
297
        "call inferior func with struct - returns long"
298
    gdb_test "p t_structs_f(struct_val1)" "= 2.12.*" \
299
        "call inferior func with struct - returns float"
300
    gdb_test "p t_structs_d(struct_val1)" "= 9.87.*" \
301
        "call inferior func with struct - returns double"
302
    gdb_test "p t_structs_a(struct_val1)" "= (.unsigned char .. )?\"foo\"" \
303
        "call inferior func with struct - returns char *"
304
 
305
}
306
 
307
# Start with a fresh gdb.
308
 
309
gdb_exit
310
gdb_start
311
gdb_reinitialize_dir $srcdir/$subdir
312
gdb_load ${binfile}
313
 
314
gdb_test "set print sevenbit-strings" ""
315
gdb_test "set print address off" ""
316
gdb_test "set width 0" ""
317
 
318
if { $hp_aCC_compiler } {
319
    # Do not set language explicitly to 'C'.  This will cause aCC
320
    # tests to fail because promotion rules are different.  Just let
321
    # the language be set to the default.
322
 
323
    if { ![runto_main] } {
324
        gdb_suppress_tests;
325
    }
326
 
327
    gdb_test "set overload-resolution 0" ".*"
328
} else {
329
    if { ![set_lang_c] } {
330
        gdb_suppress_tests;
331
    } else {
332
        if { ![runto_main] } {
333
            gdb_suppress_tests;
334
        }
335
    }
336
}
337
 
338
gdb_test "next" ".*"
339
do_function_calls
340
 
341
return 0

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.