This is the mail archive of the gdb-patches@sourceware.cygnus.com 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]

Re: awatch and rwatch vs watch



  From: Jim Blandy <jimb@cygnus.com>
  Date: 12 Jul 1999 18:29:50 -0500
> 
> > Why is bp_hardware_watchpoint treated specially here?  At least in
> > the DJGPP version (and I'd expect in other x86-based versions as
> > well), bp_read_watchpoint and bp_access_watchpoint are implemented
> > using the same mechanism as bp_hardware_watchpoint, so I don't
> > understand the cause for the different treatment here.
> 
> I have no idea...

Okay, I looked at this some more, and I'm now quite convinced that
either (1) I miss some aspect of how watchpoints work on Unix
x86-based platforms; or (2) the code in point was written with some
non-x86 platform in mind, which implements watchpoints in a totally
different way.

DJGPP implements watchpoints with debug registers.  Write-only and
read/write watchpoints (set, respectively, by "watch" and "awatch"
commands) are implemented almost identically, except that the access
bits in the DR7 register are set accordingly.  Read-only watchpoints
(set by the "rwatch" command) are handled like read/write watchpoints,
and the code in breakpoint.c then makes sure that if the watched value
changed, we don't tell the user the read-only watchpoint fired.

I expect this to be implemented in a similar way for other x86
platforms, but maybe this is not so.  Can someone confirm or refute
this?

With the above setup it is totally unclear why would GDB refuse to set
an `awatch' or `rwatch', but agree to `watch'.  Yet the following
snippet (from watch_command_1) does exactly that:


  mem_cnt = can_use_hardware_watchpoint (val);
  if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
    error ("Expression cannot be implemented with read/access watchpoint.");
  if (mem_cnt != 0) { 
    i = hw_watchpoint_used_count (bp_type, &other_type_used);
    target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT(
		bp_type, i + mem_cnt, other_type_used);
    if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
      error ("Target does not have this type of hardware watchpoint support.");
    if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
      error ("Target resources have been allocated for other types of watchpoints.");
  }

Here, can_use_hardware_watchpoint simply makes sure that the
expression to be watched doesn't yield a data type whose length is
more than the target hardware watchpoint facility can handle.  For
example, if the target cannot watch more that 4-byte regions, then
"watch foo" where `foo' is a double will cause GDB use a software
watchpoint for `foo'.

It seems that this snippet implies that software watchpoints cannot be
set with "awatch" and "rwatch", only with "watch".

Can someone tell why?  Should I submit a patch to handle all
watchpoints equally, at least on x86 platforms?

Btw, the manual clearly has traces of limitations that are pertinent
for platforms other than x86: it says something about "setting both
watchpoints with the same command" (what ``both watchpoints''?).

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