Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Tom de Vries <tdevries@suse.de>, gdb-patches@sourceware.org
Subject: Re: [PATCH][gdb/testsuite] Detect gdb prompt after monitor exit
Date: Wed, 16 Sep 2020 11:59:34 +0100	[thread overview]
Message-ID: <98ef5ad6-3a12-7dc9-1561-b46758f39c8f@palves.net> (raw)
In-Reply-To: <2bdf800f-1f54-871c-0769-e833873cc099@suse.de>

On 9/15/20 3:17 PM, Tom de Vries wrote:

> Anyway, this seems to work:
> ...
> index a2cc80f28d..24733275ae 100644
> --- a/gdb/testsuite/lib/gdbserver-support.exp
> +++ b/gdb/testsuite/lib/gdbserver-support.exp
> @@ -451,13 +451,20 @@ proc gdbserver_exit { is_mi } {
>             # We use expect rather than gdb_expect because
>             # we want to suppress printing exception messages, otherwise,
>             # remote_expect, invoked by gdb_expect, prints the exceptions.
> +           set have_prompt 0
>             expect {
>                 -i "$gdb_spawn_id" -re "$gdb_prompt $" {
> -                   exp_continue
> +                   if { [info exists server_spawn_id] } {
> +                       set have_prompt 1

I'd put this "set have_prompt 1" outside of the if, seems would read
clearer to me.

Otherwise LGTM.

> +                       exp_continue
> +                   }
>                 }
>                 -i "$server_spawn_id" eof {
>                     wait -i $expect_out(spawn_id)
>                     unset server_spawn_id
> +                   if { ! $have_prompt } {
> +                       exp_continue
> +                   }
>                 }
>                 timeout {
>                     warning "Timed out waiting for EOF in server after
> $monitor_exit"
> ...
> 
> I do wonder though about unsetting server_spawn_id and doing
> exp_continue while we still have the clause -i $server_spawn_id eof.  I
> wonder this is supported behaviour.

I'm not super sure, but I think it is, in that I don't think
the -i expression is reevaluated after exp_continue.

For example, this works:

$ cat exp.exp 
set fake_spawn_id foo

expect {
    -re "foo" {
        puts " got foo"
        if [info exists fake_spawn_id] {
            puts " unset"
            unset fake_spawn_id
        }
        exp_continue
    }
    -i "$fake_spawn_id" -re "bar" {
            puts " got bar?"
    }
}

$ expect exp.exp 
foo
 got foo
 unset
foo
 got foo
foo
 got foo
bar
foo
 got foo

If it turns out to be an issue, we can always use an indirect
spawn id instead:

  "The -i flag may also name a global variable in which case the variable is read for a list of spawn ids. The variable is reread   
   whenever it changes. This provides a way of changing the I/O source while the command is in execution. Spawn ids provided this way 
   are called "indirect" spawn ids. "

Pedro Alves


  reply	other threads:[~2020-09-16 10:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-14 19:21 Tom de Vries
2020-09-15 13:05 ` Pedro Alves
2020-09-15 14:17   ` Tom de Vries
2020-09-16 10:59     ` Pedro Alves [this message]
2020-09-16 12:55       ` Tom de Vries

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=98ef5ad6-3a12-7dc9-1561-b46758f39c8f@palves.net \
    --to=pedro@palves.net \
    --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