Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pubx
delve
提交
ab2b9ad1
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,发现更多精彩内容 >>
提交
ab2b9ad1
编写于
11月 24, 2015
作者:
A
aarzilli
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
proc: refactoring of Continue
上级
17d8aa2b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
71 addition
and
127 deletion
+71
-127
proc/proc.go
proc/proc.go
+46
-110
proc/proc_darwin.go
proc/proc_darwin.go
+9
-12
proc/proc_linux.go
proc/proc_linux.go
+2
-2
proc/threads.go
proc/threads.go
+14
-3
未找到文件。
proc/proc.go
浏览文件 @
ab2b9ad1
...
...
@@ -320,105 +320,71 @@ func (dbp *Process) setChanRecvBreakpoints() (int, error) {
return
count
,
nil
}
// Resume process
func
(
dbp
*
Process
)
Continue
()
error
{
for
{
if
err
:=
dbp
.
continueOnc
e
();
err
!=
nil
{
if
err
:=
dbp
.
resum
e
();
err
!=
nil
{
return
err
}
// if dbp.CurrentThread.CurrentBreakpoint is nil a manual stop was requested
exitAnyway
:=
(
dbp
.
CurrentThread
.
CurrentBreakpoint
==
nil
)
if
err
:=
dbp
.
runBreakpointConditions
();
err
!=
nil
{
return
err
}
if
dbp
.
CurrentThread
.
onTriggeredBreakpoint
()
{
if
dbp
.
CurrentThread
.
onTriggeredTempBreakpoint
()
{
if
err
:=
dbp
.
clearTempBreakpoints
();
err
!=
nil
{
return
err
}
}
return
nil
}
if
exitAnyway
{
return
nil
}
}
}
func
(
dbp
*
Process
)
runBreakpointConditions
()
error
{
// first thread stopped on a breakpoint with true condition
var
trigth
*
Thread
// first thread stopped on a temp breakpoint with true condition
var
tempth
*
Thread
for
_
,
th
:=
range
dbp
.
Threads
{
if
th
.
CurrentBreakpoint
==
nil
{
continue
}
th
.
BreakpointConditionMet
=
th
.
CurrentBreakpoint
.
checkCondition
(
th
)
if
th
.
onTriggeredBreakpoint
()
{
if
th
.
onTriggeredTempBreakpoint
()
{
if
tempth
==
nil
{
tempth
=
th
}
}
else
{
if
trigth
==
nil
{
trigth
=
th
}
}
}
}
// If a temp breakpoint was encountered make its thread the CurrenThread
// otherwise ensure that CurrentThread is on a triggered breakpoint if there is one
cth
:=
dbp
.
CurrentThread
var
err
error
if
tempth
!=
nil
{
if
!
cth
.
onTriggeredTempBreakpoint
()
{
err
=
dbp
.
SwitchThread
(
tempth
.
Id
)
}
}
else
if
trigth
!=
nil
{
if
!
cth
.
onTriggeredBreakpoint
()
{
err
=
dbp
.
SwitchThread
(
trigth
.
Id
)
}
}
return
err
}
var
trapthread
*
Thread
var
err
error
// Resume process, does not evaluate breakpoint conditionals
func
(
dbp
*
Process
)
continueOnce
()
error
{
if
err
:=
dbp
.
resume
();
err
!=
nil
{
return
err
}
return
dbp
.
run
(
func
()
error
{
thread
,
err
:=
dbp
.
trapWait
(
-
1
)
dbp
.
run
(
func
()
error
{
trapthread
,
err
=
dbp
.
trapWait
(
-
1
)
return
nil
})
if
err
!=
nil
{
return
err
}
if
err
:=
dbp
.
Halt
();
err
!=
nil
{
return
dbp
.
exitGuard
(
err
)
}
dbp
.
SwitchThread
(
thread
.
Id
)
if
err
:=
dbp
.
setExtraBreakpoints
();
err
!=
nil
{
if
err
:=
dbp
.
setCurrentBreakpoints
(
trapthread
);
err
!=
nil
{
return
err
}
loc
,
err
:=
thread
.
Location
()
if
err
!=
nil
{
if
err
:=
dbp
.
pickCurrentThread
(
trapthread
);
err
!=
nil
{
return
err
}
// Check to see if we hit a runtime.breakpoint
if
loc
.
Fn
!=
nil
&&
loc
.
Fn
.
Name
==
"runtime.breakpoint"
{
// Step twice to get back to user code
for
i
:=
0
;
i
<
2
;
i
++
{
if
err
=
thread
.
Step
();
err
!=
nil
{
return
err
switch
{
case
dbp
.
CurrentThread
.
CurrentBreakpoint
==
nil
:
// runtime.Breakpoint or manual stop
if
dbp
.
CurrentThread
.
onRuntimeBreakpoint
()
{
for
i
:=
0
;
i
<
2
;
i
++
{
if
err
=
dbp
.
CurrentThread
.
Step
();
err
!=
nil
{
return
err
}
}
}
return
nil
case
dbp
.
CurrentThread
.
onTriggeredTempBreakpoint
()
:
return
dbp
.
clearTempBreakpoints
()
case
dbp
.
CurrentThread
.
onTriggeredBreakpoint
()
:
return
nil
default
:
// not a manual stop, not on runtime.Breakpoint, not on a breakpoint, just repeat
}
return
nil
})
}
}
// pick a new dbp.CurrentThread, with the following priority:
// - a thread with onTriggeredTempBreakpoint() == true
// - a thread with onTriggeredBreakpoint() == true (prioritizing trapthread)
// - trapthread
func
(
dbp
*
Process
)
pickCurrentThread
(
trapthread
*
Thread
)
error
{
for
_
,
th
:=
range
dbp
.
Threads
{
if
th
.
onTriggeredTempBreakpoint
()
{
return
dbp
.
SwitchThread
(
th
.
Id
)
}
}
if
trapthread
.
onTriggeredBreakpoint
()
{
return
dbp
.
SwitchThread
(
trapthread
.
Id
)
}
for
_
,
th
:=
range
dbp
.
Threads
{
if
th
.
onTriggeredBreakpoint
()
{
return
dbp
.
SwitchThread
(
th
.
Id
)
}
}
return
dbp
.
SwitchThread
(
trapthread
.
Id
)
}
// Single step, will execute a single instruction.
...
...
@@ -667,36 +633,6 @@ func (dbp *Process) clearTempBreakpoints() error {
return
nil
}
func
(
dbp
*
Process
)
handleBreakpointOnThread
(
id
int
)
(
*
Thread
,
error
)
{
thread
,
ok
:=
dbp
.
Threads
[
id
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"could not find thread for %d"
,
id
)
}
// Check to see if we have hit a breakpoint.
err
:=
thread
.
SetCurrentBreakpoint
()
if
err
!=
nil
{
return
nil
,
err
}
if
(
thread
.
CurrentBreakpoint
!=
nil
)
||
(
dbp
.
halt
)
{
return
thread
,
nil
}
pc
,
err
:=
thread
.
PC
()
if
err
!=
nil
{
return
nil
,
err
}
fn
:=
dbp
.
goSymTable
.
PCToFunc
(
pc
)
if
fn
!=
nil
&&
fn
.
Name
==
"runtime.breakpoint"
{
for
i
:=
0
;
i
<
2
;
i
++
{
if
err
:=
thread
.
Step
();
err
!=
nil
{
return
nil
,
err
}
}
return
thread
,
nil
}
return
nil
,
NoBreakpointError
{
addr
:
pc
}
}
func
(
dbp
*
Process
)
run
(
fn
func
()
error
)
error
{
dbp
.
allGCache
=
nil
if
dbp
.
exited
{
...
...
proc/proc_darwin.go
浏览文件 @
ab2b9ad1
...
...
@@ -78,7 +78,7 @@ func Launch(cmd []string) (*Process, error) {
if
err
!=
nil
{
return
nil
,
err
}
err
=
dbp
.
continueOnc
e
()
err
=
dbp
.
Continu
e
()
return
dbp
,
err
}
...
...
@@ -295,21 +295,17 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
// 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
()
th
,
err
:=
dbp
.
handleBreakpointOnThread
(
int
(
port
))
if
err
!=
nil
{
if
_
,
ok
:=
err
.
(
NoBreakpointError
);
!
ok
{
return
nil
,
err
}
thread
:=
dbp
.
Threads
[
int
(
port
)]
th
,
ok
:=
dbp
.
Threads
[
int
(
port
)]
if
!
ok
{
if
dbp
.
halt
{
dbp
.
halt
=
false
return
th
read
,
nil
return
th
,
nil
}
if
dbp
.
firstStart
||
th
read
.
singleStepping
{
if
dbp
.
firstStart
||
th
.
singleStepping
{
dbp
.
firstStart
=
false
return
th
read
,
nil
return
th
,
nil
}
if
err
:=
th
read
.
Continue
();
err
!=
nil
{
if
err
:=
th
.
Continue
();
err
!=
nil
{
return
nil
,
err
}
continue
...
...
@@ -318,7 +314,8 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
}
}
func
(
dbp
*
Process
)
setExtraBreakpoints
()
error
{
func
(
dbp
*
Process
)
setCurrentBreakpoints
(
trapthread
*
Thread
)
error
{
trapthread
.
SetCurrentBreakpoint
()
for
{
port
:=
C
.
mach_port_wait
(
dbp
.
os
.
portSet
,
C
.
int
(
1
))
if
port
==
0
{
...
...
proc/proc_linux.go
浏览文件 @
ab2b9ad1
...
...
@@ -303,7 +303,7 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
}
if
status
.
StopSignal
()
==
sys
.
SIGTRAP
{
th
.
running
=
false
return
dbp
.
handleBreakpointOnThread
(
wpid
)
return
th
,
nil
}
if
th
!=
nil
{
// TODO(dp) alert user about unexpected signals here.
...
...
@@ -380,7 +380,7 @@ func (dbp *Process) wait(pid, options int) (int, *sys.WaitStatus, error) {
}
}
func
(
dbp
*
Process
)
set
ExtraBreakpoints
(
)
error
{
func
(
dbp
*
Process
)
set
CurrentBreakpoints
(
trapthread
*
Thread
)
error
{
for
_
,
th
:=
range
dbp
.
Threads
{
if
th
.
CurrentBreakpoint
==
nil
{
err
:=
th
.
SetCurrentBreakpoint
()
...
...
proc/threads.go
浏览文件 @
ab2b9ad1
...
...
@@ -326,10 +326,13 @@ func (thread *Thread) SetCurrentBreakpoint() error {
if
err
=
thread
.
SetPC
(
bp
.
Addr
);
err
!=
nil
{
return
err
}
if
g
,
err
:=
thread
.
GetG
();
err
==
nil
{
thread
.
CurrentBreakpoint
.
HitCount
[
g
.
Id
]
++
thread
.
BreakpointConditionMet
=
bp
.
checkCondition
(
thread
)
if
thread
.
onTriggeredBreakpoint
()
{
if
g
,
err
:=
thread
.
GetG
();
err
==
nil
{
thread
.
CurrentBreakpoint
.
HitCount
[
g
.
Id
]
++
}
thread
.
CurrentBreakpoint
.
TotalHitCount
++
}
thread
.
CurrentBreakpoint
.
TotalHitCount
++
}
return
nil
}
...
...
@@ -341,3 +344,11 @@ func (th *Thread) onTriggeredBreakpoint() bool {
func
(
th
*
Thread
)
onTriggeredTempBreakpoint
()
bool
{
return
th
.
onTriggeredBreakpoint
()
&&
th
.
CurrentBreakpoint
.
Temp
}
func
(
th
*
Thread
)
onRuntimeBreakpoint
()
bool
{
loc
,
err
:=
th
.
Location
()
if
err
!=
nil
{
return
false
}
return
loc
.
Fn
!=
nil
&&
loc
.
Fn
.
Name
==
"runtime.breakpoint"
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录