go-delve/delve · error

arithmetic exception

Error message

arithmetic exception

What it means

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).

Source

Thrown at pkg/proc/gdbserial/gdbserver.go:2229

	savedRegs.init(regs.regsInfo, regs.arch, regs.regnames)
	copy(savedRegs.buf, regs.buf)
	copy(savedRegs.loaded, regs.loaded)
	return savedRegs, nil
}

func registerName(arch *proc.Arch, regNum uint64) string {
	regName, _, _ := arch.DwarfRegisterToString(int(regNum), nil)
	return strings.ToLower(regName)
}

func machTargetExcToError(sig uint8) error {
	switch sig {
	case 0x91:
		return errors.New("bad access")
	case 0x92:
		return errors.New("bad instruction")
	case 0x93:
		return errors.New("arithmetic exception")
	case 0x94:
		return errors.New("emulation exception")
	case 0x95:
		return errors.New("software exception")
	case 0x96:
		return errors.New("breakpoint exception")
	}
	return nil
}

func checkRosettaExpensive() error {
	if runtime.GOOS != "darwin" {
		return nil
	}
	if runtime.GOARCH != "arm64" {
		return nil
	}

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Look at the stopped frame and the division instruction's divisor; add a zero check before dividing.
  2. Reproduce with plain 'go run' to get a stack trace if the fault comes from Go code.
  3. If in cgo/C code, add guards or use fp check before division in the native code.
  4. If it's expected behavior (e.g. probing), handle/avoid triggering it under the debugger.

Example fix

// before
q := a / b
// after
if b == 0 { return errors.New("division by zero") }
q := a / b
Defensive patterns

Strategy: try-catch

Validate before calling

if divisor == 0 { return errors.New("division by zero") }

Try / catch

if err != nil && strings.Contains(err.Error(), "arithmetic exception") {
    // SIGFPE: inspect the division at the stop location
}

Prevention

When it happens

Trigger: Target divides by zero or triggers another arithmetic trap on macOS; the stub reports Mach exception code 0x93 and delve surfaces this error.

Common situations: Integer division by a variable that can be zero (Go turns some into runtime panics, but cgo/assembly division raises SIGFPE directly).

Related errors


AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31). Data as JSON: /api/errors/b49898589f3faee8. Report an issue: GitHub.