{
pid_t pid;
int fds[2];
+
pipe(fds);
pid = fork();
}
else if (pid == 0)
{ /* child */
- char *arg[10];
+ char *arg[20];
int arg_no = 0;
char pidstr[40];
const char *cp = "backtrace: could not exec gdb";
}
arg[arg_no++] = "/usr/bin/gdb";
arg[arg_no++] = "-n";
+ arg[arg_no++] = "-batch";
+ arg[arg_no++] = "-ex";
+ arg[arg_no++] = "info threads";
+ arg[arg_no++] = "-ex";
+ arg[arg_no++] = "thread apply all bt";
arg[arg_no++] = static_progname;
sprintf(pidstr, NMEM_INT_PRINTF, (nmem_int_t) getppid());
arg[arg_no++] = pidstr;
else
{ /* parent */
- char *dbg_commands = "info threads\nthread apply all bt\n";
- int off = 0;
int sec = 0;
close(fds[0]);
- while (off < strlen(dbg_commands))
- {
- ssize_t r = write(fds[1], dbg_commands + off,
- strlen(dbg_commands) - off);
- if (r == (ssize_t) (-1))
- break;
- off += r;
- }
- close(fds[1]);
+
+ write(fds[1], "quit\n", 5);
while (1)
{
int status;
if (sec == 4)
break;
sleep(1);
+ write(fds[1], "quit\n", 5);
sec++;
}
+ close(fds[1]);
}
}
#else