Handle runtime.Breakpoint
This commit is contained in:
parent
6c7363b0ed
commit
da688b8184
11
_fixtures/testruntimebreakpoint.go
Normal file
11
_fixtures/testruntimebreakpoint.go
Normal file
@ -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 {
|
if dbp.halt {
|
||||||
return thread, nil
|
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}
|
return nil, NoBreakPointError{addr: pc}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -294,6 +294,24 @@ func TestNextFunctionReturn(t *testing.T) {
|
|||||||
testnext(testcases, "main.helloworld", 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) {
|
func TestFindReturnAddress(t *testing.T) {
|
||||||
var testfile, _ = filepath.Abs("../_fixtures/testnextprog")
|
var testfile, _ = filepath.Abs("../_fixtures/testnextprog")
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user