RE: [PATCH 1/2 version 3] fix for gdb.reverse/finish-precsave.exp and gdb.reverse/finish-reverse.exp

Carl Love via Gdb-patches
2023-01-23T21:13:43Z

Pedro:

On Mon, 2023-01-23 at 19:17 +0000, Pedro Alves wrote:
> > Currently on X86, when executing the finish command in reverse, gdb
> > does a
> > single step from the first instruction in the callee to get back to
> > the
> > caller. GDB stops on the last instruction in the source code line
> > where
> > the call was made. When stopped at the last instruction of the
> > source code
> > line, a reverse next or step command will stop at the first
> > instruction
> > of the same source code line thus requiring two step/next commands
> > to
> > reach the previous source code line. It should only require one
> > step/next
> > command to reach the previous source code line.
> >
> > By contrast, a reverse next or step command from the first line in
> > a
> > function stops at the first instruction in the source code line
> > where the
> > call was made.
>
> I'd think this was on purpose. Note that next/step/reverse-
> {next/step} are line-oriented
> stepping commands, they step/next until the previous/next line.
> While "finish" is described
> as undoing the _function call_.
>
> The manual says:
>
> reverse-finish
> Just as the finish command takes you to the point where the current
> function returns,
> reverse-finish takes you to the point where it was called. Instead
> of ending up at the end of
> the current function invocation, you end up at the beginning.
>
> Say you have a line with multiple statements involving multiple
> function calls.
> The simplest would be:
>
> func1 (); func2 ();
>
> Say you'd stopped inside 'func2'. If you do finish there, in current
> master gdb
> stops at the call to 'func2', and you can then decide to reverse step
> into 'func1'.

I don't think you followed the issue.

So, if you are in func2 and do a reverse-finish, without the patch gdb
stops on the last instruction for the line that calls func2. Now if
you issue a reverse-step, you stop at the first instruction for the
call to func2, i.e. you are still on the same source code line. You
have not stepped back into func1 like you wanted to. Now you have to
issue a second reverse-step to get into func1. With the patch, you
issue the reverse-finish from func2 and stop at the first instruction
in the line that calls func2. Now when you issue the reverse-step you
step back into func1 as expected.

> While with your change, reverse-finish in func2 will make gdb stop at
> the beginning
> of the line, before the call to func1.
>
> Thus I'm really not convinced (yet) this change is a good one. It
> removes
> a user choice. You can always do reverse-next/step do get what you
> want
> reverse-finish do to, already.

Carl