Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pubx
delve
提交
684dc92c
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,发现更多精彩内容 >>
提交
684dc92c
编写于
3月 21, 2015
作者:
D
Derek Parker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve handling of process natural death (OS X)
上级
6b3d724f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
60 addition
and
32 deletion
+60
-32
client/cli/cli.go
client/cli/cli.go
+33
-27
proctl/proctl.go
proctl/proctl.go
+11
-0
proctl/proctl_darwin.c
proctl/proctl_darwin.c
+3
-3
proctl/proctl_darwin.go
proctl/proctl_darwin.go
+13
-2
未找到文件。
client/cli/cli.go
浏览文件 @
684dc92c
...
...
@@ -105,11 +105,15 @@ func Run(args []string) {
}
cmdstr
,
args
:=
parseCommand
(
cmdstr
)
if
cmdstr
==
"exit"
{
handleExit
(
dbp
,
t
,
0
)
}
if
dbp
.
Exited
()
&&
cmdstr
!=
"help"
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Process has already exited.
\n
"
)
continue
}
cmd
:=
cmds
.
Find
(
cmdstr
)
if
err
:=
cmd
(
dbp
,
args
...
);
err
!=
nil
{
switch
err
.
(
type
)
{
...
...
@@ -132,39 +136,41 @@ func handleExit(dbp *proctl.DebuggedProcess, t *Term, status int) {
f
.
Close
()
}
answer
,
err
:=
t
.
line
.
Prompt
(
"Would you like to kill the process? [y/n]"
)
if
err
!=
nil
{
t
.
die
(
2
,
io
.
EOF
)
}
answer
=
strings
.
TrimSuffix
(
answer
,
"
\n
"
)
for
_
,
bp
:=
range
dbp
.
HWBreakPoints
{
if
bp
==
nil
{
continue
if
!
dbp
.
Exited
()
{
for
_
,
bp
:=
range
dbp
.
HWBreakPoints
{
if
bp
==
nil
{
continue
}
if
_
,
err
:=
dbp
.
Clear
(
bp
.
Addr
);
err
!=
nil
{
fmt
.
Printf
(
"Can't clear breakpoint @%x: %s
\n
"
,
bp
.
Addr
,
err
)
}
}
if
_
,
err
:=
dbp
.
Clear
(
bp
.
Addr
);
err
!=
nil
{
fmt
.
Printf
(
"Can't clear breakpoint @%x: %s
\n
"
,
bp
.
Addr
,
err
)
for
pc
:=
range
dbp
.
BreakPoints
{
if
_
,
err
:=
dbp
.
Clear
(
pc
);
err
!=
nil
{
fmt
.
Printf
(
"Can't clear breakpoint @%x: %s
\n
"
,
pc
,
err
)
}
}
}
for
pc
:=
range
dbp
.
BreakPoints
{
if
_
,
err
:=
dbp
.
Clear
(
pc
);
err
!=
nil
{
fmt
.
Printf
(
"Can't clear breakpoint @%x: %s
\n
"
,
pc
,
err
)
answer
,
err
:=
t
.
line
.
Prompt
(
"Would you like to kill the process? [y/n]"
)
if
err
!=
nil
{
t
.
die
(
2
,
io
.
EOF
)
}
}
answer
=
strings
.
TrimSuffix
(
answer
,
"
\n
"
)
fmt
.
Println
(
"Detaching from process..."
)
err
=
sys
.
PtraceDetach
(
dbp
.
Process
.
Pid
)
if
err
!=
nil
{
t
.
die
(
2
,
"Could not detach"
,
err
)
}
fmt
.
Println
(
"Detaching from process..."
)
err
=
sys
.
PtraceDetach
(
dbp
.
Process
.
Pid
)
if
err
!=
nil
{
t
.
die
(
2
,
"Could not detach"
,
err
)
}
if
answer
==
"y"
{
fmt
.
Println
(
"Killing process"
,
dbp
.
Process
.
Pid
)
if
answer
==
"y"
{
fmt
.
Println
(
"Killing process"
,
dbp
.
Process
.
Pid
)
err
:=
dbp
.
Process
.
Kill
()
if
err
!=
nil
{
fmt
.
Println
(
"Could not kill process"
,
err
)
err
:=
dbp
.
Process
.
Kill
()
if
err
!=
nil
{
fmt
.
Println
(
"Could not kill process"
,
err
)
}
}
}
...
...
proctl/proctl.go
浏览文件 @
684dc92c
...
...
@@ -35,6 +35,7 @@ type DebuggedProcess struct {
breakpointIDCounter
int
running
bool
halt
bool
exited
bool
}
// A ManualStopError happens when the user triggers a
...
...
@@ -87,6 +88,12 @@ func Launch(cmd []string) (*DebuggedProcess, error) {
return
newDebugProcess
(
proc
.
Process
.
Pid
,
false
)
}
// Returns whether or not Delve thinks the debugged
// process has exited.
func
(
dbp
*
DebuggedProcess
)
Exited
()
bool
{
return
dbp
.
exited
}
// Returns whether or not Delve thinks the debugged
// process is currently executing.
func
(
dbp
*
DebuggedProcess
)
Running
()
bool
{
...
...
@@ -242,6 +249,7 @@ func (dbp *DebuggedProcess) Continue() error {
if
err
!=
nil
{
return
err
}
thread
,
ok
:=
dbp
.
Threads
[
wpid
]
if
!
ok
{
return
fmt
.
Errorf
(
"could not find thread for %d"
,
wpid
)
...
...
@@ -380,6 +388,9 @@ func newDebugProcess(pid int, attach bool) (*DebuggedProcess, error) {
}
func
(
dbp
*
DebuggedProcess
)
run
(
fn
func
()
error
)
error
{
if
dbp
.
exited
{
return
fmt
.
Errorf
(
"process has already exited"
)
}
dbp
.
running
=
true
dbp
.
halt
=
false
defer
func
()
{
dbp
.
running
=
false
}()
...
...
proctl/proctl_darwin.c
浏览文件 @
684dc92c
...
...
@@ -122,14 +122,14 @@ mach_port_wait(mach_port_t port_set) {
// Wait for mach msg.
kret
=
mach_msg
(
&
msg
.
hdr
,
MACH_RCV_MSG
|
MACH_RCV_INTERRUPT
,
0
,
sizeof
(
msg
.
data
),
port_set
,
0
,
MACH_PORT_NULL
);
if
(
kret
==
MACH_RCV_INTERRUPTED
||
kret
!=
MACH_MSG_SUCCESS
)
return
0
;
if
(
kret
==
MACH_RCV_INTERRUPTED
)
return
kret
;
if
(
kret
!=
MACH_MSG_SUCCESS
)
return
0
;
mach_msg_body_t
*
bod
=
(
mach_msg_body_t
*
)(
&
msg
.
hdr
+
1
);
mach_msg_port_descriptor_t
*
desc
=
(
mach_msg_port_descriptor_t
*
)(
bod
+
1
);
thread
=
desc
[
0
].
name
;
// Exception
switch
(
msg
.
hdr
.
msgh_id
)
{
case
2401
:
// Exception
kret
=
thread_suspend
(
thread
);
...
...
proctl/proctl_darwin.go
浏览文件 @
684dc92c
...
...
@@ -177,20 +177,31 @@ func (dbp *DebuggedProcess) findExecutable() (*macho.File, error) {
func
trapWait
(
dbp
*
DebuggedProcess
,
pid
int
)
(
int
,
error
)
{
port
:=
C
.
mach_port_wait
(
dbp
.
os
.
portSet
)
switch
port
{
case
C
.
MACH_RCV_INTERRUPTED
:
return
-
1
,
ManualStopError
{}
case
dbp
.
os
.
notificationPort
:
_
,
status
,
err
:=
wait
(
dbp
.
Pid
,
0
)
if
err
!=
nil
{
return
-
1
,
err
}
dbp
.
exited
=
true
return
-
1
,
ProcessExitedError
{
Pid
:
dbp
.
Pid
,
Status
:
status
.
ExitStatus
()}
case
C
.
MACH_RCV_INTERRUPTED
:
if
!
dbp
.
halt
{
// Call trapWait again, it seems
// MACH_RCV_INTERRUPTED is emitted before
// process natural death _sometimes_.
return
trapWait
(
dbp
,
pid
)
}
return
-
1
,
ManualStopError
{}
case
0
:
return
-
1
,
fmt
.
Errorf
(
"error while waiting for task"
)
}
// Since we cannot be notified of new threads on OS X
// this is as good a time as any to check for them.
dbp
.
updateThreadList
()
return
int
(
port
),
nil
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录