使用backtrace调试
{
printf("\n ***** start dump *****\n");
void*array[30];
size_t size;char**strings;
size_t i;
size = backtrace (array,30);
strings = backtrace_symbols (array, size);
fprintf (stdout,"Obtained %zd stack frames.nm\n", size);
for(i =0; i < size; i++)
fprintf (stdout,"%s ", strings[i]);
free (strings);
printf("\n ***** end dump *****\n");
exit(0);
}
static void signal_handler(int sig) {
char *name;
switch (sig) {
case SIGILL:
name = "SIGILL";
break;
case SIGABRT:
name = "SIGABRT";
break;
case SIGBUS:
name = "SIGBUS";
break;
case SIGSEGV:
name = "SIGSEGV";
break;
default:
name = "??";
}
fprintf(stdout, "[received signal] [%s]\n", name);
printStackTrace();
printProfileInfo();
signal(SIGILL, NULL);
signal(SIGABRT, NULL);
signal(SIGBUS, NULL);
//signal(SIGSEGV, NULL);
signal(SIGSEGV, dump);
abort();
}
void InitializeNativeCode()
{
/*
* Create signal handlers to dump Java stack in case of coredumps
*/
signal(SIGILL, signal_handler);
signal(SIGABRT, signal_handler);
signal(SIGBUS, signal_handler);
//signal(SIGSEGV, signal_handler);
signal(SIGSEGV, dump);
signal(SIGPIPE, SIG_IGN);
}
{
printf("\n ***** start dump *****\n");
void*array[30];
size_t size;char**strings;
size_t i;
size = backtrace (array,30);
strings = backtrace_symbols (array, size);
fprintf (stdout,"Obtained %zd stack frames.nm\n", size);
for(i =0; i < size; i++)
fprintf (stdout,"%s ", strings[i]);
free (strings);
printf("\n ***** end dump *****\n");
exit(0);
}
static void signal_handler(int sig) {
char *name;
switch (sig) {
case SIGILL:
name = "SIGILL";
break;
case SIGABRT:
name = "SIGABRT";
break;
case SIGBUS:
name = "SIGBUS";
break;
case SIGSEGV:
name = "SIGSEGV";
break;
default:
name = "??";
}
fprintf(stdout, "[received signal] [%s]\n", name);
printStackTrace();
printProfileInfo();
signal(SIGILL, NULL);
signal(SIGABRT, NULL);
signal(SIGBUS, NULL);
//signal(SIGSEGV, NULL);
signal(SIGSEGV, dump);
abort();
}
void InitializeNativeCode()
{
/*
* Create signal handlers to dump Java stack in case of coredumps
*/
signal(SIGILL, signal_handler);
signal(SIGABRT, signal_handler);
signal(SIGBUS, signal_handler);
//signal(SIGSEGV, signal_handler);
signal(SIGSEGV, dump);
signal(SIGPIPE, SIG_IGN);
}