Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pubx
delve
提交
40284111
D
delve
项目概览
pubx
/
delve
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
delve
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
40284111
编写于
7月 11, 2015
作者:
D
Derek Parker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Kill process outright if manually forked
上级
e6448556
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
70 addition
and
8 deletion
+70
-8
proc/proc.go
proc/proc.go
+8
-6
proc/proc_darwin.go
proc/proc_darwin.go
+21
-0
proc/proc_linux.go
proc/proc_linux.go
+17
-0
proc/proc_test.go
proc/proc_test.go
+19
-1
service/debugger/debugger.go
service/debugger/debugger.go
+5
-1
未找到文件。
proc/proc.go
浏览文件 @
40284111
...
@@ -90,12 +90,14 @@ func Attach(pid int) (*Process, error) {
...
@@ -90,12 +90,14 @@ func Attach(pid int) (*Process, error) {
// Detach from the process being debugged, optionally killing it.
// Detach from the process being debugged, optionally killing it.
func
(
dbp
*
Process
)
Detach
(
kill
bool
)
(
err
error
)
{
func
(
dbp
*
Process
)
Detach
(
kill
bool
)
(
err
error
)
{
// Clean up any breakpoints we've set.
if
!
kill
{
for
_
,
bp
:=
range
dbp
.
Breakpoints
{
// Clean up any breakpoints we've set.
if
bp
!=
nil
{
for
_
,
bp
:=
range
dbp
.
Breakpoints
{
_
,
err
:=
dbp
.
ClearBreakpoint
(
bp
.
Addr
)
if
bp
!=
nil
{
if
err
!=
nil
{
_
,
err
:=
dbp
.
ClearBreakpoint
(
bp
.
Addr
)
return
err
if
err
!=
nil
{
return
err
}
}
}
}
}
}
}
...
...
proc/proc_darwin.go
浏览文件 @
40284111
...
@@ -7,6 +7,7 @@ import "C"
...
@@ -7,6 +7,7 @@ import "C"
import
(
import
(
"debug/gosym"
"debug/gosym"
"debug/macho"
"debug/macho"
"errors"
"fmt"
"fmt"
"os"
"os"
"os/exec"
"os/exec"
...
@@ -81,6 +82,26 @@ func Launch(cmd []string) (*Process, error) {
...
@@ -81,6 +82,26 @@ func Launch(cmd []string) (*Process, error) {
return
dbp
,
err
return
dbp
,
err
}
}
func
(
dbp
*
Process
)
Kill
()
(
err
error
)
{
err
=
sys
.
Kill
(
dbp
.
Pid
,
sys
.
SIGKILL
)
if
err
!=
nil
{
return
errors
.
New
(
"could not deliver signal: "
+
err
.
Error
())
}
for
port
:=
range
dbp
.
Threads
{
if
C
.
thread_resume
(
C
.
thread_act_t
(
port
))
!=
C
.
KERN_SUCCESS
{
return
errors
.
New
(
"could not resume task"
)
}
}
for
{
port
:=
C
.
mach_port_wait
(
dbp
.
os
.
portSet
)
if
port
==
dbp
.
os
.
notificationPort
{
break
}
}
dbp
.
exited
=
true
return
}
func
(
dbp
*
Process
)
requestManualStop
()
(
err
error
)
{
func
(
dbp
*
Process
)
requestManualStop
()
(
err
error
)
{
var
(
var
(
task
=
C
.
mach_port_t
(
dbp
.
os
.
task
)
task
=
C
.
mach_port_t
(
dbp
.
os
.
task
)
...
...
proc/proc_linux.go
浏览文件 @
40284111
...
@@ -3,6 +3,7 @@ package proc
...
@@ -3,6 +3,7 @@ package proc
import
(
import
(
"debug/elf"
"debug/elf"
"debug/gosym"
"debug/gosym"
"errors"
"fmt"
"fmt"
"os"
"os"
"os/exec"
"os/exec"
...
@@ -56,6 +57,22 @@ func Launch(cmd []string) (*Process, error) {
...
@@ -56,6 +57,22 @@ func Launch(cmd []string) (*Process, error) {
return
initializeDebugProcess
(
dbp
,
proc
.
Path
,
false
)
return
initializeDebugProcess
(
dbp
,
proc
.
Path
,
false
)
}
}
func
(
dbp
*
Process
)
Kill
()
(
err
error
)
{
if
!
stopped
(
dbp
.
Pid
)
{
return
errors
.
New
(
"process must be stopped in order to kill it"
)
}
err
=
sys
.
Kill
(
dbp
.
Pid
,
sys
.
SIGKILL
)
if
err
!=
nil
{
return
errors
.
New
(
"could not deliver signal "
+
err
.
Error
())
}
_
,
_
,
err
=
wait
(
-
1
,
dbp
.
Pid
,
0
)
if
err
!=
nil
{
return
}
dbp
.
exited
=
true
return
}
func
(
dbp
*
Process
)
requestManualStop
()
(
err
error
)
{
func
(
dbp
*
Process
)
requestManualStop
()
(
err
error
)
{
return
sys
.
Kill
(
dbp
.
Pid
,
sys
.
SIGTRAP
)
return
sys
.
Kill
(
dbp
.
Pid
,
sys
.
SIGTRAP
)
}
}
...
...
proc/proc_test.go
浏览文件 @
40284111
...
@@ -3,6 +3,7 @@ package proc
...
@@ -3,6 +3,7 @@ package proc
import
(
import
(
"bytes"
"bytes"
"encoding/binary"
"encoding/binary"
"fmt"
"os"
"os"
"path/filepath"
"path/filepath"
"runtime"
"runtime"
...
@@ -29,7 +30,7 @@ func withTestProcess(name string, t *testing.T, fn func(p *Process, fixture prot
...
@@ -29,7 +30,7 @@ func withTestProcess(name string, t *testing.T, fn func(p *Process, fixture prot
defer
func
()
{
defer
func
()
{
p
.
Halt
()
p
.
Halt
()
p
.
Detach
(
true
)
p
.
Kill
(
)
}()
}()
fn
(
p
,
fixture
)
fn
(
p
,
fixture
)
...
@@ -531,3 +532,20 @@ func TestStacktraceGoroutine(t *testing.T) {
...
@@ -531,3 +532,20 @@ func TestStacktraceGoroutine(t *testing.T) {
p
.
Continue
()
p
.
Continue
()
})
})
}
}
func
TestKill
(
t
*
testing
.
T
)
{
withTestProcess
(
"testprog"
,
t
,
func
(
p
*
Process
,
fixture
protest
.
Fixture
)
{
if
err
:=
p
.
Kill
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
p
.
Exited
()
!=
true
{
t
.
Fatal
(
"expected process to have exited"
)
}
if
runtime
.
GOOS
==
"linux"
{
_
,
err
:=
os
.
Open
(
fmt
.
Sprintf
(
"/proc/%d/"
,
p
.
Pid
))
if
err
==
nil
{
t
.
Fatal
(
"process has not exited"
,
p
.
Pid
)
}
}
})
}
service/debugger/debugger.go
浏览文件 @
40284111
...
@@ -67,7 +67,11 @@ func (d *Debugger) ProcessPid() int {
...
@@ -67,7 +67,11 @@ func (d *Debugger) ProcessPid() int {
}
}
func
(
d
*
Debugger
)
Detach
(
kill
bool
)
error
{
func
(
d
*
Debugger
)
Detach
(
kill
bool
)
error
{
return
d
.
process
.
Detach
(
kill
)
if
d
.
config
.
AttachPid
!=
0
{
return
d
.
process
.
Detach
(
kill
)
}
else
{
return
d
.
process
.
Kill
()
}
}
}
func
(
d
*
Debugger
)
Restart
()
error
{
func
(
d
*
Debugger
)
Restart
()
error
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录