diff --git a/_fixtures/issue1615.go b/_fixtures/issue1615.go new file mode 100644 index 00000000..2550e1af --- /dev/null +++ b/_fixtures/issue1615.go @@ -0,0 +1,21 @@ +package main + +var strings = []string{ + "one", + "two", + "three", + "four", + "projects/my-gcp-project-id-string/locations/us-central1/queues/my-task-queue-name", + "five", + "six", +} + +func f(s string) { + // ... +} + +func main() { + for _, s := range strings { + f(s) + } +} diff --git a/pkg/proc/eval.go b/pkg/proc/eval.go index b3490d46..6e003532 100644 --- a/pkg/proc/eval.go +++ b/pkg/proc/eval.go @@ -983,7 +983,9 @@ func (scope *EvalScope) evalBinary(node *ast.BinaryExpr) (*Variable, error) { if err != nil { return nil, err } - xv.loadValue(loadFullValue) + if xv.Kind != reflect.String { // delay loading strings until we use them + xv.loadValue(loadFullValue) + } if xv.Unreadable != nil { return nil, xv.Unreadable } @@ -1004,7 +1006,9 @@ func (scope *EvalScope) evalBinary(node *ast.BinaryExpr) (*Variable, error) { if err != nil { return nil, err } - yv.loadValue(loadFullValue) + if yv.Kind != reflect.String { // delay loading strings until we use them + yv.loadValue(loadFullValue) + } if yv.Unreadable != nil { return nil, yv.Unreadable } @@ -1037,6 +1041,12 @@ func (scope *EvalScope) evalBinary(node *ast.BinaryExpr) (*Variable, error) { return newConstant(constant.MakeBool(v), xv.mem), nil default: + if xv.Kind == reflect.String { + xv.loadValue(loadFullValueLongerStrings) + } + if yv.Kind == reflect.String { + yv.loadValue(loadFullValueLongerStrings) + } if xv.Value == nil { return nil, fmt.Errorf("operator %s can not be applied to \"%s\"", node.Op.String(), exprToString(node.X)) } @@ -1084,6 +1094,12 @@ func compareOp(op token.Token, xv *Variable, yv *Variable) (bool, error) { return true, nil } } + if xv.Kind == reflect.String { + xv.loadValue(loadFullValueLongerStrings) + } + if yv.Kind == reflect.String { + yv.loadValue(loadFullValueLongerStrings) + } if int64(len(constant.StringVal(xv.Value))) != xv.Len || int64(len(constant.StringVal(yv.Value))) != yv.Len { return false, fmt.Errorf("string too long for comparison") } diff --git a/pkg/proc/proc_test.go b/pkg/proc/proc_test.go index ff48b8b7..4942a225 100644 --- a/pkg/proc/proc_test.go +++ b/pkg/proc/proc_test.go @@ -4448,3 +4448,19 @@ func TestIssue1601(t *testing.T) { evalVariable(p, t, "C.globalq") }) } + +func TestIssue1615(t *testing.T) { + // A breakpoint condition that tests for string equality with a constant string shouldn't fail with 'string too long for comparison' error + + withTestProcess("issue1615", t, func(p proc.Process, fixture protest.Fixture) { + bp := setFileBreakpoint(p, t, fixture, 19) + bp.Cond = &ast.BinaryExpr{ + Op: token.EQL, + X: &ast.Ident{Name: "s"}, + Y: &ast.BasicLit{Kind: token.STRING, Value: `"projects/my-gcp-project-id-string/locations/us-central1/queues/my-task-queue-name"`}, + } + + assertNoError(proc.Continue(p), t, "Continue") + assertLineNumber(p, t, 19, "") + }) +} diff --git a/pkg/proc/variables.go b/pkg/proc/variables.go index d6240053..7ea7357c 100644 --- a/pkg/proc/variables.go +++ b/pkg/proc/variables.go @@ -163,6 +163,7 @@ type LoadConfig struct { var loadSingleValue = LoadConfig{false, 0, 64, 0, 0, 0} var loadFullValue = LoadConfig{true, 1, 64, 64, -1, 0} +var loadFullValueLongerStrings = LoadConfig{true, 1, 1024 * 1024, 64, -1, 0} // G status, from: src/runtime/runtime2.go const (