{"record":{"id":"cdc3e4102f1f80f3","repo":"go-delve/delve","slug":"bad-access","errorCode":null,"errorMessage":"bad access","messagePattern":"bad access","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/gdbserial/gdbserver.go","lineNumber":2225,"sourceCode":"}\n\nfunc (regs *gdbRegisters) Copy() (proc.Registers, error) {\n\tsavedRegs := &gdbRegisters{}\n\tsavedRegs.init(regs.regsInfo, regs.arch, regs.regnames)\n\tcopy(savedRegs.buf, regs.buf)\n\tcopy(savedRegs.loaded, regs.loaded)\n\treturn savedRegs, nil\n}\n\nfunc registerName(arch *proc.Arch, regNum uint64) string {\n\tregName, _, _ := arch.DwarfRegisterToString(int(regNum), nil)\n\treturn strings.ToLower(regName)\n}\n\nfunc machTargetExcToError(sig uint8) error {\n\tswitch sig {\n\tcase 0x91:\n\t\treturn errors.New(\"bad access\")\n\tcase 0x92:\n\t\treturn errors.New(\"bad instruction\")\n\tcase 0x93:\n\t\treturn errors.New(\"arithmetic exception\")\n\tcase 0x94:\n\t\treturn errors.New(\"emulation exception\")\n\tcase 0x95:\n\t\treturn errors.New(\"software exception\")\n\tcase 0x96:\n\t\treturn errors.New(\"breakpoint exception\")\n\t}\n\treturn nil\n}\n\nfunc checkRosettaExpensive() error {\n\tif runtime.GOOS != \"darwin\" {\n\t\treturn nil\n\t}","sourceCodeStart":2207,"sourceCodeEnd":2243,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/gdbserial/gdbserver.go#L2207-L2243","documentation":"machTargetExcToError maps Mach exception codes reported over the GDB remote protocol to Go errors. Code 0x91 (EXC_BAD_ACCESS) becomes 'bad access', meaning the process accessed invalid memory (the Go equivalent of a SIGSEGV).","triggerScenarios":"On macOS, the target receives a Mach exception with code 0x91 during a continue/wait; the gdbserial layer translates it into this error for the stop reason.","commonSituations":"Nil/invalid pointer dereference in the debugged program, stack overflow, or genuinely invalid memory access while debugging on macOS with the lldb backend.","solutions":["This is a real fault in the target: inspect the stopped goroutine's stack and variables to find the bad memory access.","Check for nil map/pointer use or out-of-bounds writes in the code at the stop location.","Increase stack limits if the access is a stack overflow (goroutine stacks grow, but cgo recursion can overflow).","If it appears without a real fault, check macOS version compatibility of lldb-server/delve."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"bad access\") {\n    // target hit SIGSEGV; inspect stopped goroutine state\n}","preventionTips":["Check pointers/maps for nil before dereferencing in debugged code.","Watch for stack-overflow-prone recursion (especially cgo).","Treat 'bad access' stops as real program faults, not debugger issues."],"tags":["macos","mach-exception","sigsegv","gdbserial"],"backgroundTag":"bad-memory-access","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}