{"record":{"id":"99efb1f08710ffcf","repo":"go-delve/delve","slug":"call-is-only-supported-with-topmost-stack-frame","errorCode":null,"errorMessage":"call is only supported with topmost stack frame","messagePattern":"call is only supported with topmost stack frame","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/dap/server.go","lineNumber":3374,"sourceCode":"\t\t// these contexts are used to copy the value.\n\t\tif ctxt == \"clipboard\" || ctxt == \"variables\" {\n\t\t\topts |= showFullValue\n\t\t}\n\t\texprVal, exprRef := s.convertVariableWithOpts(exprVar, fmt.Sprintf(\"(%s)\", request.Arguments.Expression), opts, goid, frame)\n\t\tresponse.Body = dap.EvaluateResponseBody{Result: exprVal, Type: s.getTypeIfSupported(exprVar), VariablesReference: exprRef, IndexedVariables: getIndexedVariableCount(exprVar), NamedVariables: getNamedVariableCount(exprVar)}\n\t}\n\ts.send(response)\n}\n\nfunc (s *Session) doCall(goid, frame int, expr string) (*api.DebuggerState, []*proc.Variable, error) {\n\t// This call might be evaluated in the context of the frame that is not topmost\n\t// if the editor is set to view the variables for one of the parent frames.\n\t// If the call expression refers to any of these variables, unlike regular\n\t// expressions, it will evaluate them in the context of the topmost frame,\n\t// and the user will get an unexpected result or an unexpected symbol error.\n\t// We prevent this but disallowing any frames other than topmost.\n\tif frame > 0 {\n\t\treturn nil, nil, errors.New(\"call is only supported with topmost stack frame\")\n\t}\n\tstateBeforeCall, err := s.debugger.State( /*nowait*/ true)\n\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\t// The return values of injected function calls are volatile.\n\t// Load as much useful data as possible.\n\t// TODO: investigate whether we need to increase other limits. For example,\n\t// the return value is a pointer to a temporary object, which can become\n\t// invalid by other injected function calls. Do we care about such use cases?\n\tloadCfg := s.loadConfig()\n\tloadCfg.MaxStringLen = maxStringLenInCallRetVars\n\n\t// TODO(polina): since call will resume execution of all goroutines,\n\t// we should do this asynchronously and send a continued event to the\n\t// editor, followed by a stop event when the call completes.\n\tstate, err := s.debugger.Command(&api.DebuggerCommand{\n\t\tName:                 api.Call,","sourceCodeStart":3356,"sourceCodeEnd":3392,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/dap/server.go#L3356-L3392","documentation":"The DAP server's injected function-call (call) evaluation only supports expressions evaluated in the topmost stack frame. If the frameId refers to a parent frame (frame > 0), it returns this error, because variables of parent frames would silently be evaluated in the wrong (topmost) context, producing misleading results.","triggerScenarios":"Invoking a function call from a Watch/REPL/evaluate request while a non-topmost frame is selected (stackFramesId pointing to frame index > 0); drag-and-drop of a call expression onto a parent frame in the Variables view.","commonSituations":"Developers stopped deep in a call stack selecting an outer frame and typing a function call into the debug console; IDE watch expressions that reference a call while an ancestor frame is active.","solutions":["Select the topmost (innermost) stack frame before issuing the call expression","Evaluate the call after stepping until the relevant frame is topmost","Rewrite the expression to only use variables accessible from the topmost frame, or evaluate plain (non-call) expressions which work on any frame","If the call must run in an outer context, stop at a breakpoint located in that frame instead"],"exampleFix":"// before: evaluate with frameId of frame 2\n{expression: 'helper(x)', frameId: parentFrameId}\n// after: use topmost frame or a non-call expression\n{expression: 'helper(x)', frameId: topFrameId}\n{expression: 'x', frameId: parentFrameId} // plain reads are allowed on any frame","handlingStrategy":"validation","validationCode":"// only send call expressions when the selected frame is the topmost\nif selectedFrameIndex != 0 && isLikelyCall(expr) {\n    return errors.New(\"select the topmost frame to evaluate calls\")\n}","typeGuard":null,"tryCatchPattern":"if err.Error() == \"call is only supported with topmost stack frame\" {\n    // re-issue the evaluation with the topmost frameId\n}","preventionTips":["Bind call evaluation in the UI to the topmost frame only","Allow arbitrary-frame evaluation only for plain (non-call) expressions","Educate users that calls always run in the topmost frame context"],"tags":["dap","function-call","stack-frames","go"],"backgroundTag":"call-only-supported-topmost-frame","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}