Thursday, December 25, 2008

Where am I? The stack trace

Printing Stack Trace in Solaris

On Solaris 9 and later libc provides the printstack function, to print a stack trace to the specified file descriptor.
printstack() returns -1 if the stack is corrupted.

This is a very useful function when the application under question is a large legacy application. Basic debugging can be done using truss.but if truss is also not providing the necessary info, better start embedding printstack call in your code.

A sample program


#include < stdio.h >
#include < ucontext.h >

int sampletrace(int file)
{
printstack(file);
return (0);
}

void function()
{
int a = fileno(stdout);
sampletrace(a);
}

int main()
{
function();
return (0);
}



Looking for similar function calls in other NIX platforms...

No comments: