diff --git a/_fixtures/testnextprog.go b/_fixtures/testnextprog.go index 9334f2d2..a72d4c41 100644 --- a/_fixtures/testnextprog.go +++ b/_fixtures/testnextprog.go @@ -37,7 +37,7 @@ func testnext() { func main() { runtime.LockOSThread() for { - helloworld() testnext() + fmt.Println("foo") } } diff --git a/dwarf/frame/table_test.go b/dwarf/frame/table_test.go index de8c2c68..fdfa88b2 100644 --- a/dwarf/frame/table_test.go +++ b/dwarf/frame/table_test.go @@ -56,7 +56,7 @@ func TestFindReturnAddress(t *testing.T) { syscall.PtracePeekText(p.Pid, uintptr(addr), data) addr = binary.LittleEndian.Uint64(data) - expected := uint64(0x400ed4) + expected := uint64(0x400ed3) if addr != expected { t.Fatalf("return address not found correctly, expected %#v got %#v", expected, addr) } diff --git a/proctl/proctl_linux_amd64.go b/proctl/proctl_linux_amd64.go index e322fa33..be626953 100644 --- a/proctl/proctl_linux_amd64.go +++ b/proctl/proctl_linux_amd64.go @@ -254,27 +254,28 @@ func (dbp *DebuggedProcess) Next() error { loc := dbp.DebugLine.NextLocation(pc, f, l) if !fde.Cover(loc.Address) { - // Step once to ensure we're not going to step - // into another function before returning. - pc, err = step() - if err != nil { - return err + ret := dbp.ReturnAddressFromOffset(fde.ReturnAddressOffset(pc)) + + // Attempt to step out of function. + for fde.Cover(pc) { + pc, err = step() + if err != nil { + return err + } } - if fde.Cover(pc) { - // Unconditionally step out of current function - // Don't bother looking up ret addr, next line is - // outside of current fn, should only be a few - // instructions left to RET - for fde.Cover(pc) { - pc, err = step() - if err != nil { - return err - } - } + if pc == ret { return nil } + // We have stepped into another function, return from it + // and continue single stepping through until we + // reach our real destination. + err = dbp.continueToReturnAddress(pc, fde) + if err != nil { + return err + } + } for { diff --git a/proctl/proctl_test.go b/proctl/proctl_test.go index 8bb4f9a0..10d5c8d7 100644 --- a/proctl/proctl_test.go +++ b/proctl/proctl_test.go @@ -177,9 +177,9 @@ func TestNext(t *testing.T) { {26, 27}, {27, 34}, {34, 35}, - {35, 40}, - {40, 41}, + {35, 41}, {41, 40}, + {40, 41}, } fp, err := filepath.Abs("../_fixtures/testnextprog.go")