diff options
author | David Xu <davidxu@FreeBSD.org> | 2012-07-09 09:24:46 +0000 |
---|---|---|
committer | David Xu <davidxu@FreeBSD.org> | 2012-07-09 09:24:46 +0000 |
commit | 5985d615565ae327e0db57e323fb1ec45dda3a65 (patch) | |
tree | 9c02ec99941b87fa63c34111d5fd647d8713252d /sys/kern/sys_process.c | |
parent | 3d184db2f82e0bfab9e52a155be9d3eb8c71382a (diff) | |
download | src-5985d615565ae327e0db57e323fb1ec45dda3a65.tar.gz src-5985d615565ae327e0db57e323fb1ec45dda3a65.zip |
If you have pressed CTRL+Z and a process is suspended, then you use gdb
to attach to the process, it is surprising that the process is resumed
without inputting any gdb commands, however ptrace manual said:
The tracing process will see the newly-traced process stop and may
then control it as if it had been traced all along.
But the current code does not work in this way, unless traced process
received a signal later, it will continue to run as a background task.
To fix this problem, just send signal SIGSTOP to the traced process after
we resumed it, this works like that you are attaching to a running process,
it is not perfect but better than nothing.
Notes
Notes:
svn path=/head/; revision=238287
Diffstat (limited to 'sys/kern/sys_process.c')
-rw-r--r-- | sys/kern/sys_process.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index 9c6c204feca4..10209ec6ff49 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -635,7 +635,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data) struct iovec iov; struct uio uio; struct proc *curp, *p, *pp; - struct thread *td2 = NULL; + struct thread *td2 = NULL, *td3; struct ptrace_io_desc *piod = NULL; struct ptrace_lwpinfo *pl; int error, write, tmp, num; @@ -953,10 +953,8 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data) td2->td_xsig = data; if (req == PT_DETACH) { - struct thread *td3; - FOREACH_THREAD_IN_PROC(p, td3) { + FOREACH_THREAD_IN_PROC(p, td3) td3->td_dbgflags &= ~TDB_SUSPEND; - } } /* * unsuspend all threads, to not let a thread run, @@ -967,6 +965,8 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data) p->p_flag &= ~(P_STOPPED_TRACE|P_STOPPED_SIG|P_WAITED); thread_unsuspend(p); PROC_SUNLOCK(p); + if (req == PT_ATTACH) + kern_psignal(p, data); } else { if (data) kern_psignal(p, data); |