Fix: Null pointer dereference in ldlex.l
[binutils-gdb.git] / gdb / testsuite / gdb.base / radix.exp
blob32000e56e56ec6e196bb54acde3d7a6c4d98fd22
1 # This testcase is part of GDB, the GNU debugger.
2 # Copyright 1993-2023 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file was written by Fred Fish. (fnf@cygnus.com)
18 # And rewritten by Michael Chastain (mec.gnu@mindspring.com)
21 # Start with a fresh gdb.
23 gdb_exit
24 gdb_start
26 # Test input radices.
28 proc test_one_input { iradix input output } {
29 gdb_test "print $input" "$output" \
30 "print $input; expect $output; input radix $iradix"
33 proc test_input_radix { iradix iradixhex iradixoctal } {
34 # set input-radix = $iradix, output-radix = ten
35 gdb_test "set radix" \
36 "Input and output radices now set to decimal 10, hex a, octal 12." \
37 "initialize radix, input radix $iradix"
38 gdb_test "set input-radix $iradix" \
39 "Input radix now set to decimal $iradix, hex $iradixhex, octal $iradixoctal."
40 if {$iradix == 10} {
41 gdb_test "show radix" \
42 "Input and output radices set to decimal 10, hex a, octal 12." \
43 "show radix, input radix $iradix"
44 } else {
45 gdb_test "show radix" \
46 "Input radix set to decimal $iradix, hex $iradixhex, octal $iradixoctal.\r\nOutput radix set to decimal 10, hex a, octal 12." \
47 "show radix, input radix $iradix"
50 # test constants with specific bases that do not use $iradix
51 test_one_input $iradix "010" "8"
52 test_one_input $iradix "20." "20"
53 test_one_input $iradix "(int) 20." "20"
54 test_one_input $iradix "0xf" "15"
56 # test simple one-digit constants
57 test_one_input $iradix "0" "0"
58 test_one_input $iradix "1" "1"
59 test_one_input $iradix "-1" "-1"
61 # test simple two-digit constants
62 test_one_input $iradix "10" [expr $iradix]
63 test_one_input $iradix "11" [expr $iradix + 1]
64 test_one_input $iradix "-10" [expr 0 - $iradix]
65 test_one_input $iradix "-11" [expr 0 - $iradix - 1]
67 # test simple three-digit constants
68 test_one_input $iradix "100" [expr $iradix * $iradix]
69 test_one_input $iradix "101" [expr $iradix * $iradix + 1]
70 test_one_input $iradix "-100" [expr 0 - $iradix * $iradix]
71 test_one_input $iradix "-101" [expr 0 - $iradix * $iradix - 1]
73 # test a five-digit constant
74 test_one_input $iradix "10101" \
75 [expr $iradix * $iradix * $iradix * $iradix + $iradix * $iradix + 1]
78 test_input_radix 2 "2" "2"
79 test_one_input 2 "4" "Invalid number \"4\"\\."
80 test_one_input 2 "-2" "Invalid number \"2\"\\."
82 test_input_radix 3 "3" "3"
83 test_one_input 3 "2" "2"
84 test_one_input 3 "20" "6"
85 test_one_input 3 "3" "Invalid number \"3\"\\."
86 test_one_input 2 "30" "Invalid number \"30\"\\."
88 test_input_radix 8 "8" "10"
89 test_one_input 8 "20" "16"
90 test_one_input 8 "-20" "-16"
91 test_one_input 8 "8" "Invalid number \"8\"."
92 test_one_input 8 "-9" "Invalid number \"9\"."
94 test_input_radix 10 "a" "12"
95 test_one_input 10 "-12" "-12"
97 test_input_radix 16 "10" "20"
99 # Test output radices.
101 proc test_one_output { oradix input output } {
102 gdb_test "print $input" "$output" \
103 "print $input; expect $output; output radix $oradix"
106 proc test_output_radix { oradix oradixhex oradixoctal } {
107 # set input-radix = ten, output-radix = $oradix
108 gdb_test "set radix" \
109 "Input and output radices now set to decimal 10, hex a, octal 12." \
110 "initialize radix, output radix $oradix"
111 gdb_test "set output-radix $oradix" \
112 "Output radix now set to decimal $oradix, hex $oradixhex, octal $oradixoctal."
113 if {$oradix == 10} {
114 gdb_test "show radix" \
115 "Input and output radices set to decimal 10, hex a, octal 12." \
116 "show radix, output radix $oradix"
117 } else {
118 gdb_test "show radix" \
119 "Input radix set to decimal 10, hex a, octal 12.\r\nOutput radix set to decimal $oradix, hex $oradixhex, octal $oradixoctal." \
120 "show radix, output radix $oradix"
123 # no standard tests for output radix
126 test_output_radix 8 "8" "10"
127 test_one_output 8 "010" "010"
128 test_one_output 8 "0xf" "17"
129 test_one_output 8 "10" "12"
130 test_one_output 8 "100" "144"
131 setup_kfail "gdb/1715" *-*-*
132 test_one_output 8 "20." "24"
133 test_one_output 8 "(int) 20." "24"
135 test_output_radix 10 "a" "12"
136 test_one_output 10 "010" "8"
137 test_one_output 10 "0xf" "15"
138 test_one_output 10 "10" "10"
139 test_one_output 10 "100" "100"
140 test_one_output 10 "20." "20"
141 test_one_output 10 "(int) 20." "20"
143 test_output_radix 16 "10" "20"
144 test_one_output 16 "010" "8"
145 test_one_output 16 "0xf" "f"
146 test_one_output 16 "10" "a"
147 test_one_output 16 "100" "64"
148 setup_kfail "gdb/1715" *-*-*
149 test_one_output 16 "20." "14"
150 test_one_output 16 "(int) 20." "14"
152 # Test rejecting invalid input radices and unsupported output radices
153 # really rejects the radices, instead of just claiming so (PR 7536).
155 gdb_test "set radix" \
156 "Input and output radices now set to decimal 10, hex a, octal 12\." \
157 "reset radices"
159 gdb_test "set input-radix 0" \
160 "Nonsense input radix ``decimal 0''; input radix unchanged\\." \
161 "Reject input-radix 0"
162 gdb_test "show input-radix" \
163 "Default input radix for entering numbers is 10\\." \
164 "input radix unchanged after rejecting 0"
166 gdb_test "set input-radix 1" \
167 "Nonsense input radix ``decimal 1''; input radix unchanged\\." \
168 "Reject input-radix 1"
169 gdb_test "show input-radix" \
170 "Default input radix for entering numbers is 10\\." \
171 "input radix unchanged after rejecting 1"
173 gdb_test "set output-radix 0" \
174 "Unsupported output radix ``decimal 0''; output radix unchanged\\." \
175 "Reject output-radix 0"
176 gdb_test "show output-radix" \
177 "Default output radix for printing of values is 10\\." \
178 "Output radix unchanged after rejecting 0"
179 gdb_test "set output-radix 1" \
180 "Unsupported output radix ``decimal 1''; output radix unchanged\\." \
181 "Reject output-radix 1"
182 gdb_test "show output-radix" \
183 "Default output radix for printing of values is 10\\." \
184 "output radix unchanged after rejecting 1"
186 gdb_test "set radix 7" \
187 "Unsupported output radix ``decimal 7''; output radix unchanged\\." \
188 "set radix 7 rejected"
189 gdb_test "show output-radix" \
190 "Default output radix for printing of values is 10\\." \
191 "output radix unchanged after rejection through set radix command"