backtrace without abort
gan_xiao_jun@yahoo.com
gan_xiao_jun@yahoo.com
Thu Feb 10 13:05:00 GMT 2005
Hi,
I want to print the backtrace at runtime.
I use following way to get it:
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
#include <stdio.h>
#include <signal.h>
#include <execinfo.h>
void handler()
{
int i;
void *bt[128];
int bt_size;
fprintf(stderr,"\n########## Backtrace
##########\n");
bt_size = backtrace(bt, sizeof(bt) / sizeof(void *));
fprintf(stderr,"Number of elements in backtrace:
%d\n", bt_size);
for (i = 0; i < bt_size; i++) {
fprintf(stdout,"%p\n", bt[i]);
}
fprintf(stderr,"Handler done.\n");
}
void g()
{
abort();
}
void f()
{
g();
}
int main(int argc, char **argv)
{
struct sigaction SignalAction;
SignalAction.sa_sigaction = handler;
sigemptyset(&SignalAction.sa_mask);
SignalAction.sa_flags = SA_SIGINFO;
sigaction(SIGABRT, &SignalAction, NULL);
f();
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
but it would cause application abort.
Is there a proper way to call backtrace without abort?
Thanks in advance.
gan
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Libc-alpha
mailing list