aboutsummaryrefslogtreecommitdiff
path: root/gdb/doc
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-09-15 01:09:22 -0600
committerTom Tromey <tom@tromey.com>2018-09-23 23:15:12 -0600
commitae778caf097e08497f2e9218cf68b254b8da38f1 (patch)
tree4d9491413ed523cd72c541def36f1bafba954dca /gdb/doc
parent2b4ad2fe4300489fd40dbe07e1675ff1cf0bee58 (diff)
downloadbinutils-ae778caf097e08497f2e9218cf68b254b8da38f1.zip
binutils-ae778caf097e08497f2e9218cf68b254b8da38f1.tar.gz
binutils-ae778caf097e08497f2e9218cf68b254b8da38f1.tar.bz2
Allow setting a parameter to raise gdb.GdbError
A convention in the Python layer is that raising a gdb.GdbError will not print the Python stack -- instead the exception is treated as any other gdb exception. PR python/18852 asks that this treatment be extended the the get_set_value method of gdb.Parameter. This makes sense, because it lets Python-created parameters act like gdb parameters. 2018-09-23 Tom Tromey <tom@tromey.com> PR python/18852: * python/py-param.c (get_set_value): Use gdbpy_handle_exception. gdb/doc/ChangeLog 2018-09-23 Tom Tromey <tom@tromey.com> PR python/18852: * python.texi (Parameters In Python): Document exception behavior of get_set_string. gdb/testsuite/ChangeLog 2018-09-23 Tom Tromey <tom@tromey.com> PR python/18852: * gdb.python/py-parameter.exp: Add test for parameter that throws on "set".
Diffstat (limited to 'gdb/doc')
-rw-r--r--gdb/doc/ChangeLog6
-rw-r--r--gdb/doc/python.texi24
2 files changed, 30 insertions, 0 deletions
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 6d12553..4285a4d 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,9 @@
+2018-09-23 Tom Tromey <tom@tromey.com>
+
+ PR python/18852:
+ * python.texi (Parameters In Python): Document exception behavior
+ of get_set_string.
+
2018-09-18 John Baldwin <jhb@FreeBSD.org>
* gdb.texinfo (info proc): Remove "running".
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index e98178a..1035be3 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -3828,6 +3828,30 @@ example, @kbd{set foo off}). The @code{value} attribute has already
been populated with the new value and may be used in output. This
method must return a string. If the returned string is not empty,
@value{GDBN} will present it to the user.
+
+If this method raises the @code{gdb.GdbError} exception
+(@pxref{Exception Handling}), then @value{GDBN} will print the
+exception's string and the @code{set} command will fail. Note,
+however, that the @code{value} attribute will not be reset in this
+case. So, if your parameter must validate values, it should store the
+old value internally and reset the exposed value, like so:
+
+@smallexample
+class ExampleParam (gdb.Parameter):
+ def __init__ (self, name):
+ super (ExampleParam, self).__init__ (name,
+ gdb.COMMAND_DATA,
+ gdb.PARAM_BOOLEAN)
+ self.value = True
+ self.saved_value = True
+ def validate(self):
+ return False
+ def get_set_string (self):
+ if not self.validate():
+ self.value = self.saved_value
+ raise gdb.GdbError('Failed to validate')
+ self.saved_value = self.value
+@end smallexample
@end defun
@defun Parameter.get_show_string (self, svalue)