This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
backtrace without abort
- From: <gan_xiao_jun at yahoo dot com>
- To: libc-alpha at sources dot redhat dot com
- Date: Wed, 9 Feb 2005 19:18:03 -0800 (PST)
- Subject: backtrace without abort
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