1 # Copyright 1999-2024 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/>.
16 # Tests for reference types with short type variables in GDB, based on
17 # gdb.cp/ref-types.exp.
19 require allow_cplus_tests
23 if {[prepare_for_testing $testfile.exp $testfile $srcfile \
24 {debug c++ additional_flags="-std=gnu++11"}]} {
29 # Set it up at a breakpoint so we can play with the variable values.
35 if {![runto 'marker1']} {
39 gdb_test "up" ".*main.*" "up from marker1 1"
41 gdb_test "print rrt" " = \\(short( int)? &&\\) @$hex: -1" "print value of rrt"
43 gdb_test "ptype rrt" "type = short( int)? &&"
45 gdb_test "print *rrpt" ".$decimal = -1" "print value of *rrpt"
47 # gdb had a bug about dereferencing a pointer type
48 # that would lead to wrong results
49 # if we try to examine memory at pointer value.
51 gdb_test "x /hd rrpt" "$hex:\[ \t\]*-1" "examine value at rrpt"
53 gdb_test "ptype rrpt" "type = short( int)? \\*&&"
55 gdb_test "print rrat\[0\]" ".$decimal = 0" "print value of rrat\[0\]"
57 gdb_test "ptype rrat" "type = short( int)? \\\(&&\\\)\\\[4\\\]"
59 gdb_test "print rrat\[1\]" ".$decimal = 1" "print value of rrat\[1\]"
60 gdb_test "print rrat\[2\]" ".$decimal = 2" "print value of rrat\[2\]"
61 gdb_test "print rrat\[3\]" ".$decimal = 3" "print value of rrat\[3\]"
68 gdb_test "up" ".main2.*" "up from f"
70 gdb_test "ptype rrC" "type = char &&"
72 gdb_test "ptype rrUC" "type = unsigned char &&"
74 gdb_test "ptype rrS" "type = short( int)? &&"
76 gdb_test "ptype rrUS" "type = unsigned short( int)? &&"
78 gdb_test "ptype rrI" "type = int &&"
80 gdb_test "ptype rrUI" "type = unsigned int &&"
82 gdb_test "ptype rrL" "type = long( int)? &&"
84 gdb_test "ptype rrUL" "type = unsigned long( int)? &&"
86 gdb_test "ptype rrF" "type = float &&"
88 gdb_test "ptype rrD" "type = double &&"
90 gdb_test "print rrC" "$decimal = \\(char &&\\) @$hex: 65 \'A\'" \
93 gdb_test "print rrUC" \
94 "$decimal = \\(unsigned char &&\\) @$hex: 21 \'.025\'" \
97 gdb_test "print rrS" "$decimal = \\(short( int)? &&\\) @$hex: -14" \
100 gdb_test "print rrUS" \
101 "$decimal = \\(unsigned short( int)? &&\\) @$hex: 7" \
102 "print value of rrUS"
104 gdb_test "print rrI" "$decimal = \\(int &&\\) @$hex: 102" \
107 gdb_test "print rrUI" \
108 "$decimal = \\(unsigned int &&\\) @$hex: 1002" \
109 "print value of rrUI"
111 gdb_test "print rrL" \
112 "$decimal = \\(long( int)? &&\\) @$hex: -234" \
115 gdb_test "print rrUL" \
116 "$decimal = \\((unsigned long|long unsigned int)? &&\\) @$hex: 234" \
117 "print value of rrUL"
119 gdb_test "print rrF" \
120 "$decimal = \\(float &&\\) @$hex: 1.2${decimal}e\\+0?10.*" \
123 gdb_test "print rrD" \
124 "$decimal = \\(double &&\\) @$hex: -1.375e-123.*" \