proc: Breakpoint to catch unrecovered panics

Automatically sets a breakpoint on runtime.startpanic, the function
that gets called by runtime.dopanic when a panic is not recovered.

Implements #317
This commit is contained in:
aarzilli
2016-03-06 18:54:43 +01:00
parent c66c6408a5
commit c4797ea445
6 changed files with 58 additions and 6 deletions

View File

@ -269,7 +269,7 @@ func TestClearBreakpointBreakpoint(t *testing.T) {
t.Fatalf("Breakpoint was not cleared data: %#v, int3: %#v", data, int3)
}
if len(p.Breakpoints) != 0 {
if countBreakpoints(p) != 0 {
t.Fatal("Breakpoint not removed internally")
}
})
@ -279,6 +279,16 @@ type nextTest struct {
begin, end int
}
func countBreakpoints(p *Process) int {
bpcount := 0
for _, bp := range p.Breakpoints {
if bp.ID >= 0 {
bpcount++
}
}
return bpcount
}
func testnext(program string, testcases []nextTest, initialLocation string, t *testing.T) {
withTestProcess(program, t, func(p *Process, fixture protest.Fixture) {
bp, err := setFunctionBreakpoint(p, initialLocation)
@ -301,7 +311,7 @@ func testnext(program string, testcases []nextTest, initialLocation string, t *t
}
}
if len(p.Breakpoints) != 0 {
if countBreakpoints(p) != 0 {
t.Fatal("Not all breakpoints were cleaned up", len(p.Breakpoints))
}
})
@ -1635,3 +1645,13 @@ func TestIssue149(t *testing.T) {
assertNoError(err, t, "FindFileLocation()")
})
}
func TestPanicBreakpoint(t *testing.T) {
withTestProcess("panic", t, func(p *Process, fixture protest.Fixture) {
assertNoError(p.Continue(), t, "Continue()")
bp := p.CurrentBreakpoint()
if bp == nil || bp.Name != "unrecovered-panic" {
t.Fatalf("not on unrecovered-panic breakpoint: %v", p.CurrentBreakpoint)
}
})
}