Automatic date update in version.in
[binutils-gdb.git] / gdb / testsuite / gdb.python / py-parameter.exp
blob74e4178bf3513db3925e19d66c03642d5ca205a5
1 # Copyright (C) 2010-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the GDB testsuite.
17 # It tests gdb.parameter and gdb.Parameter.
19 load_lib gdb-python.exp
21 require allow_python_tests
23 # Start with a fresh gdb.
24 clean_restart
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     }
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"
43     }
44     gdb_test "python print (gdb.parameter ('directories'))" $directories
47 proc_with_prefix test_data_directory { } {
48     clean_restart
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         }
61     # Now print the data-directory from Python.
62     gdb_test "python print (gdb.parameter ('data-directory'))" $dd
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.
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}] ""]]
79     gdb_test_no_output "set data-directory ${rel_path_to_output_dir}" \
80         "set data-directory to relative path"
82     gdb_test "python print (gdb.parameter ('data-directory'))" \
83         ${abs_path_to_output_dir} \
84         "python sees absolute version of data-directory path"
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"
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"
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"
100     gdb_test "python print (gdb.parameter ('data-directory'))" ${dd} \
101         "python sees restored data-directory value"
104 # Test a simple boolean parameter.
105 proc_with_prefix test_boolean_parameter { } {
106     clean_restart
108     gdb_test_multiline "Simple gdb booleanparameter" \
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"
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"
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"
141     gdb_test "help show print test-param" \
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"
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"
153 # Test an enum parameter.
154 proc_with_prefix test_enum_parameter { } {
155     clean_restart
157     gdb_test_multiline "enum gdb parameter" \
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"
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"
188 # Test an color parameter.
189 proc_with_prefix test_color_parameter { } {
190     global env
191     with_ansi_styling_terminal {
192         # This enables 256 colors support and disables colors approximation.
193         setenv TERM xterm-256color
194         setenv COLORTERM truecolor
196         clean_restart
198         gdb_test_multiline "color gdb parameter" \
199             "python" "" \
200             "class TestColorParam (gdb.Parameter):" "" \
201             "   \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \
202             "   show_doc = \"Show the state of the color\"" ""\
203             "   set_doc = \"Set the state of the color\"" "" \
204             "   def get_show_string (self, pvalue):" ""\
205             "      return \"The state of the color is \" + str(pvalue)" ""\
206             "   def get_set_string (self):" ""\
207             "      return \"The state of the color has been set to \" + str(self.value)" ""\
208             "   def __init__ (self, name):" "" \
209             "      super (TestColorParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_COLOR)" "" \
210             "      self.value = gdb.Color(\"green\")" "" \
211             "test_color_param = TestColorParam ('print test-color-param')" ""\
212             "end"
214         gdb_test "python print (test_color_param.value)" "green" \
215             "test color parameter value is green"
216         gdb_test "show print test-color-param" \
217             "The state of the color is green.*" \
218             "show parameter is initial value"
219         gdb_test "set print test-color-param 255" \
220             "The state of the color has been set to 255" "set color to 255"
221         gdb_test "show print test-color-param" \
222             "The state of the color is 255.*" "show parameter is new value"
223         gdb_test "python print (test_color_param.value)" "255" \
224             "test color parameter value is 255"
225         gdb_test_no_output "python test_color_param.value = gdb.Color(254)" \
226             "assign test_color_param.value to 254"
227         gdb_test "python print (test_color_param.value)" "254" \
228             "test color parameter value is integer"
229         gdb_test_no_output "python test_color_param.value =  gdb.Color('#FED210')" \
230             "assign test_color_param.value to #FED210"
231         gdb_test "python print (test_color_param.value.components)" "\\(254, 210, 16\\)" \
232             "test color parameter components from RGB hex tripple value"
233         gdb_test "set print test-color-param 256" \
234             "integer 256 out of range.*" "set invalid color parameter"
235         gdb_test "python test_color_param.value = gdb.Color(256)" \
236             ".*Error occurred in Python: Palette color index 256 is out of range.*" "set invalid color value"
237     }
240 # Test a file parameter.
241 proc_with_prefix test_file_parameter { } {
242     clean_restart
244     gdb_test_multiline "file gdb parameter" \
245         "python" "" \
246         "class TestFileParam (gdb.Parameter):" "" \
247         "   \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \
248         "   show_doc = \"Show the name of the file\"" ""\
249         "   set_doc = \"Set the name of the file\"" "" \
250         "   def get_show_string (self, pvalue):" ""\
251         "      return \"The name of the file is \" + pvalue" ""\
252         "   def get_set_string (self):" ""\
253         "      return \"The name of the file has been changed to \" + self.value" ""\
254         "   def __init__ (self, name):" "" \
255         "      super (TestFileParam, self).__init__ (name, gdb.COMMAND_FILES, gdb.PARAM_FILENAME)" "" \
256         "      self.value = \"foo.txt\"" "" \
257         "test_file_param = TestFileParam ('test-file-param')" ""\
258         "end"
260     gdb_test "python print (test_file_param.value)" "foo.txt" \
261         "test file parameter value"
262     gdb_test "show test-file-param" \
263         "The name of the file is foo.txt.*" "show initial file value"
264     gdb_test "set test-file-param bar.txt" \
265         "The name of the file has been changed to bar.txt" \
266         "set new file parameter"
267     gdb_test "show test-file-param" \
268         "The name of the file is bar.txt.*" "show new file value"
269     gdb_test "python print (test_file_param.value)" \
270         "bar.txt" "test new file parameter value"
271     gdb_test "set test-file-param" "Argument required.*"
274 # Test a parameter that is not documented.
275 proc_with_prefix test_undocumented_parameter { } {
276     clean_restart
278     gdb_test_multiline "Simple gdb booleanparameter" \
279         "python" "" \
280         "class TestUndocParam (gdb.Parameter):" "" \
281         "   def get_show_string (self, pvalue):" ""\
282         "      return \"The state of the Test Parameter is \" + pvalue" ""\
283         "   def get_set_string (self):" ""\
284         "      val = \"on\"" ""\
285         "      if (self.value == False):" ""\
286         "         val = \"off\"" ""\
287         "      return \"Test Parameter has been set to \" + val" ""\
288         "   def __init__ (self, name):" "" \
289         "      super (TestUndocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
290         "      self.value = True" "" \
291         "test_undoc_param = TestUndocParam ('print test-undoc-param')" ""\
292         "end"
294     gdb_test "show print test-undoc-param" \
295         "The state of the Test Parameter is on.*" "show parameter on"
296     gdb_test "set print test-undoc-param off" \
297         "Test Parameter has been set to off" "turn off parameter"
298     gdb_test "show print test-undoc-param" \
299         "The state of the Test Parameter is off.*" "show parameter off"
300     gdb_test "python print (test_undoc_param.value)" \
301         "False" "test undocumented parameter value is False"
302     gdb_test "help show print test-undoc-param" \
303         [multi_line \
304              "Show the current value of 'print test-undoc-param'\\." \
305              "This command is not documented.*"] \
306         "test show help"
307     gdb_test "help set print test-undoc-param" \
308         "This command is not documented.*" "test set help"
309     gdb_test "help set print" \
310         "set print test-undoc-param -- Set the current value of 'print test-undoc-param'\\..*" \
311         "test general help"
314 # Test a parameter that is not documented in any way..
315 proc_with_prefix test_really_undocumented_parameter { } {
316     clean_restart
318     gdb_test_multiline "Simple gdb booleanparameter" \
319         "python" "" \
320         "class TestNodocParam (gdb.Parameter):" "" \
321         "   def __init__ (self, name):" "" \
322         "      super (TestNodocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
323         "      self.value = True" "" \
324         "test_nodoc_param = TestNodocParam ('print test-nodoc-param')" ""\
325         "end"
327     gdb_test "show print test-nodoc-param" \
328         "The current value of 'print test-nodoc-param' is \"on\"\\." \
329         "show parameter on"
330     gdb_test_no_output "set print test-nodoc-param off" \
331         "turn off parameter"
332     gdb_test "show print test-nodoc-param" \
333         "The current value of 'print test-nodoc-param' is \"off\"\\." \
334         "show parameter off"
335     gdb_test "python print (test_nodoc_param.value)" \
336         "False" "test really undocumented parameter value is False"
337     gdb_test "help show print test-nodoc-param" \
338         [multi_line \
339              "Show the current value of 'print test-nodoc-param'\\." \
340              "This command is not documented.*"] \
341         "test show help"
342     gdb_test "help set print test-nodoc-param" \
343         "This command is not documented.*" "test set help"
344     gdb_test "help set print" \
345         "set print test-nodoc-param -- Set the current value of 'print test-nodoc-param'\\..*" \
346         "test general help"
349 # Test deprecated API. Do not use in your own implementations.
350 proc_with_prefix test_deprecated_api_parameter { } {
351     clean_restart
353     gdb_test_multiline "Simple gdb booleanparameter" \
354         "python" "" \
355         "class TestParam (gdb.Parameter):" "" \
356         "   \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \
357         "   show_doc = \"State of the Test Parameter\"" ""\
358         "   set_doc = \"Set the state of the Test Parameter\"" "" \
359         "   def __init__ (self, name):" "" \
360         "      super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
361         "      self.value = True" "" \
362         "test_param = TestParam ('print test-param')" ""\
363         "end"
365     gdb_test "python print (test_param.value)" "True" \
366         "test deprecated API parameter value is True"
367     gdb_test "show print test-param" \
368         "The current value of 'print test-param' is \"on\"\\." \
369         "show parameter on"
370     gdb_test_no_output "set print test-param off" "turn off parameter"
371     gdb_test "show print test-param" \
372         "The current value of 'print test-param' is \"off\"\\." \
373         "show parameter off"
374     gdb_test "python print (test_param.value)" "False" \
375         "test deprecated API parameter value is False"
376     gdb_test "help show print test-param" \
377         [multi_line \
378              "State of the Test Parameter" \
379              "When enabled, test param does something useful\\. When disabled, does nothing\\."] \
380         "test show help"
381     gdb_test "help set print test-param" \
382         "Set the state of the Test Parameter.*" "test set help"
383     gdb_test "help set print" \
384         "set print test-param -- Set the state of the Test Parameter.*" \
385         "test general help"
388 proc_with_prefix test_gdb_parameter { } {
389     foreach_with_prefix param {
390         "listsize"
391         "print elements"
392         "max-completions"
393         "print characters"
394     } {
395         clean_restart
397         set param_range_error ".*gdb.error.*: integer -1 out of range.*"
398         switch -- $param {
399             "listsize" {
400                 set param_get_zero None
401                 set param_get_minus_one -1
402                 set param_get_none None
403                 set param_get_unlimited None
404                 set param_set_minus_one ""
405             }
406             "print elements" -
407             "print characters" {
408                 set param_get_zero None
409                 set param_get_minus_one None
410                 set param_get_none None
411                 set param_get_unlimited None
412                 set param_set_minus_one $param_range_error
413             }
414             "max-completions" {
415                 set param_get_zero 0
416                 set param_get_minus_one -1
417                 set param_get_none -1
418                 set param_get_unlimited -1
419                 set param_set_minus_one ""
420             }
421             default {
422                 error "invalid param: $param"
423             }
424         }
426         gdb_test_no_output "python gdb.set_parameter('$param', 1)" \
427             "test set to 1"
429         gdb_test "python print(gdb.parameter('$param'))" \
430             1 "test value of 1"
432         gdb_test_no_output "python gdb.set_parameter('$param', 0)" \
433             "test set to 0"
435         gdb_test "python print(gdb.parameter('$param'))" \
436             $param_get_zero "test value of 0"
438         py_param_test_maybe_no_output \
439             "python gdb.set_parameter('$param', -1)" \
440             $param_set_minus_one "test set to -1"
442         gdb_test "python print(gdb.parameter('$param'))" \
443             $param_get_minus_one "test value of -1"
445         gdb_test_no_output "python gdb.set_parameter('$param', None)" \
446             "test set to None"
448         gdb_test "python print(gdb.parameter('$param'))" \
449             $param_get_none "test value of None"
451         gdb_test_no_output "python gdb.set_parameter('$param', 'unlimited')" \
452             "test set to 'unlimited'"
454         gdb_test "python print(gdb.parameter('$param'))" \
455             $param_get_unlimited "test value of 'unlimited'"
457         if {$param == "print characters"} {
458             gdb_test_no_output \
459                 "python gdb.set_parameter('$param', 'elements')" \
460                 "test set to 'elements'"
462             gdb_test "python print(gdb.parameter('$param'))" \
463                 elements "test value of 'elements'"
464         }
465     }
467     clean_restart
469     # This caused a gdb crash.
470     gdb_test "python print(gdb.parameter('endian'))" "auto" \
471         "print endian parameter"
474 proc_with_prefix test_integer_parameter { } {
475     foreach_with_prefix kind {
476         PARAM_UINTEGER
477         PARAM_INTEGER
478         PARAM_ZINTEGER
479         PARAM_ZUINTEGER
480         PARAM_ZUINTEGER_UNLIMITED
481     } {
482         clean_restart
484         gdb_test_multiline "create parameter" \
485             "python" "" \
486             "class TestNodocParam (gdb.Parameter):" "" \
487             "   def __init__ (self, name):" "" \
488             "      super (TestNodocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.$kind)" "" \
489             "      self.value = 0" "" \
490             "test_param_$kind = TestNodocParam ('test-$kind')" "" \
491             "end"
493         set param_range_error "RuntimeError.*: Range exceeded.*"
494         set param_integer_error "RuntimeError.*: The value must be integer.*"
495         switch -- $kind {
496             PARAM_UINTEGER {
497                 set param_get_zero None
498                 set param_get_minus_one None
499                 set param_get_minus_five 1
500                 set param_get_none None
501                 set param_get_unlimited None
502                 set param_set_minus_one $param_range_error
503                 set param_set_minus_five $param_range_error
504                 set param_set_none ""
505             }
506             PARAM_INTEGER {
507                 set param_get_zero None
508                 set param_get_minus_one -1
509                 set param_get_minus_five -5
510                 set param_get_none None
511                 set param_get_unlimited None
512                 set param_set_minus_one -1
513                 set param_set_minus_five -5
514                 set param_set_none ""
515             }
516             PARAM_ZINTEGER {
517                 set param_get_zero 0
518                 set param_get_minus_one -1
519                 set param_get_minus_five -5
520                 set param_get_none 5
521                 set param_get_unlimited 0
522                 set param_set_minus_one ""
523                 set param_set_minus_five ""
524                 set param_set_none $param_integer_error
525             }
526             PARAM_ZUINTEGER {
527                 set param_get_zero 0
528                 set param_get_minus_one 0
529                 set param_get_minus_five 1
530                 set param_get_none 5
531                 set param_get_unlimited 0
532                 set param_set_minus_one $param_range_error
533                 set param_set_minus_five $param_range_error
534                 set param_set_none $param_integer_error
535             }
536             PARAM_ZUINTEGER_UNLIMITED {
537                 set param_get_zero 0
538                 set param_get_minus_one -1
539                 set param_get_minus_five 1
540                 set param_get_none -1
541                 set param_get_unlimited -1
542                 set param_set_minus_one ""
543                 set param_set_minus_five $param_range_error
544                 set param_set_none ""
545             }
546             default {
547                 error "invalid kind: $kind"
548             }
549         }
551         gdb_test "python print(test_param_$kind.value)" \
552             $param_get_zero "test default value"
554         gdb_test "python print(gdb.parameter('test-$kind'))" \
555             $param_get_zero "test default value via gdb.parameter"
557         py_param_test_maybe_no_output "python test_param_$kind.value = -1" \
558             $param_set_minus_one "test set to -1"
560         gdb_test "python print(test_param_$kind.value)" \
561             $param_get_minus_one "test value of -1"
563         gdb_test "python print(gdb.parameter('test-$kind'))" \
564             $param_get_minus_one "test value of -1 via gdb.parameter"
566         gdb_test_no_output "python test_param_$kind.value = 1" "test set to 1"
568         gdb_test "python print(test_param_$kind.value)" 1 "test value of 1"
570         gdb_test "python print(gdb.parameter('test-$kind'))" \
571             1 "test value of 1 via gdb.parameter"
573         py_param_test_maybe_no_output "python test_param_$kind.value = -5" \
574             $param_set_minus_five "test set to -5"
576         gdb_test "python print(gdb.parameter('test-$kind'))" \
577             $param_get_minus_five "test value of -5 via gdb.parameter"
579         gdb_test_no_output "python test_param_$kind.value = 5" "test set to 5"
581         gdb_test "python print(gdb.parameter('test-$kind'))" \
582             5 "test value of 5 via gdb.parameter"
584         py_param_test_maybe_no_output "python test_param_$kind.value = None" \
585             $param_set_none "test set to None"
587         gdb_test "python print(test_param_$kind.value)" \
588             $param_get_none "test value of None"
590         gdb_test "python print(gdb.parameter('test-$kind'))" \
591             $param_get_none "test value of None via gdb.parameter"
593         gdb_test_no_output "python test_param_$kind.value = 0" \
594             "test set to 0"
596         gdb_test "python print(gdb.parameter('test-$kind'))" \
597             $param_get_zero "test value of 0 via gdb.parameter"
599         py_param_test_maybe_no_output \
600             "python test_param_$kind.value = 'unlimited'" \
601             $param_set_none "test set to 'unlimited'"
603         gdb_test "python print(test_param_$kind.value)" \
604             $param_get_unlimited "test value of 'unlimited'"
606         gdb_test "python print(gdb.parameter('test-$kind'))" \
607             $param_get_unlimited "test value of 'unlimited' via gdb.parameter"
608     }
611 proc_with_prefix test_throwing_parameter { } {
612     clean_restart
614     gdb_test_multiline "Throwing gdb parameter" \
615         "python" "" \
616         "class TestThrowParam (gdb.Parameter):" "" \
617         "   def __init__ (self, name):" "" \
618         "      super (TestThrowParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_STRING)" "" \
619         "      self.value = True" "" \
620         "   def get_set_string (self):" "" \
621         "      raise gdb.GdbError('Ordinary gdb error')" "" \
622         "test_throw_param = TestThrowParam ('print test-throw-param')" ""\
623         "end"
625     gdb_test "set print test-throw-param whoops" \
626         "Ordinary gdb error" \
627         "gdb.GdbError does not show Python stack"
630 proc_with_prefix test_language {} {
631     gdb_test "python print(gdb.parameter('language'))" "auto" \
632         "print language parameter"
633     gdb_test "python print(gdb.current_language())" "c" \
634         "print current language"
635     gdb_test_no_output "set lang rust"
636     gdb_test "python print(gdb.parameter('language'))" "rust" \
637         "print language parameter for rust"
638     gdb_test "python print(gdb.current_language())" "rust" \
639         "print current language for rust"
640     gdb_test_no_output "set lang auto"
643 proc_with_prefix test_ambiguous_parameter {} {
644     gdb_test_multiline "create parameter" \
645         "python" "" \
646         "class TestAmbiguousParam (gdb.Parameter):" "" \
647         "   def __init__ (self, name, value):" "" \
648         "      super (TestAmbiguousParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_INTEGER)" "" \
649         "      self.value = value" "" \
650         "end"
652     # Create parameters.
653     gdb_test "python TestAmbiguousParam('test-ambiguous-value-1', 1)" ""
654     gdb_test "python TestAmbiguousParam('test-ambiguous-value-2-extra', 2)" ""
655     gdb_test "python TestAmbiguousParam('test-ambiguous', 3)" ""
657     # Test unambiguous matches.
658     gdb_test "python print(gdb.parameter('test-ambiguous-value-1'))" "1"
659     gdb_test "python print(gdb.parameter('test-ambiguous-value-2-extra'))" "2"
660     gdb_test "python print(gdb.parameter('test-ambiguous-value-2'))" "2"
661     gdb_test "python print(gdb.parameter('test-ambiguous'))" "3"
663     # Test ambiguous names.
664     gdb_test "python print(gdb.parameter('test-ambiguou'))" \
665         "Parameter .* is ambiguous.*Error occurred in Python.*"
666     gdb_test "python print(gdb.parameter('test-ambiguous-'))" \
667         "Parameter .* is ambiguous.*Error occurred in Python.*"
668     gdb_test "python print(gdb.parameter('test-ambiguous-v'))" \
669         "Parameter .* is ambiguous.*Error occurred in Python.*"
670     gdb_test "python print(gdb.parameter('test-ambiguous-value-1a'))" \
671         "Could not find parameter.*Error occurred in Python.*"
674 test_directories
675 test_data_directory
676 test_boolean_parameter
677 test_enum_parameter
678 test_color_parameter
679 test_file_parameter
680 test_undocumented_parameter
681 test_really_undocumented_parameter
682 test_deprecated_api_parameter
683 test_gdb_parameter
684 test_integer_parameter
685 test_throwing_parameter
686 test_language
687 test_ambiguous_parameter
689 rename py_param_test_maybe_no_output ""