From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sonic312-26.consmr.mail.ir2.yahoo.com (sonic312-26.consmr.mail.ir2.yahoo.com [77.238.178.97]) by sourceware.org (Postfix) with ESMTPS id 1E1D738582A2 for ; Mon, 29 Jan 2024 16:04:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E1D738582A2 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=yahoo.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=yahoo.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1E1D738582A2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=77.238.178.97 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706544257; cv=none; b=GnJFOwymq87/tciwM/KlUpMMD5l3CLeXy7dvoytwip5UOsZq6wXyzlV5XKHRAKI28p3A9+lINDxhYAyQ/2q2/aLMIskKwhCOUy8grPvp66PgXawSa+oiQ5PAZsaA5Ew0XdBF/w8U3YQ9vLcR9B9oCCrBGkBXpwEbR61XwtvKqUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706544257; c=relaxed/simple; bh=LPyqg2sGFUU+MTIPv8dQmNBzNQR6oWjDfFQV7oFXcoQ=; h=DKIM-Signature:Date:From:To:Message-ID:Subject:MIME-Version; b=a14MFVhXPSvujG51QZAcZ5hfFQNBSPhCDub+zmLPxIXWXewVtr4Z/pQy7cgGMuqseUoTvekJXmAbzXWoQxDtKiojxM7V3BNB6ehN1TkrNgW/3XbVyZrXyQp0PkB7nNVHo9TVgozXmADMdn4xMNkfUU4dJY2ruRvTbEZobyRHrjk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s2048; t=1706544248; bh=LPyqg2sGFUU+MTIPv8dQmNBzNQR6oWjDfFQV7oFXcoQ=; h=Date:From:To:In-Reply-To:References:Subject:From:Subject:Reply-To; b=kIYnJcT7uTTdZU9x7Gf0K/XAkfzPgZehIyCsPacKIWn9frgmzHqHFFbXCi0H4S4jU3xqL+SJFwd5RifXFfUkrXEtt0NDjBa3+IQhiULG9WJSC8EYElF7RwAPbmaqyCUAP0CG1XrlkOb3jfnTYmJSQ8ageXoCGIRuBLaRTbP2T+sUfrzFl74T84G3GhsfM6ljq528waJdRrzOLaIfO6uE35LQx+7pRvJiUm5dzR0i5oj0kU6zIj5JEPofrEXasvEoidl2HeXfwc3hvv0jdvL5VOVqcDYvsFNeG94TlNQTxhb9kyskBV6Upi4/cAytUgm8twtH3CTyGx6ZK4/X8t2VJA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1706544248; bh=B9aTu4GejQ5qlziKW9Q38SgFcUJDLpmfIdFjgdgKBRK=; h=X-Sonic-MF:Date:From:To:Subject:From:Subject; b=F2BeI4tQL+YSc8TosVG79rW0Mb5yZwR/Fsgao0X1oyOJiwAM7UfPeDq8ZU041P7RaVMp0kBMAx2mCw45umOZKoauP8ilIBTX9M/hVvCfcT70VvNwtUQOjlYUFrZFkiz0l6sr/erOryaNSQpLh1Rap2xDkkL2yuwEup2UmPUtnGp8jtolkNAkcHShlgrwPvQKeSDG+URcxQ76+ht4h4joSPF2Ch7reMNLaFNTA1L3y57jJOF8ZowqPza0vFU6wCDbyrZS985qqAVpJsZX/kqjurTCkl4WIi4AlRLPJbDMaYHBOuEOjsr/tNS5DJYJFAiqfU/lTj8ApdaLxaN6RXvT1Q== X-YMail-OSG: uV3WDpIVM1n0MHgxmFhefW42Ldk_dlD_9mSGzPWA1F68_sCxRW.OxM06UiBUOuZ fa8uBbffBUe_doe3ISRXR5r59aF0DFucCZl5NtaL..HLBUx1wOg3NZgulTkHww2wTlQXnzK9nNrV ngXB9vWM9fsmM5lYBobUumLY3x1aPRBZc2lBHgJFpPZ.auncJs5Yupro5VgwMQs28hYYJ0QdK20A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bc33e258 Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.ir2.yahoo.com with HTTP; Mon, 29 Jan 2024 16:04:08 +0000 Date: Mon, 29 Jan 2024 16:04:06 +0000 (UTC) From: Hannes Domani To: "gdb-patches@sourceware.org" , Andrew Burgess Message-ID: <351596538.3681084.1706544246480@mail.yahoo.com> In-Reply-To: <87sf2gxoob.fsf@redhat.com> References: <20231219163851.2748-1-ssbssa.ref@yahoo.de> <20231219163851.2748-1-ssbssa@yahoo.de> <87sf2gxoob.fsf@redhat.com> Subject: Re: [PATCH v2] Raise exception if ambiguous name is used in gdb.parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Mailer: WebService/1.1.22046 YMailNorrin X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,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: Am Montag, 29. Januar 2024 um 14:19:23 MEZ hat Andrew Burgess Folgendes geschrieben: > Hannes Domani writes: > > > Currently gdb.parameter doesn't raise an exception if an > > ambiguous 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-loa= ding. > > (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, and by setting *CMD to the special value > > CMD_LIST_AMBIGUOUS in this case, gdbpy_parameter can now show > > the appropriate error message: > > ``` > > (gdb) py print(gdb.parameter("print sym")) > > Traceback (most recent call last): > >=C2=A0 File "", line 1, in > > RuntimeError: Parameter `print sym' is ambiguous. > > Error while executing Python code. > > (gdb) py print(gdb.parameter("print symbol")) > > True > > (gdb) py print(gdb.parameter("print symbol-")) > > Traceback (most recent call last): > >=C2=A0 File "", line 1, in > > RuntimeError: Parameter `print symbol-' is ambiguous. > > Error while executing Python code. > > (gdb) py print(gdb.parameter("print symbol-load")) > > full > > ``` > > > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D14639 > > --- > > v2: > > - Small changes in commit message. > > - Use CMD_LIST_AMBIGUOUS in lookup_cmd_composition_1 to mark > >=C2=A0 ambiguous commands, so gdbpy_parameter can show a better > >=C2=A0 error message. > > --- > >=C2=A0 gdb/cli/cli-decode.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 | 13 ++++++--- > >=C2=A0 gdb/python/python.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 |=C2=A0 5 +++- > >=C2=A0 gdb/testsuite/gdb.python/py-parameter.exp | 32 ++++++++++++++++++= +++++ > >=C2=A0 3 files changed, 46 insertions(+), 4 deletions(-) > > > > diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c > > index 940cd6a2c8e..db57764578d 100644 > > --- a/gdb/cli/cli-decode.c > > +++ b/gdb/cli/cli-decode.c > > @@ -2549,7 +2549,8 @@ deprecated_cmd_warning (const char *text, struct = cmd_list_element *list) > >=C2=A0=C2=A0=C2=A0 If TEXT is a subcommand (i.e. one that is preceded by= a prefix > >=C2=A0=C2=A0=C2=A0 command) set *PREFIX_CMD. > > > > -=C2=A0 Set *CMD to point to the command TEXT indicates. > > +=C2=A0 Set *CMD to point to the command TEXT indicates, or to > > +=C2=A0 CMD_LIST_AMBIGUOUS if there are multiple possible matches. > > > >=C2=A0=C2=A0=C2=A0 If any of *ALIAS, *PREFIX_CMD, or *CMD cannot be dete= rmined or do not > >=C2=A0=C2=A0=C2=A0 exist, they are NULL when we return. > > @@ -2589,7 +2590,12 @@ lookup_cmd_composition_1 (const char *text, > >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *cmd =3D find_cmd (command.c_= str (), len, cur_list, 1, &nfound); > > > >=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* We only handle the case wh= ere a single command was found.=C2=A0 */ > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (*cmd =3D=3D CMD_LIST_AMBIGUOUS || *= cmd =3D=3D nullptr) > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (nfound > 1) > > +=C2=A0=C2=A0=C2=A0 { > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *cmd =3D CMD_LIST_AMBIGUOUS; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return 0; > > This changes the API of lookup_cmd_composition.=C2=A0 You need to audit a= ll > the calls to this function to check that non are depending on CMD being > set to nullptr.=C2=A0 I only looked at one in cli/cli-script.c in the > function do_document_command that is a problem, try this: > >=C2=A0=C2=A0 (gdb) define foo_1 >=C2=A0=C2=A0 Type commands for definition of "foo_1". >=C2=A0=C2=A0 End with a line saying just "end". >=C2=A0=C2=A0 >echo aa\n >=C2=A0=C2=A0 >end >=C2=A0=C2=A0 (gdb) define foo_2 >=C2=A0=C2=A0 Type commands for definition of "foo_2". >=C2=A0=C2=A0 End with a line saying just "end". >=C2=A0=C2=A0 >echo bb\n >=C2=A0=C2=A0 >end >=C2=A0=C2=A0 (gdb) document foo > =C2=A0 > =C2=A0 >=C2=A0=C2=A0 Fatal signal: Segmentation fault >=C2=A0=C2=A0 ... etc ... > > Not every use of lookup_cmd_composition is a problem, e.g. in > alias_command in cli/cli-cmds.c it's not an issue, so you'll need to > check 'em all. > > If you do find cases that would have triggered bugs with this change, it > would be awesome if you could add tests to cover these cases, though I > guess that's not a hard requirement. Thanks for catching this. I've now checked all uses of lookup_cmd_composition, and could not find another problem (either it bailed because of lookup_cmd_composition return value, or the returned *cmd was not used at all afterwards). So I've fixed do_document_command, and added a test for this, in the v3: https://sourceware.org/pipermail/gdb-patches/2024-January/206257.html Hannes