From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YVCUONOmnmqp6jMAWB0awg (envelope-from ) for ; Mon, 07 Sep 2026 07:58:11 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=KlhVOOk+; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id DFA281E09E; Mon, 07 Sep 2026 07:58:11 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 49C631E091 for ; Mon, 07 Sep 2026 07:58:10 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D9B7D4CCCA2A for ; Mon, 7 Sep 2026 11:58:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D9B7D4CCCA2A Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=KlhVOOk+ Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) by sourceware.org (Postfix) with ESMTPS id 060234BB3B8D for ; Mon, 7 Sep 2026 11:55:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 060234BB3B8D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 060234BB3B8D Authentication-Results: sourceware.org; arc=none smtp.remote-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788782154; cv=none; b=Vq0RtiCQYyKwwKsGfFK5lIgZ1+x0igdyRLPVI3r694WvxY3yuyMT+WNRGTfmdmK0t+KmnzzX+5xQQ8J7b93GkZhCyicazLyF8cZGtvmf/NO+EIHGTqNbOpjlRRlczdFRjVoFiYjKtTWIg5yfcaa6RfyMvGn5zPCW6Q95jWxvk5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788782154; c=relaxed/simple; bh=vqXt0VR63cOEeprgveFDEFSUiuXte+zZjNm8XZXFnmw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=q+coBTxg5VhadttXgHpayPJVzuAVJoKEIQCCFWopLbUKEqmUYSItdsODLulOVaZQAmXnbVrV9RKRomOe8kLcIoBlugPdzQvoBdc98Xa5qzLB2lxXQW4215affK1YMn1d/wQRkJ+DWkXfngoy4j447QIT08W+Mp/CvG8Y4y75RFM= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=KlhVOOk+ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 060234BB3B8D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1788782154; x=1820318154; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vqXt0VR63cOEeprgveFDEFSUiuXte+zZjNm8XZXFnmw=; b=KlhVOOk+VldT39cQ8C4Sdf//LcR8w1JICkcGCM0DhxHlMK8oqOeKzYDE GExtr+JjhBUInpZT71tKB7q2FBjVrTIrXCLawMHnIfbSGCnhTTzB6t8ER wayJCxuncLNm6WCRQ55yjepJpESesW2UVxSHZqY5hMYyIx7e/U5oecvt+ D/LqqqypD9pbdWaQM3SuNuyEV3Bj4bVTmV0XriARYrar7rVjOJCCF7frW iUvQZtmk/1ZRq0j0CWtsqnSbN2naxrb1gjTGi/wPrLVjT+pgnuU0x2O+4 fIas+chC/0WiYzpdw/v+rQbubYs9BMQxRu9tmZKNsaLBExgPw3a09RUbo A==; X-CSE-ConnectionGUID: 38GVGV64RsGmZJxKyJBwPw== X-CSE-MsgGUID: ekR0B6dsT2KFb3XBxkTphg== X-IronPort-AV: E=McAfee;i="6800,10657,11898"; a="99517519" X-IronPort-AV: E=Sophos;i="6.25,267,1779174000"; d="scan'208";a="99517519" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2026 04:55:53 -0700 X-CSE-ConnectionGUID: QhvAiFfGTx6fiZFFI4IbpA== X-CSE-MsgGUID: 7YkFKPwbQg+1AsH2ggnuYQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,267,1779174000"; d="scan'208";a="264496076" Received: from dut1583dg2frd.igk.intel.com (HELO localhost) ([10.211.179.243]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2026 04:55:51 -0700 From: Klaus Gerlicher To: gdb-patches@sourceware.org Cc: tom@tromey.com, aburgess@redhat.com, eliz@gnu.org, guinevere@redhat.com Subject: [PATCH v9 3/6] gdb, cli: pass the argument of a set command to its callback. Date: Mon, 7 Sep 2026 11:55:34 +0000 Message-Id: <20260907115537.307049-4-klaus.gerlicher@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260907115537.307049-1-klaus.gerlicher@intel.com> References: <20260907115537.307049-1-klaus.gerlicher@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Natalia Saiapova Passing the original argument to the callback is useful when a command needs to distinguish being invoked with no argument from being invoked with a specific value. I am going to use it in gdb: refine commands to control scheduler locking. to keep the old behaviour of the set scheduler-locking step which should set both set scheduler-locking step on set scheduler-locking replay step on To do this, the set-command needs to detect that it was issued without arguments and have a special handling for this. Without the special handling, the command set scheduler-locking step would set only set scheduler-locking step on --- gdb/cli/cli-setshow.c | 4 +- gdb/maint-test-settings.c | 33 +++++--- gdb/testsuite/gdb.base/settings.exp | 113 +++++++++++++++++++++------- gdb/testsuite/gdb.base/with.exp | 3 +- 4 files changed, 110 insertions(+), 43 deletions(-) diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c index 7688da015de..1e0954a560d 100644 --- a/gdb/cli/cli-setshow.c +++ b/gdb/cli/cli-setshow.c @@ -335,6 +335,8 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c) if (arg == NULL) arg = ""; + const char *org_arg = arg; + gdb_assert (c->var.has_value ()); switch (c->var->type ()) @@ -455,7 +457,7 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c) error (_("gdb internal error: bad var_type in do_setshow_command")); } - c->func (NULL, from_tty, c); + c->func (org_arg, from_tty, c); if (notify_command_param_changed_p (option_changed, c)) { diff --git a/gdb/maint-test-settings.c b/gdb/maint-test-settings.c index f2e8a68a10f..6995f8b7bfb 100644 --- a/gdb/maint-test-settings.c +++ b/gdb/maint-test-settings.c @@ -67,6 +67,15 @@ static const char *const maintenance_test_settings_enums[] = { static const char *maintenance_test_settings_enum = maintenance_test_settings_xxx; +/* The "maintenance set test-settings xxx" commands. */ + +static void +maintenance_set_test_settings_cmd (const char *args, int from_tty, + cmd_list_element *c) +{ + gdb_printf ("set-callback: arg='%s'\n", args == nullptr ? "" : args); +} + /* The "maintenance show test-settings xxx" commands. */ static void @@ -96,7 +105,7 @@ Show GDB internal variables used for set/show command infrastructure testing."), command used for internal testing."), _("\ command used for internal testing."), nullptr, /* help_doc */ - nullptr, /* set_cmd */ + maintenance_set_test_settings_cmd, maintenance_show_test_settings_value_cmd, &maintenance_set_test_settings_list, &maintenance_show_test_settings_list); @@ -106,7 +115,7 @@ command used for internal testing."), command used for internal testing."), _("\ command used for internal testing."), nullptr, /* help_doc */ - nullptr, /* set_cmd */ + maintenance_set_test_settings_cmd, maintenance_show_test_settings_value_cmd, &maintenance_set_test_settings_list, &maintenance_show_test_settings_list); @@ -116,7 +125,7 @@ command used for internal testing."), command used for internal testing."), _("\ command used for internal testing."), nullptr, /* help_doc */ - nullptr, /* set_cmd */ + maintenance_set_test_settings_cmd, maintenance_show_test_settings_value_cmd, &maintenance_set_test_settings_list, &maintenance_show_test_settings_list); @@ -126,7 +135,7 @@ command used for internal testing."), command used for internal testing."), _("\ command used for internal testing."), nullptr, /* help_doc */ - nullptr, /* set_cmd */ + maintenance_set_test_settings_cmd, maintenance_show_test_settings_value_cmd, &maintenance_set_test_settings_list, &maintenance_show_test_settings_list); @@ -136,7 +145,7 @@ command used for internal testing."), command used for internal testing."), _("\ command used for internal testing."), nullptr, /* help_doc */ - nullptr, /* set_cmd */ + maintenance_set_test_settings_cmd, maintenance_show_test_settings_value_cmd, &maintenance_set_test_settings_list, &maintenance_show_test_settings_list); @@ -147,7 +156,7 @@ command used for internal testing."), command used for internal testing."), _("\ command used for internal testing."), nullptr, /* help_doc */ - nullptr, /* set_cmd */ + maintenance_set_test_settings_cmd, maintenance_show_test_settings_value_cmd, &maintenance_set_test_settings_list, &maintenance_show_test_settings_list); @@ -158,7 +167,7 @@ command used for internal testing."), command used for internal testing."), _("\ command used for internal testing."), nullptr, /* help_doc */ - nullptr, /* set_cmd */ + maintenance_set_test_settings_cmd, maintenance_show_test_settings_value_cmd, &maintenance_set_test_settings_list, &maintenance_show_test_settings_list); @@ -168,7 +177,7 @@ command used for internal testing."), command used for internal testing."), _("\ command used for internal testing."), nullptr, /* help_doc */ - nullptr, /* set_cmd */ + maintenance_set_test_settings_cmd, maintenance_show_test_settings_value_cmd, &maintenance_set_test_settings_list, &maintenance_show_test_settings_list); @@ -178,7 +187,7 @@ command used for internal testing."), command used for internal testing."), _("\ command used for internal testing."), nullptr, /* help_doc */ - nullptr, /* set_cmd */ + maintenance_set_test_settings_cmd, maintenance_show_test_settings_value_cmd, &maintenance_set_test_settings_list, &maintenance_show_test_settings_list); @@ -188,7 +197,7 @@ command used for internal testing."), command used for internal testing."), _("\ command used for internal testing."), nullptr, /* help_doc */ - nullptr, /* set_cmd */ + maintenance_set_test_settings_cmd, maintenance_show_test_settings_value_cmd, &maintenance_set_test_settings_list, &maintenance_show_test_settings_list); @@ -199,7 +208,7 @@ command used for internal testing."), command used for internal testing."), _("\ command used for internal testing."), nullptr, /* help_doc */ - nullptr, /* set_cmd */ + maintenance_set_test_settings_cmd, maintenance_show_test_settings_value_cmd, &maintenance_set_test_settings_list, &maintenance_show_test_settings_list); @@ -210,7 +219,7 @@ command used for internal testing."), command used for internal testing."), _("\ command used for internal testing."), nullptr, /* help_doc */ - nullptr, /* set_cmd */ + maintenance_set_test_settings_cmd, maintenance_show_test_settings_value_cmd, &maintenance_set_test_settings_list, &maintenance_show_test_settings_list); diff --git a/gdb/testsuite/gdb.base/settings.exp b/gdb/testsuite/gdb.base/settings.exp index 2da8d47405b..54408bb64f4 100644 --- a/gdb/testsuite/gdb.base/settings.exp +++ b/gdb/testsuite/gdb.base/settings.exp @@ -34,6 +34,14 @@ if { ![readline_is_used] } { return } +# Run a "maint set test-settings ..." command and expect the callback output. +proc set_setting {cmd {test_name ""}} { + if {$test_name eq ""} { + set test_name $cmd + } + gdb_test $cmd "set-callback: arg='.*'" $test_name +} + # Test the show command SHOW_CMD. EXPECTED_RE is the expected output. # Also verifies that $_gdb_maint_setting_str produces an equivalent output, # matching it with EXPECTED_RE. EXPECTED_RE double quotes are escaped @@ -52,6 +60,7 @@ if { ![readline_is_used] } { # This procedure makes it easier to make the test # name/message unique, since we test the "show" commands many times. # EXPECTED_RE is made part of the test name. + proc show_setting {show_cmd expected_re {expected_re_escaped 0} {reset_value 0}} { global gdb_prompt @@ -78,8 +87,8 @@ proc show_setting {show_cmd expected_re {expected_re_escaped 0} {reset_value 0}} # Change the setting value to RESET_VALUE, set it back to setting_str_value # and check we still have the original value. - gdb_test_no_output "maintenance set $maint_setting $reset_value" "str reset $reset_value" - gdb_test_no_output "maintenance set $maint_setting $setting_str_value" "str set again" + set_setting "maintenance set $maint_setting $reset_value" "str reset $reset_value" + set_setting "maintenance set $maint_setting $setting_str_value" "str set again" gdb_test "$show_cmd" $expected_re "str show after reset+set again" # Same test, but with value captured from $_gdb_maint_setting. @@ -97,8 +106,8 @@ proc show_setting {show_cmd expected_re {expected_re_escaped 0} {reset_value 0}} } } - gdb_test_no_output "maintenance set $maint_setting $reset_value" "reset $reset_value" - gdb_test_no_output "maintenance set $maint_setting $setting_value" "set again" + set_setting "maintenance set $maint_setting $reset_value" "reset $reset_value" + set_setting "maintenance set $maint_setting $setting_value" "set again" gdb_test "$show_cmd" $expected_re "show after reset+set again" } } @@ -152,20 +161,20 @@ proc test-integer {variant} { check_type "test-settings $variant" "type = unsigned int" } else { # Negative values are not accepted. - gdb_test_no_output "$set_cmd -1" + set_setting "$set_cmd -1" show_setting "$show_cmd" "-1" - gdb_test_no_output "$set_cmd -2" + set_setting "$set_cmd -2" show_setting "$show_cmd" "-2" check_type "test-settings $variant" "type = int" } # Regular integer is accepted. - gdb_test_no_output "$set_cmd 999" + set_setting "$set_cmd 999" show_setting "$show_cmd" "999" if {$variant == "zinteger" || $variant == "zuinteger"} { # 0 means 0. - gdb_test_no_output "$set_cmd 0" + set_setting "$set_cmd 0" show_setting "$show_cmd" "0" } else { # Either 0 or -1 mean unlimited. Test both the number and @@ -173,9 +182,9 @@ proc test-integer {variant} { # abbreviations. if {$variant == "zuinteger-unlimited"} { - gdb_test_no_output "$set_cmd -1" + set_setting "$set_cmd -1" } else { - gdb_test_no_output "$set_cmd 0" + set_setting "$set_cmd 0" } show_setting "$show_cmd" "unlimited" @@ -192,10 +201,10 @@ proc test-integer {variant} { } { # Alternate between integer and unlimited, to make sure the # setting really took effect. - gdb_test_no_output "$set_cmd 1" + set_setting "$set_cmd 1" show_setting "$show_cmd" "1" - gdb_test_no_output "$set_cmd $value" + set_setting "$set_cmd $value" show_setting "$show_cmd" "unlimited" } } @@ -312,10 +321,10 @@ proc_with_prefix test-boolean {} { "enabl" "enable" } { - gdb_test_no_output "$set_cmd off" + set_setting "$set_cmd off" show_setting "$show_cmd" "off" - gdb_test_no_output "$set_cmd $value" + set_setting "$set_cmd $value" show_setting "$show_cmd" "on" } @@ -335,10 +344,10 @@ proc_with_prefix test-boolean {} { "disabl" "disable" } { - gdb_test_no_output "$set_cmd on" + set_setting "$set_cmd on" show_setting "$show_cmd" "on" - gdb_test_no_output "$set_cmd $value" + set_setting "$set_cmd $value" show_setting "$show_cmd" "off" } @@ -399,10 +408,10 @@ proc_with_prefix test-auto-boolean {} { "enabl" "enable" } { - gdb_test_no_output "$set_cmd off" + set_setting "$set_cmd off" show_setting "$show_cmd" "off" - gdb_test_no_output "$set_cmd $value" + set_setting "$set_cmd $value" show_setting "$show_cmd" "on" } @@ -420,10 +429,10 @@ proc_with_prefix test-auto-boolean {} { "disabl" "disable" } { - gdb_test_no_output "$set_cmd on" + set_setting "$set_cmd on" show_setting "$show_cmd" "on" - gdb_test_no_output "$set_cmd $value" + set_setting "$set_cmd $value" show_setting "$show_cmd" "off" } @@ -434,10 +443,10 @@ proc_with_prefix test-auto-boolean {} { "auto" "-1" } { - gdb_test_no_output "$set_cmd on" + set_setting "$set_cmd on" show_setting "$show_cmd" "on" - gdb_test_no_output "$set_cmd $value" + set_setting "$set_cmd $value" show_setting "$show_cmd" "auto" } @@ -497,11 +506,11 @@ proc_with_prefix test-enum {} { # Various valid values. Test both full value names and # abbreviations. - gdb_test_no_output "$set_cmd x" + set_setting "$set_cmd x" show_setting "$show_cmd" "xxx" 0 "zzz" - gdb_test_no_output "$set_cmd yy" + set_setting "$set_cmd yy" show_setting "$show_cmd" "yyy" 0 "zzz" - gdb_test_no_output "$set_cmd zzz" + set_setting "$set_cmd zzz" show_setting "$show_cmd" "zzz" 0 "yyy" check_type "test-settings enum" "type = char \\\[4\\\]" @@ -548,17 +557,17 @@ proc test-string {variant} { } # A string value. - gdb_test_no_output "$set_cmd hello world" + set_setting "$set_cmd hello world" show_setting "$show_cmd" "hello world" check_type "test-settings $variant" "type = char \\\[$::positive\\\]" # A quoted string value. if {$variant == "string"} { - gdb_test_no_output "$set_cmd \"hello world\"" + set_setting "$set_cmd \"hello world\"" show_setting "$show_cmd" "\\\\\"hello world\\\\\"" 1 } else { - gdb_test_no_output "$set_cmd \"hello world\"" + set_setting "$set_cmd \"hello world\"" show_setting "$show_cmd" "\"hello world\"" } @@ -571,7 +580,7 @@ proc test-string {variant} { # Check the value didn't change. show_setting "$show_cmd" "\"hello world\"" } else { - gdb_test_no_output "$set_cmd" + set_setting "$set_cmd" # This odd expected output here is because we expect GDB to # emit a single blank line as a result of this command. gdb_test -nonl "$show_cmd" "^\r\n" "$show_cmd: empty second time" @@ -666,3 +675,49 @@ foreach variant { } test-setting-error + +# Verify that the set-command callback receives the original argument +# string, including for integer settings where parse_cli_var_integer +# advances the internal pointer. +proc_with_prefix test-set-callback {} { + # Integer types: the original arg string must reach the callback + # unchanged even though parse_cli_var_integer moves the pointer. + foreach_with_prefix variant { + uinteger integer zinteger zuinteger zuinteger-unlimited + } { + set set_cmd "maint set test-settings $variant" + + gdb_test "$set_cmd 999" \ + "set-callback: arg='999'" \ + "integer arg passed through" + + if {$variant == "uinteger" || $variant == "integer" + || $variant == "zuinteger-unlimited"} { + gdb_test "$set_cmd unlimited" \ + "set-callback: arg='unlimited'" \ + "unlimited arg passed through" + } + } + + # Boolean: empty arg (no argument given) must arrive as "". + gdb_test "maint set test-settings boolean" \ + "set-callback: arg=''" \ + "boolean no-arg callback" + + # Boolean: explicit value. + gdb_test "maint set test-settings boolean on" \ + "set-callback: arg='on'" \ + "boolean on arg passed through" + + # Enum: arg must be the full original token. + gdb_test "maint set test-settings enum yyy" \ + "set-callback: arg='yyy'" \ + "enum arg passed through" + + # String: arg must be the literal string typed. + gdb_test "maint set test-settings string hello" \ + "set-callback: arg='hello'" \ + "string arg passed through" +} + +test-set-callback diff --git a/gdb/testsuite/gdb.base/with.exp b/gdb/testsuite/gdb.base/with.exp index 101c6dcccf9..aa44a23c8c0 100644 --- a/gdb/testsuite/gdb.base/with.exp +++ b/gdb/testsuite/gdb.base/with.exp @@ -35,11 +35,12 @@ clean_restart $testfile # level, but maps to -1 internally. proc test_with {setting values} { + set cb "set-callback: arg='.*'" foreach val1 $values { foreach val2 $values { gdb_test \ "maint with test-settings $setting $val1 -- maint with test-settings $setting $val2 -- p 1" \ - " = 1" + "${cb}\r\n${cb}\r\n\\$\[0-9\]+ = 1\r\n${cb}\r\n${cb}" } } } -- 2.34.1 ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.