From: Bruno Larsen <blarsen@redhat.com>
To: Thiago Jung Bauermann <thiago.bauermann@linaro.org>,
gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>, Tom de Vries <tdevries@suse.de>
Subject: Re: [PATCH v2] gdb/testsuite: Avoid infinite loop in gdb.reverse/step-reverse.exp
Date: Mon, 5 Jun 2023 10:00:18 +0200 [thread overview]
Message-ID: <45ff5e98-9e03-79fa-d73c-746b0f2d980e@redhat.com> (raw)
In-Reply-To: <20230601214239.209822-1-thiago.bauermann@linaro.org>
On 01/06/2023 23:42, Thiago Jung Bauermann wrote:
> This testcase sometimes gets stuck in a loop for hours when running in our
> CI. The problem is that due to an issue unrelated to reverse debugging the
> inferior exits early, and because of the overly generic ".*" pattern the
> testcase keeps sending the "next" command without noticing that the
> inferior is gone.
>
> gdb_test_multiple has a pattern to detect that "The program is not being
> run.", but since it is placed after the patterns from the caller it won't
> be triggered. It also has a timeout pattern but because it is triggered
> between successful matches, each time the test matches the '-re -wrap ".*"'
> this counts as a successful match and the timeout is reset.
>
> Since the test binary is compiled with debug information, fix by changing
> one of the generic patterns to match entering the main function and the
> other one to match the source code line number that is shown by GDB right
> after the "step" command.
>
> Also, as a precaution add a maximum number of times the "next" command will
> be sent.
>
> Co-Authored-By: Tom de Vries <tdevries@suse.de>
> ---
>
> Changes since v1:
> - Added maximum number of iterations (code provided by Tom).
> - Changed one of the patterns to match the main function (suggested by Bruno).
> - Clarified why the timeout pattern isn't effective (explanation from Andrew).
>
> Tom,
>
> Most of the patch now is the iteration-counting code. Since I copied it
> from your email, I thought it made sense to record you as co-author.
> I hope it's ok.
>
> gdb/testsuite/gdb.reverse/step-reverse.exp | 25 ++++++++++++++++++++--
> 1 file changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/gdb/testsuite/gdb.reverse/step-reverse.exp b/gdb/testsuite/gdb.reverse/step-reverse.exp
> index 729218d4cb8c..c70d2fcb5166 100644
> --- a/gdb/testsuite/gdb.reverse/step-reverse.exp
> +++ b/gdb/testsuite/gdb.reverse/step-reverse.exp
> @@ -247,6 +247,7 @@ gdb_test_multiple "step" "$test_message" {
> gdb_test "next" ".*NEXT OVER THIS CALL.*" "reverse next over call"
>
> set step_out 0
> +set max_iterations 1000
> gdb_test_multiple "next" "reverse next over recursion" {
> -re -wrap ".*NEXT OVER THIS RECURSION.*" {
> pass "$gdb_test_name"
> @@ -257,11 +258,18 @@ gdb_test_multiple "next" "reverse next over recursion" {
> }
> }
> if { "$step_out" == 1 } {
> + set iterations 0
> gdb_test_multiple "next" "stepping out of recursion" {
> -re -wrap "NEXT OVER THIS RECURSION.*" {
> set step_out 0
> }
> - -re -wrap ".*" {
> + -re -wrap "^main .*" {
> + incr iterations
> + if { $iterations == $max_iterations } {
> + fail "$gdb_test_name (reached $max_iterations iterations)"
> + return
> + }
> +
I'm fine with the idea of a maximum iteration count (even if I find it
unnecessary), but your use of it here is incorrect. What your code is
doing is doing is _only_ exiting once you see GDB returning to the main
function $max_iterations times.
if { "$step_out" == 1 } {
gdb_test_multiple "next" "stepping out of recursion" {
-re -wrap "NEXT OVER THIS RECURSION.*" {
set step_out 0
+ pass "$gdb_test_name"
}
- -re -wrap ".*" {
+ -re -wrap "^main.*" {
+ pass "$gdb_test_name"
+ }
+ -re -wrap "^\[0-9\].*" {
+ incr iterations
+ if { $iterations == $max_iterations } {
+ fail "$gdb_test_name (reached $max_iterations iterations)"
+ return
+ }
send_gdb "next\n"
exp_continue
}
}
}
And I wonder if we'd like to add a pass if step_out was never set to 1,
so we don't get fewer passes when everything works? Not sure, I'd defer
to Andrew or Tom on this one.
--
Cheers,
Bruno
> send_gdb "next\n"
> exp_continue
> }
> @@ -276,9 +284,16 @@ gdb_test_no_output "set exec-dir reverse" "reverse again to test recursion"
>
> gdb_test "step" ".*EXIT RECURSIVE FUNCTION.*" "enter recursive function"
> set seen_recursive_call 0
> +set iterations 0
> gdb_test_multiple "next" "step over recursion inside the recursion" {
> -re -wrap ".*RECURSIVE CALL.*" {
> incr seen_recursive_call
> + incr iterations
> + if { $iterations == $max_iterations } {
> + fail "$gdb_test_name (reached $max_iterations iterations)"
> + return
> + }
> +
> send_gdb "next\n"
> exp_continue
> }
> @@ -286,7 +301,13 @@ gdb_test_multiple "next" "step over recursion inside the recursion" {
> gdb_assert {"$seen_recursive_call" == 1} \
> "step over recursion inside the recursion"
> }
> - -re -wrap ".*" {
> + -re -wrap "^\[0-9\].*" {
> + incr iterations
> + if { $iterations == $max_iterations } {
> + fail "$gdb_test_name (reached $max_iterations iterations)"
> + return
> + }
> +
> send_gdb "next\n"
> exp_continue
> }
>
> base-commit: d987df5c95340a8b41b23d68ad6a8f9f33485835
>
next prev parent reply other threads:[~2023-06-05 8:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-01 21:42 Thiago Jung Bauermann
2023-06-05 8:00 ` Bruno Larsen [this message]
2023-06-05 23:35 ` Thiago Jung Bauermann
2023-06-06 7:18 ` Bruno Larsen
2023-06-06 13:00 ` Thiago Jung Bauermann
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=45ff5e98-9e03-79fa-d73c-746b0f2d980e@redhat.com \
--to=blarsen@redhat.com \
--cc=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=tdevries@suse.de \
--cc=thiago.bauermann@linaro.org \
/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).