[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Backtrace.



[Sorry to reply to the reply rather than to the original message(s),
which I never received.]

	Date: Mon, 5 Jun 89 22:58:55 EDT
	From: barmar@Think.COM

	   Date: Mon, 5 Jun 89  15:05:06 MDT
	   From: snicoud@atc.boeing.com (Stephen Nicoud)

	   How can a process get a backtrace of its own stack?

	See the section in book 2A on the Condition system and the Debugger.
	It describes a multitude of functions for getting pointers to stack
	frames and accessing information in them.  It describes just about
	everything you'd need to reimplement the debugger yourself.  Look up
	DBG:WITH-ERRING-FRAME in the index, and this should get you close
	(unfortunately, the page numbers in Symbolics indexes are only an
	approximation to reality -- hopefully this will be improved in future
	manuals written with Concordia).

You should know that 1dbg:with-erring-frame0 can only be used inside a
1condition-bind0 handler; it isn't legal to talk about frames with the
debugger tools unless you are actively handling a condition.
1condition-case0 is not sufficient; by the time you enter the handler of a
1condition-case0, a 1throw0 has been done which invalidates the stack
frame(s) which contain the error.

There is a (compiled-code-only) function named 1sys:%stack-frame-pointer
0which returns the current frame.  You can use non-debugger accessors
with this frame pointer, e.g., 1sys:frame-function0.  I believe you have
the source for the definition of a stack frame, so you can play with
this.  The layout of a stack frame is architecture-dependent (i.e.,
different on the 36xx and Ivory), so watch out (and don't change
anything unless you2 really0 know what you're doing!).  Use the editor
command meta-. to edit the source of 1sys:stack-frame0 if you're curious.

You might be interested in the function 1dbg:automatic-bug-report0, which
is called with a condition object from a 1condition-bind 0handler.  It
uses 1dbg:with-erring-frame 0and various other debugger tools to generate
a backtrace.

This function is tailored for use in network servers, so you may need to
play with it a bit to get it to do the right thing for you.  It will
mail and/or file a copy of the backtrace as generated by the debugger's
control-M command, as desired.  1dbg:automatic-bug-report 0is called by
1fs:file-server-error-filter0, inter alia, for which you should also have
the source. (1fs:f-s-e-f0 is used in the NFILE server, etc., as follows:

	     [...]
	     (condition-bind ((error #'file-server-error-filter))
	     [...]

in case you need to figure out what's going on.  As usual, having a full
who-calls database is quite valuable when it comes to figuring out what
the system is doing).