From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29683 invoked by alias); 15 Sep 2018 07:25:21 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 29489 invoked by uid 89); 15 Sep 2018 07:25:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway30.websitewelcome.com Received: from gateway30.websitewelcome.com (HELO gateway30.websitewelcome.com) (192.185.194.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 15 Sep 2018 07:25:06 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 257F3A13E for ; Sat, 15 Sep 2018 02:25:05 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 14wzgjSxjRPoj14wzg6QB6; Sat, 15 Sep 2018 02:25:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=M4CgXLG30fvFmwvQiYSUO7hKyzxfDCoPK7UZRl0ZZEE=; b=vV8CQAaKiZZuA5NxsR3bZYBFcw QaSzjY3LXilI6y1G+LqGGewbyEYEAxDSuUL3cUUCnsfL9PYul2bzNcS2odmzrK70m9l1b+vAt9Uiw 30ZSiZbTt321gzVlA2V2j9mLb; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:41846 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1g14wy-00253W-TM; Sat, 15 Sep 2018 02:25:05 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 7/7] Allow setting a parameter to raise gdb.GdbError Date: Sat, 15 Sep 2018 07:25:00 -0000 Message-Id: <20180915072459.14934-8-tom@tromey.com> In-Reply-To: <20180915072459.14934-1-tom@tromey.com> References: <20180915072459.14934-1-tom@tromey.com> X-SW-Source: 2018-09/txt/msg00484.txt.bz2 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. gdb/ChangeLog 2018-09-15 Tom Tromey PR python/18852: * python/py-param.c (get_set_value): Use gdbpy_handle_exception. gdb/doc/ChangeLog 2018-09-15 Tom Tromey PR python/18852: * python.texi (Parameters In Python): Document exception behavior of get_set_string. gdb/testsuite/ChangeLog 2018-09-15 Tom Tromey PR python/18852: * gdb.python/py-parameter.exp: Add test for parameter that throws on "set". --- gdb/ChangeLog | 5 +++++ gdb/doc/ChangeLog | 6 ++++++ gdb/doc/python.texi | 24 +++++++++++++++++++++++ gdb/python/py-param.c | 5 +---- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.python/py-parameter.exp | 15 ++++++++++++++ 6 files changed, 57 insertions(+), 4 deletions(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index aca6ec858cf..0487a6f3bf3 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3824,6 +3824,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 @code{gdb.GdbError} (@pxref{Exception +Handling}), then gdb 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 0f0214befe0..bff5d60fc26 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/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp index 0508544f9d9..9a36e6372de 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" -- 2.17.1