|
|
Kaz Kylheku wrote:
On Mar 28, 12:47 pm, Keith Thompson <ks...@xxxxxxx> wrote:
sophia <sophia.ag...@xxxxxxxxx> writes:
can any one suggest ways of implementing a backtrace function in ANSI/
standard C as given in the following link ?
http://pramode.net/2006/09/12/getting-a-backtrace-from-running-c-code...
There's no portable way to do that in standard C.
Also, there is no nonportable way to do that in standard C, either.
:)
No, In non portable C you can do it
1) Read the frame pointer (This is the only assembly yo need)
2) See at what offset from the frame pointer is the pushed return
address
3) The value stored in the saved frame pointer position points to
the next frame.
Here you have the next frame and the address of some point in the
calling procedure.
4) Read the debug information.
5) Find out into which function the return address points to.
6) Is that the function "main"?
7) If not, get the next frame pointer and go to (2)
---------------
This supposes that
(1) you have a frame pointer
(2) The calling function has a frame pointer
GDB is written in C, and the lcc-win debugger is
written in C. So there is OBVIOUSLY a way of doing
this in C!
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
www.cs.virginia.edu/~lcc-win32">http://www.cs.virginia.edu/~lcc-win32
|
|