{"record":{"id":"02b1d521689ea333","repo":"go-delve/delve","slug":"error-derefing-g-s","errorCode":null,"errorMessage":"error derefing *G %s","messagePattern":"error derefing \\*G (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/variables.go","lineNumber":895,"sourceCode":"\ttid int\n}\n\nfunc (ng ErrNoGoroutine) Error() string {\n\treturn fmt.Sprintf(\"no G executing on thread %d\", ng.tid)\n}\n\nvar ErrUnreadableG = errors.New(\"could not read G struct\")\n\nfunc (v *Variable) parseG() (*G, error) {\n\tmem := v.mem\n\tgaddr := v.Addr\n\t_, deref := v.RealType.(*godwarf.PtrType)\n\n\tif deref {\n\t\tvar err error\n\t\tgaddr, err = readUintRaw(mem, gaddr, int64(v.bi.Arch.PtrSize()))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error derefing *G %s\", err)\n\t\t}\n\t}\n\tif gaddr == 0 {\n\t\tid := 0\n\t\tif thread, ok := mem.(Thread); ok {\n\t\t\tid = thread.ThreadID()\n\t\t}\n\t\treturn nil, ErrNoGoroutine{tid: id}\n\t}\n\tisptr := func(t godwarf.Type) bool {\n\t\t_, ok := t.(*godwarf.PtrType)\n\t\treturn ok\n\t}\n\tfor isptr(v.RealType) {\n\t\tv = v.maybeDereference() // +rtype g\n\t}\n\n\tv.mem = cacheMemory(v.mem, v.Addr, int(v.RealType.Size()))","sourceCodeStart":877,"sourceCodeEnd":913,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/variables.go#L877-L913","documentation":"When decoding a runtime G struct, if the variable's real type is a *G pointer, the code first reads the pointer target address from memory (readUintRaw). If that raw memory read fails (unmapped memory, dead process, bad address), the error is wrapped as 'error derefing *G <cause>'. The goroutine state cannot be decoded.","triggerScenarios":"Decoding thread/goroutine state where gaddr points through a pointer whose memory read fails — reading registers or memory of a thread whose process is dying, or a corrupted g pointer.","commonSituations":"Attaching to a crashing/exiting process; core dump debugging where the G pointer references a page not in the core; corrupted runtime state from a broken binary.","solutions":["Read the wrapped cause (after 'error derefing *G ') to see the underlying memory error and act on it.","Verify the process is still alive and the attached binary matches the running one.","Retry after the target stops again; if debugging a core, confirm the core is complete (full memory dump)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"state, err := client.GetState()\nif err != nil { return err } // target must be stopped and alive before decoding goroutines\nif state.Exited { return errors.New(\"target exited; G decode impossible\") }","typeGuard":null,"tryCatchPattern":"g, err := proc.DecodeG(mem, gaddr, thread)\nif err != nil && strings.HasPrefix(err.Error(), \"error derefing *G\") {\n    // memory read failed: process dying or bad address; re-acquire state and retry once\n}","preventionTips":["Only decode goroutines while the target is fully stopped","Re-check process liveness after each continue/step","Use complete core dumps (full memory) when core debugging"],"tags":["go","debugger","memory","goroutines"],"backgroundTag":"memory-read-failed","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}