--- ac_clean/arch/um/include/kern_util.h Tue Apr 17 08:54:59 2001 +++ ac/arch/um/include/kern_util.h Tue Apr 17 18:54:43 2001 @@ -114,6 +114,7 @@ extern void kern_start_exec(int new_pid); extern void do_exitcalls(void); extern int get_restore_regs(void *t); +extern int attach_debugger(int idle_pid, int pid); #endif /* --- ac_clean/arch/um/include/user_util.h Tue Apr 17 08:54:59 2001 +++ ac/arch/um/include/user_util.h Tue Apr 17 18:55:02 2001 @@ -51,6 +51,8 @@ extern char saved_command_line[]; extern char command_line[]; +extern int gdb_pid; + extern void *open_maps(void); extern int read_map(void *fd, unsigned long *start_out, unsigned long *end_out, char *r_out, char *w_out, --- ac_clean/arch/um/kernel/trap_kern.c Tue Apr 17 08:54:59 2001 +++ ac/arch/um/kernel/trap_kern.c Tue Apr 17 18:55:47 2001 @@ -184,6 +184,19 @@ return(pid); } +int attach_debugger(int idle_pid, int pid) +{ + int status; + + if(ptrace(PTRACE_ATTACH, pid, 0, 0) < 0){ + printf("Failed to attach pid %d, errno = %d\n", pid, errno); + return(-1); + } + status = wait_for_stop(idle_pid, SIGSTOP, PTRACE_CONT); + init_proxy(pid, 1, status); + return(pid); +} + void exit_debugger(void) { close_chan_pair(&gdb_chan); --- ac_clean/arch/um/kernel/trap_user.c Tue Apr 17 08:54:59 2001 +++ ac/arch/um/kernel/trap_user.c Tue Apr 17 19:00:51 2001 @@ -57,6 +57,7 @@ int debugger_pid = -1; int debugger_fd = -1; +int gdb_pid = -1; struct { unsigned long address; @@ -103,7 +104,11 @@ tracing_pid = getpid(); printk("tracing thread pid = %d\n", tracing_pid); pid = clone(signal_tramp, sp, CLONE_FILES | SIGCHLD, init_proc); - if(debug) debugger_pid = init_ptrace_proxy(pid, 1, debug_stop); + if(debug){ + if(gdb_pid != -1) + debugger_pid = attach_debugger(pid, gdb_pid); + else debugger_pid = init_ptrace_proxy(pid, 1, debug_stop); + } set_cmdline("(tracing thread)"); if(debug_trace){ printk("Tracing thread pausing to be attached\n"); @@ -210,15 +215,12 @@ sig = 0; if(switching_modes(task)) tracing = 0; else { - if(!do_syscall(task, pid)){ - if(!tracing) - child_signal(pid, - status); - else { - tracing = 0; - sig = SIGTRAP; - break; - } + if(!tracing && (debugger_pid != -1)) + child_signal(pid, status); + else if(!do_syscall(task, pid)){ + tracing = 0; + sig = SIGTRAP; + break; } continue; } @@ -226,10 +228,16 @@ case SIGCONT: break; case SIGSEGV: + tracing = 0; + break; case SIGIO: case SIGALRM: case SIGVTALRM: case SIGFPE: + if(!tracing && debugger_pid != -1){ + child_signal(pid, status); + continue; + } tracing = 0; break; case SIGPROF: --- ac_clean/arch/um/kernel/um_arch.c Tue Apr 17 08:54:59 2001 +++ ac/arch/um/kernel/um_arch.c Tue Apr 17 18:59:52 2001 @@ -210,6 +210,9 @@ #ifdef CONFIG_PT_PROXY else if(!strncmp(argv[i], "gdb=", strlen("gdb="))) gdb_init = &argv[i][strlen("gdb=")]; + else if(!strncmp(argv[i], "gdb-pid=", strlen("gdb-pid="))) + gdb_pid = simple_strtoul(&argv[i][strlen("gdb-pid=")], + NULL, 0); #endif else if(!strncmp(argv[i], "umid=", strlen("umid="))){ create_pid_file(&argv[i][strlen("umid=")]); --- ac_clean/arch/um/ptproxy/ptrace.c Tue Apr 17 08:54:59 2001 +++ ac/arch/um/ptproxy/ptrace.c Tue Apr 17 19:00:15 2001 @@ -182,7 +182,9 @@ break; case PTRACE_SYSCALL: - debugger->result = -EINVAL; + debugger->result = ptrace (PTRACE_SYSCALL, child, arg3, arg4); + if (debugger->result == -1) + debugger->result = -errno; break; case PTRACE_TRACEME: