From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix Tcl quoting in gdb_assert
Date: Thu, 16 Feb 2023 11:06:32 -0500 [thread overview]
Message-ID: <bc1a81ef-cb63-eeac-8147-15561254a183@simark.ca> (raw)
In-Reply-To: <20230215215828.1337884-1-tromey@adacore.com>
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
next prev parent reply other threads:[~2023-02-16 16:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-15 21:58 Tom Tromey
2023-02-16 16:06 ` Simon Marchi [this message]
2023-02-16 18:12 ` Tom Tromey
2023-02-23 18:11 ` Tom Tromey
2023-02-23 19:16 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bc1a81ef-cb63-eeac-8147-15561254a183@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=tromey@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).