public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Joel Brobecker <brobecker@adacore.com>,
	Simon Marchi <simon.marchi@polymtl.ca>
Cc: Tim Newsome <tim@sifive.com>, gdb <gdb@sourceware.org>
Subject: Re: gdb requires watchpoints to fire after the write
Date: Wed, 29 Aug 2018 15:56:00 -0000	[thread overview]
Message-ID: <2e51a311-1cdb-a94e-b38f-1c19171aa362@redhat.com> (raw)
In-Reply-To: <20180829154739.GB2521@adacore.com>

On 08/29/2018 04:47 PM, Joel Brobecker wrote:
>> I don't have experience with many different architectures, but as far as I
>> know, the expectation of the GDB is that the watchpoint is reported after
>> the write.  Otherwise it wouldn't need to save the value of the watched
>> expression.  That's also how software watchpoints seem to work.
>>
>> The easiest way to deal with this would be to match GDB's expectation.  But
>> if you really prefer the behavior of reporting the watchpoint before the
>> event, I suppose it's always possible to teach GDB about this, but it's a
>> less trivial task.  Especially that when you GDB evaluates whether the watch
>> expression has changed value, it would need to consider the not-yet-written
>> value in memory.
>>
>> I'm also curious to know if other architectures work in this way (report the
>> event before the write actually take place).
> 
> I seem to remember some architectures having different behaviors,
> and so we have a couple of entry points in GDB. For architecture-specific
> settings, we have gdbarch_have_nonsteppable_watchpoint. For target-specific
> settings, you would use target_have_steppable_watchpoint. (IIRC)

Yes, the key bit is this here in infrun.c:

  /* If necessary, step over this watchpoint.  We'll be back to display
     it in a moment.  */
  if (stopped_by_watchpoint
      && (target_have_steppable_watchpoint
	  || gdbarch_have_nonsteppable_watchpoint (gdbarch)))
    {
      /* At this point, we are stopped at an instruction which has
         attempted to write to a piece of memory under control of
         a watchpoint.  The instruction hasn't actually executed
         yet.  If we were to evaluate the watchpoint expression
         now, we would get the old value, and therefore no change
         would seem to have occurred.

         In order to make watchpoints work `right', we really need
         to complete the memory write, and then evaluate the
         watchpoint expression.  We do this by single-stepping the
	 target.

	 It may not be necessary to disable the watchpoint to step over
	 it.  For example, the PA can (with some kernel cooperation)
	 single step over a watchpoint without disabling the watchpoint.

	 It is far more common to need to disable a watchpoint to step
	 the inferior over it.  If we have non-steppable watchpoints,
	 we must disable the current watchpoint; it's simplest to
	 disable all watchpoints.

	 Any breakpoint at PC must also be stepped over -- if there's
	 one, it will have already triggered before the watchpoint
	 triggered, and we either already reported it to the user, or
	 it didn't cause a stop and we called keep_going.  In either
	 case, if there was a breakpoint at PC, we must be trying to
	 step past it.  */
      ecs->event_thread->stepping_over_watchpoint = 1;
      keep_going (ecs);
      return;
    }

Thanks,
Pedro Alves

  reply	other threads:[~2018-08-29 15:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-28 22:08 Tim Newsome
2018-08-29 15:33 ` Simon Marchi
2018-08-29 15:47   ` Joel Brobecker
2018-08-29 15:56     ` Pedro Alves [this message]
2018-08-29 16:02     ` Simon Marchi
2018-08-29 17:29       ` Pedro Alves
2018-08-29 20:13         ` Tim Newsome
2018-08-29 20:58         ` Tom Tromey
2018-08-30  8:05           ` Joel Brobecker
2018-08-31 15:37             ` Pedro Alves
2018-08-31 15:13           ` 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=2e51a311-1cdb-a94e-b38f-1c19171aa362@redhat.com \
    --to=palves@redhat.com \
    --cc=brobecker@adacore.com \
    --cc=gdb@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    --cc=tim@sifive.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).