This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]