Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
HugeYuan
delve
提交
e7a9daf2
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,发现更多精彩内容 >>
提交
e7a9daf2
编写于
4月 03, 2015
作者:
D
Derek Parker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Return thread directly from trapWait
上级
c6d9b0e6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
32 addition
and
36 deletion
+32
-36
proctl/proctl.go
proctl/proctl.go
+9
-20
proctl/proctl_darwin.go
proctl/proctl_darwin.go
+10
-7
proctl/proctl_linux.go
proctl/proctl_linux.go
+13
-9
未找到文件。
proctl/proctl.go
浏览文件 @
e7a9daf2
...
@@ -279,32 +279,28 @@ func (dbp *DebuggedProcess) next() error {
...
@@ -279,32 +279,28 @@ func (dbp *DebuggedProcess) next() error {
}
}
for
{
for
{
t
i
d
,
err
:=
trapWait
(
dbp
,
-
1
)
t
hrea
d
,
err
:=
trapWait
(
dbp
,
-
1
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
th
,
ok
:=
dbp
.
Threads
[
tid
]
pc
,
err
:=
thread
.
CurrentPC
()
if
!
ok
{
return
fmt
.
Errorf
(
"unknown thread %d"
,
tid
)
}
pc
,
err
:=
th
.
CurrentPC
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
// Check if we've hit a software breakpoint. If so, reset PC.
// Check if we've hit a software breakpoint. If so, reset PC.
if
err
=
th
.
clearTempBreakpoint
(
pc
-
1
);
err
!=
nil
{
if
err
=
th
read
.
clearTempBreakpoint
(
pc
-
1
);
err
!=
nil
{
return
err
return
err
}
}
// Grab the current goroutine for this thread.
// Grab the current goroutine for this thread.
tg
,
err
:=
th
.
curG
()
tg
,
err
:=
th
read
.
curG
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
// Make sure we're on the same goroutine.
// Make sure we're on the same goroutine.
// TODO(dp) take into account goroutine exit.
// TODO(dp) take into account goroutine exit.
if
tg
.
id
==
curg
.
id
{
if
tg
.
id
==
curg
.
id
{
if
dbp
.
CurrentThread
.
Id
!=
ti
d
{
if
dbp
.
CurrentThread
!=
threa
d
{
dbp
.
SwitchThread
(
t
i
d
)
dbp
.
SwitchThread
(
t
hread
.
I
d
)
}
}
break
break
}
}
...
@@ -322,20 +318,13 @@ func (dbp *DebuggedProcess) Continue() error {
...
@@ -322,20 +318,13 @@ func (dbp *DebuggedProcess) Continue() error {
}
}
fn
:=
func
()
error
{
fn
:=
func
()
error
{
wpi
d
,
err
:=
trapWait
(
dbp
,
-
1
)
threa
d
,
err
:=
trapWait
(
dbp
,
-
1
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
dbp
.
CurrentThread
!=
thread
{
thread
,
ok
:=
dbp
.
Threads
[
wpid
]
dbp
.
SwitchThread
(
thread
.
Id
)
if
!
ok
{
return
fmt
.
Errorf
(
"could not find thread for %d"
,
wpid
)
}
if
wpid
!=
dbp
.
CurrentThread
.
Id
{
dbp
.
SwitchThread
(
wpid
)
}
}
pc
,
err
:=
thread
.
CurrentPC
()
pc
,
err
:=
thread
.
CurrentPC
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
proctl/proctl_darwin.go
浏览文件 @
e7a9daf2
...
@@ -171,17 +171,17 @@ func (dbp *DebuggedProcess) findExecutable() (*macho.File, error) {
...
@@ -171,17 +171,17 @@ func (dbp *DebuggedProcess) findExecutable() (*macho.File, error) {
return
exe
,
nil
return
exe
,
nil
}
}
func
trapWait
(
dbp
*
DebuggedProcess
,
pid
int
)
(
in
t
,
error
)
{
func
trapWait
(
dbp
*
DebuggedProcess
,
pid
int
)
(
*
ThreadContex
t
,
error
)
{
port
:=
C
.
mach_port_wait
(
dbp
.
os
.
portSet
)
port
:=
C
.
mach_port_wait
(
dbp
.
os
.
portSet
)
switch
port
{
switch
port
{
case
dbp
.
os
.
notificationPort
:
case
dbp
.
os
.
notificationPort
:
_
,
status
,
err
:=
wait
(
dbp
.
Pid
,
0
)
_
,
status
,
err
:=
wait
(
dbp
.
Pid
,
0
)
if
err
!=
nil
{
if
err
!=
nil
{
return
-
1
,
err
return
nil
,
err
}
}
dbp
.
exited
=
true
dbp
.
exited
=
true
return
-
1
,
ProcessExitedError
{
Pid
:
dbp
.
Pid
,
Status
:
status
.
ExitStatus
()}
return
nil
,
ProcessExitedError
{
Pid
:
dbp
.
Pid
,
Status
:
status
.
ExitStatus
()}
case
C
.
MACH_RCV_INTERRUPTED
:
case
C
.
MACH_RCV_INTERRUPTED
:
if
!
dbp
.
halt
{
if
!
dbp
.
halt
{
// Call trapWait again, it seems
// Call trapWait again, it seems
...
@@ -189,16 +189,19 @@ func trapWait(dbp *DebuggedProcess, pid int) (int, error) {
...
@@ -189,16 +189,19 @@ func trapWait(dbp *DebuggedProcess, pid int) (int, error) {
// process natural death _sometimes_.
// process natural death _sometimes_.
return
trapWait
(
dbp
,
pid
)
return
trapWait
(
dbp
,
pid
)
}
}
return
-
1
,
ManualStopError
{}
return
nil
,
ManualStopError
{}
case
0
:
case
0
:
return
-
1
,
fmt
.
Errorf
(
"error while waiting for task"
)
return
nil
,
fmt
.
Errorf
(
"error while waiting for task"
)
}
}
// Since we cannot be notified of new threads on OS X
// Since we cannot be notified of new threads on OS X
// this is as good a time as any to check for them.
// this is as good a time as any to check for them.
dbp
.
updateThreadList
()
dbp
.
updateThreadList
()
thread
,
ok
:=
dbp
.
Threads
[
int
(
port
)]
return
int
(
port
),
nil
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"could not find thread for %d"
,
port
)
}
return
thread
,
nil
}
}
func
wait
(
pid
,
options
int
)
(
int
,
*
sys
.
WaitStatus
,
error
)
{
func
wait
(
pid
,
options
int
)
(
int
,
*
sys
.
WaitStatus
,
error
)
{
...
...
proctl/proctl_linux.go
浏览文件 @
e7a9daf2
...
@@ -216,11 +216,11 @@ func stopped(pid int) bool {
...
@@ -216,11 +216,11 @@ func stopped(pid int) bool {
return
false
return
false
}
}
func
trapWait
(
dbp
*
DebuggedProcess
,
pid
int
)
(
in
t
,
error
)
{
func
trapWait
(
dbp
*
DebuggedProcess
,
pid
int
)
(
*
ThreadContex
t
,
error
)
{
for
{
for
{
wpid
,
status
,
err
:=
wait
(
pid
,
0
)
wpid
,
status
,
err
:=
wait
(
pid
,
0
)
if
err
!=
nil
{
if
err
!=
nil
{
return
-
1
,
fmt
.
Errorf
(
"wait err %s %d"
,
err
,
pid
)
return
nil
,
fmt
.
Errorf
(
"wait err %s %d"
,
err
,
pid
)
}
}
if
wpid
==
0
{
if
wpid
==
0
{
continue
continue
...
@@ -231,37 +231,41 @@ func trapWait(dbp *DebuggedProcess, pid int) (int, error) {
...
@@ -231,37 +231,41 @@ func trapWait(dbp *DebuggedProcess, pid int) (int, error) {
if
status
.
Exited
()
&&
wpid
==
dbp
.
Pid
{
if
status
.
Exited
()
&&
wpid
==
dbp
.
Pid
{
dbp
.
exited
=
true
dbp
.
exited
=
true
return
-
1
,
ProcessExitedError
{
Pid
:
wpid
,
Status
:
status
.
ExitStatus
()}
return
nil
,
ProcessExitedError
{
Pid
:
wpid
,
Status
:
status
.
ExitStatus
()}
}
}
if
status
.
StopSignal
()
==
sys
.
SIGTRAP
&&
status
.
TrapCause
()
==
sys
.
PTRACE_EVENT_CLONE
{
if
status
.
StopSignal
()
==
sys
.
SIGTRAP
&&
status
.
TrapCause
()
==
sys
.
PTRACE_EVENT_CLONE
{
// A traced thread has cloned a new thread, grab the pid and
// A traced thread has cloned a new thread, grab the pid and
// add it to our list of traced threads.
// add it to our list of traced threads.
cloned
,
err
:=
sys
.
PtraceGetEventMsg
(
wpid
)
cloned
,
err
:=
sys
.
PtraceGetEventMsg
(
wpid
)
if
err
!=
nil
{
if
err
!=
nil
{
return
-
1
,
fmt
.
Errorf
(
"could not get event message: %s"
,
err
)
return
nil
,
fmt
.
Errorf
(
"could not get event message: %s"
,
err
)
}
}
th
,
err
:=
dbp
.
addThread
(
int
(
cloned
),
false
)
th
,
err
:=
dbp
.
addThread
(
int
(
cloned
),
false
)
if
err
!=
nil
{
if
err
!=
nil
{
return
-
1
,
err
return
nil
,
err
}
}
err
=
th
.
Continue
()
err
=
th
.
Continue
()
if
err
!=
nil
{
if
err
!=
nil
{
return
-
1
,
fmt
.
Errorf
(
"could not continue new thread %d %s"
,
cloned
,
err
)
return
nil
,
fmt
.
Errorf
(
"could not continue new thread %d %s"
,
cloned
,
err
)
}
}
err
=
dbp
.
Threads
[
int
(
wpid
)]
.
Continue
()
err
=
dbp
.
Threads
[
int
(
wpid
)]
.
Continue
()
if
err
!=
nil
{
if
err
!=
nil
{
return
-
1
,
fmt
.
Errorf
(
"could not continue new thread %d %s"
,
cloned
,
err
)
return
nil
,
fmt
.
Errorf
(
"could not continue new thread %d %s"
,
cloned
,
err
)
}
}
continue
continue
}
}
if
status
.
StopSignal
()
==
sys
.
SIGTRAP
{
if
status
.
StopSignal
()
==
sys
.
SIGTRAP
{
return
wpid
,
nil
thread
,
ok
:=
dbp
.
Threads
[
wpid
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"could not find thread for %d"
,
wpid
)
}
return
thread
,
nil
}
}
if
status
.
StopSignal
()
==
sys
.
SIGSTOP
&&
dbp
.
halt
{
if
status
.
StopSignal
()
==
sys
.
SIGSTOP
&&
dbp
.
halt
{
return
-
1
,
ManualStopError
{}
return
nil
,
ManualStopError
{}
}
}
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录