1# Copyright 1999-2023 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# Tests for reference types with short type variables in GDB, based on
17# gdb.cp/ref-types.exp.
18
19if { [skip_cplus_tests] } { return }
20
21standard_testfile .cc
22
23if {[prepare_for_testing $testfile.exp $testfile $srcfile \
24    {debug c++ additional_flags="-std=gnu++11"}]} {
25    return -1
26}
27
28#
29# Set it up at a breakpoint so we can play with the variable values.
30#
31if {![runto_main]} {
32    return -1
33}
34
35if {![runto 'marker1']} {
36    return -1
37}
38
39gdb_test "up" ".*main.*" "up from marker1 1"
40
41gdb_test "print rrt" " = \\(short( int)? &&\\) @$hex: -1" "print value of rrt"
42
43gdb_test "ptype rrt" "type = short( int)? &&"
44
45gdb_test "print *rrpt" ".$decimal = -1" "print value of *rrpt"
46
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.
50
51gdb_test "x /hd rrpt" "$hex:\[ \t\]*-1" "examine value at rrpt"
52
53gdb_test "ptype rrpt" "type = short( int)? \\*&&"
54
55gdb_test "print rrat\[0\]" ".$decimal = 0" "print value of rrat\[0\]"
56
57gdb_test "ptype rrat" "type = short( int)? \\\(&&\\\)\\\[4\\\]"
58
59gdb_test "print rrat\[1\]" ".$decimal = 1" "print value of rrat\[1\]"
60gdb_test "print rrat\[2\]" ".$decimal = 2" "print value of rrat\[2\]"
61gdb_test "print rrat\[3\]" ".$decimal = 3" "print value of rrat\[3\]"
62
63
64if {![runto 'f']} {
65    return
66}
67
68gdb_test "up" ".main2.*" "up from f"
69
70gdb_test "ptype rrC" "type = char &&"
71
72gdb_test "ptype rrUC" "type = unsigned char &&"
73
74gdb_test "ptype rrS" "type = short( int)? &&"
75
76gdb_test "ptype rrUS" "type = unsigned short( int)? &&"
77
78gdb_test "ptype rrI" "type = int &&"
79
80gdb_test "ptype rrUI" "type = unsigned int &&"
81
82gdb_test "ptype rrL" "type = long( int)? &&"
83
84gdb_test "ptype rrUL" "type = unsigned long( int)? &&"
85
86gdb_test "ptype rrF" "type = float &&"
87
88gdb_test "ptype rrD" "type = double &&"
89
90gdb_test "print rrC" "$decimal = \\(char &&\\) @$hex: 65 \'A\'" \
91    "print value of rrC"
92
93gdb_test "print rrUC" \
94    "$decimal = \\(unsigned char &&\\) @$hex: 21 \'.025\'" \
95    "print value of rrUC"
96
97gdb_test "print rrS" "$decimal = \\(short( int)? &&\\) @$hex: -14" \
98                  "print value of rrS"
99
100gdb_test "print rrUS" \
101         "$decimal = \\(unsigned short( int)? &&\\) @$hex: 7" \
102         "print value of rrUS"
103
104gdb_test "print rrI" "$decimal = \\(int &&\\) @$hex: 102" \
105       "print value of rrI"
106
107gdb_test "print rrUI" \
108    "$decimal = \\(unsigned int &&\\) @$hex: 1002" \
109        "print value of rrUI"
110
111gdb_test "print rrL" \
112       "$decimal = \\(long( int)? &&\\) @$hex: -234" \
113         "print value of rrL"
114
115gdb_test "print rrUL" \
116    "$decimal = \\((unsigned long|long unsigned int)? &&\\) @$hex: 234" \
117    "print value of rrUL"
118
119gdb_test "print rrF" \
120    "$decimal = \\(float &&\\) @$hex: 1.2${decimal}e\\+0?10.*" \
121    "print value of rrF"
122
123gdb_test "print rrD" \
124    "$decimal = \\(double &&\\) @$hex: -1.375e-123.*" \
125    "print value of rrD"
126