Re: [RFC]: x86 threaded watchpoint support [1/3]

Eli Zaretskii
2004-06-12T09:35:01Z

> /* Mirror the inferior's DRi registers. We keep the status and
> - control registers separated because they don't hold addresses. */
> + control registers separated because they don't hold addresses.
> +
> + Note that the DR_STATUS register is thread-specific and the
> + mirror value should be refreshed as necessary. */
> static CORE_ADDR dr_mirror[DR_NADDR];

If the DR_STATUS register is thread specific, I think the mirroring
should be redesigned to support that out of the box. The solution you
suggest sounds like working around the existing code, but there's no
reason to do that, IMHO.

> +extern ptid_t trap_ptid;
> +extern ptid_t inferior_ptid;

As Mark points out, this will break any x86 target that doesn't
define these in its source files. So this solution is not a good
one. A better solution would be to define target-specific accessor
functions that would return these values.

> + ptid_t saved_ptid = inferior_ptid;
>
> + /* Debug status register is thread-specific. A watchpoint will
> + cause a trap to occur. Switch to trap ptid to get relevant
> + status for that thread. */
> + inferior_ptid = trap_ptid;
> dr_status_mirror = I386_DR_LOW_GET_STATUS ();
> + inferior_ptid = saved_ptid;

Yikes! Why not redesign I386_DR_LOW_GET_STATUS so that it could
accept the required thread id directly?

Bottom line: I think we need to redesign the low-level watchpoint
support for x86 so that it supports per-thread hardware watchpoints.
(I actually raised this issue back when the current code was designed
and was told to disregard it. Now it came back to haunt us.)