Handle runtime.Breakpoint

This commit is contained in:
Derek Parker 2015-04-25 14:13:35 -05:00
parent 6c7363b0ed
commit da688b8184
3 changed files with 40 additions and 0 deletions

@ -0,0 +1,11 @@
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")