提交 da688b81 编写于 作者: D Derek Parker

Handle runtime.Breakpoint

上级 6c7363b0
package main
import (
"fmt"
"runtime"
)
func main() {
runtime.Breakpoint()
fmt.Println("broke")
}
......@@ -554,6 +554,17 @@ func (dbp *DebuggedProcess) handleBreakpointOnThread(id int) (*ThreadContext, er
if dbp.halt {
return thread, nil
}
fn := dbp.goSymTable.PCToFunc(pc)
if fn != nil && fn.Name == "runtime.breakpoint" {
dbp.singleStep = true
defer func() { dbp.singleStep = false }()
for i := 0; i < 2; i++ {
if err := thread.Step(); err != nil {
return nil, err
}
}
return thread, nil
}
return nil, NoBreakPointError{addr: pc}
}
......
......@@ -294,6 +294,24 @@ func TestNextFunctionReturn(t *testing.T) {
testnext(testcases, "main.helloworld", t)
}
func TestRuntimeBreakpoint(t *testing.T) {
var testfile, _ = filepath.Abs("../_fixtures/testruntimebreakpoint")
withTestProcess(testfile, t, func(p *DebuggedProcess) {
err := p.Continue()
if err != nil {
t.Fatal(err)
}
pc, err := p.PC()
if err != nil {
t.Fatal(err)
}
_, l, _ := p.PCToLine(pc)
if l != 10 {
t.Fatal("did not respect breakpoint")
}
})
}
func TestFindReturnAddress(t *testing.T) {
var testfile, _ = filepath.Abs("../_fixtures/testnextprog")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册