Re: tracing a function without knowing its name



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?
.



Relevant Pages

  • Re: Continuous Network Diagram for a Single Task
    ... Go to my website and download the "Trace" macro. ... Now switch to the network diagram. ... >From the project menu select filtered for, ...
    (microsoft.public.project)
  • Re: Searching for Predecessors
    ... The Trace Macro or the relationship diagram won't work in this case. ... I autofilter or create a filter and it just doesn't seem to work...all ...
    (microsoft.public.project)
  • Re: Use trace macro
    ... TRACE is a MFC macro. ... You can try using OutputDebugString() API if you ...
    (microsoft.public.vc.language)
  • Re: A simple debugging macro
    ... I wrote this simple macro a while back and I've found it to be ... extremely useful for old-fashioned trace style debugging. ... Inserting a string in a string and printing that. ... TRACE: before fib loop A=10 ...
    (comp.lang.lisp)
  • Re: Problem in the calling the dll functions
    ... Some other reasons are possible, ... into the application and the DLL as possible (at least, trace all function calls). ... Check that all DLL functions are properly declared, and the declarations ...
    (microsoft.public.dotnet.languages.vc)