This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem with can_use_hw_breakpoint


On Sat, 2008-08-09 at 15:19 +0300, Eli Zaretskii wrote:
> > From: Jeremy Bennett <jeremy.bennett@embecosm.com>
> > Date: Sat, 09 Aug 2008 13:03:06 +0100
> > 
> > This function is called in response to watch, rwatch, awatch or hbreak
> > commands. My architecture can support up to 4 hardware watchpoints.
> > Consider the sequence
> > 
> > awatch a (watchpoint 1)
> > awatch b (watchpoint 2)
> > rwatch c (watchpoint 3)
> > rwatch d (watchpoint 4)
> > rwatch e
> > 
> > rwatch e should fail (5th request), but all I know from the call to
> > can_use_hw_breakpoint() is that 3 of this type are requested and that
> > some other type of watchpoint (but not how many) has previously been
> > requested.
> 
> You say above that your architecture supports up to 4 hardware
> watchpoints.  Given that, isn't it enough to simply add 3+1 and
> compare that to 4?

Hi Eli,

Thanks for the quick response.

The problem is that I should be adding 3 (the rwatch) + 2 (the awatch)
and thus rejecting the watchpoint, but I have no way of knowing that the
count of awatch points is 2 - just that is is greater than zero.

> > Ideally I would like can_use_hw_breakpoint to supply me with an array
> > with the counts of all types of HW breakpoint/watchpoint requested, so I
> > could determine the total resource currently required.
> 
> What are the exact limitations of your architecture?  Do they depend
> on the types of the watchpoints, and if so, how?

It's the OpenRISC 1000 architecture. It implements 8 hardware
"matchpoints" which can be used for GDB HW breakpoints (needs one
matchpoint) or GDB HW watchpoints of any type (each needs a pair of
matchpoints). So I could handle 2 HW breakpoints with 1 rwatch and 2
awatch watchpoints for example.

> Take a look at i386-nat.c: it maintains a mirror of the hardware
> watchpoints related resources, and consults them for both allowing
> multiple watchpoints that watch the same addresses, and for deciding
> when another watchpoint cannot be defined.

Many thanks - this gave me some more hints.

I've realized that TARGET_CAN_USE_HARDWARE_WATCHPOINT is not guaranteed
to give a correct answer - it is just a "best guess". Section 5.1.2 of
the User Guide explains (if in doubt always read the manual :-))

        "If you set too many hardware watchpoints, GDB might be unable
        to insert all of them when you resume the execution of your
        program. Since the precise number of active watchpoints is
        unknown until such time as the program is about to be resumed,
        GDB might not be able to warn you about this when you set the
        watchpoints, and the warning will be printed only when the
        program is resumed:
        
               Hardware watchpoint num : Could not insert watchpoint
        
        If this happens, delete or disable some of the watchpoints."

This is good enough for me. I can get it right most of the time from the
data supplied and stop worrying about the corner cases (my example
above). I notice that the i386 has the simplest approximation of all -
it always returns 1 for TARGET_CAN_USE_HARDWARE_WATCHPOINT.

Best wishes,


Jeremy

-- 
Tel:      +44 (1202) 416955
Cell:     +44 (7970) 676050
SkypeID: jeremybennett
Email:   jeremy.bennett@embecosm.com
Web:     www.embecosm.com



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]