Handle void * conversions in FreeBSD/x86 native code to fix C++ build.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-parameter.exp
CommitLineData
618f726f 1# Copyright (C) 2010-2016 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
9325cb04 60gdb_test "python print (test_param.value)" "True" "Test parameter value"
ecec24e6
PM
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"
9325cb04 64gdb_test "python print (test_param.value)" "False" "Test parameter value"
ecec24e6
PM
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"
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
9325cb04 87gdb_test "python print (test_enum_param.value)" "one" "Test enum parameter value"
ecec24e6
PM
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"
9325cb04 91gdb_test "python print (test_enum_param.value)" "two" "Test enum parameter value"
b521dba8
DE
92gdb_test "set print test-enum-param three" "Undefined item: \"three\".*" "Set invalid enum parameter"
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
9325cb04 111gdb_test "python print (test_file_param.value)" "foo.txt" "Test file parameter value"
ecec24e6
PM
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"
9325cb04 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
ecec24e6
PM
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"
9325cb04 138gdb_test "python print (test_undoc_param.value)" "False" "Test parameter value"
ecec24e6
PM
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"
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
153gdb_test "show print test-nodoc-param" "This command is not documented.*" "Show parameter on"
154gdb_test "set print test-nodoc-param off" "This command is not documented.*" "Turn off parameter"
155gdb_test "show print test-nodoc-param" "This command is not documented.*.*" "Show parameter off"
9325cb04 156gdb_test "python print (test_nodoc_param.value)" "False" "Test parameter value"
ecec24e6
PM
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"
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
9325cb04 174gdb_test "python print (test_param.value)" "True" "Test parameter value"
ecec24e6
PM
175gdb_test "show print test-param" "State of the Test Parameter on.*" "Show parameter on"
176gdb_test "set print test-param off" "Set the state of the Test Parameter.*" "Turn off parameter"
177gdb_test "show print test-param" "State of the Test Parameter off.*" "Show parameter off"
9325cb04 178gdb_test "python print (test_param.value)" "False" "Test parameter value"
ecec24e6
PM
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"
This page took 0.618197 seconds and 4 git commands to generate.