]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-parameter.exp
Update copyright year range in all GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-parameter.exp
CommitLineData
42a4f53d 1# Copyright (C) 2010-2019 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
19load_lib gdb-python.exp
20
21# Start with a fresh gdb.
22gdb_exit
23gdb_start
24gdb_reinitialize_dir $srcdir/$subdir
25
26# Skip all tests if Python scripting is not enabled.
27if { [skip_python_tests] } { continue }
28
29# We use "." here instead of ":" so that this works on win32 too.
10c5f0a8
YQ
30if { [is_remote host] } {
31 # Don't match $srcdir/$subdir because proc gdb_reinitialize_dir
32 # doesn't set search directories on remote host.
33 set directories ".*\\\$cdir.\\\$cwd"
34} else {
2631b16a
AW
35 set escaped_directory [string_to_regexp "$srcdir/$subdir"]
36 set directories "$escaped_directory.\\\$cdir.\\\$cwd"
10c5f0a8
YQ
37}
38gdb_test "python print (gdb.parameter ('directories'))" $directories
b521dba8
DE
39
40# Test a simple boolean parameter.
41gdb_py_test_multiple "Simple gdb booleanparameter" \
42 "python" "" \
43 "class TestParam (gdb.Parameter):" "" \
44 " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \
ecec24e6
PM
45 " show_doc = \"Show the state of the boolean test-param\"" ""\
46 " set_doc = \"Set the state of the boolean test-param\"" "" \
47 " def get_show_string (self, pvalue):" ""\
48 " return \"The state of the Test Parameter is \" + pvalue" ""\
49 " def get_set_string (self):" ""\
50 " val = \"on\"" ""\
51 " if (self.value == False):" ""\
52 " val = \"off\"" ""\
53 " return \"Test Parameter has been set to \" + val" ""\
b521dba8
DE
54 " def __init__ (self, name):" "" \
55 " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
56 " self.value = True" "" \
57 "test_param = TestParam ('print test-param')" ""\
58 "end"
59
cdc7edd7
LM
60gdb_test "python print (test_param.value)" "True" "test parameter value"
61gdb_test "show print test-param" "The state of the Test Parameter is on.*" "show parameter on"
62gdb_test "set print test-param off" "Test Parameter has been set to off" "turn off parameter"
63gdb_test "show print test-param" "The state of the Test Parameter is off.*" "show parameter off"
64gdb_test "python print (test_param.value)" "False" "test parameter value"
65gdb_test "help show print test-param" "Show the state of the boolean test-param.*" "test show help"
66gdb_test "help set print test-param" "Set the state of the boolean test-param.*" "test set help"
67gdb_test "help set print" "set print test-param -- Set the state of the boolean test-param.*" "test general help"
ecec24e6 68
b521dba8
DE
69
70# Test an enum parameter.
71gdb_py_test_multiple "enum gdb parameter" \
72 "python" "" \
73 "class TestEnumParam (gdb.Parameter):" "" \
74 " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \
75 " show_doc = \"Show the state of the enum\"" ""\
76 " set_doc = \"Set the state of the enum\"" "" \
ecec24e6
PM
77 " def get_show_string (self, pvalue):" ""\
78 " return \"The state of the enum is \" + pvalue" ""\
79 " def get_set_string (self):" ""\
80 " return \"The state of the enum has been set to \" + self.value" ""\
b521dba8
DE
81 " def __init__ (self, name):" "" \
82 " super (TestEnumParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_ENUM, \[\"one\", \"two\"\])" "" \
83 " self.value = \"one\"" "" \
84 "test_enum_param = TestEnumParam ('print test-enum-param')" ""\
85 "end"
86
cdc7edd7
LM
87gdb_test "python print (test_enum_param.value)" "one" "test enum parameter value"
88gdb_test "show print test-enum-param" "The state of the enum is one.*" "show parameter is initial value"
89gdb_test "set print test-enum-param two" "The state of the enum has been set to two" "set enum to two"
90gdb_test "show print test-enum-param" "The state of the enum is two.*" "show parameter is new value"
91gdb_test "python print (test_enum_param.value)" "two" "test enum parameter value"
92gdb_test "set print test-enum-param three" "Undefined item: \"three\".*" "set invalid enum parameter"
b521dba8
DE
93
94# Test a file parameter.
95gdb_py_test_multiple "file gdb parameter" \
96 "python" "" \
97 "class TestFileParam (gdb.Parameter):" "" \
98 " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \
99 " show_doc = \"Show the name of the file\"" ""\
100 " set_doc = \"Set the name of the file\"" "" \
ecec24e6
PM
101 " def get_show_string (self, pvalue):" ""\
102 " return \"The name of the file is \" + pvalue" ""\
103 " def get_set_string (self):" ""\
104 " return \"The name of the file has been changed to \" + self.value" ""\
b521dba8
DE
105 " def __init__ (self, name):" "" \
106 " super (TestFileParam, self).__init__ (name, gdb.COMMAND_FILES, gdb.PARAM_FILENAME)" "" \
107 " self.value = \"foo.txt\"" "" \
108 "test_file_param = TestFileParam ('test-file-param')" ""\
109 "end"
110
cdc7edd7
LM
111gdb_test "python print (test_file_param.value)" "foo.txt" "test file parameter value"
112gdb_test "show test-file-param" "The name of the file is foo.txt.*" "show initial file value"
113gdb_test "set test-file-param bar.txt" "The name of the file has been changed to bar.txt" "set new file parameter" 1
114gdb_test "show test-file-param" "The name of the file is bar.txt.*" "show new file value"
115gdb_test "python print (test_file_param.value)" "bar.txt" "test new file parameter value"
b521dba8
DE
116gdb_test "set test-file-param" "Argument required.*"
117
ecec24e6
PM
118# Test a parameter that is not documented.
119gdb_py_test_multiple "Simple gdb booleanparameter" \
b521dba8 120 "python" "" \
ecec24e6
PM
121 "class TestUndocParam (gdb.Parameter):" "" \
122 " def get_show_string (self, pvalue):" ""\
123 " return \"The state of the Test Parameter is \" + pvalue" ""\
124 " def get_set_string (self):" ""\
125 " val = \"on\"" ""\
126 " if (self.value == False):" ""\
127 " val = \"off\"" ""\
128 " return \"Test Parameter has been set to \" + val" ""\
b521dba8 129 " def __init__ (self, name):" "" \
ecec24e6
PM
130 " super (TestUndocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
131 " self.value = True" "" \
132 "test_undoc_param = TestUndocParam ('print test-undoc-param')" ""\
b521dba8
DE
133 "end"
134
cdc7edd7
LM
135gdb_test "show print test-undoc-param" "The state of the Test Parameter is on.*" "show parameter on"
136gdb_test "set print test-undoc-param off" "Test Parameter has been set to off" "turn off parameter"
137gdb_test "show print test-undoc-param" "The state of the Test Parameter is off.*" "show parameter off"
138gdb_test "python print (test_undoc_param.value)" "False" "test parameter value"
139gdb_test "help show print test-undoc-param" "This command is not documented.*" "test show help"
140gdb_test "help set print test-undoc-param" "This command is not documented.*" "test set help"
141gdb_test "help set print" "set print test-undoc-param -- This command is not documented.*" "test general help"
ecec24e6
PM
142
143# Test a parameter that is not documented in any way..
144gdb_py_test_multiple "Simple gdb booleanparameter" \
145 "python" "" \
146 "class TestNodocParam (gdb.Parameter):" "" \
147 " def __init__ (self, name):" "" \
148 " super (TestNodocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
149 " self.value = True" "" \
150 "test_nodoc_param = TestNodocParam ('print test-nodoc-param')" ""\
151 "end"
152
cdc7edd7 153gdb_test "show print test-nodoc-param" "This command is not documented.*" "show parameter on"
984ee559 154gdb_test_no_output "set print test-nodoc-param off" "turn off parameter"
cdc7edd7
LM
155gdb_test "show print test-nodoc-param" "This command is not documented.*.*" "show parameter off"
156gdb_test "python print (test_nodoc_param.value)" "False" "test parameter value"
157gdb_test "help show print test-nodoc-param" "This command is not documented.*" "test show help"
158gdb_test "help set print test-nodoc-param" "This command is not documented.*" "test set help"
159gdb_test "help set print" "set print test-nodoc-param -- This command is not documented.*" "test general help"
ecec24e6
PM
160
161# Test deprecated API. Do not use in your own implementations.
162gdb_py_test_multiple "Simple gdb booleanparameter" \
163 "python" "" \
164 "class TestParam (gdb.Parameter):" "" \
165 " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \
166 " show_doc = \"State of the Test Parameter\"" ""\
167 " set_doc = \"Set the state of the Test Parameter\"" "" \
168 " def __init__ (self, name):" "" \
169 " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
170 " self.value = True" "" \
171 "test_param = TestParam ('print test-param')" ""\
172 "end"
173
cdc7edd7
LM
174gdb_test "python print (test_param.value)" "True" "test parameter value"
175gdb_test "show print test-param" "State of the Test Parameter on.*" "show parameter on"
984ee559 176gdb_test_no_output "set print test-param off" "turn off parameter"
cdc7edd7
LM
177gdb_test "show print test-param" "State of the Test Parameter off.*" "show parameter off"
178gdb_test "python print (test_param.value)" "False" "test parameter value"
179gdb_test "help show print test-param" "State of the Test Parameter.*" "test show help"
180gdb_test "help set print test-param" "Set the state of the Test Parameter.*" "test set help"
181gdb_test "help set print" "set print test-param -- Set the state of the Test Parameter.*" "test general help"
0489430a
TT
182
183foreach kind {PARAM_ZUINTEGER PARAM_ZUINTEGER_UNLIMITED} {
184 gdb_py_test_multiple "Simple gdb $kind" \
185 "python" "" \
186 "class TestNodocParam (gdb.Parameter):" "" \
187 " def __init__ (self, name):" "" \
188 " super (TestNodocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.$kind)" "" \
189 " self.value = 0" "" \
190 "test_param_$kind = TestNodocParam ('test-$kind')" "" \
191 "end"
192
193 gdb_test "python print(gdb.parameter('test-$kind'))" "0"
194
195 gdb_test "python test_param_$kind.value = -5" "RuntimeError: Range exceeded.*"
196
197 if {$kind == "PARAM_ZUINTEGER"} {
198 gdb_test "python test_param_$kind.value = -1" "RuntimeError: Range exceeded.*"
199 } else {
77d3c63b
TT
200 gdb_test_no_output "python test_param_$kind.value = -1" \
201 "check that PARAM_ZUINTEGER value can be set to -1"
0489430a
TT
202 gdb_test "python print(gdb.parameter('test-$kind'))" "-1" \
203 "check that PARAM_ZUINTEGER value is -1 after setting"
204 }
205}
ae778caf
TT
206
207gdb_py_test_multiple "Throwing gdb parameter" \
208 "python" "" \
209 "class TestThrowParam (gdb.Parameter):" "" \
210 " def __init__ (self, name):" "" \
211 " super (TestThrowParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_STRING)" "" \
212 " self.value = True" "" \
213 " def get_set_string (self):" "" \
214 " raise gdb.GdbError('Ordinary gdb error')" "" \
215 "test_throw_param = TestThrowParam ('print test-throw-param')" ""\
216 "end"
217
218gdb_test "set print test-throw-param whoops" \
219 "Ordinary gdb error" \
220 "gdb.GdbError does not show Python stack"