Subject: ns32532 "address break" for ptrace()?
To: None <port-pc532@NetBSD.ORG>
From: Phil Budne <budd@cs.bu.edu>
List: port-pc532
Date: 03/28/1997 22:35:28
Has anyone ever looked at making the ns32532 (or x86) "address break"
features available via ptrace()?

I got used to being able to trap on accesses to a specific address in
my first life (as a PDP-10 person), and in my third (doing embeded
develpment with ICE's).

I remember early die revisions of the 532 didn't implement "Address
Compare Debug Traps", and some of the intermediate revisions had
restrictions. I expect bugs, but would personally be willing to abide
by certain restrictions at times, to allow me to catch "random" memory
trashing bugs.

It looks like very little kernel work would be needed; the harder part
is adding support to "gdb" (which already allows you to "watch"
memory, but does so VERY slowly, by single stepping the program).
SunOS4 on the 386i implemented implemented: PTRACE_SET{WR,RD}BKPT,
PTRACE_CLRBKPT functions, but it doesn't look like there is gdb support
for them.

For ptrace() I'd add two functions: PT_SET_ADBRK and PT_CLR_ADBRK; I'd
use the "addr" arg for the address, and "data" in a machine dependant
way (various stuff or-ed together).

The ns32532 could have flags for;

	Compare Byte Enable 0
	Compare Byte Enable 1
	Compare Byte Enable 2
	Compare Byte Enable 3
	Compare on Write
	Compare on Read
	Compare PC

It looks like the T_DBG alreads sends a SIGTRAP, which is what I want.

A x86 implementation might have;

	Operand length: 1/2/4
	Breakpoint number: 0/1/2/3
	Break on Read/Write
		
I'd add the information to load on context switch to the pcb struct.
The only part I feel queasy about is access during copy in/out of the
kernel; the simple solution is to make sure address comparison is
disabled while in-kernel (memory trashed by bad system call arguments
would not be tracable).

-phil