[Openmcl-devel] watched objects
dlw at itasoftware.com
Mon Sep 28 11:48:48 EDT 2009
In Ye Olde Days at the AI lab, when we used assembly
language on the PDP-10, we had the ability to set up
a memory location so that if one attempted to write
it, the program would pause and the debugger would
take over so you could see what was happening. (I believe
that the AI guys made a hardware mod to the PDP-10
to get this functionality; I'm not sure, I'd have to check
with Greenblatt or Knight or Moon.) It was sometimes
incredibly useful (bug: somebody is changing that
value but I don't know who). We had it in the Lisp
machine too, for the same reason. You only need
it rarely but for some bugs, it's incredibly helpful.
On the Lispm, if I remember right, you could specify
a "place" to watch, using the same "place" concept
used by setf. So you could watch element 7 of a
particular array object. The problem with complex
objects (hash tables) was the same; the feature is
defined at a low level of abstraction. Nevertheless,
it was very useful.
R. Matthew Emerson wrote:
> There's an experimental new debugging feature in the trunk that allows
> certain lisp objects to be "watched".
> When a write takes place to a watched object, a condition of type
> write-to-watched-object is signaled, and you get a break loop. You
> can then get a backtrace, etc., to see what happened. There's a
> restart that will unwatch the object and let you proceed. You can't
> (yet) say "allow just this one write to happen, but keep the object
> watched." To continue, you have to unwatch.
> The functions CCL::WATCH and CCL::UNWATCH are the interface to this.
> Silly example:
> ? (defvar *a* (make-array 3))
> ? (watch *a*)
> ? (setf (aref *a* 2) 'foo)
> > Error: Write to watched object #<SIMPLE-VECTOR 3> at address
> #xD5018 (uvector index 2).
> > While executing: ASET, in process listener(1).
> > Type :POP to abort, :R for a list of available restarts.
> > Type :? for other options.
> Calling WATCH with no arguments will return a list of objects being
> To a reasonable approximation, heap-allocated objects in CCL are
> either UVECTORs or CONSes. You can watch either kind of object, but
> there are some restrictions.
> Basically everything that isn't cons cell is a uvector (this includes
> all sorts of arrays, functions, symbols, hash-tables, bignums, etc.).
> For vectors, there's a one-to-one correspondence between the uvector
> indicies and the vector indicies.
> For more complicated objects (other arrays, hash tables, etc.), simply
> saying, e.g., (watch *my-2d-array*) won't do what you probably want:
> you'd need to watch the actual data vector, which is one element of
> the uvector that represents the 2d array.
> Although you can watch cons cells, you can watch only indivdual cons
> cells. This means if you say something like (watch (list 3 4 5)),
> you'll end up watching only the first cons (3 . (4 5)) instead of the
> whole chain of cons cells.
> The way watching objects is currently implemented is fairly simple
> (and simple-minded); getting rid of these limitations would probably
> involve writing most of a copying GC.
> Anyway, if you want, try it out and let me know how it works (or more
> importantly, if it doesn't). It is only implemented on x86 for now.
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
More information about the Openmcl-devel