{"record":{"id":"8e4d3c61a6de2712","repo":"go-delve/delve","slug":"could-not-decode-first-frame","errorCode":null,"errorMessage":"could not decode first frame","messagePattern":"could not decode first frame","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":166,"sourceCode":"\t\tmaxaddr = uint64(frames[0].Regs.CFA)\n\t}\n\tif maxaddr > minaddr && maxaddr-minaddr < maxFramePrefetchSize {\n\t\tthread = cacheMemory(thread, minaddr, int(maxaddr-minaddr))\n\t}\n\n\ts := &EvalScope{Location: frames[0].Call, Regs: frames[0].Regs, Mem: thread, g: g, BinInfo: t.BinInfo(), target: t, frameOffset: frames[0].FrameOffset(), threadID: threadID}\n\ts.PC = frames[0].lastpc\n\treturn s\n}\n\n// ThreadScope returns an EvalScope for the given thread.\nfunc ThreadScope(t *Target, thread Thread) (*EvalScope, error) {\n\tlocations, err := ThreadStacktrace(t, thread, 1)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif len(locations) < 1 {\n\t\treturn nil, errors.New(\"could not decode first frame\")\n\t}\n\treturn FrameToScope(t, thread.ProcessMemory(), nil, thread.ThreadID(), locations...), nil\n}\n\n// GoroutineScope returns an EvalScope for the goroutine running on the given thread.\nfunc GoroutineScope(t *Target, thread Thread) (*EvalScope, error) {\n\tlocations, err := ThreadStacktrace(t, thread, 1)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif len(locations) < 1 {\n\t\treturn nil, errors.New(\"could not decode first frame\")\n\t}\n\tg, err := GetG(thread)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tthreadID := 0","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L148-L184","documentation":"ThreadScope builds an EvalScope for evaluating expressions in the context of a paused OS thread. It requests a 1-frame stack trace; if the trace decodes to zero frames, delve cannot determine where the thread stopped and throws this error. It is thrown when ThreadStacktrace succeeds but returns no frames, so no PC/Fn context exists to evaluate against.","triggerScenarios":"Calling ThreadScope on a thread whose stack cannot be decoded: thread stopped in code without frame metadata, thread just created/killed between attach and stack walk, or a corrupted/unreadable stack for that thread ID.","commonSituations":"Attaching to a process where a thread is stopped in a syscall stub, signal trampoline, or early runtime startup before G frames exist; debugging stripped or partially-loaded binaries; racing with thread exit during attach.","solutions":["Use GoroutineScope(t, thread) instead, which resolves the goroutine running on the thread and often succeeds where the raw thread frame decode yields nothing.","Retry after the target stops again (continue and hit a breakpoint); transient states during attach often resolve once runtime metadata is loaded.","Verify the binary has DWARF debug info (not stripped) so stack decoding can produce frames.","Enumerate valid threads with process threads / ListThreads and pick a thread that has a resolvable goroutine."],"exampleFix":"// before\nscope, err := proc.ThreadScope(t, thread)\n// after\nscope, err := proc.GoroutineScope(t, thread)\nif err != nil {\n    // thread has no decodable frames; skip or retry after next stop\n    return err\n}","handlingStrategy":"fallback","validationCode":"locs, err := proc.ThreadStacktrace(t, thread, 1)\nif err != nil || len(locs) < 1 {\n    // scope will fail; use goroutine-based scope or skip thread\n    return nil\n}","typeGuard":"func threadHasFrames(t *proc.Target, th proc.Thread) bool {\n    locs, err := proc.ThreadStacktrace(t, th, 1)\n    return err == nil && len(locs) >= 1\n}","tryCatchPattern":"scope, err := proc.ThreadScope(t, thread)\nif err != nil && strings.Contains(err.Error(), \"could not decode first frame\") {\n    scope, err = proc.GoroutineScope(t, thread)\n}\nif err != nil { return err }","preventionTips":["Prefer GoroutineScope over ThreadScope for expression evaluation","Skip threads without decodable frames when iterating all threads","Ensure binaries keep DWARF debug info","Retry evaluation on the next stop event after attach"],"tags":["go","debugger","stack-trace","eval-scope"],"backgroundTag":"empty-stack-frame","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}