Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Pedro Alves <palves@redhat.com>
Cc: Pedro Franco de Carvalho <pedromfc@linux.ibm.com>,
	       Joel Brobecker <brobecker@adacore.com>,
	gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix testsuite hangs when gdb_test_multiple body errors out (Re: GDB 8.2.90 available for testing)
Date: Fri, 22 Mar 2019 14:42:00 -0000	[thread overview]
Message-ID: <fc6a46bd19e2a6040b3870500b644836@polymtl.ca> (raw)
In-Reply-To: <4d855905-32ce-ba4b-72f5-037f1796b37e@redhat.com>

On 2019-03-22 08:39, Pedro Alves wrote:
> Hi Pedro,
> 
> Thanks for the detailed report.
> 
> On 03/07/2019 05:42 PM, Pedro Franco de Carvalho wrote:
> 
>> I'm not sure if there is a proper way to work around this in GDB, but 
>> it
>> would be useful so that the testsuite doesn't hang in these cases.
> 
> I spent a while trying to fix this, and I came up with the patch below.
> 
> WDYT?
> 
> From 17e8f28072cce040524eab7b85b8767764a54cd2 Mon Sep 17 00:00:00 2001
> From: Pedro Alves <palves@redhat.com>
> Date: Fri, 22 Mar 2019 11:33:19 +0000
> Subject: [PATCH] Fix testsuite hangs when gdb_test_multiple body errors 
> out
> 
> This commit fixes a regression in the testsuite itself, triggered by
> errors being raised from within gdb_test_multiple, originally reported
> by Pedro Franco de Carvalho's at
> <https://sourceware.org/ml/gdb-patches/2019-03/msg00160.html>.  Parts
> of the commit message are based on his report.
> 
> This started happening due to a commit that was introduced recently,
> and it can cause the testsuite to hang.
> 
> The commit that triggers this is:
> 
>  fe1a5cad302b5535030cdf62895e79512713d738
>  [gdb/testsuite] Log wait status on process no longer exists error
> 
> That commit introduces a new "eof" block in gdb_test_multiple.  That
> is not incorrect itself, but dejagnu's remote_expect is picking that
> block as the "default" action when an error is raised from within the
> commands inside a call to gdb_test_multiple:
> 
>   # remote_expect works basically the same as standard expect, but it
>   # also takes care of getting the file descriptor from the specified
>   # host and also calling the timeout/eof/default section if there is 
> an
>   # error on the expect call.
>   #
>   proc remote_expect { board timeout args } {
> 
> I find that "feature" surprising, and I don't really know why it
> exists, but this means that the eof section that remote_expect picks
> as the error block can be executed even when there was no actual eof
> and the GDB process is still running, so the wait introduced in the
> commit that tries to get the exit status of GDB hangs forever, while
> GDB itself waits for input.
> 
> This only happens when there are internal testsuite errors (not
> testcase failures).  This can be reproduced easily with a testcase
> such as:
> 
>   gdb_start
>   gdb_test_multiple "show version" "show version" {
>     -re ".*" {
>        error "forced error"
>     }
>   }
> 
> I think that working around this in GDB is useful so that the
> testsuite doesn't hang in these cases.
> 
> Adding an empty "default" block at the end of the expect body in
> gdb_test_multiple doesn't work, because dejagnu gives preference to
> "eof" blocks:
> 
> 	    if { $x eq "eof" } {
> 		set save_next 1
> 	    } elseif { $x eq "default" || $x eq "timeout" } {
> 		if { $error_sect eq "" } {
> 		    set save_next 1
> 		}
> 	    }
> 
> And we do have "eof" blocks.  So we need to make sure that the last
> "eof" block is safe to use as the default error block.  It's also
> pedantically incorrect to print
> 
>  "ERROR: Process no longer exists"
> 
> which is what we'd get if the last eof block we have was selected
> (more below on this).
> 
> So this commit solves this by appending an "eof" with an empty
> spawn_id list, so that it won't ever match.
> 
> Now, why is the first "eof" block selected today as the error block,
> instead of the last one?
> 
> The reason is that remote_expect, while parsing the body to select the
> default block to execute after an error, is affected by the comments
> in the body (since they are also parsed).
> 
> If this comment in gdb_test_multiple
> 
>  # patterns below apply to any spawn id specified.
> 
> is changed to
> 
>  # The patterns below apply to any spawn id specified.
> 
> then the second eof block is selected and there is no hang.
> 
> Any comment at that same place with an even-numbered of tokens also
> works.
> 
> This is IMO a coincidence caused by how comments work in TCL.
> Comments should only appear in places where a command can appear.  And
> here, remote_expect is parsing a list of options, not commands, so
> it's not unreasonable to not parse comments, similarly to how this:
> 
>   set a_list {
>      an_element
>      # another_element
>   }
> 
> results in a list with three elements, not one element.
> 
> The fact that comments with an even number of tokens work is just a
> coincidence of how remote_expect's little state machine is
> implemented.
> 
> I thought we could solve this by stripping out comment lines in
> gdb_expect, but I didn't find an easy way to do that.  Particularly, a
> couple naive approaches I tried run into complications.  For example,
> we have gdb_test calls with regular expressions that include sequences
> like "\r\n#", and by the time we get to gdb_expect, the \r\n have
> already been expanded to a real newline, so just splitting the whole
> body at newline boundaries, looking for lines that start with #
> results in incorrectly stripping out half of the gdb_text regexp.  I
> think it's better (at least in this commit), to move the comments out
> of the list, because it's much simpler and risk free.

Wow, this is top-notch TCL/expect/DejaGnu investigation skills.

I agree with just moving the comments out, since that's the correct 
thing to do.  Trying to strip them programmatically just adds some dark 
magic that can potentially introduce more weird behaviors.

But we need to remember this when writing tests, should we have an entry 
in the testcase wiki page?

https://sourceware.org/gdb/wiki/GDBTestcaseCookbook

Simon


  parent reply	other threads:[~2019-03-22 14:42 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-27  5:51 GDB 8.2.90 available for testing Joel Brobecker
2019-02-27 22:05 ` Jim Wilson
2019-03-04 11:15   ` Andrew Burgess
2019-03-04 13:57     ` Alan Hayward
2019-03-04 20:00     ` Jim Wilson
2019-02-28 18:31 ` MinGW build of GDB 8.2.90 (was: GDB 8.2.90 available for testing) Eli Zaretskii
2019-02-28 18:55   ` MinGW build of GDB 8.2.90 Sergio Durigan Junior
2019-02-28 19:06     ` LRN
2019-02-28 19:45     ` Eli Zaretskii
2019-02-28 20:17       ` Sergio Durigan Junior
2019-02-28 20:29         ` Eli Zaretskii
2019-02-28 20:37           ` Sergio Durigan Junior
2019-02-28 18:34 ` GDB 8.2.90 available for testing Eli Zaretskii
2019-03-01 16:35   ` Pedro Alves
2019-03-01 18:50     ` Tom Tromey
2019-03-07 22:44     ` Tom Tromey
2019-03-08  7:46       ` Eli Zaretskii
2019-03-08 20:57         ` Tom Tromey
2019-03-09  6:13           ` Eli Zaretskii
2019-03-14 17:32             ` Tom Tromey
2019-03-14 19:49               ` Eli Zaretskii
2019-03-15 12:55                 ` Tom Tromey
2019-03-17 15:56               ` Eli Zaretskii
2019-03-17 17:31                 ` Tom Tromey
2019-03-17 18:36                   ` Eli Zaretskii
2019-03-18 14:13                     ` Tom Tromey
2019-03-18 18:08                       ` Eli Zaretskii
2019-03-07 17:42 ` Pedro Franco de Carvalho
     [not found]   ` <4d855905-32ce-ba4b-72f5-037f1796b37e@redhat.com>
2019-03-22 14:42     ` Simon Marchi [this message]
2019-03-25 13:23       ` [PATCH] Fix testsuite hangs when gdb_test_multiple body errors out (Re: GDB 8.2.90 available for testing) Pedro Alves
2019-03-22 20:44     ` Pedro Franco de Carvalho
2019-03-25 13:21       ` Pedro Alves
2019-03-25 19:43         ` Pedro Franco de Carvalho
2019-03-26 18:58           ` Pedro Alves
2019-03-26 21:01             ` Pedro Franco de Carvalho
2019-03-28 17:36               ` Joel Brobecker

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=fc6a46bd19e2a6040b3870500b644836@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    --cc=pedromfc@linux.ibm.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