{"record":{"id":"05a8853f50da3620","repo":"go-delve/delve","slug":"could-not-set-register-s-wrong-size-expected-d","errorCode":null,"errorMessage":"could not set register %s: wrong size, expected %d got %d","messagePattern":"could not set register (.+?): wrong size, expected (.+?) got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/gdbserial/gdbserver.go","lineNumber":2104,"sourceCode":"\tif !ok && t.p.bi.Arch.Name == \"arm64\" && regName == \"x30\" {\n\t\tgdbreg, ok = t.regs.regs[\"lr\"]\n\t}\n\tif !ok && regName == \"rflags\" {\n\t\t// rr has eflags instead of rflags\n\t\tregName = \"eflags\"\n\t\tgdbreg, ok = t.regs.regs[regName]\n\t\tif ok {\n\t\t\treg.FillBytes()\n\t\t\treg.Bytes = reg.Bytes[:4]\n\t\t}\n\t}\n\tif !ok {\n\t\treturn fmt.Errorf(\"could not set register %s: not found\", regName)\n\t}\n\treg.FillBytes()\n\n\twrongSizeErr := func(n int) error {\n\t\treturn fmt.Errorf(\"could not set register %s: wrong size, expected %d got %d\", regName, n, len(reg.Bytes))\n\t}\n\n\tif len(reg.Bytes) == len(gdbreg.value) {\n\t\tcopy(gdbreg.value, reg.Bytes)\n\t\terr := t.p.conn.writeRegister(t.strID, gdbreg.regnum, gdbreg.value)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif t.p.conn.workaroundReg != nil && len(gdbreg.value) > 16 {\n\t\t\t// This is a workaround for a bug in debugserver where register writes (P\n\t\t\t// packet) on AVX-2 and AVX-512 registers are ignored unless they are\n\t\t\t// followed by a write to an AVX register.\n\t\t\t// See:\n\t\t\t//  Issue #2767\n\t\t\t//  https://bugs.llvm.org/show_bug.cgi?id=52362\n\t\t\treg := t.regs.gdbRegisterNew(t.p.conn.workaroundReg)\n\t\t\treturn t.p.conn.writeRegister(t.strID, reg.regnum, reg.value)\n\t\t}","sourceCodeStart":2086,"sourceCodeEnd":2122,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/gdbserial/gdbserver.go#L2086-L2122","documentation":"SetReg found the register, but the value supplied by Delve has a byte length different from the stub-reported register size (gdbreg.value). The write is refused with this error specifying expected vs got sizes.","triggerScenarios":"Writing a register where the computed byte slice length disagrees with the stub's register size — commonly after the special-case truncation to 4 bytes (for 32-bit-compatible regs on 64-bit stubs) when the stub's declared size is neither the full nor the truncated size.","commonSituations":"Mixed 32/64-bit debugging where the stub declares a different register width than Delve's architecture expects; lldb-server/debugserver quirks where a register is reported at one size but must be written at another; architecture mapping bugs for less common targets (ppc64le, riscv64, loong64).","solutions":["Ensure the remote stub and the inferior architecture match (no 32-bit inferior on stub built for different register layout)","Update Delve and the stub so register sizes come from the same target.xml","Check the expected/got sizes in the message to identify which register and size mismatch and avoid writing it","If writing a 64-bit register from 32-bit-derived data, pad the value to the stub's declared size"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// size-check before writing:\nsizeOK := func(reg *proc.Register, gdbregValueLen int) bool {\n    return len(reg.Bytes) == gdbregValueLen\n}","typeGuard":null,"tryCatchPattern":"err := thread.SetReg(reg)\nif err != nil && strings.Contains(err.Error(), \"wrong size\") {\n    // pad or truncate reg.Bytes to the stub-declared size and retry\n    return fmt.Errorf(\"register size mismatch: %w\", err)\n}","preventionTips":["Ensure the remote stub binary matches the target architecture and bitness","Keep Delve and stub versions aligned so register sizes agree","Avoid 32-on-64 mixed register writes without proper padding","Read the expected/got sizes from the error to target the offending register"],"tags":["gdbserial","register","size-mismatch","gdb-remote"],"backgroundTag":"register-size-mismatch","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}