From f72c48c034f8a876421a6a4b2bc2cebb3b65391c Mon Sep 17 00:00:00 2001 From: aarzilli Date: Tue, 16 Oct 2018 10:15:31 +0200 Subject: [PATCH] proc: Continue should always work after CallFunction Continue did not resume execution after a call to CallFunction if the point where the process was stopped, before the call CallFunction, was a breakpoint. Fixes #1374 --- _fixtures/issue1374.go | 12 ++++++++++++ pkg/proc/proc.go | 2 +- pkg/proc/proc_test.go | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 _fixtures/issue1374.go diff --git a/_fixtures/issue1374.go b/_fixtures/issue1374.go new file mode 100644 index 00000000..ba4501ad --- /dev/null +++ b/_fixtures/issue1374.go @@ -0,0 +1,12 @@ +package main + +import "fmt" + +func main() { + i := getNum() + fmt.Println(i) +} + +func getNum() int { + return 0 +} diff --git a/pkg/proc/proc.go b/pkg/proc/proc.go index d633e853..7d2abfbd 100644 --- a/pkg/proc/proc.go +++ b/pkg/proc/proc.go @@ -281,7 +281,7 @@ func stepInstructionOut(dbp Process, curthread Thread, fnname1, fnname2 string) if g := dbp.SelectedGoroutine(); g != nil { g.CurrentLoc = *loc } - return nil + return curthread.SetCurrentBreakpoint() } } } diff --git a/pkg/proc/proc_test.go b/pkg/proc/proc_test.go index 12bdfdaa..5865b7b1 100644 --- a/pkg/proc/proc_test.go +++ b/pkg/proc/proc_test.go @@ -4084,3 +4084,20 @@ func TestReadDeferArgs(t *testing.T) { } }) } + +func TestIssue1374(t *testing.T) { + // Continue did not work when stopped at a breakpoint immediately after calling CallFunction. + protest.MustSupportFunctionCalls(t, testBackend) + withTestProcess("issue1374", t, func(p proc.Process, fixture protest.Fixture) { + setFileBreakpoint(p, t, fixture, 7) + assertNoError(proc.Continue(p), t, "First Continue") + assertLineNumber(p, t, 7, "Did not continue to correct location (first continue),") + assertNoError(proc.CallFunction(p, "getNum()", &normalLoadConfig, true), t, "Call") + err := proc.Continue(p) + if _, isexited := err.(proc.ErrProcessExited); !isexited { + regs, _ := p.CurrentThread().Registers(false) + f, l, _ := p.BinInfo().PCToLine(regs.PC()) + t.Fatalf("expected process exited error got %v at %s:%d", err, f, l) + } + }) +}