From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 19B623858C42 for ; Tue, 19 Dec 2023 13:23:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 19B623858C42 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 19B623858C42 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702992215; cv=none; b=P9QC1j0ScUeK+W6O+1ChNkXtLsRFZZxG/DZxHfYlqyaLJ5V7rphuKHUuajRxX5ulekgH3k2i41gYFCBiQT9ILvTcqVnL7fU0G68i/XL9g6nzV0T0Yt1YekzAEnBpRv2SM516uquUk1gItSJqBCDAKh6yw65sr7/mMFTRxQPukPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702992215; c=relaxed/simple; bh=ryVjUi+CAPAJkdLhYcyee4epP4Eyzkosh947Xw4k9vU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=A2rFrGhNl9inudxob+JkOcp72qhDmEiJUT1AoNj2uEAHJbOXeKWbtwhVaRZ7L33bxs9PjYRSm0t5drkupRbt+frB41bhYS1FSoPSVq0LYDo1cmttBQTThhravhycpa7QdLxS4WgJIEEcXvEr+FISjwS6M1JKalHY5V6fsS1/7dI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702992213; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5a6w+Z1/DVLOSfjldMx4RfsvMxoNZn2tw41kzf5Das8=; b=Ob8tpxyZRnMRTJBeWeOE7VdS2IaRo54Jh/k7msZiaIp5VnBEHwXAILieqgg3/GaR287q6R h9nQjvLHtJrAD7qDIj8kCNjlY1IEvbdZ6eahwoc8JSiC0UCzLI+f8W6fRcKCymdqIbvWBt nkgb79009gOGozuz6Bmv/e8APDumMTk= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-216-jV79oR3mPFeMFbjsjYtnyg-1; Tue, 19 Dec 2023 08:23:32 -0500 X-MC-Unique: jV79oR3mPFeMFbjsjYtnyg-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-40c3826d6feso30289605e9.0 for ; Tue, 19 Dec 2023 05:23:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702992211; x=1703597011; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5a6w+Z1/DVLOSfjldMx4RfsvMxoNZn2tw41kzf5Das8=; b=v9L0BgDlDeyL+kIOa9NOeul7uellDRetT8n5MRk1mqtkdioGDehew6DxQo95NR1nZo a7eWez9/5zPbHfH35bR/NoUNYcT5jCnO8IynyJenC+8JlDPFHu+z4TiGCybbAwXtYfKK CFKcqT1AzREZdP7V8GrWJWjfkAjqlcQzuKYXdsGZSvAesQ1lWuczvoLGEVfk3i+AsQsw joWKhqiRN9hfTmmWUxtV2R6GlnVbw5IaKw2W52M9umA2y+DJVj7YlMMOtqGrKNIdSMEX BoEvA/55dpV4lMpl7WuWeKoiw9t25E4q2sdvswh3Gtkvt/DJPhJtHbNEspnxqEyh200c lxTw== X-Gm-Message-State: AOJu0Yw08CpDkV0cDJ1HFD5E/dJqSvL9o0TI/R9SEAyuWTur9CgTZrzU QuFuwZlaaM9+j5BF9vo+dsAm62dMjSGkHK9Ton1qZAtGfrV3T2ovFgEi0zu5ly5PzkT62YX0fHM kQF318rl+leJ5QM1XwcYMcQ== X-Received: by 2002:a05:6000:1d84:b0:336:1fc0:82f0 with SMTP id bk4-20020a0560001d8400b003361fc082f0mr10229628wrb.108.1702992211121; Tue, 19 Dec 2023 05:23:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZqL/EJQMOFd3l4Ej92/O3GYfD9VIXAA8cBI0Dl+Yeqll6/Tzb/aWszJLV1b7BVMai8pX+TA== X-Received: by 2002:a05:6000:1d84:b0:336:1fc0:82f0 with SMTP id bk4-20020a0560001d8400b003361fc082f0mr10229620wrb.108.1702992210701; Tue, 19 Dec 2023 05:23:30 -0800 (PST) Received: from localhost (105.226.159.143.dyn.plus.net. [143.159.226.105]) by smtp.gmail.com with ESMTPSA id r16-20020a5d4e50000000b0033660fe128fsm8102776wrt.43.2023.12.19.05.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 05:23:30 -0800 (PST) From: Andrew Burgess To: Hannes Domani , gdb-patches@sourceware.org Subject: Re: [PATCH] Throw error if ambiguous name is used in gdb.parameter In-Reply-To: <20231216125600.3592-1-ssbssa@yahoo.de> References: <20231216125600.3592-1-ssbssa.ref@yahoo.de> <20231216125600.3592-1-ssbssa@yahoo.de> Date: Tue, 19 Dec 2023 13:23:29 +0000 Message-ID: <87le9qz5pq.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Thanks for addressing this. Hannes Domani writes: > Currently gdb.parameter doesn't throw an error if an ambiguous In the subject line and again here you talk about thowing an error. I think the correct Python terminology would be raising an exception. > name is used, it instead returns the value of the last partly > matching parameter: > ``` > (gdb) show print sym > Ambiguous show print command "sym": symbol, symbol-filename, symbol-loading. > (gdb) show print symbol-loading > Printing of symbol loading messages is "full". > (gdb) py print(gdb.parameter("print sym")) > full > ``` > > It's because lookup_cmd_composition_1 tries to detect > ambigous names by checking the return value of find_cmd > for CMD_LIST_AMBIGUOUS, which never happens, since only > lookup_cmd_1 returns CMD_LIST_AMBIGUOUS. > Instead the nfound argument contains the number of found > matches. > > By using it instead, it's working/failing as expected: > ``` > (gdb) py print(gdb.parameter("print sym")) > Traceback (most recent call last): > File "", line 1, in > RuntimeError: Could not find parameter `print sym'. > Error while executing Python code. It might be nice if this error could indicate that the named parameter was ambiguous rather than not found. Similar to how on the command line when I do this: (gdb) set print sym Ambiguous set print command "sym": symbol, symbol-filename, symbol-loading. But I looked at how this might be done, and it looks like it would need some larger restructuring, so I don't think that should prevent your patch going in. > (gdb) py print(gdb.parameter("print symbol")) > True > (gdb) py print(gdb.parameter("print symbol-")) > Traceback (most recent call last): > File "", line 1, in > RuntimeError: Could not find parameter `print symbol-'. > Error while executing Python code. > (gdb) py print(gdb.parameter("print symbol-load")) > full > ``` > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=14639 > --- > gdb/cli/cli-decode.c | 2 +- > gdb/testsuite/gdb.python/py-parameter.exp | 32 +++++++++++++++++++++++ > 2 files changed, 33 insertions(+), 1 deletion(-) > > diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c > index 940cd6a2c8e..12aa152d0c4 100644 > --- a/gdb/cli/cli-decode.c > +++ b/gdb/cli/cli-decode.c > @@ -2589,7 +2589,7 @@ lookup_cmd_composition_1 (const char *text, > *cmd = find_cmd (command.c_str (), len, cur_list, 1, &nfound); > > /* We only handle the case where a single command was found. */ > - if (*cmd == CMD_LIST_AMBIGUOUS || *cmd == nullptr) > + if (nfound > 1 || *cmd == nullptr) I wonder if `find_cmd` should return nullptr if `nfound != 1`? It doesn't seem like returning what is basically a random setting is ever going to be useful... But I think it's optional if you want to make that change. I'm happy with this as it is: Approved-By: Andrew Burgess Thanks, Andrew > return 0; > else > { > diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp > index c1f8a80c6b7..df1b93028ad 100644 > --- a/gdb/testsuite/gdb.python/py-parameter.exp > +++ b/gdb/testsuite/gdb.python/py-parameter.exp > @@ -588,6 +588,37 @@ proc_with_prefix test_language {} { > gdb_test_no_output "set lang auto" > } > > +proc_with_prefix test_ambiguous_parameter {} { > + gdb_test_multiline "create parameter" \ > + "python" "" \ > + "class TestAmbiguousParam (gdb.Parameter):" "" \ > + " def __init__ (self, name, value):" "" \ > + " super (TestAmbiguousParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_INTEGER)" "" \ > + " self.value = value" "" \ > + "end" > + > + # Create parameters. > + gdb_test "python TestAmbiguousParam('test-ambiguous-value-1', 1)" "" > + gdb_test "python TestAmbiguousParam('test-ambiguous-value-2-extra', 2)" "" > + gdb_test "python TestAmbiguousParam('test-ambiguous', 3)" "" > + > + # Test unambiguous matches. > + gdb_test "python print(gdb.parameter('test-ambiguous-value-1'))" "1" > + gdb_test "python print(gdb.parameter('test-ambiguous-value-2-extra'))" "2" > + gdb_test "python print(gdb.parameter('test-ambiguous-value-2'))" "2" > + gdb_test "python print(gdb.parameter('test-ambiguous'))" "3" > + > + # Test ambiguous names. > + gdb_test "python print(gdb.parameter('test-ambiguou'))" \ > + "Could not find parameter.*Error while executing Python code." > + gdb_test "python print(gdb.parameter('test-ambiguous-'))" \ > + "Could not find parameter.*Error while executing Python code." > + gdb_test "python print(gdb.parameter('test-ambiguous-v'))" \ > + "Could not find parameter.*Error while executing Python code." > + gdb_test "python print(gdb.parameter('test-ambiguous-value-1a'))" \ > + "Could not find parameter.*Error while executing Python code." > +} > + > test_directories > test_data_directory > test_boolean_parameter > @@ -600,5 +631,6 @@ test_gdb_parameter > test_integer_parameter > test_throwing_parameter > test_language > +test_ambiguous_parameter > > rename py_param_test_maybe_no_output "" > -- > 2.35.1