void *buffer[256];
int total = backtrace (buffer, 256);
char **result = backtrace_symbols (buffer, total);
void *buffer[256];
int total = backtrace (buffer, 256);
char **result = backtrace_symbols (buffer, total);
// used to terminate child processes when program terminates
static void handle_exit(int signum)
{
//printf("child %d exit\n", getpid());
exit(0);
}
// used to terminate child processes when program terminates
static void handle_exit(int signum)
{
//printf("child %d exit\n", getpid());
exit(0);
}
if( enable ) {
// causes SIGHUP to be generated when parent dies
signal(SIGHUP, handle_exit);
if( enable ) {
// causes SIGHUP to be generated when parent dies
signal(SIGHUP, handle_exit);
signal(SIGHUP, signal_entry);
prctl(PR_SET_PDEATHSIG, 0,0,0,0);
}
signal(SIGHUP, signal_entry);
prctl(PR_SET_PDEATHSIG, 0,0,0,0);
}
fprintf(stderr, "BC_Signals::x_error_handler: error_code=%d opcode=%d,%d id=0x%jx %s\n",
event->error_code, event->request_code, event->minor_code,
(int64_t)event->resourceid, string);
fprintf(stderr, "BC_Signals::x_error_handler: error_code=%d opcode=%d,%d id=0x%jx %s\n",
event->error_code, event->request_code, event->minor_code,
(int64_t)event->resourceid, string);
// it is not necessary to be root if ptrace is allowed via:
// echo 0 > /proc/sys/kernel/yama/ptrace_scope (usually set to 1)
// if( uid != 0 ) return;
// it is not necessary to be root if ptrace is allowed via:
// echo 0 > /proc/sys/kernel/yama/ptrace_scope (usually set to 1)
// if( uid != 0 ) return;
fprintf(stderr,"** %s at %p in pid %d, tid %d\n",
n==SIGSEGV? "segv" : n==SIGINT? "intr" : "trap",
fprintf(stderr,"** %s at %p in pid %d, tid %d\n",
n==SIGSEGV? "segv" : n==SIGINT? "intr" : "trap",
fprintf(stderr,"writing debug data to %s\n", fn);
fprintf(fp,"** %s at %p in pid %d, tid %d\n",
n==SIGSEGV? "segv" : n==SIGINT? "intr" : "trap",
fprintf(stderr,"writing debug data to %s\n", fn);
fprintf(fp,"** %s at %p in pid %d, tid %d\n",
n==SIGSEGV? "segv" : n==SIGINT? "intr" : "trap",
fprintf(fp," by %d:%d %s(%s)\n",
pw->pw_uid, pw->pw_gid, pw->pw_name, pw->pw_gecos);
}
fprintf(fp," by %d:%d %s(%s)\n",
pw->pw_uid, pw->pw_gid, pw->pw_name, pw->pw_gecos);
}
fprintf(fp,"\nCPUS: %d\n", BC_Resources::get_machine_cpus());
fprintf(fp,"\nCPUINFO:\n"); bc_copy_textfile(32, fp,"/proc/cpuinfo");
fprintf(fp,"\nTHREADS:\n"); BC_Trace::dump_threads(fp);
fprintf(fp,"\nCPUS: %d\n", BC_Resources::get_machine_cpus());
fprintf(fp,"\nCPUINFO:\n"); bc_copy_textfile(32, fp,"/proc/cpuinfo");
fprintf(fp,"\nTHREADS:\n"); BC_Trace::dump_threads(fp);
fprintf(fp,"\nSTATUS:\n"); bc_copy_textfile(INT_MAX, fp,"/proc/%d/status",pid);
fprintf(fp,"\nFD:\n"); bc_list_openfiles(INT_MAX, fp,"/proc/%d/fd", pid);
fprintf(fp,"\nMAPS:\n"); bc_copy_textfile(INT_MAX, fp,"/proc/%d/maps",pid);
fprintf(fp,"\nSTATUS:\n"); bc_copy_textfile(INT_MAX, fp,"/proc/%d/status",pid);
fprintf(fp,"\nFD:\n"); bc_list_openfiles(INT_MAX, fp,"/proc/%d/fd", pid);
fprintf(fp,"\nMAPS:\n"); bc_copy_textfile(INT_MAX, fp,"/proc/%d/maps",pid);
char proc_mem[64];
if( tid > 0 && tid != pid )
sprintf(proc_mem,"/proc/%d/task/%d/mem",pid,tid);
char proc_mem[64];
if( tid > 0 && tid != pid )
sprintf(proc_mem,"/proc/%d/task/%d/mem",pid,tid);
if( !(i & 7) ) fprintf(fp,"%p: ", vp);
if( pread(pfd,&v,sizeof(v),(off_t)vp) != sizeof(v) ) break;
fprintf(fp,"%c%02x", !i ? '>' : ' ', v);
if( !(i & 7) ) fprintf(fp,"%p: ", vp);
if( pread(pfd,&v,sizeof(v),(off_t)vp) != sizeof(v) ) break;
fprintf(fp,"%c%02x", !i ? '>' : ' ', v);
}
else
fprintf(fp,"err opening: %s, %m\n", proc_mem);
}
else
fprintf(fp,"err opening: %s, %m\n", proc_mem);
char cmd[1024], *cp = cmd;
cp += sprintf(cp, "exec gdb /proc/%d/exe -p %d --batch --quiet "
"-ex \"thread apply all info registers\" "
char cmd[1024], *cp = cmd;
cp += sprintf(cp, "exec gdb /proc/%d/exe -p %d --batch --quiet "
"-ex \"thread apply all info registers\" "
}
char *const argv[4] = { (char*) "/bin/sh", (char*) "-c", cmd, 0 };
execvp(argv[0], &argv[0]);
}
char *const argv[4] = { (char*) "/bin/sh", (char*) "-c", cmd, 0 };
execvp(argv[0], &argv[0]);