public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Tom de Vries <tdevries@suse.de>, gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb/testsuite: get_set_option_choices: expect \r\n after each item
Date: Tue, 15 Nov 2022 09:59:22 -0500	[thread overview]
Message-ID: <33cbb0f0-72b2-7202-db84-2e3def9b126c@polymtl.ca> (raw)
In-Reply-To: <3c8249a8-4cc3-8fcb-05fa-bb70a2f55209@suse.de>

On 11/15/22 02:01, Tom de Vries wrote:
> On 11/14/22 16:14, Simon Marchi via Gdb-patches wrote:
>> I get some random failures since commit 8d45c3a82a0e ("[gdb/testsuite]
>> Set completions to unlimited in get_set_option_choices"), which can be
>> reproduced with:
>>
>>      $ make check-read1 TESTS="gdb.base/parse_number.exp"
>>
> 
> Hi,
> 
> sorry, that's my fault.  I can reproduce this.
> 
>> For instance:
>>
>>      set architecture A^M
>>      Ambiguous item "A".^M
>>      (gdb) FAIL: gdb.base/parse_number.exp: arch=A: set architecture A
>>
>> The problem is the regexp in get_set_option_choices, it can match only
>> part of a completion result.  With check-read1, that is alwasy one
>> letter.  Fix this by expecting the \r\n at the end of the line, so we
>> only match entire results.
>>
> 
> Now, with --enable-targets=all I have 364 architectures:
> ...
> $ gdb -q -batch -ex "set max-completions unlimited" -ex "complete set architecture " 2>&1 | grep -v -c "set architecture"
> 0
> $ gdb -q -batch -ex "set max-completions unlimited" -ex "complete set architecture " 2>&1 | grep -c "set architecture"
> 364
> ...
> 
> And using this:
> ...
> @@ -9156,6 +9156,7 @@ proc get_set_option_choices {set_cmd} {
>         }
>      }
> 
> +    verbose -log "Found [llength $values] choices for $set_cmd"
>      return $values
>  }
> 
> ...
> we can see how many choices get_set_option_choices finds.
> 
> Without this patch I get:
> ...
> (gdb) Found 364 choices for set architecture
> ...
> but with the patch:
> ...
> (gdb) Found 182 choices for set architecture
> ...
> 
> The problem is that by consuming \r\n both at the start and the end of the line, we drop about half of the choices.

Ah, noob mistake, thanks for catching, it would have been bad.

> 
> I usually solve this by using positive lookahead:
> ...
> -           -re "\r\n$set_cmd (\[^\r\n\]+)\r\n" {
> +           -re "\r\n$set_cmd (\[^\r\n\]+)(?=\r\n)" {

I had to look up what ?= does (positive lookahead), but that looks good
to me.

> ...
> This fixes the number of choices for me, and still passes with check-read1.
> 
> Note that in the original patch I did:
> ...
> -       -re "$set_cmd (\[^\r\n\]+)\r\n" {
> +       -re "\r\n$set_cmd (\[^\r\n\]+)" {
> ...
> in order to be able to use -wrap (which requires a leading \r\n) instead of gdb_prompt. I remember typing that up in the commit message, but it seems to have gone missing.

Since this let me make a mistake, I'm thinking that we could be a bit
more paranoid in the match patterns, ensuring that we match at the
beginning of the expect buffer, and that no output is left behind.
Something like:


     with_set max-completions unlimited {
         gdb_test_multiple $cmd $test {
             -re "^[string_to_regexp $cmd]" {
                 exp_continue
             }

             -re "^\r\n$set_cmd (\[^\r\n\]+)(?=\r\n)" {
                 lappend values $expect_out(1,string)
                 exp_continue
             }

             -re "^\r\n$::gdb_prompt $" {
                 pass $gdb_test_name
             }
         }
     }

Simon

  reply	other threads:[~2022-11-15 14:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-14 15:14 Simon Marchi
2022-11-15  7:01 ` Tom de Vries
2022-11-15 14:59   ` Simon Marchi [this message]
2022-11-15 15:05     ` Tom de Vries
2022-11-15 15:49       ` 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=33cbb0f0-72b2-7202-db84-2e3def9b126c@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tdevries@suse.de \
    /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).