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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [testsuite/] [gdb.base/] [sizeof.exp] - Blame information for rev 1767

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

Line No. Rev Author Line
1 578 markom
# Copyright 2000 Free Software Foundation, Inc.
2
 
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 
17
# Please email any bugs, comments, and/or additions to this file to:
18
# bug-gdb@prep.ai.mit.edu
19
 
20
if $tracelevel {
21
    strace $tracelevel
22
}
23
 
24
#
25
# test running programs
26
#
27
set prms_id 0
28
set bug_id 0
29
 
30
set testfile "sizeof"
31
set srcfile ${testfile}.c
32
set binfile ${objdir}/${subdir}/${testfile}
33
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
34
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
35
}
36
 
37
if [get_compiler_info ${binfile}] {
38
    return -1;
39
}
40
 
41
gdb_exit
42
gdb_start
43
gdb_reinitialize_dir $srcdir/$subdir
44
gdb_load ${binfile}
45
 
46
#
47
# set it up at a breakpoint so we can play with the variable values
48
#
49
 
50
if ![runto_main] then {
51
    perror "couldn't run to breakpoint"
52
    continue
53
}
54
 
55
#
56
# Query GDB for the size of various types
57
#
58
 
59
proc get_sizeof { type default } {
60
    global gdb_prompt
61
    send_gdb "print/d sizeof (${type})\n"
62
    gdb_expect {
63
        -re "\\$\[0-9\]* = (\[0-9\]*).*$gdb_prompt $" {
64
            set size $expect_out(1,string)
65
            pass "get sizeof ${type} ($size)"
66
        }
67
        timeout {
68
            set size ${default}
69
            fail "get sizeof ${type} (timeout)"
70
        }
71
    }
72
    return ${size}
73
}
74
 
75
set sizeof_char [get_sizeof "char" 1]
76
set sizeof_short [get_sizeof "short" 2]
77
set sizeof_int [get_sizeof "int" 4]
78
set sizeof_long [get_sizeof "long" 4]
79
set sizeof_long_long [get_sizeof "long long" 8]
80
 
81
set sizeof_data_ptr [get_sizeof "void *" 4]
82
set sizeof_func_ptr [get_sizeof "void (*)(void)" 4]
83
 
84
set sizeof_float [get_sizeof "float" 4]
85
set sizeof_double [get_sizeof "double" 8]
86
set sizeof_long_double [get_sizeof "long double" 8]
87
 
88
 
89
#
90
# Compare GDB's idea of types with the running program
91
#
92
 
93
proc check_sizeof { type size } {
94
    global gdb_prompt
95
 
96
    if [gdb_skip_stdio_test "check sizeof $type == $size"] {
97
        return;
98
    }
99
 
100
    set pat [string_to_regexp ${type}]
101
    send_gdb "next\n"
102
    gdb_expect {
103
        -re "sizeof \\(${pat}\\) == ${size}\[\r\n\].*$gdb_prompt $" {
104
            pass "check sizeof ${type} == ${size}"
105
        }
106
        -re ".*$gdb_prompt $" {
107
            fail "check sizeof ${type} == ${size}"
108
        }
109
        timeout {
110
            fail "check sizeof ${type} == ${size} (timeout)"
111
        }
112
    }
113
}
114
 
115
check_sizeof "char" ${sizeof_char}
116
check_sizeof "short" ${sizeof_short}
117
check_sizeof "int" ${sizeof_int}
118
check_sizeof "long" ${sizeof_long}
119
check_sizeof "long long" ${sizeof_long_long}
120
 
121
check_sizeof "void *" ${sizeof_data_ptr}
122
check_sizeof "void (*)(void)" ${sizeof_func_ptr}
123
 
124
check_sizeof "float" ${sizeof_float}
125
check_sizeof "double" ${sizeof_double}
126
check_sizeof "long double" ${sizeof_long_double}
127
 
128
 
129
#
130
# For reference, dump out the entire architecture
131
#
132
# The output is very long so use a while loop to consume it
133
send_gdb "maint print arch\n"
134
set ok 1
135
while { $ok } {
136
    gdb_expect {
137
        -re ".*dump" {
138
            #pass "maint print arch $ok"
139
            #set ok [expr $ok + 1]
140
        }
141
        -re "$gdb_prompt $" {
142
            pass "maint print arch"
143
            set ok 0
144
        }
145
        timeout {
146
            fail "maint print arch (timeout)"
147
            set ok 0
148
        }
149
    }
150
}

powered by: WebSVN 2.1.0

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