Anyone know's how can I get a self-stack trace of program in C.
Program could be like
#include <stdio.h>
int main(int argc, char **argv, char **envp){
/* Do something with the args */
func_a();
func_b();
/* Print stack trace to stdout or stderr */
<--------------HOW TO ACCOMPLISH THIS??
return 0;
}
func_a() {
/* Do something */
}
func_b() {
/* Do something */
}
I don't want to use pstack or dbx or forking or whatever.
Thanx in advaance.
#include <stdio.h>
/*ARGSUSED*/
main(argc, argv, envv)
int argc;
char **argv, **envv;
{
register int *bp = &argc;
for (; *bp != 0; bp--) {
printf("%d\n", bp);
}
}
--
/Srk
This is included in the FAQ posted on comp.unix.programmer. Shows
how to use the debugger to generate the stack trace.
jrs
follow-up set to comp.unix.programmer
If not, and if you want to print our the processes stack segment,
then it depends. Typically, hardware provides a general purpose
register that contains a pointer to the stack segment, ie sp.
Unfortunately, C does not support a special sp register notion,
so you have to link your code to assembly to get it.
At any rate, your post seems unclear about what it is your really
after. Please explain what your looking for. Thanks.
Ajay Pal Singh wrote:
>
> Hi,
>
> Anyone know's how can I get a self-stack trace of program in C.