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