Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 30 Jun 2001 17:25:22 -0400
From:      Brian Dean <bsd@bsdhome.com>
To:        freebsd-audit@freebsd.org
Cc:        freebsd-hackers@freebsd.org
Subject:   kernel ddb patch for setting hardware watchpoints
Message-ID:  <20010630172522.A64393@neutrino.bsdhome.com>

next in thread | raw e-mail | index | archive | help
Hi,

Please look over the following patch to ddb.  This patch adds the
'hwatch' and 'dhwatch' commands to set and delete hardware
watchpoints.  These commands allow one to utilize hardware watchpoints
without having to modify the debug registers directly (which can be
tricky).

I modified the 'show watch' command to display information about
hardware watchpoints as well.  These commands result in no-ops for
architectures that don't support them.

I originally tried to overload the 'watch' and 'dwatch' command but
their operation was sufficiently different that I decided it best to
make a new command.  For one thing, watchpoints are not actually
installed until a 'continue' command is given which makes it
impossible see the effects on the debug registers until after the next
break or watchpoint has been hit.  More serious, though, the 'watch'
command really seems to be designed for watching addresses in user
address space and not the kernel.

To support the hwatch/dhwatch commands, I needed three machine
dependent hooks from ddb:

	db_md_set_watchpoint()
	db_md_clr_watchpoint()
	db_md_list_watchpoints()

These are all called from within ddb/db_watch.c and are defined in
$arch/$arch/db_trace.c.

The patch is located at:

	http://people.freebsd.org/~bsd/ddb/ddb.patch2

I've built an alpha kernel with the patch applied and it built ok.  I
don't have hardware to actually run it, though, but since this ends up
as a no-op on alpha (and ia64), I suspect it is Ok (famous last
words). I don't know where I can build this on an ia64 machine.  Do we
have a machine available for this kind of thing?

Caveats: This patch won't do the right thing on SMP systems.  The
	 debug registers are set/cleared only for the CPU running ddb.
	 Since the debug registers are a per-cpu thing, they won't be
	 set for the other CPUs.  I'll work on that next.

See below for a sample session.

Thanks,
-Brian
-- 
Brian Dean
bsd@FreeBSD.org
bsd@bsdhome.com


Example session:

login: 
FreeBSD/i386 (stage.bsdhome.com) (ttyd1)

login: Debugger("manual escape to debugger")
Stopped at      Debugger+0x44:  pushl   %ebx
db> show reg
cs                 0x8
ds                0x10
es          0xc9a80010
fs          0xc0300018  harvestring+0x2b38
ss                0x10
eax               0x26
ecx              0x2fd
edx              0x2f9
ebx              0x202
esp         0xc9a8ded0
ebp         0xc9a8dedc
esi         0xc0cff400
edi         0xc0d16800
eip         0xc0276974  Debugger+0x44
efl               0x46
dr0                  0
dr1                  0
dr2                  0
dr3                  0
dr4         0xffff0ff0
dr5              0x400
dr6         0xffff0ff0
dr7              0x400
Debugger+0x44:  pushl   %ebx
db> hwatch 0xcaae6740,9
db> show watch
No watchpoints set

hardware watchpoints:
  watch    status        type  len     address
  -----  --------  ----------  ---  ----------
  0      enabled        write    4  0xcaae6740
  1      enabled        write    4  0xcaae6744
  2      enabled        write    1  0xcaae6748
  3      disabled

debug register values:
  dr0 0xcaae6740
  dr1 0xcaae6744
  dr2 0xcaae6748
  dr3 0x00000000
  dr4 0xffff0ff0
  dr5 0x01dd042a
  dr6 0xffff0ff0
  dr7 0x01dd042a

db> cont
Stopped at      runq_add+0x41:  movl    0x4(%edx),%eax
db> dhwatch 0xcaae6740,9
db> show watch
No watchpoints set

hardware watchpoints:
  watch    status        type  len     address
  -----  --------  ----------  ---  ----------
  0      disabled
  1      disabled
  2      disabled
  3      disabled

debug register values:
  dr0 0x00000000
  dr1 0x00000000
  dr2 0x00000000
  dr3 0x00000000
  dr4 0xffff0ff1
  dr5 0x00000400
  dr6 0xffff0ff1
  dr7 0x00000400

db> cont

FreeBSD/i386 (stage.bsdhome.com) (ttyd1)

login: 

-- 
Brian Dean					bsd@bsdhome.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010630172522.A64393>