{"record":{"id":"b49898589f3faee8","repo":"go-delve/delve","slug":"arithmetic-exception","errorCode":null,"errorMessage":"arithmetic exception","messagePattern":"arithmetic exception","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/gdbserial/gdbserver.go","lineNumber":2229,"sourceCode":"\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}\n\tif runtime.GOARCH != \"arm64\" {\n\t\treturn nil\n\t}\n","sourceCodeStart":2211,"sourceCodeEnd":2247,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/gdbserial/gdbserver.go#L2211-L2247","documentation":"machTargetExcToError maps Mach exception 0x93 (EXC_ARITHMETIC) to 'arithmetic exception', meaning the process hit a CPU-level arithmetic fault, on x86 typically integer division by zero (equivalent of SIGFPE).","triggerScenarios":"Target divides by zero or triggers another arithmetic trap on macOS; the stub reports Mach exception code 0x93 and delve surfaces this error.","commonSituations":"Integer division by a variable that can be zero (Go turns some into runtime panics, but cgo/assembly division raises SIGFPE directly).","solutions":["Look at the stopped frame and the division instruction's divisor; add a zero check before dividing.","Reproduce with plain 'go run' to get a stack trace if the fault comes from Go code.","If in cgo/C code, add guards or use fp check before division in the native code.","If it's expected behavior (e.g. probing), handle/avoid triggering it under the debugger."],"exampleFix":"// before\nq := a / b\n// after\nif b == 0 { return errors.New(\"division by zero\") }\nq := a / b","handlingStrategy":"try-catch","validationCode":"if divisor == 0 { return errors.New(\"division by zero\") }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"arithmetic exception\") {\n    // SIGFPE: inspect the division at the stop location\n}","preventionTips":["Guard integer divisions against zero divisors.","Be extra careful with division in cgo/assembly where Go's runtime panics don't apply.","Reproduce outside the debugger to confirm the arithmetic fault."],"tags":["macos","mach-exception","sigfpe","division-by-zero"],"backgroundTag":"arithmetic-exception","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}