Commit | Line | Data |
---|---|---|
4a1135b8 | 1 | # This testcase is part of GDB, the GNU debugger. |
4c38e0a4 JB |
2 | # Copyright 1993, 1997, 2004, 2007, 2008, 2009, 2010 |
3 | # Free Software Foundation, Inc. | |
c906108c SS |
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 | |
e22f8b7c | 7 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 8 | # (at your option) any later version. |
e22f8b7c | 9 | # |
c906108c SS |
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. | |
e22f8b7c | 14 | # |
c906108c | 15 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 17 | |
c906108c | 18 | # This file was written by Fred Fish. (fnf@cygnus.com) |
4a1135b8 | 19 | # And rewritten by Michael Chastain (mec.gnu@mindspring.com) |
c906108c SS |
20 | |
21 | if $tracelevel then { | |
22 | strace $tracelevel | |
23 | } | |
24 | ||
c906108c | 25 | |
4a1135b8 | 26 | # Start with a fresh gdb. |
c906108c | 27 | |
4a1135b8 MC |
28 | gdb_exit |
29 | gdb_start | |
c906108c | 30 | |
4a1135b8 | 31 | # Test input radices. |
c906108c | 32 | |
4a1135b8 MC |
33 | proc test_one_input { iradix input output } { |
34 | gdb_test "print $input" "$output" \ | |
35 | "print $input; expect $output; input radix $iradix" | |
c906108c SS |
36 | } |
37 | ||
4a1135b8 MC |
38 | proc test_input_radix { iradix iradixhex iradixoctal } { |
39 | # set input-radix = $iradix, output-radix = ten | |
c906108c SS |
40 | gdb_test "set radix" \ |
41 | "Input and output radices now set to decimal 10, hex a, octal 12." \ | |
4a1135b8 MC |
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] | |
c906108c SS |
81 | } |
82 | ||
4a1135b8 MC |
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\"\\." | |
c906108c | 86 | |
4a1135b8 MC |
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\"\\." | |
c906108c | 92 | |
4a1135b8 MC |
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" | |
c906108c SS |
109 | } |
110 | ||
4a1135b8 MC |
111 | proc test_output_radix { oradix oradixhex oradixoctal } { |
112 | # set input-radix = ten, output-radix = $oradix | |
c906108c SS |
113 | gdb_test "set radix" \ |
114 | "Input and output radices now set to decimal 10, hex a, octal 12." \ | |
4a1135b8 MC |
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 | |
c906108c SS |
129 | } |
130 | ||
4a1135b8 MC |
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" | |
bbc8b958 | 136 | setup_kfail "gdb/1715" *-*-* |
4a1135b8 MC |
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" | |
bbc8b958 | 153 | setup_kfail "gdb/1715" *-*-* |
4a1135b8 MC |
154 | test_one_output 16 "20." "14" |
155 | test_one_output 16 "(int) 20." "14" | |
09e6485f PA |
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 | ||
1e8fb976 PA |
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 | ||
09e6485f PA |
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\\." \ | |
1e8fb976 | 176 | "Input radix unchanged after rejecting 1" |
09e6485f | 177 | |
1e8fb976 PA |
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" | |
09e6485f PA |
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\\." \ | |
1e8fb976 | 189 | "Output radix unchanged after rejecting 1" |
09e6485f PA |
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" |