Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
HugeYuan
delve
提交
40284111
D
delve
项目概览
HugeYuan
/
delve
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
delve
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
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) {
// Detach from the process being debugged, optionally killing it.
func
(
dbp
*
Process
)
Detach
(
kill
bool
)
(
err
error
)
{
// Clean up any breakpoints we've set.
for
_
,
bp
:=
range
dbp
.
Breakpoints
{
if
bp
!=
nil
{
_
,
err
:=
dbp
.
ClearBreakpoint
(
bp
.
Addr
)
if
err
!=
nil
{
return
err
if
!
kill
{
// Clean up any breakpoints we've set.
for
_
,
bp
:=
range
dbp
.
Breakpoints
{
if
bp
!=
nil
{
_
,
err
:=
dbp
.
ClearBreakpoint
(
bp
.
Addr
)
if
err
!=
nil
{
return
err
}
}
}
}
...
...
proc/proc_darwin.go
浏览文件 @
40284111
...
...
@@ -7,6 +7,7 @@ import "C"
import
(
"debug/gosym"
"debug/macho"
"errors"
"fmt"
"os"
"os/exec"
...
...
@@ -81,6 +82,26 @@ func Launch(cmd []string) (*Process, error) {
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
)
{
var
(
task
=
C
.
mach_port_t
(
dbp
.
os
.
task
)
...
...
proc/proc_linux.go
浏览文件 @
40284111
...
...
@@ -3,6 +3,7 @@ package proc
import
(
"debug/elf"
"debug/gosym"
"errors"
"fmt"
"os"
"os/exec"
...
...
@@ -56,6 +57,22 @@ func Launch(cmd []string) (*Process, error) {
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
)
{
return
sys
.
Kill
(
dbp
.
Pid
,
sys
.
SIGTRAP
)
}
...
...
proc/proc_test.go
浏览文件 @
40284111
...
...
@@ -3,6 +3,7 @@ package proc
import
(
"bytes"
"encoding/binary"
"fmt"
"os"
"path/filepath"
"runtime"
...
...
@@ -29,7 +30,7 @@ func withTestProcess(name string, t *testing.T, fn func(p *Process, fixture prot
defer
func
()
{
p
.
Halt
()
p
.
Detach
(
true
)
p
.
Kill
(
)
}()
fn
(
p
,
fixture
)
...
...
@@ -531,3 +532,20 @@ func TestStacktraceGoroutine(t *testing.T) {
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 {
}
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
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录