From bdcbcc68366980a0347eef8eb3fa959ab6ac3f2b Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Wed, 13 Oct 2021 17:44:59 +0200 Subject: [PATCH] proc: return error when assigning between function variables (#2692) Fixes #2691 --- pkg/proc/eval.go | 7 +++++++ pkg/proc/proc_test.go | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/pkg/proc/eval.go b/pkg/proc/eval.go index d67c1e68..eed01c2c 100644 --- a/pkg/proc/eval.go +++ b/pkg/proc/eval.go @@ -383,6 +383,13 @@ func (scope *EvalScope) setValue(dstv, srcv *Variable, srcExpr string) error { real, _ := constant.Float64Val(constant.Real(srcv.Value)) imag, _ := constant.Float64Val(constant.Imag(srcv.Value)) return dstv.writeComplex(real, imag, dstv.RealType.Size()) + case reflect.Func: + if dstv.RealType.Size() == 0 { + if dstv.Name != "" { + return fmt.Errorf("can not assign to %s", dstv.Name) + } + return errors.New("can not assign to function expression") + } } // nilling nillable variables diff --git a/pkg/proc/proc_test.go b/pkg/proc/proc_test.go index cf73e266..32c1f719 100644 --- a/pkg/proc/proc_test.go +++ b/pkg/proc/proc_test.go @@ -5681,3 +5681,18 @@ func TestWatchpointStackBackwardsOutOfScope(t *testing.T) { } }) } + +func TestSetOnFunctions(t *testing.T) { + // The set command between function variables should fail with an error + // Issue #2691 + withTestProcess("goroutinestackprog", t, func(p *proc.Target, fixture protest.Fixture) { + setFunctionBreakpoint(p, t, "main.main") + assertNoError(p.Continue(), t, "Continue()") + scope, err := proc.GoroutineScope(p, p.CurrentThread()) + assertNoError(err, t, "GoroutineScope") + err = scope.SetVariable("main.func1", "main.func2") + if err == nil { + t.Fatal("expected error when assigning between function variables") + } + }) +}