diff options
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/doc/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/doc/python.texi | 24 | ||||
-rw-r--r-- | gdb/python/py-param.c | 5 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-parameter.exp | 15 |
6 files changed, 57 insertions, 4 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index cbbd146..e8005c0 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2018-09-23 Tom Tromey <tom@tromey.com> + PR python/18852: + * python/py-param.c (get_set_value): Use gdbpy_handle_exception. + +2018-09-23 Tom Tromey <tom@tromey.com> + * python/py-function.c (fnpy_call): Use gdbpy_handle_exception. * python/py-cmd.c (cmdpy_function): Use gdbpy_handle_exception. * python/python-internal.h (gdbpy_handle_exception): Declare. 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) diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c index 0f0214b..bff5d60 100644 --- a/gdb/python/py-param.c +++ b/gdb/python/py-param.c @@ -396,10 +396,7 @@ get_set_value (const char *args, int from_tty, { set_doc_string = call_doc_function (obj, set_doc_func.get (), NULL); if (! set_doc_string) - { - gdbpy_print_stack (); - return; - } + gdbpy_handle_exception (); } const char *str = set_doc_string.get (); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 4a624dd..877edc0 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2018-09-23 Tom Tromey <tom@tromey.com> + PR python/18852: + * gdb.python/py-parameter.exp: Add test for parameter that throws + on "set". + +2018-09-23 Tom Tromey <tom@tromey.com> + PR python/17284: * gdb.python/py-template.exp (test_template_arg): Add test for negative template argument number. diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp index 0508544..9a36e63 100644 --- a/gdb/testsuite/gdb.python/py-parameter.exp +++ b/gdb/testsuite/gdb.python/py-parameter.exp @@ -203,3 +203,18 @@ foreach kind {PARAM_ZUINTEGER PARAM_ZUINTEGER_UNLIMITED} { "check that PARAM_ZUINTEGER value is -1 after setting" } } + +gdb_py_test_multiple "Throwing gdb parameter" \ + "python" "" \ + "class TestThrowParam (gdb.Parameter):" "" \ + " def __init__ (self, name):" "" \ + " super (TestThrowParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_STRING)" "" \ + " self.value = True" "" \ + " def get_set_string (self):" "" \ + " raise gdb.GdbError('Ordinary gdb error')" "" \ + "test_throw_param = TestThrowParam ('print test-throw-param')" ""\ + "end" + +gdb_test "set print test-throw-param whoops" \ + "Ordinary gdb error" \ + "gdb.GdbError does not show Python stack" |