Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
To: Pedro Alves <palves@redhat.com>
Cc: Jan Kratochvil <jan.kratochvil@redhat.com>,
	Joel Brobecker <brobecker@adacore.com>,
	gdb-patches@sourceware.org
Subject: Re: [patch] [i386] Put hlt at the ON_STACK breakpoint  [Re: GDB 7.4.91 available for testing]
Date: Wed, 25 Jul 2012 20:24:00 -0000	[thread overview]
Message-ID: <1343247870.2240.29.camel@soleil> (raw)
In-Reply-To: <501009AE.40901@redhat.com>

On Wed, 2012-07-25 at 15:58 +0100, Pedro Alves wrote:
> On 07/23/2012 09:36 PM, Philippe Waroquiers wrote:
> 
> >> So the GDB patch is no longer needed when you have fixed valgrind to put 0xcc
> >> during Z0? Why valgrind cannot write 0xcc into stack memory when it already
> >> has to write there to create the stack frame / parameters passed by stack?
> > Effectively, I have a patch which fixes the problem.
> > But the patch is a kludge which heuristically guesses that GDB is
> > pushing an infcall.
> 
> Why do you have to guess that, rather than just detecting a breakpoint is
> being set on a stack (or non text) address?  If something sets a breakpoint
> in a data address, it is basically telling valgrind "this is actually code".

This is explained by the way Valgrind gdbsrv (must) implement
breakpoints.
(this is a little bit tricky, as it is linked to Valgrind internals).

Valgrind translates guest code instructions in small blocks.
As part of the translation, if there is a breakpoint at addr XXXX
then the translation of address XXXX will start with a call to a
helper function which reports to GDB that a breakpoint has been
encountered. This function then reads/executes protocol packets till a
continue packet is received.
The translated block is then continued <<< This is the critical info !!!

There is no way to re-translate the block currently being executed :
Valgrind has no way to "drop" the translated block it is currently
executing.
So, a breakpoint cannot be translated using a 0xCC because when GDB
tells to continue after the breakpoint, there is no way to retranslate
the original instructions (without the 0xCC) as long as the block
is being executed.
So, for normal breakpoints, Valgrind gdbsrv cannot insert 0xCC, as this
would just not work.

"Normal" breakpoints on the stack (trampoline code or whatever) or
JITted code or ... must be handled the same way: V gdbsrv cannot
touch the code to handle breakpoints.

The only special case in which Valgrind gdbsrv can insert a 0xCC is
when it is sure that this code will *not* be executed.
This is the case for the 0xcc for the push_dummy_code.
This code will not be executed because GDB will change the pc register.
When the continue packet is received, the execution of the block is
then not continued, instead the continue will cause a jump to the
"original pc" (the one before the infcall).

So, in summary:
   * for all normal breakpoints, Valgrind gdbsrv cannot insert a 0xcc
   * for "dummy inferior call return breakpoint", Valgrind gdbsrv can
     insert a 0xcc, as GDB will ensure this piece of code is not
     executed, and so there is no need to re-translate it without the
     0xcc

So, the kludge patch I have done tries to guess if the breakpoint
on the stack is a normal breakpoint (so, V gdbsrv cannot touch it)
or is a "infcall" breakpoint (then the kludge patch inserts a 0xcc).

It would be much cleaner to have GDB inserting the 0xCC, as GDB *knows*
it is doing a infcall, and so knows it can safely insert a 0xCC.
(Valgrind gdbsrv needs in any case the Z0 packet, as this is what
will ensure the 0xCC is not executed).

Not too sure if the above explanations are clear, it is somewhat tricky.

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.

