Re: [patch] [i386] Put hlt at the ON_STACK breakpoint [Re: GDB 7.4.91 available for testing]

Philippe Waroquiers
2012-07-25T21:46:19Z

On Wed, 2012-07-25 at 14:26 -0700, Joel Brobecker wrote:
> > The translated block is then continued <<< This is the critical info !!!
>
> I am having trouble understanding why the translated block would
> be continued in the case of an inferior function call, since
> the code is not to be executed (thanks to resetting the PC to its
> original value prior to the inferior function call when reaching
> the Z0 breakpoint we inserted). But...
The "continued" explanation above is only for normal breakpoints.

The "infcall breakpoints" are effectively *not* continued, thanks
to GDB changing the program counter. This is what allows the
kludgy Valgrind patch to work.

>
> > So, if it is easy to change GDB to insert 0xcc (for x86 and amd84)
> > and the equivalent breakpoint instr for mips32, then that avoids
> > the kludgy patch in Valgrind, which is for sure fragile.
>
> ... if I still understand correctly, as long as we write a valid
> instruction at the point where we place the infcall breakpoint,
> we should be fine, right? Jan selected the hlt instruction, but
> we could go with the breakpoint trap instruction as well (0xcc),
> which I think should be simpler to generalize in the future.
> It should not matter which instruction is chosen as long as it
> fits the available space, since that instruction will never be
> executed (thanks to the Z0 packet introducing an official breakpoint
> there).
A valid instruction is not enough. We need a valid instruction
that will cause Valgrind to terminate block translation.
The breakpoint trap instruction is ok for that.
(0xcc for x86 and amd64, 0x0005000d for mips32).

Philippe