Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: Pedro Alves <palves@redhat.com>
Cc: Yao Qi <qiyaoltc@gmail.com>,
	 Jan Kratochvil <jan.kratochvil@redhat.com>,
	 gdb-patches@sourceware.org
Subject: Re: [patch] aarch64: PR 19806: watchpoints: false negatives -> false positives
Date: Tue, 07 Jun 2016 15:25:00 -0000	[thread overview]
Message-ID: <86a8ixvx5k.fsf@gmail.com> (raw)
In-Reply-To: <48622de4-dc45-c48f-7172-495b669f2334@redhat.com> (Pedro Alves's	message of "Tue, 7 Jun 2016 14:41:02 +0100")

Pedro Alves <palves@redhat.com> writes:

> How do you plan on handling remote targets though?  Done that way, it 
> sounds to me like the alignment restrictions should either be a gdbarch
> property, or you need some RSP extension, e.g., extend the "watch" stop
> reply to indicate an stop data address range instead of a sole address,
> or make the stub report back the alignment restriction when GDB tells it
> to insert the watchpoint in the first place, instead of just saying
> "OK".
>

I want to use a gdbarch method to decide whether a watchpoint is
triggered in remote target, like this, [note that all the code below is
not compiled at all]

static enum watchpoint_triggered
remote_watchpoint_triggered (struct target_ops *target, struct watchpoint *w)
{
  struct thread_info *thread = inferior_thread ();

  if (thread->priv != NULL
      && thread->priv->stop_reason == TARGET_STOPPED_BY_WATCHPOINT)
    {
      return gdbarch_watchpoint_triggered (w->base.gdbarch, w,
					   thread->priv->watch_data_address);
    }

  return watchpoint_triggered_unknown;
}

The default implementation of gdbarch_watchpoint_triggered returns
watchpoint_triggered_yes if address is in the range of
loc->address,+loc->length.  Otherwise return watchpoint_triggered_no.
Then, we can rewrite breakpoint.c:watchpoints_triggered like this,

int
watchpoints_triggered (void)
{
  int ret = 0;

  ALL_BREAKPOINTS (b)
    if (is_hardware_watchpoint (b))
      {
	struct watchpoint *w = (struct watchpoint *) b;

	w->watchpoint_triggered = target_watchpoint_triggered (w);

	if (w->watchpoint_triggered != watch_triggered_no)
	  ret = 1;
      }

  return ret;
}

> A gdbarch method poses problems for remote stubs that are actually emulators,
> and thus can support hardware watchpoints without these restrictions.

Then, the address reported by the target should fall in the range of
loc->address,+loc->length.

> I think it's actually problematic for real machines, as the restrictions
> will often depend on process revisions/models.  So a gdbarch approach
> would be undesirable, IMO.

On the real machine, nowadays, the restriction is that address must be
8-byte-aligned on linux.  The restriction can only be relaxed and
may be removed finally in the future, IOW, the restriction won't become
16-byte aligned, so we can write the gdbarch method for aarch64-linux
like this,

static enum watchpoint_triggered
aarch64_linux_watchpoint_triggered (struct gdbarch *gdbarch,
				    struct watchpoint *w,
				    CORE_ADDR addr)
{
  struct bp_location *loc;

  for (loc = w->base.loc; loc; loc = loc->next)
    {
      if (addr >= loc->address && addr < loc->address + loc->length)
	{
	  /* If the address reported by the target falls in the memory
	     range that watchpoint W is monitoring, the watchpoint is
	     definitely hit.  */
	  return watchpoint_triggered_yes;
	}
      else if (addr >= align_down (loc->address, 8) && addr < loc->address)
	{
	  /* The debugging stub, like GDBserver, may adjust the address
	     to meet kernel's alignment requirements (8-aligned for
	     example), we are not sure watchpoint W is hit or not.  */
	  return watchpoint_triggered_unknown;
	}
    }

  return watchpoint_triggered_no;
}

-- 
Yao (齐尧)


  reply	other threads:[~2016-06-07 15:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-06  8:00 Jan Kratochvil
2016-06-07 13:23 ` Yao Qi
2016-06-07 13:41   ` Pedro Alves
2016-06-07 15:25     ` Yao Qi [this message]
2016-06-07 16:04       ` Pedro Alves
2016-06-08 16:42         ` Yao Qi
2016-06-08 17:54           ` Pedro Alves
2016-06-08 18:46             ` Pedro Alves
2016-06-10  8:11               ` Yao Qi
2016-06-19 18:29               ` Jan Kratochvil
2016-06-20 11:47                 ` Pedro Alves
2016-06-20 14:12                   ` Jan Kratochvil
2016-06-20 14:40                     ` Pedro Alves
2017-03-27 21:11 ` obsolete: " Jan Kratochvil

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=86a8ixvx5k.fsf@gmail.com \
    --to=qiyaoltc@gmail.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