Philippe



  reply	other threads:[~2012-07-25 20:24 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20120718163413.GA17548@adacore.com>
     [not found] ` <1342739016.2220.32.camel@soleil>
     [not found]   ` <20120720071158.GA7053@host2.jankratochvil.net>
     [not found]     ` <1342817409.2149.41.camel@soleil>
     [not found]       ` <20120722173053.GA22036@host2.jankratochvil.net>
     [not found]         ` <1342983655.2301.55.camel@soleil>
2012-07-23  7:22           ` Jan Kratochvil
2012-07-23 16:00             ` Joel Brobecker
2012-07-23 16:36               ` Jan Kratochvil
2012-07-23 20:07                 ` Philippe Waroquiers
2012-07-23 20:16                   ` Jan Kratochvil
2012-07-23 20:37                     ` Philippe Waroquiers
2012-07-25 14:49                       ` Joel Brobecker
2012-07-25 20:04                         ` Philippe Waroquiers
2012-07-25 20:11                           ` Jan Kratochvil
2012-07-25 20:39                             ` Philippe Waroquiers
2012-07-25 14:59                       ` Pedro Alves
2012-07-25 20:24                         ` Philippe Waroquiers [this message]
2012-07-25 21:27                           ` Joel Brobecker
2012-07-25 21:46                             ` Philippe Waroquiers
2012-07-25 22:39                               ` Joel Brobecker
2012-07-26 21:24                                 ` [patchv2] Write bpt at the ON_STACK bpt address Jan Kratochvil
2012-07-26 21:50                                   ` Philippe Waroquiers
2012-07-27 18:47                                     ` Jan Kratochvil
2012-07-28  7:28                                       ` Eli Zaretskii
2012-07-28  7:42                                         ` Jan Kratochvil
2012-07-31  7:37                                       ` [commit+7.5] " Jan Kratochvil
2012-08-01  9:08                                         ` [commit#2+7.5] testsuite: valgrind-infcall.exp UNSUPPORTED update [Re: [commit+7.5] [patchv2] Write bpt at the ON_STACK bpt address] Jan Kratochvil
2012-08-02 22:49                                         ` [commit+7.5] [patchv2] Write bpt at the ON_STACK bpt address Edjunior Barbosa Machado
2012-08-02 23:09                                           ` Sergio Durigan Junior
2012-08-03  0:15                                             ` Edjunior Barbosa Machado
2012-08-03 11:23                                               ` Jan Kratochvil
2012-08-03 12:09                                                 ` Edjunior Barbosa Machado
2012-08-03  1:00                                             ` Pedro Alves
2012-08-03  1:48                                               ` Sergio Durigan Junior
2012-08-03  2:30                                                 ` Edjunior Barbosa Machado
2012-08-03 21:45                                                   ` Philippe Waroquiers
2012-08-03 14:23                                               ` Tom Tromey
2012-08-03 14:31                                                 ` Jan Kratochvil
2012-08-03 15:02                                                   ` Edjunior Barbosa Machado
2012-08-03 15:08                                                     ` Jan Kratochvil
2012-08-03 16:43                                                       ` Edjunior Barbosa Machado
2012-08-03 16:46                                                         ` Jan Kratochvil
2012-08-03 18:00                                                           ` Edjunior Barbosa Machado
2012-08-03 20:23                                           ` Jan Kratochvil
2012-08-03 21:46                                             ` Edjunior Barbosa Machado
2012-08-06 18:40                                               ` Tom Tromey
2012-07-31  7:40                                       ` [commit] valgrind-db-attach.exp: Do not run in remote mode [Re: [patchv2] Write bpt at the ON_STACK bpt address] Jan Kratochvil
2012-07-26 23:14                                   ` [patchv2] Write bpt at the ON_STACK bpt address Maciej W. Rozycki
2012-07-27 16:02                                     ` Jan Kratochvil
2012-07-28  0:10                                       ` Maciej W. Rozycki
2012-07-28  6:06                                         ` Jan Kratochvil
2012-07-30 18:09                                           ` Maciej W. Rozycki
2012-07-26 23:15                                   ` Philippe Waroquiers
2012-07-27 16:03                                     ` Jan Kratochvil
2012-07-27 15:21                                   ` Pedro Alves
2012-07-26 21:56                                 ` [patch] [i386] Put hlt at the ON_STACK breakpoint [Re: GDB 7.4.91 available for testing] Philippe Waroquiers
2012-07-26 22:41                                   ` Philippe Waroquiers
2012-07-26  5:13                               ` Jan Kratochvil
2012-07-26 12:48                           ` Pedro Alves
2012-07-26 22:21                             ` Philippe Waroquiers
2012-07-27 14:59                               ` Pedro Alves

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=1343247870.2240.29.camel@soleil \
    --to=philippe.waroquiers@skynet.be \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=palves@redhat.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