1# Copyright 1999-2020 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] } { continue } 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 untested "couldn't run to breakpoint" 33 return -1 34} 35 36if {![runto 'marker1']} { 37 untested "couldn't run to marker1" 38 return -1 39} 40 41gdb_test "up" ".*main.*" "up from marker1 1" 42 43gdb_test "print rrt" " = \\(short( int)? &&\\) @$hex: -1" "print value of rrt" 44 45gdb_test "ptype rrt" "type = short( int)? &&" 46 47gdb_test "print *rrpt" ".$decimal = -1" "print value of *rrpt" 48 49# gdb had a bug about dereferencing a pointer type 50# that would lead to wrong results 51# if we try to examine memory at pointer value. 52 53gdb_test "x /hd rrpt" "$hex:\[ \t\]*-1" "examine value at rrpt" 54 55gdb_test "ptype rrpt" "type = short( int)? \\*&&" 56 57gdb_test "print rrat\[0\]" ".$decimal = 0" "print value of rrat\[0\]" 58 59gdb_test "ptype rrat" "type = short( int)? \\\(&&\\\)\\\[4\\\]" 60 61gdb_test "print rrat\[1\]" ".$decimal = 1" "print value of rrat\[1\]" 62gdb_test "print rrat\[2\]" ".$decimal = 2" "print value of rrat\[2\]" 63gdb_test "print rrat\[3\]" ".$decimal = 3" "print value of rrat\[3\]" 64 65 66if {![runto 'f']} then { 67 perror "couldn't run to f" 68 continue 69} 70 71gdb_test "up" ".main2.*" "up from f" 72 73gdb_test "ptype rrC" "type = char &&" 74 75gdb_test "ptype rrUC" "type = unsigned char &&" 76 77gdb_test "ptype rrS" "type = short( int)? &&" 78 79gdb_test "ptype rrUS" "type = unsigned short( int)? &&" 80 81gdb_test "ptype rrI" "type = int &&" 82 83gdb_test "ptype rrUI" "type = unsigned int &&" 84 85gdb_test "ptype rrL" "type = long( int)? &&" 86 87gdb_test "ptype rrUL" "type = unsigned long( int)? &&" 88 89gdb_test "ptype rrF" "type = float &&" 90 91gdb_test "ptype rrD" "type = double &&" 92 93gdb_test "print rrC" "$decimal = \\(char &&\\) @$hex: 65 \'A\'" \ 94 "print value of rrC" 95 96gdb_test "print rrUC" \ 97 "$decimal = \\(unsigned char &&\\) @$hex: 21 \'.025\'" \ 98 "print value of rrUC" 99 100gdb_test "print rrS" "$decimal = \\(short( int)? &&\\) @$hex: -14" \ 101 "print value of rrS" 102 103gdb_test "print rrUS" \ 104 "$decimal = \\(unsigned short( int)? &&\\) @$hex: 7" \ 105 "print value of rrUS" 106 107gdb_test "print rrI" "$decimal = \\(int &&\\) @$hex: 102" \ 108 "print value of rrI" 109 110gdb_test "print rrUI" \ 111 "$decimal = \\(unsigned int &&\\) @$hex: 1002" \ 112 "print value of rrUI" 113 114gdb_test "print rrL" \ 115 "$decimal = \\(long( int)? &&\\) @$hex: -234" \ 116 "print value of rrL" 117 118gdb_test "print rrUL" \ 119 "$decimal = \\((unsigned long|long unsigned int)? &&\\) @$hex: 234" \ 120 "print value of rrUL" 121 122gdb_test "print rrF" \ 123 "$decimal = \\(float &&\\) @$hex: 1.2${decimal}e\\+0?10.*" \ 124 "print value of rrF" 125 126gdb_test "print rrD" \ 127 "$decimal = \\(double &&\\) @$hex: -1.375e-123.*" \ 128 "print value of rrD" 129