xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/miscexprs.exp (revision 7c192b2a5e1093666e67801684f930ef49b3b363)
1# Copyright 1998-2015 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 3 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, see <http://www.gnu.org/licenses/>.
15
16
17# This file is part of the gdb testsuite
18# file written by Elena Zannoni (ezannoni@cygnus.com)
19
20#
21# tests for expressions with struct/array elements and mixed operator types
22# with elementary types
23#
24
25# By default, the datastructures are allocated on the stack.  For targets
26# with very small stack, that will not work.  In that case, just set
27# storage to `-DSTORAGE=static' which changes the datastructures to be
28# allocated in data segment.
29set storage "-DSTORAGE="
30if [target_info exists gdb,small_stack_section] {
31    set storage "-DSTORAGE=static"
32}
33
34set additional_flags "additional_flags=${storage}"
35
36#
37# test running programs
38#
39
40standard_testfile .c
41
42if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ${additional_flags} nowarnings]] != "" } {
43    untested miscexprs.exp
44    return -1
45}
46
47if [get_compiler_info] {
48    return -1
49}
50
51clean_restart ${binfile}
52
53
54#
55# set it up at a breakpoint so we can play with the variable values
56#
57if ![runto_main] then {
58    perror "couldn't run to breakpoint"
59    continue
60}
61
62gdb_test "break marker1" ".*" ""
63
64gdb_test "cont" \
65    "Break.* marker1 \\(\\) at .*:$decimal.*" \
66    "continue to marker1"
67
68gdb_test "up" " main .*" "up from marker1"
69
70global hex
71
72gdb_test "print &ibig.i\[0\]" " = \\(int \\*\\) $hex" \
73    "print value of &ibig.i\[0\]"
74
75gdb_test_multiple "print &cbig.c\[0\]" "print value of &cbig.c\[0\]" {
76    -re ".\[0-9\]* = $hex \"\".*$gdb_prompt $" {
77        pass "print value of &cbig.c\[0\]"
78    }
79    -re ".\[0-9\]* = $hex \"*\".*$gdb_prompt $" {
80        pass "print value of &cbig.c\[0\]"
81    }
82}
83
84gdb_test "print &fbig.f\[0\]" " = \\(float \\*\\) $hex" \
85    "print value of &fbig.f\[0\]"
86
87gdb_test "print &dbig.d\[0\]" " = \\(double \\*\\) $hex" \
88    "print value of &dbig.d\[0\]"
89
90gdb_test_multiple "print &sbig.s\[0\]" "print value of &sbig.s\[0\]" {
91    -re ".\[0-9\]* = \\(short \\*\\) $hex.*$gdb_prompt $" {
92        pass "print value of &sbig.s\[0\]"
93    }
94    -re ".\[0-9\]* = \\(short int \\*\\) $hex.*$gdb_prompt $" {
95        pass "print value of &sbig.s\[0\]"
96    }
97}
98
99gdb_test_multiple "print &lbig.l\[0\]" "print value of &lbig.l\[0\]" {
100    -re ".\[0-9\]* = \\(long \\*\\) $hex.*$gdb_prompt $" {
101        pass "print value of &lbig.l\[0\]"
102    }
103    -re ".\[0-9\]* = \\(long int \\*\\) $hex.*$gdb_prompt $" {
104        pass "print value of &lbig.l\[0\]"
105    }
106}
107
108gdb_test "print ibig.i\[100\] | 1" " = 5" \
109    "print value of ibig.i\[100\] | 1"
110
111gdb_test "print sbig.s\[90\] & 127" " = 127" \
112    "print value of sbig.s\[90\] & 127"
113
114gdb_test "print !ibig.i\[100\]" " = $false" \
115    "print value of !ibig.i\[100\]"
116
117gdb_test "print !sbig.s\[90\]" " = $false" \
118    "print value of !sbig.s\[90\]"
119
120gdb_test "print !fbig.f\[100\]" " = $false" \
121    "print value of !ibig.i\[100\]"
122
123gdb_test "print !dbig.d\[202\]" " = $false" \
124    "print value of !ibig.i\[100\]"
125
126gdb_test "print sbig.s\[90\] * 10" " = 2550" \
127    "print value of !sbig.s\[90\] * 10"
128
129gdb_test "print ibig.i\[100\] * sbig.s\[90\]" " = 1275" \
130    "print value of ibig.i\[100\] * sbig.s\[90\]"
131
132gdb_test "print fbig.f\[100\] * dbig.d\[202\]" " = 119.99\[0-9\]*" \
133    "print value of fbig.f\[100\] * dbig.d\[202\]"
134
135gdb_test "print !(sbig.s\[90\] * 2)" " = $false" \
136    "print value of !(sbig.s\[90\] * 2)"
137
138gdb_test "print sizeof(sbig)" " = 800" "print value of sizeof sbig"
139
140gdb_test "print sizeof(cbig)" " = 100" "print value of sizeof cbig"
141
142gdb_test "print sizeof(lbig)/sizeof(long)" " = 900" \
143    "print value of sizeof lbig / sizeof long"
144
145gdb_test "print ibig.i\[100\] << 2" " = 20" \
146    "print value of ibig.i\[100\] << 2"
147
148gdb_test "print sbig.s\[90\] >> 4" " = 15" \
149    "print value of sbig.s\[90\] >> 4"
150
151gdb_test "print lbig.l\[333\] >> 6" " = 15624999" \
152    "print value of lbig.l\[333\] >> 6"
153
154