Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Self stack trace

9 views
Skip to first unread message

Ajay Pal Singh

unread,
Jan 14, 1999, 3:00:00 AM1/14/99
to
Hi,

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.


T. Srikanth

unread,
Jan 14, 1999, 3:00:00 AM1/14/99
to
Here is roughly the idea:

#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

http://www.freegate.com

j r s

unread,
Jan 15, 1999, 3:00:00 AM1/15/99
to
In article <369E6A8A...@sybase.com>,

Ajay Pal Singh <asi...@sybase.com> writes:
> Hi,
>
> Anyone know's how can I get a self-stack trace of program in C.

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

Zeke

unread,
Jan 15, 1999, 3:00:00 AM1/15/99
to
Huh? In your example the stack would just have 'main' where you want
to print it. Is that what you want? Or do you want the process traced?
If so, then just insert trace hooks in all of your routines.

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.

0 new messages