From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id EDC7F3858C60 for ; Thu, 16 Feb 2023 16:06:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EDC7F3858C60 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [172.16.0.192] (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 2FE3D1E110; Thu, 16 Feb 2023 11:06:33 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1676563593; bh=ODC5gsBmNpEYT4rjraqbXjekxMHnWoAXT7IHw6gLvfU=; h=Date:Subject:To:References:From:In-Reply-To:From; b=v5afHee10Ds/u5FQZiVYu25telXJPin/ZpBimSomyBHF/PV//JZ9eSoDQHinfm9LA 2AWyQ8QC/BBwiFK8GJTVWCtpUPH81VT3BbiobtoeALP8qZ5R9PI9NKXJuOL0pQ7x+B jj3RGVghbMgo1ZldMZfxLQJTcXQZK9eE/BNdqKBU= Message-ID: Date: Thu, 16 Feb 2023 11:06:32 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: Re: [PATCH] Fix Tcl quoting in gdb_assert To: Tom Tromey , gdb-patches@sourceware.org References: <20230215215828.1337884-1-tromey@adacore.com> Content-Language: fr From: Simon Marchi In-Reply-To: <20230215215828.1337884-1-tromey@adacore.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP 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: On 2/15/23 16:58, Tom Tromey via Gdb-patches wrote: > The gdb_assert proc under-quotes the expression that is passed in. > This leads to weird code in a couple of spots that tries to > compensate: > > gdb_assert {{$all_regs eq $completed_regs}} ... > > The fix is to add a bit of quoting when evaluating the expression. > --- > gdb/testsuite/gdb.base/completion.exp | 2 +- > gdb/testsuite/gdb.base/step-over-no-symbols.exp | 6 +++--- > gdb/testsuite/lib/gdb.exp | 2 +- > 3 files changed, 5 insertions(+), 5 deletions(-) > > diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp > index 1533acbf4f9..4686e6f8f34 100644 > --- a/gdb/testsuite/gdb.base/completion.exp > +++ b/gdb/testsuite/gdb.base/completion.exp > @@ -159,7 +159,7 @@ foreach {-> reg} [regexp -all -inline -line {^info registers (\w+\S*)} $regs_out > lappend completed_regs $reg > } > set completed_regs [join [lsort $completed_regs]] > -gdb_assert {{$all_regs eq $completed_regs}} "complete 'info registers '" > +gdb_assert {$all_regs eq $completed_regs} "complete 'info registers '" > > # Tests below are about tab-completion, which doesn't work if readline > # library isn't used. Check it first. > diff --git a/gdb/testsuite/gdb.base/step-over-no-symbols.exp b/gdb/testsuite/gdb.base/step-over-no-symbols.exp > index 00b32deacf7..1136b47571b 100644 > --- a/gdb/testsuite/gdb.base/step-over-no-symbols.exp > +++ b/gdb/testsuite/gdb.base/step-over-no-symbols.exp > @@ -76,9 +76,9 @@ proc test_step_over { displaced } { > > set after_addr [get_pc "get after PC"] > > - gdb_assert {{[regexp "^${hex}$" $before_addr] \ > - && [regexp "^${hex}$" $after_addr] \ > - && $before_addr != $after_addr}} "advanced" > + gdb_assert {[regexp "^${hex}$" $before_addr] \ > + && [regexp "^${hex}$" $after_addr] \ > + && $before_addr != $after_addr} "advanced" > } > > foreach displaced { "off" "on" "auto" } { > diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp > index e48228ed4f6..ecd6ca0a8ef 100644 > --- a/gdb/testsuite/lib/gdb.exp > +++ b/gdb/testsuite/lib/gdb.exp > @@ -1947,7 +1947,7 @@ proc gdb_assert { condition {message ""} } { > set message $condition > } > > - set code [catch {uplevel 1 expr $condition} res] > + set code [catch {uplevel 1 [list expr $condition]} res] I don't understand why this would be needed. The doc of uplevel says: All of the arg arguments are concatenated as if they had been passed to concat So uplevel should end up executing "expr $condition" just fine, it should concatenate "expr" with $condition and evaluate that. But I see that when I remove your fix, gdb.base/completion.exp gives: WARNING: While evaluating expression in gdb_assert: invalid bareword "ah" in expression "ah al all ax bh bl bp bp..."; should be "$ah" or "{ah}" or "ah(...)" or ... If I add a `puts "expr $condition"` in gdb_assert, I see it passes this to uplevel: expr $all_regs eq $completed_regs When trying the same kind of thing with tclsh, I see the same message: $ rlwrap tclsh % set a allo allo % set b bonjour bonjour % expr $a eq $b invalid bareword "allo" in expression "allo eq bonjour"; should be "$allo" or "{allo}" or "allo(...)" or ... What happens above is that $a and $b are expanded before expr is called, expr receives "allo" and "bonjour" literally, and it doesn't like that (I don't know why). It seems like expr wants to receive '$a' and '$b' and to the expansion itself: % expr {$a eq $b} 0 So, I'm not saying your fix is wrong, I am just saying I don't understand the situation. Simon