]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright (C) 2010-2024 Free Software Foundation, Inc. |
99e7ae30 DE |
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 | ||
b521dba8 DE |
16 | # This file is part of the GDB testsuite. |
17 | # It tests gdb.parameter and gdb.Parameter. | |
99e7ae30 | 18 | |
99e7ae30 DE |
19 | load_lib gdb-python.exp |
20 | ||
d82e5429 | 21 | require allow_python_tests |
79749205 | 22 | |
99e7ae30 | 23 | # Start with a fresh gdb. |
a52b41bf | 24 | clean_restart |
99e7ae30 | 25 | |
e7e1f203 MR |
26 | proc py_param_test_maybe_no_output { command pattern args } { |
27 | if [string length $pattern] { | |
28 | gdb_test $command $pattern $args | |
29 | } else { | |
30 | gdb_test_no_output $command $args | |
31 | } | |
32 | } | |
33 | ||
a52b41bf SM |
34 | proc_with_prefix test_directories { } { |
35 | # We use "." here instead of ":" so that this works on win32 too. | |
36 | if { [is_remote host] } { | |
37 | # Don't match $srcdir/$subdir because proc gdb_reinitialize_dir | |
38 | # doesn't set search directories on remote host. | |
39 | set directories ".*\\\$cdir.\\\$cwd" | |
40 | } else { | |
41 | set escaped_directory [string_to_regexp "$::srcdir/$::subdir"] | |
42 | set directories "$escaped_directory.\\\$cdir.\\\$cwd" | |
79c02443 | 43 | } |
a52b41bf SM |
44 | gdb_test "python print (gdb.parameter ('directories'))" $directories |
45 | } | |
79c02443 | 46 | |
a52b41bf SM |
47 | proc_with_prefix test_data_directory { } { |
48 | clean_restart | |
49 | ||
50 | # Check we can correctly read the data-directory parameter. First, | |
51 | # grab the value as read directly from the GDB CLI. | |
52 | set dd "" | |
53 | gdb_test_multiple "show data-directory" \ | |
54 | "find the initial data-directory value" { | |
55 | -re -wrap "GDB's data directory is \"(\[^\r\n\]+)\"\\." { | |
56 | set dd $expect_out(1,string) | |
57 | pass $gdb_test_name | |
58 | } | |
59 | } | |
79c02443 | 60 | |
a52b41bf SM |
61 | # Now print the data-directory from Python. |
62 | gdb_test "python print (gdb.parameter ('data-directory'))" $dd | |
63 | ||
64 | # Next change the data-directory to a relative path. Internally GDB | |
65 | # will resolve this to an absolute path, which Python should then see. | |
66 | # | |
67 | # GDB is currently running in '...../build/gdb/testsuite/' and the | |
68 | # test output is being written to: | |
69 | # ...../build/gdb/testsuite/outputs/gdb.python/py-parameter/ | |
70 | # | |
71 | # So create the relative path './outputs/gdb.python/py-parameter/' and | |
72 | # set the data-directory to that, we should then see the absolute path. | |
73 | ||
74 | set abs_path_to_output_dir [standard_output_file ""] | |
75 | set abs_path_to_cwd $::objdir | |
76 | set rel_path_to_output_dir \ | |
77 | [file join "." [string replace ${abs_path_to_output_dir} 0 \ | |
78 | [string length ${abs_path_to_cwd}] ""]] | |
2292e336 TT |
79 | gdb_test_no_output "set data-directory ${rel_path_to_output_dir}" \ |
80 | "set data-directory to relative path" | |
a52b41bf SM |
81 | |
82 | gdb_test "python print (gdb.parameter ('data-directory'))" \ | |
83 | ${abs_path_to_output_dir} \ | |
84 | "python sees absolute version of data-directory path" | |
85 | ||
86 | # While we're here, check we see the correct path at GDB's CLI. | |
87 | gdb_test "show data-directory" \ | |
88 | "GDB's data directory is \"${abs_path_to_output_dir}\"\\." \ | |
89 | "check modified data-directory at the CLI" | |
90 | ||
91 | # Now lets set the data-directory back to what it was initially. | |
92 | gdb_test_no_output "set data-directory ${dd}" \ | |
93 | "set data-directory back to its original value" | |
94 | ||
95 | # And check we see the restored value at CLI and from Python. | |
96 | gdb_test "show data-directory" \ | |
97 | "GDB's data directory is \"${dd}\"\\." \ | |
98 | "check original data-directory was restored at the CLI" | |
99 | ||
100 | gdb_test "python print (gdb.parameter ('data-directory'))" ${dd} \ | |
101 | "python sees restored data-directory value" | |
102 | } | |
79c02443 | 103 | |
b521dba8 | 104 | # Test a simple boolean parameter. |
a52b41bf SM |
105 | proc_with_prefix test_boolean_parameter { } { |
106 | clean_restart | |
107 | ||
2a17c803 | 108 | gdb_test_multiline "Simple gdb booleanparameter" \ |
082cce05 AB |
109 | "python" "" \ |
110 | "class TestParam (gdb.Parameter):" "" \ | |
111 | " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \ | |
112 | " show_doc = \"Show the state of the boolean test-param\"" ""\ | |
113 | " set_doc = \"Set the state of the boolean test-param\"" "" \ | |
114 | " def get_show_string (self, pvalue):" ""\ | |
115 | " return \"The state of the Test Parameter is \" + pvalue" ""\ | |
116 | " def get_set_string (self):" ""\ | |
117 | " val = \"on\"" ""\ | |
118 | " if (self.value == False):" ""\ | |
119 | " val = \"off\"" ""\ | |
120 | " return \"Test Parameter has been set to \" + val" ""\ | |
121 | " def __init__ (self, name):" "" \ | |
122 | " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \ | |
123 | " self.value = True" "" \ | |
124 | "test_param = TestParam ('print test-param')" ""\ | |
125 | "end" | |
ecec24e6 | 126 | |
082cce05 AB |
127 | gdb_test "python print (test_param.value)" "True" \ |
128 | "test boolean parameter value is True" | |
129 | gdb_test "show print test-param" \ | |
130 | "The state of the Test Parameter is on.*" "show parameter on" | |
131 | gdb_test "set print test-param off" \ | |
132 | "Test Parameter has been set to off" "turn off parameter" | |
133 | gdb_test "show print test-param" \ | |
134 | "The state of the Test Parameter is off.*" "show parameter off" | |
135 | gdb_test "python print (test_param.value)" "False" \ | |
136 | "test boolean parameter value is False" | |
fa17a681 TT |
137 | gdb_test_no_output "python gdb.set_parameter('print test-param', True)" \ |
138 | "set boolean parameter using set_parameter" | |
139 | gdb_test "python print(gdb.parameter('print test-param'))" "True" \ | |
140 | "get boolean parameter using gdb.parameter" | |
082cce05 | 141 | gdb_test "help show print test-param" \ |
bbea6807 AB |
142 | [multi_line \ |
143 | "Show the state of the boolean test-param" \ | |
144 | "When enabled, test param does something useful\\. When disabled, does nothing\\."] \ | |
145 | "test show help" | |
082cce05 AB |
146 | gdb_test "help set print test-param" \ |
147 | "Set the state of the boolean test-param.*" "test set help" | |
148 | gdb_test "help set print" \ | |
149 | "set print test-param -- Set the state of the boolean test-param.*" \ | |
150 | "test general help" | |
151 | } | |
b521dba8 DE |
152 | |
153 | # Test an enum parameter. | |
a52b41bf SM |
154 | proc_with_prefix test_enum_parameter { } { |
155 | clean_restart | |
156 | ||
2a17c803 | 157 | gdb_test_multiline "enum gdb parameter" \ |
082cce05 AB |
158 | "python" "" \ |
159 | "class TestEnumParam (gdb.Parameter):" "" \ | |
160 | " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \ | |
161 | " show_doc = \"Show the state of the enum\"" ""\ | |
162 | " set_doc = \"Set the state of the enum\"" "" \ | |
163 | " def get_show_string (self, pvalue):" ""\ | |
164 | " return \"The state of the enum is \" + pvalue" ""\ | |
165 | " def get_set_string (self):" ""\ | |
166 | " return \"The state of the enum has been set to \" + self.value" ""\ | |
167 | " def __init__ (self, name):" "" \ | |
168 | " super (TestEnumParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_ENUM, \[\"one\", \"two\"\])" "" \ | |
169 | " self.value = \"one\"" "" \ | |
170 | "test_enum_param = TestEnumParam ('print test-enum-param')" ""\ | |
171 | "end" | |
172 | ||
173 | gdb_test "python print (test_enum_param.value)" "one" \ | |
174 | "test enum parameter value is one" | |
175 | gdb_test "show print test-enum-param" \ | |
176 | "The state of the enum is one.*" \ | |
177 | "show parameter is initial value" | |
178 | gdb_test "set print test-enum-param two" \ | |
179 | "The state of the enum has been set to two" "set enum to two" | |
180 | gdb_test "show print test-enum-param" \ | |
181 | "The state of the enum is two.*" "show parameter is new value" | |
182 | gdb_test "python print (test_enum_param.value)" "two" \ | |
183 | "test enum parameter value is two" | |
184 | gdb_test "set print test-enum-param three" \ | |
185 | "Undefined item: \"three\".*" "set invalid enum parameter" | |
186 | } | |
b521dba8 DE |
187 | |
188 | # Test a file parameter. | |
a52b41bf SM |
189 | proc_with_prefix test_file_parameter { } { |
190 | clean_restart | |
191 | ||
2a17c803 | 192 | gdb_test_multiline "file gdb parameter" \ |
082cce05 AB |
193 | "python" "" \ |
194 | "class TestFileParam (gdb.Parameter):" "" \ | |
195 | " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \ | |
196 | " show_doc = \"Show the name of the file\"" ""\ | |
197 | " set_doc = \"Set the name of the file\"" "" \ | |
198 | " def get_show_string (self, pvalue):" ""\ | |
199 | " return \"The name of the file is \" + pvalue" ""\ | |
200 | " def get_set_string (self):" ""\ | |
201 | " return \"The name of the file has been changed to \" + self.value" ""\ | |
202 | " def __init__ (self, name):" "" \ | |
203 | " super (TestFileParam, self).__init__ (name, gdb.COMMAND_FILES, gdb.PARAM_FILENAME)" "" \ | |
204 | " self.value = \"foo.txt\"" "" \ | |
205 | "test_file_param = TestFileParam ('test-file-param')" ""\ | |
206 | "end" | |
207 | ||
208 | gdb_test "python print (test_file_param.value)" "foo.txt" \ | |
209 | "test file parameter value" | |
210 | gdb_test "show test-file-param" \ | |
211 | "The name of the file is foo.txt.*" "show initial file value" | |
212 | gdb_test "set test-file-param bar.txt" \ | |
213 | "The name of the file has been changed to bar.txt" \ | |
1fe69430 | 214 | "set new file parameter" |
082cce05 AB |
215 | gdb_test "show test-file-param" \ |
216 | "The name of the file is bar.txt.*" "show new file value" | |
217 | gdb_test "python print (test_file_param.value)" \ | |
218 | "bar.txt" "test new file parameter value" | |
219 | gdb_test "set test-file-param" "Argument required.*" | |
220 | } | |
b521dba8 | 221 | |
ecec24e6 | 222 | # Test a parameter that is not documented. |
a52b41bf SM |
223 | proc_with_prefix test_undocumented_parameter { } { |
224 | clean_restart | |
225 | ||
2a17c803 | 226 | gdb_test_multiline "Simple gdb booleanparameter" \ |
082cce05 AB |
227 | "python" "" \ |
228 | "class TestUndocParam (gdb.Parameter):" "" \ | |
229 | " def get_show_string (self, pvalue):" ""\ | |
230 | " return \"The state of the Test Parameter is \" + pvalue" ""\ | |
231 | " def get_set_string (self):" ""\ | |
232 | " val = \"on\"" ""\ | |
233 | " if (self.value == False):" ""\ | |
234 | " val = \"off\"" ""\ | |
235 | " return \"Test Parameter has been set to \" + val" ""\ | |
236 | " def __init__ (self, name):" "" \ | |
237 | " super (TestUndocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \ | |
238 | " self.value = True" "" \ | |
239 | "test_undoc_param = TestUndocParam ('print test-undoc-param')" ""\ | |
240 | "end" | |
241 | ||
242 | gdb_test "show print test-undoc-param" \ | |
243 | "The state of the Test Parameter is on.*" "show parameter on" | |
244 | gdb_test "set print test-undoc-param off" \ | |
245 | "Test Parameter has been set to off" "turn off parameter" | |
246 | gdb_test "show print test-undoc-param" \ | |
247 | "The state of the Test Parameter is off.*" "show parameter off" | |
248 | gdb_test "python print (test_undoc_param.value)" \ | |
249 | "False" "test undocumented parameter value is False" | |
250 | gdb_test "help show print test-undoc-param" \ | |
bbea6807 AB |
251 | [multi_line \ |
252 | "Show the current value of 'print test-undoc-param'\\." \ | |
253 | "This command is not documented.*"] \ | |
254 | "test show help" | |
082cce05 AB |
255 | gdb_test "help set print test-undoc-param" \ |
256 | "This command is not documented.*" "test set help" | |
257 | gdb_test "help set print" \ | |
bbea6807 | 258 | "set print test-undoc-param -- Set the current value of 'print test-undoc-param'\\..*" \ |
082cce05 AB |
259 | "test general help" |
260 | } | |
ecec24e6 PM |
261 | |
262 | # Test a parameter that is not documented in any way.. | |
a52b41bf SM |
263 | proc_with_prefix test_really_undocumented_parameter { } { |
264 | clean_restart | |
265 | ||
2a17c803 | 266 | gdb_test_multiline "Simple gdb booleanparameter" \ |
082cce05 AB |
267 | "python" "" \ |
268 | "class TestNodocParam (gdb.Parameter):" "" \ | |
269 | " def __init__ (self, name):" "" \ | |
270 | " super (TestNodocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \ | |
271 | " self.value = True" "" \ | |
272 | "test_nodoc_param = TestNodocParam ('print test-nodoc-param')" ""\ | |
273 | "end" | |
274 | ||
275 | gdb_test "show print test-nodoc-param" \ | |
bbea6807 AB |
276 | "The current value of 'print test-nodoc-param' is \"on\"\\." \ |
277 | "show parameter on" | |
082cce05 AB |
278 | gdb_test_no_output "set print test-nodoc-param off" \ |
279 | "turn off parameter" | |
280 | gdb_test "show print test-nodoc-param" \ | |
bbea6807 AB |
281 | "The current value of 'print test-nodoc-param' is \"off\"\\." \ |
282 | "show parameter off" | |
082cce05 AB |
283 | gdb_test "python print (test_nodoc_param.value)" \ |
284 | "False" "test really undocumented parameter value is False" | |
285 | gdb_test "help show print test-nodoc-param" \ | |
bbea6807 AB |
286 | [multi_line \ |
287 | "Show the current value of 'print test-nodoc-param'\\." \ | |
288 | "This command is not documented.*"] \ | |
289 | "test show help" | |
082cce05 AB |
290 | gdb_test "help set print test-nodoc-param" \ |
291 | "This command is not documented.*" "test set help" | |
292 | gdb_test "help set print" \ | |
bbea6807 | 293 | "set print test-nodoc-param -- Set the current value of 'print test-nodoc-param'\\..*" \ |
082cce05 AB |
294 | "test general help" |
295 | } | |
ecec24e6 PM |
296 | |
297 | # Test deprecated API. Do not use in your own implementations. | |
a52b41bf SM |
298 | proc_with_prefix test_deprecated_api_parameter { } { |
299 | clean_restart | |
300 | ||
2a17c803 | 301 | gdb_test_multiline "Simple gdb booleanparameter" \ |
082cce05 AB |
302 | "python" "" \ |
303 | "class TestParam (gdb.Parameter):" "" \ | |
304 | " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \ | |
305 | " show_doc = \"State of the Test Parameter\"" ""\ | |
306 | " set_doc = \"Set the state of the Test Parameter\"" "" \ | |
307 | " def __init__ (self, name):" "" \ | |
308 | " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \ | |
309 | " self.value = True" "" \ | |
310 | "test_param = TestParam ('print test-param')" ""\ | |
311 | "end" | |
312 | ||
313 | gdb_test "python print (test_param.value)" "True" \ | |
314 | "test deprecated API parameter value is True" | |
315 | gdb_test "show print test-param" \ | |
bbea6807 AB |
316 | "The current value of 'print test-param' is \"on\"\\." \ |
317 | "show parameter on" | |
082cce05 AB |
318 | gdb_test_no_output "set print test-param off" "turn off parameter" |
319 | gdb_test "show print test-param" \ | |
bbea6807 AB |
320 | "The current value of 'print test-param' is \"off\"\\." \ |
321 | "show parameter off" | |
082cce05 AB |
322 | gdb_test "python print (test_param.value)" "False" \ |
323 | "test deprecated API parameter value is False" | |
324 | gdb_test "help show print test-param" \ | |
bbea6807 AB |
325 | [multi_line \ |
326 | "State of the Test Parameter" \ | |
327 | "When enabled, test param does something useful\\. When disabled, does nothing\\."] \ | |
328 | "test show help" | |
082cce05 AB |
329 | gdb_test "help set print test-param" \ |
330 | "Set the state of the Test Parameter.*" "test set help" | |
331 | gdb_test "help set print" \ | |
332 | "set print test-param -- Set the state of the Test Parameter.*" \ | |
333 | "test general help" | |
334 | } | |
0489430a | 335 | |
e7e1f203 MR |
336 | proc_with_prefix test_gdb_parameter { } { |
337 | foreach_with_prefix param { | |
338 | "listsize" | |
339 | "print elements" | |
340 | "max-completions" | |
77519ab3 | 341 | "print characters" |
e7e1f203 MR |
342 | } { |
343 | clean_restart | |
344 | ||
345 | set param_range_error ".*gdb.error: integer -1 out of range.*" | |
346 | switch -- $param { | |
347 | "listsize" { | |
348 | set param_get_zero None | |
349 | set param_get_minus_one -1 | |
c506be7d | 350 | set param_get_none None |
e7e1f203 MR |
351 | set param_get_unlimited None |
352 | set param_set_minus_one "" | |
353 | } | |
77519ab3 AB |
354 | "print elements" - |
355 | "print characters" { | |
e7e1f203 MR |
356 | set param_get_zero None |
357 | set param_get_minus_one None | |
c506be7d | 358 | set param_get_none None |
e7e1f203 MR |
359 | set param_get_unlimited None |
360 | set param_set_minus_one $param_range_error | |
361 | } | |
362 | "max-completions" { | |
363 | set param_get_zero 0 | |
364 | set param_get_minus_one -1 | |
c506be7d | 365 | set param_get_none -1 |
e7e1f203 MR |
366 | set param_get_unlimited -1 |
367 | set param_set_minus_one "" | |
368 | } | |
369 | default { | |
370 | error "invalid param: $param" | |
371 | } | |
372 | } | |
373 | ||
374 | gdb_test_no_output "python gdb.set_parameter('$param', 1)" \ | |
375 | "test set to 1" | |
376 | ||
377 | gdb_test "python print(gdb.parameter('$param'))" \ | |
378 | 1 "test value of 1" | |
379 | ||
380 | gdb_test_no_output "python gdb.set_parameter('$param', 0)" \ | |
381 | "test set to 0" | |
382 | ||
383 | gdb_test "python print(gdb.parameter('$param'))" \ | |
384 | $param_get_zero "test value of 0" | |
385 | ||
386 | py_param_test_maybe_no_output \ | |
387 | "python gdb.set_parameter('$param', -1)" \ | |
388 | $param_set_minus_one "test set to -1" | |
389 | ||
390 | gdb_test "python print(gdb.parameter('$param'))" \ | |
391 | $param_get_minus_one "test value of -1" | |
392 | ||
c506be7d MR |
393 | gdb_test_no_output "python gdb.set_parameter('$param', None)" \ |
394 | "test set to None" | |
395 | ||
396 | gdb_test "python print(gdb.parameter('$param'))" \ | |
397 | $param_get_none "test value of None" | |
398 | ||
e7e1f203 MR |
399 | gdb_test_no_output "python gdb.set_parameter('$param', 'unlimited')" \ |
400 | "test set to 'unlimited'" | |
401 | ||
402 | gdb_test "python print(gdb.parameter('$param'))" \ | |
403 | $param_get_unlimited "test value of 'unlimited'" | |
77519ab3 AB |
404 | |
405 | if {$param == "print characters"} { | |
406 | gdb_test_no_output \ | |
407 | "python gdb.set_parameter('$param', 'elements')" \ | |
408 | "test set to 'elements'" | |
409 | ||
410 | gdb_test "python print(gdb.parameter('$param'))" \ | |
411 | elements "test value of 'elements'" | |
412 | } | |
e7e1f203 MR |
413 | } |
414 | ||
415 | clean_restart | |
416 | ||
417 | # This caused a gdb crash. | |
418 | gdb_test "python print(gdb.parameter('endian'))" "auto" \ | |
419 | "print endian parameter" | |
420 | } | |
421 | ||
a52b41bf | 422 | proc_with_prefix test_integer_parameter { } { |
e7e1f203 MR |
423 | foreach_with_prefix kind { |
424 | PARAM_UINTEGER | |
425 | PARAM_INTEGER | |
426 | PARAM_ZINTEGER | |
427 | PARAM_ZUINTEGER | |
428 | PARAM_ZUINTEGER_UNLIMITED | |
429 | } { | |
a52b41bf SM |
430 | clean_restart |
431 | ||
432 | gdb_test_multiline "create parameter" \ | |
433 | "python" "" \ | |
434 | "class TestNodocParam (gdb.Parameter):" "" \ | |
435 | " def __init__ (self, name):" "" \ | |
436 | " super (TestNodocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.$kind)" "" \ | |
437 | " self.value = 0" "" \ | |
438 | "test_param_$kind = TestNodocParam ('test-$kind')" "" \ | |
439 | "end" | |
440 | ||
e7e1f203 MR |
441 | set param_range_error "RuntimeError: Range exceeded.*" |
442 | set param_integer_error "RuntimeError: The value must be integer.*" | |
443 | switch -- $kind { | |
444 | PARAM_UINTEGER { | |
445 | set param_get_zero None | |
446 | set param_get_minus_one None | |
447 | set param_get_minus_five 1 | |
c506be7d | 448 | set param_get_none None |
7aeb03e2 | 449 | set param_get_unlimited None |
e7e1f203 MR |
450 | set param_set_minus_one $param_range_error |
451 | set param_set_minus_five $param_range_error | |
c506be7d | 452 | set param_set_none "" |
e7e1f203 MR |
453 | } |
454 | PARAM_INTEGER { | |
455 | set param_get_zero None | |
456 | set param_get_minus_one -1 | |
457 | set param_get_minus_five -5 | |
c506be7d | 458 | set param_get_none None |
7aeb03e2 | 459 | set param_get_unlimited None |
e7e1f203 MR |
460 | set param_set_minus_one -1 |
461 | set param_set_minus_five -5 | |
c506be7d | 462 | set param_set_none "" |
e7e1f203 MR |
463 | } |
464 | PARAM_ZINTEGER { | |
465 | set param_get_zero 0 | |
466 | set param_get_minus_one -1 | |
467 | set param_get_minus_five -5 | |
468 | set param_get_none 5 | |
7aeb03e2 | 469 | set param_get_unlimited 0 |
e7e1f203 MR |
470 | set param_set_minus_one "" |
471 | set param_set_minus_five "" | |
472 | set param_set_none $param_integer_error | |
473 | } | |
474 | PARAM_ZUINTEGER { | |
475 | set param_get_zero 0 | |
476 | set param_get_minus_one 0 | |
477 | set param_get_minus_five 1 | |
478 | set param_get_none 5 | |
7aeb03e2 | 479 | set param_get_unlimited 0 |
e7e1f203 MR |
480 | set param_set_minus_one $param_range_error |
481 | set param_set_minus_five $param_range_error | |
482 | set param_set_none $param_integer_error | |
483 | } | |
484 | PARAM_ZUINTEGER_UNLIMITED { | |
485 | set param_get_zero 0 | |
486 | set param_get_minus_one -1 | |
487 | set param_get_minus_five 1 | |
c506be7d | 488 | set param_get_none -1 |
7aeb03e2 | 489 | set param_get_unlimited -1 |
e7e1f203 MR |
490 | set param_set_minus_one "" |
491 | set param_set_minus_five $param_range_error | |
c506be7d | 492 | set param_set_none "" |
e7e1f203 MR |
493 | } |
494 | default { | |
495 | error "invalid kind: $kind" | |
496 | } | |
497 | } | |
498 | ||
499 | gdb_test "python print(test_param_$kind.value)" \ | |
500 | $param_get_zero "test default value" | |
a52b41bf | 501 | |
e7e1f203 MR |
502 | gdb_test "python print(gdb.parameter('test-$kind'))" \ |
503 | $param_get_zero "test default value via gdb.parameter" | |
a52b41bf | 504 | |
e7e1f203 MR |
505 | py_param_test_maybe_no_output "python test_param_$kind.value = -1" \ |
506 | $param_set_minus_one "test set to -1" | |
507 | ||
508 | gdb_test "python print(test_param_$kind.value)" \ | |
509 | $param_get_minus_one "test value of -1" | |
510 | ||
511 | gdb_test "python print(gdb.parameter('test-$kind'))" \ | |
512 | $param_get_minus_one "test value of -1 via gdb.parameter" | |
513 | ||
514 | gdb_test_no_output "python test_param_$kind.value = 1" "test set to 1" | |
515 | ||
516 | gdb_test "python print(test_param_$kind.value)" 1 "test value of 1" | |
517 | ||
518 | gdb_test "python print(gdb.parameter('test-$kind'))" \ | |
519 | 1 "test value of 1 via gdb.parameter" | |
520 | ||
521 | py_param_test_maybe_no_output "python test_param_$kind.value = -5" \ | |
522 | $param_set_minus_five "test set to -5" | |
523 | ||
524 | gdb_test "python print(gdb.parameter('test-$kind'))" \ | |
525 | $param_get_minus_five "test value of -5 via gdb.parameter" | |
526 | ||
527 | gdb_test_no_output "python test_param_$kind.value = 5" "test set to 5" | |
528 | ||
529 | gdb_test "python print(gdb.parameter('test-$kind'))" \ | |
530 | 5 "test value of 5 via gdb.parameter" | |
531 | ||
532 | py_param_test_maybe_no_output "python test_param_$kind.value = None" \ | |
533 | $param_set_none "test set to None" | |
534 | ||
535 | gdb_test "python print(test_param_$kind.value)" \ | |
536 | $param_get_none "test value of None" | |
537 | ||
538 | gdb_test "python print(gdb.parameter('test-$kind'))" \ | |
539 | $param_get_none "test value of None via gdb.parameter" | |
540 | ||
541 | gdb_test_no_output "python test_param_$kind.value = 0" \ | |
542 | "test set to 0" | |
543 | ||
544 | gdb_test "python print(gdb.parameter('test-$kind'))" \ | |
545 | $param_get_zero "test value of 0 via gdb.parameter" | |
7aeb03e2 MR |
546 | |
547 | py_param_test_maybe_no_output \ | |
548 | "python test_param_$kind.value = 'unlimited'" \ | |
549 | $param_set_none "test set to 'unlimited'" | |
550 | ||
551 | gdb_test "python print(test_param_$kind.value)" \ | |
552 | $param_get_unlimited "test value of 'unlimited'" | |
553 | ||
554 | gdb_test "python print(gdb.parameter('test-$kind'))" \ | |
555 | $param_get_unlimited "test value of 'unlimited' via gdb.parameter" | |
a52b41bf SM |
556 | } |
557 | } | |
558 | ||
559 | proc_with_prefix test_throwing_parameter { } { | |
560 | clean_restart | |
561 | ||
562 | gdb_test_multiline "Throwing gdb parameter" \ | |
0489430a | 563 | "python" "" \ |
a52b41bf | 564 | "class TestThrowParam (gdb.Parameter):" "" \ |
0489430a | 565 | " def __init__ (self, name):" "" \ |
a52b41bf SM |
566 | " super (TestThrowParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_STRING)" "" \ |
567 | " self.value = True" "" \ | |
568 | " def get_set_string (self):" "" \ | |
569 | " raise gdb.GdbError('Ordinary gdb error')" "" \ | |
570 | "test_throw_param = TestThrowParam ('print test-throw-param')" ""\ | |
0489430a TT |
571 | "end" |
572 | ||
a52b41bf SM |
573 | gdb_test "set print test-throw-param whoops" \ |
574 | "Ordinary gdb error" \ | |
575 | "gdb.GdbError does not show Python stack" | |
0489430a | 576 | } |
ae778caf | 577 | |
80fa4b2a TT |
578 | proc_with_prefix test_language {} { |
579 | gdb_test "python print(gdb.parameter('language'))" "auto" \ | |
580 | "print language parameter" | |
581 | gdb_test "python print(gdb.current_language())" "c" \ | |
582 | "print current language" | |
583 | gdb_test_no_output "set lang rust" | |
584 | gdb_test "python print(gdb.parameter('language'))" "rust" \ | |
585 | "print language parameter for rust" | |
586 | gdb_test "python print(gdb.current_language())" "rust" \ | |
587 | "print current language for rust" | |
588 | gdb_test_no_output "set lang auto" | |
589 | } | |
590 | ||
a52b41bf SM |
591 | test_directories |
592 | test_data_directory | |
593 | test_boolean_parameter | |
594 | test_enum_parameter | |
595 | test_file_parameter | |
596 | test_undocumented_parameter | |
597 | test_really_undocumented_parameter | |
598 | test_deprecated_api_parameter | |
e7e1f203 | 599 | test_gdb_parameter |
a52b41bf SM |
600 | test_integer_parameter |
601 | test_throwing_parameter | |
80fa4b2a | 602 | test_language |
dedb7102 | 603 | |
e7e1f203 | 604 | rename py_param_test_maybe_no_output "" |