public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Bruno Larsen <blarsen@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH v4 2/2] gdb/reverse: Fix stepping over recursive functions
Date: Wed, 2 Nov 2022 13:46:40 -0400	[thread overview]
Message-ID: <1d743da0-278c-f800-10a0-d6aaa7995a92@simark.ca> (raw)
In-Reply-To: <4cc13e71-aa24-b66b-f8bc-1bb9b7e17b59@redhat.com>

On 11/2/22 13:03, Bruno Larsen via Gdb-patches wrote:
> On 25/10/2022 16:55, Simon Marchi wrote:
>> On 10/5/22 06:38, Bruno Larsen via Gdb-patches wrote:
>>> Currently, when using GDB to do reverse debugging, if we try to use the
>>> command "reverse next" to skip a recursive function, instead of skipping
>>> all of the recursive calls and stopping in the previous line, we stop at
>>> the second to last recursive call, and need to manually step backwards
>>> until we leave the first call.  This is well documented in PR gdb/16678.
>>>
>>> This bug happens because when GDB notices that a reverse step has
>>> entered into a function, GDB will add a step_resume_breakpoint at the
>>> start of the function, then single step out of the prologue once that
>>> breakpoint is hit.  The problem was happening because GDB wouldn't give
>>> that step_resume_breakpoint a frame-id, so the first time the breakpoint
>>> was hit, the inferior would be stopped.  This is fixed by giving the
>>> current frame-id to the breakpoint.
>>>
>>> This commit also changes gdb.reverse/step-reverse.c to contain a
>>> recursive function and attempt to both, skip it altogether, and to skip
>>> the second call from inside the first call, as this setup broke a
>>> previous version of the patch.
>>> ---
>>>   gdb/infrun.c                                |  2 +-
>>>   gdb/testsuite/gdb.reverse/step-precsave.exp |  6 ++-
>>>   gdb/testsuite/gdb.reverse/step-reverse.c    | 19 ++++++-
>>>   gdb/testsuite/gdb.reverse/step-reverse.exp  | 55 +++++++++++++++++++--
>>>   4 files changed, 74 insertions(+), 8 deletions(-)
>> Hi Bruno,
>>
>> I see these failures since this commit:
>>
>>      $ make check TESTS="gdb.reverse/step-reverse.exp" RUNTESTFLAGS="--target_board=native-gdbserver"
>>      FAIL: gdb.reverse/step-reverse.exp: reverse next over recursion again
>>      FAIL: gdb.reverse/step-reverse.exp: enter recursive function
>>      FAIL: gdb.reverse/step-reverse.exp: step over recursion inside the recursion
> Hi Simon,
> 
> Sorry about the delay in responding to this, took me a while to track it down.
> 
> This was actually a latent bug, not a regression. If you try to run gdb.reverse/step-reverse in the native-gdbserver setup manually, then run the following commands:
> 
> (gdb) tbreak main
> (gdb) record
> (gdb) until 61
> (gdb) rn 2
> (gdb) n
> 
> You'll see the same failures. After the final next we should be stopped at line 58, and we end up on line 61 instead.
> 
> This happens because when recording the instruction call, GDB doesn't seem to save the stack change, only registers, so when reconstructing the state we aren't aware that the return address changes. This makes it so when setting the breakpoint at the return address, we set it to the return of the second callee return, instead of the first callee in this case (or recursive_callee in the case you found).
> 
> I hope this explanation made sense...

I don't know the reverse stuff well, but the explanation makes sense.
Do you plan on tackling this bug?  If not, can you file a bug and add a
kfail?

Thanks,

Simon

  reply	other threads:[~2022-11-02 17:46 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-05 10:38 [PATCH v4 0/2] Fix reverse nexting over recursions Bruno Larsen
2022-10-05 10:38 ` [PATCH v4 1/2] Change calculation of frame_id by amd64 epilogue unwinder Bruno Larsen
2022-10-25 13:44   ` Simon Marchi
2022-10-25 13:51     ` Bruno Larsen
2022-10-25 13:59     ` Simon Marchi
2022-10-25 14:13       ` Bruno Larsen
2022-10-25 14:37         ` Simon Marchi
2022-10-05 10:38 ` [PATCH v4 2/2] gdb/reverse: Fix stepping over recursive functions Bruno Larsen
2022-10-25 14:55   ` Simon Marchi
2022-10-25 16:22     ` Tom de Vries
2022-11-02 17:03     ` Bruno Larsen
2022-11-02 17:46       ` Simon Marchi [this message]
2022-11-03  9:08         ` [PATCH] gdb/testsuite: add KFAILs to gdb.reverse/step-reverse.exp Bruno Larsen
2022-11-03 13:06           ` Simon Marchi
2022-11-03 14:30             ` [PATCHv2] " Bruno Larsen
2022-11-03 16:59               ` Simon Marchi
2022-11-04 11:06                 ` Bruno Larsen
2022-10-20  7:42 ` [PING][PATCH v4 0/2] Fix reverse nexting over recursions Bruno Larsen
2022-10-20 18:56   ` Tom Tromey
2022-10-21 10:50     ` Bruno Larsen

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=1d743da0-278c-f800-10a0-d6aaa7995a92@simark.ca \
    --to=simark@simark.ca \
    --cc=blarsen@redhat.com \
    --cc=gdb-patches@sourceware.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).