just-in-time debugging?
Quoted 2 lines · Tony Hoyle
Is there a way that gdb/ddd could be invoked when a program is about to dump core...?
Yes, I use that to get a symbolic stack dump after a crash, although I find that the gdb so invoked doesn't accept interactive commands, and I have to use 'kill -9' afterwards. Here's the code I use:
void dump_stack(int signum)
{
(void) signum;
char s[160];
// The right command to execute depends on the program. Adjust to taste.
system("echo 'info threads\nbt\nthread 3\nbt\nthread 4\nbt\nthread 5\nbt\n' > gdbcmd");
sprintf(s, "gdb -batch -x gdbcmd %s %d", argv0, (int) getpid());
printf("Crashed! Starting debugger to get stack dump. You may need to kill -9 this process afterwards.\n");
system(s);
exit(1);}
main() {
signal(SIGSEGV, dump_stack);
signal(SIGBUS, dump_stack);
...