Fix: Null pointer dereference in ldlex.l
[binutils-gdb.git] / gdb / testsuite / gdb.base / miscexprs.exp
bloba173dd8edd0004285fb85466cf1df8d7cd1d065e
1 # Copyright 1998-2023 Free Software Foundation, Inc.
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.
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.
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/>.
17 # This file is part of the gdb testsuite
18 # file written by Elena Zannoni (ezannoni@cygnus.com)
21 # tests for expressions with struct/array elements and mixed operator types
22 # with elementary types
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.
29 set storage "-DSTORAGE="
30 if [target_info exists gdb,small_stack_section] {
31 set storage "-DSTORAGE=static"
34 set additional_flags "additional_flags=${storage}"
37 # test running programs
40 standard_testfile .c
42 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ${additional_flags} nowarnings]] != "" } {
43 untested "failed to compile"
44 return -1
47 clean_restart ${binfile}
51 # set it up at a breakpoint so we can play with the variable values
53 if {![runto_main]} {
54 return
57 # This is used as an expected result value.
58 set false 0
60 gdb_test "break marker1" ".*" ""
62 gdb_test "cont" \
63 "Break.* marker1 \\(\\) at .*:$decimal.*" \
64 "continue to marker1"
66 gdb_test "up" " main .*" "up from marker1"
68 global hex
70 gdb_test "print &ibig.i\[0\]" " = \\(int \\*\\) $hex"
72 gdb_test_multiple "print &cbig.c\[0\]" "" {
73 -re ".\[0-9\]* = $hex \"\".*$gdb_prompt $" {
74 pass $gdb_test_name
76 -re ".\[0-9\]* = $hex \"*\".*$gdb_prompt $" {
77 pass $gdb_test_name
81 gdb_test "print &fbig.f\[0\]" " = \\(float \\*\\) $hex"
83 gdb_test "print &dbig.d\[0\]" " = \\(double \\*\\) $hex"
85 gdb_test_multiple "print &sbig.s\[0\]" "" {
86 -re ".\[0-9\]* = \\(short \\*\\) $hex.*$gdb_prompt $" {
87 pass $gdb_test_name
89 -re ".\[0-9\]* = \\(short int \\*\\) $hex.*$gdb_prompt $" {
90 pass $gdb_test_name
94 gdb_test_multiple "print &lbig.l\[0\]" "" {
95 -re ".\[0-9\]* = \\(long \\*\\) $hex.*$gdb_prompt $" {
96 pass $gdb_test_name
98 -re ".\[0-9\]* = \\(long int \\*\\) $hex.*$gdb_prompt $" {
99 pass $gdb_test_name
103 gdb_test "print ibig.i\[100\] | 1" " = 5"
105 gdb_test "print sbig.s\[90\] & 127" " = 127"
107 gdb_test "print !ibig.i\[100\]" " = $false"
109 gdb_test "print !sbig.s\[90\]" " = $false"
111 gdb_test "print !fbig.f\[100\]" " = $false"
113 gdb_test "print !dbig.d\[202\]" " = $false"
115 gdb_test "print sbig.s\[90\] * 10" " = 2550"
117 gdb_test "print ibig.i\[100\] * sbig.s\[90\]" " = 1275"
119 gdb_test "print fbig.f\[100\] * dbig.d\[202\]" " = 119.99\[0-9\]*"
121 gdb_test "print !(sbig.s\[90\] * 2)" " = $false"
123 gdb_test "print sizeof(sbig)" " = 800"
125 gdb_test "print sizeof(cbig)" " = 100"
127 gdb_test "print sizeof(lbig)/sizeof(long)" " = 900"
129 gdb_test "print ibig.i\[100\] << 2" " = 20"
131 gdb_test "print sbig.s\[90\] >> 4" " = 15"
133 gdb_test "print lbig.l\[333\] >> 6" " = 15624999"