Re: tracing a function without knowing its name
- From: Pascal Bourguignon <pjb@xxxxxxxxxxxxxxxxx>
- Date: Sat, 28 Apr 2007 21:59:47 +0200
jimka <jimka@xxxxxxxxx> writes:
Does anyone know how (or at least how with sbcl) to trace a function
object without knowing its name?
for example: here is a macro which is creating a function.
I'd like to trace it as well while I'm debugging.
(defmacro def-type (type-name lambda-list &rest body)
`(new-type ',type-name (lambda ,lambda-list ,@body)))
Portably, you'd have to replace the function you want to trace
everywhere it's stored.
In the happy case where it's used only from one place, like in this
macro, you can of course easily do it.
For example:
;; Not tested:
(shadow 'lambda)
(use-package :com.informatimago.common-lisp.source-form)
(defmacro lambda (arguments &body body)
(let ((declarations (extract-declarations body)))
(if (find-if (lambda (decl) (member 'trace (rest decl)))
declarations)
;; Let's trace this lambda:
`(cl:lambda ,arguments
,@declarations
,@(let ((doc (extract-documentation body)))
(when doc (list doc)))
(print ,(format nil "~&Entering function ~S~%"
`(lambda ,arguments ,@body)) *trace-output*)
(force-output *trace-output*)
(unwind-protect
(progn ,@(extract-body body))
(print ,(format nil "~&Exiting function ~S~%"
`(lambda ,arguments ,@body)) *trace-output*)
(force-output *trace-output*)))
;; Not tracing this function:
`(cl:lambda ,arguments ,@body))))
So you can now write:
(defmacro def-type (type-name lambda-list &rest body)
`(new-type ',type-name (lambda ,lambda-list (declare trace) ,@body)))
--
__Pascal Bourguignon__ http://www.informatimago.com/
In a World without Walls and Fences,
who needs Windows and Gates?
.
- References:
- tracing a function without knowing its name
- From: jimka
- tracing a function without knowing its name
- Prev by Date: programmatically determine if argument is list compatible to a given lambda list
- Next by Date: Re: Problems with slime and cmucl
- Previous by thread: Re: tracing a function without knowing its name
- Next by thread: Re: tracing a function without knowing its name
- Index(es):
Relevant Pages
|
|