{"record":{"id":"c1f9b51683d660ad","repo":"go-delve/delve","slug":"invalid-memory-address-or-nil-pointer-dereference","errorCode":null,"errorMessage":"invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation]\nUnable to propagate EXC_BAD_ACCESS signal to target process and panic (see https://github.com/go-delve/delve/issues/852)","messagePattern":"invalid memory address or nil pointer dereference \\[signal SIGSEGV: segmentation violation\\]\nUnable to propagate EXC_BAD_ACCESS signal to target process and panic \\(see https://github\\.com/go-delve/delve/issues/852\\)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/dap/server.go","lineNumber":4315,"sourceCode":"\t\t\tSeq:  s.getResponseSeq(),\n\t\t\tType: \"response\",\n\t\t},\n\t\tCommand:    request.Command,\n\t\tRequestSeq: request.Seq,\n\t\tSuccess:    true,\n\t}\n}\n\nfunc (s *Session) newEvent(event string) *dap.Event {\n\treturn &dap.Event{\n\t\tProtocolMessage: dap.ProtocolMessage{\n\t\t\tSeq:  s.getResponseSeq(),\n\t\t\tType: \"event\",\n\t\t},\n\t\tEvent: event,\n\t}\n}\n\nconst BetterBadAccessError = `invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation]\nUnable to propagate EXC_BAD_ACCESS signal to target process and panic (see https://github.com/go-delve/delve/issues/852)`\n\nconst BetterNextWhileNextingError = `Unable to step while the previous step is interrupted by a breakpoint.\nUse 'Continue' to resume the original step command.`\n\nfunc (s *Session) resetHandlesForStoppedEvent() {\n\ts.stackFrameHandles.reset()\n\ts.variableHandles.reset()\n\ts.referencesCollection.reset()\n\ts.exceptionErr = nil\n}\n\nfunc processExited(state *api.DebuggerState, err error) bool {\n\tvar errProcessExited proc.ErrProcessExited\n\tisexited := errors.As(err, &errProcessExited)\n\treturn isexited || err == nil && state.Exited\n}","sourceCodeStart":4297,"sourceCodeEnd":4333,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/dap/server.go#L4297-L4333","documentation":"BetterBadAccessError is a user-facing message DAP substitutes when the target process dies from EXC_BAD_ACCESS on macOS. Delve cannot re-inject the SIGSEGV so the Go runtime in the debuggee cannot convert it into a panic, so the process is killed and delve reports this augmented string to the IDE so the developer understands the real fault was a nil/invalid pointer dereference in their program.","triggerScenarios":"Debugging a Go program on macOS that dereferences a nil pointer or invalid memory address; the runtime attempts to propagate the SIGSEGV as EXC_BAD_ACCESS to the debuggee, fails, and the process dies while under DAP control.","commonSituations":"Nil map/slice/pointer dereference in a program being debugged in VS Code on macOS; regression where the app crashes only under the debugger; issue go-delve/delve#852 workarounds.","solutions":["Treat the message as a nil/invalid pointer dereference in your program and inspect the stack frames/variables in the IDE to find the offending dereference.","If the crash only reproduces under the debugger, check delve issue #852 for known macOS signal-propagation limitations and apply any recommended workaround or upgrade delve.","Run the program without the debugger to confirm the panic and get the standard Go stack trace pinpointing the line.","Upgrade delve to the latest version, as signal propagation behavior on macOS improves over releases."],"exampleFix":"// before (debuggee)\nu := cfg.Handler.Timeout * time.Second // cfg is nil\n// after\nif cfg == nil {\n    log.Fatal(\"cfg is nil\")\n}\nu := cfg.Handler.Timeout * time.Second","handlingStrategy":"try-catch","validationCode":"// Before running under DAP on macOS, pre-flight the code path that may fault:\nif debuggeeVal == nil {\n\treturn fmt.Errorf(\"refusing to launch: pointer may be nil\")\n}","typeGuard":"func isBetterBadAccessError(msg string) bool {\n\treturn strings.Contains(msg, \"EXC_BAD_ACCESS\") && strings.Contains(msg, \"SIGSEGV\")\n}","tryCatchPattern":"resp, err := client.StepIn(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"EXC_BAD_ACCESS\") {\n\t// process died from a real nil/invalid deref on macOS; signal propagation failed\n\tlog.Printf(\"target crashed with bad access: %v\", err)\n\treturn inspectFramesAndExit()\n}","preventionTips":["Fix the nil/invalid pointer dereference in the debuggee — this message always reflects a real fault in your program.","Keep delve updated so macOS EXC_BAD_ACCESS propagation improvements (issue #852) are included.","Cross-check crashes by running the program without the debugger to get the standard Go panic trace.","On macOS, test debug builds with Developer Mode/entitlements configured so signal handling works as expected."],"tags":["macos","sigsegv","nil-pointer","dap","signal-handling"],"backgroundTag":"exc-bad-access-signal-propagation","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}