From patchwork Wed Oct 30 22:44:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 35489 Received: (qmail 75962 invoked by alias); 30 Oct 2019 22:44:40 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 75954 invoked by uid 89); 30 Oct 2019 22:44:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=H*F:D*be X-HELO: mailsec119.isp.belgacom.be Received: from mailsec119.isp.belgacom.be (HELO mailsec119.isp.belgacom.be) (195.238.20.115) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 30 Oct 2019 22:44:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1572475477; x=1604011477; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=sonOWHZwgnnKiYpMk8cqBQaHe1J5oCfpnFW49PiHFEg=; b=QRC2w0x8agz1UXz2HLqXD6yUtbBysOnMJ9Py6W/tqOIiJf5q+VgxZYoA tEmf7qck3uzuSDxXR20FTDv6oqR+dg==; IronPort-SDR: OSAf8yDW9lQ+VryOhvmlBhijgz5sBsuw+8p5qZRAmukJ3y6bscO6OTEG4y0CwwcOGlxWmxg5N4 yx6n3naahBWIx6kUrvbfcTM0g8phC0KdkOIsaiNPU6vG8+0kKzHFrF4QM41bWkgPqxaIK0lB1A Z1kTulaPSUHuLkVjxlutgx2/YIcyDaNw53IpV5nYXUENM0JRmbFggSRnAn2ECK0rm/pkTdhQIV Qj5yaBzuLV4sdMQg5SVMJJ42BLk2kA7kR1lCfQe8M3nMoHLoyknf9kL80oLmgf5ibI4mdd/7KO 1WI= Received: from 117.79-136-217.adsl-dyn.isp.belgacom.be (HELO md.home) ([217.136.79.117]) by relay.skynet.be with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 Oct 2019 23:44:34 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Subject: [RFAv6 0/3] Convenience functions $_gdb_setting/$_gdb_setting_str Date: Wed, 30 Oct 2019 23:44:21 +0100 Message-Id: <20191030224424.9288-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes This is v6. Compared to v5, it does the minor modifications suggested by Pedro and adds the missing doc for $_gdb_maint_setting, $_gdb_maint_setting_str in gdb.texinfo. To make the re-review easier, I have appended the delta between v5 and v6 at the end of this cover note. As part of the discussion of 'show | set may-call-functions [on|off]', Eli suggested to have a way to access the GDB settings from user defined commands. So, this patch series implements this. 4 functions are provided: * $_gdb_setting_str returning a string value of the setting. * $_gdb_setting, returning an integer or string value of a setting, depending on the setting type. For integer/boolean/auto boolean settings, this is easier to use than the string version. * $_gdb_maint_setting, $_gdb_maint_setting_str : same as above, but for maintenance settings. Some notes: In settings.exp show_setting, I have not added a check that RESET_VALUE differs from the expected value: this means to add a specific reset_value to a lot of show_setting calls. As enough different values are verified, this seems not necessary. For what concerns ptype $_gdb_setting("something") always giving type int: This is "normal". For example, "ptype $_as_string(123)" similarly gives int. The reason: ptype evaluates the given expression, but in a way that avoids side effects. This then leads to eval_call in eval.c, that does: ... if (noside == EVAL_AVOID_SIDE_EFFECTS) { ... if (TYPE_CODE (ftype) == TYPE_CODE_INTERNAL_FUNCTION) { /* We don't know anything about what the internal function might return, but we have to return something. */ return value_zero (builtin_type (exp->gdbarch)->builtin_int, not_lval); and so any internal GDB function will always have the "type int". Wondering if it would not be better to report an error such as ("No type information for GDB functions") rather than lie. Delta between v5 and v6: diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index ed699894f5..4e58ddc6d6 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -2253,8 +2253,8 @@ Usage: $_gdb_setting_str (setting)\n\ \n\ auto-boolean values are \"off\", \"on\", \"auto\".\n\ boolean values are \"off\", \"on\".\n\ -The unlimited value for integer, uinteger, zuinteger-unlimited\n\ -settings is represented as \"unlimited\"."), +Some integer settings accept an unlimited value, returned\n\ +as \"unlimited\"."), gdb_setting_str_internal_fn, NULL); add_internal_function ("_gdb_setting", _("\ @@ -2262,8 +2262,8 @@ $_gdb_setting - returns the value of a GDB setting.\n\ Usage: $_gdb_setting (setting)\n\ auto-boolean values are \"off\", \"on\", \"auto\".\n\ boolean values are \"off\", \"on\".\n\ -The unlimited value for integer, uinteger settings is 0.\n\ -The unlimited value for zuinteger-unlimited is -1."), +Some integer settings accept an unlimited value, returned\n\ +as 0 or -1 depending on the setting."), gdb_setting_internal_fn, NULL); add_internal_function ("_gdb_maint_setting_str", _("\ @@ -2272,8 +2272,8 @@ Usage: $_gdb_maint_setting_str (setting)\n\ \n\ auto-boolean values are \"off\", \"on\", \"auto\".\n\ boolean values are \"off\", \"on\".\n\ -The unlimited value for integer, uinteger, zuinteger-unlimited\n\ -settings is represented as \"unlimited\"."), +Some integer settings accept an unlimited value, returned\n\ +as \"unlimited\"."), gdb_maint_setting_str_internal_fn, NULL); add_internal_function ("_gdb_maint_setting", _("\ @@ -2281,8 +2281,8 @@ $_gdb_maint_setting - returns the value of a GDB maintenance setting.\n\ Usage: $_gdb_maint_setting (setting)\n\ auto-boolean values are \"off\", \"on\", \"auto\".\n\ boolean values are \"off\", \"on\".\n\ -The unlimited value for integer, uinteger settings is 0.\n\ -The unlimited value for zuinteger-unlimited is -1."), +Some integer settings accept an unlimited value, returned\n\ +as 0 or -1 depending on the setting."), gdb_maint_setting_internal_fn, NULL); add_cmd ("commands", no_set_class, show_commands, _("\ diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index e3c9a98b68..7cf4141d20 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -12065,6 +12065,17 @@ $8 = -1 Other setting types (enum, filename, optional filename, string, string noescape) are returned as string values. + +@item $_gdb_maint_setting_str (@var{setting}) +@findex $_gdb_maint_setting_str@r{, convenience function} +Like the @code{$_gdb_setting_str} function, but works with +@code{maintenance set} variables. + +@item $_gdb_maint_setting (@var{setting}) +@findex $_gdb_maint_setting@r{, convenience function} +Like the @code{$_gdb_setting} function, but works with +@code{maintenance set} variables. + @end table The following functions require @value{GDBN} to be configured with diff --git a/gdb/testsuite/gdb.base/settings.exp b/gdb/testsuite/gdb.base/settings.exp index 3cb6e63efe..40a30387c3 100644 --- a/gdb/testsuite/gdb.base/settings.exp +++ b/gdb/testsuite/gdb.base/settings.exp @@ -108,6 +108,13 @@ proc check_type {setting expected} { with_test_prefix "check_type $setting $expected" { gdb_test "print \$_gdb_maint_setting(\"$setting\")" gdb_test "ptype $" "$expected" + + # Currently, GDB ptype always tells it is type int. + # ptype should better report an error such as: + # "No type information for GDB functions" + # Test 'type int', so as to make it fail if ptype is changed. + gdb_test "ptype \$_gdb_maint_setting(\"$setting\")" \ + "type = int" } }