{"record":{"id":"7c6f744dd3a4b726","repo":"go-delve/delve","slug":"bad-instruction","errorCode":null,"errorMessage":"bad instruction","messagePattern":"bad instruction","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/gdbserial/gdbserver.go","lineNumber":2227,"sourceCode":"func (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}\n\tif runtime.GOARCH != \"arm64\" {\n\t\treturn nil","sourceCodeStart":2209,"sourceCodeEnd":2245,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/gdbserial/gdbserver.go#L2209-L2245","documentation":"machTargetExcToError maps Mach exception 0x92 (EXC_BAD_INSTRUCTION) to 'bad instruction', meaning the CPU executed an illegal/undefined instruction (equivalent of SIGILL).","triggerScenarios":"Target process on macOS executes an illegal opcode and the stub reports Mach exception code 0x92; delve converts it to this error as the stop reason.","commonSituations":"Executing corrupted code pages, jumping to data, architecture-mismatched binaries (e.g. x86 binary under ARM via bad translation), or deliberate UD2 traps in runtime assertions.","solutions":["Inspect where the PC stopped; verify the binary matches the host architecture (build with correct GOARCH).","Rebuild the target binary; a truncated/corrupt build can produce illegal instructions.","Check for cgo/assembly bugs jumping into non-code memory.","If using Rosetta/emulation, test natively to isolate translation issues."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"bad instruction\") {\n    // target hit SIGILL; check PC and binary arch\n}","preventionTips":["Build the target with the correct GOARCH for the host.","Rebuild binaries if code pages may be corrupt.","Avoid hand-written assembly bugs that jump into data."],"tags":["macos","mach-exception","sigill","gdbserial"],"backgroundTag":"illegal-instruction","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}