{"record":{"id":"2f0df32d7e4be07b","repo":"NationalSecurityAgency/ghidra","slug":"could-not-set-target-memory","errorCode":null,"errorMessage":"Could not set target memory","messagePattern":"Could not set target memory","errorType":"exception","errorClass":"ByteBlockAccessException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryBytesProvider.java","lineNumber":366,"sourceCode":"\t\t\treturn controlService != null;\n\t\t}\n\n\t\tprotected ByteBuffer alloc(int size) {\n\t\t\treturn ByteBuffer.allocate(size)\n\t\t\t\t\t.order(isBigEndian()\n\t\t\t\t\t\t\t? ByteOrder.BIG_ENDIAN\n\t\t\t\t\t\t\t: ByteOrder.LITTLE_ENDIAN);\n\t\t}\n\n\t\tprotected void doSet(Address address, ByteBuffer buffer) throws ByteBlockAccessException {\n\t\t\tcheckEditsAllowed(address, buffer.capacity());\n\t\t\ttry {\n\t\t\t\tcontrolService.createStateEditor(current)\n\t\t\t\t\t\t.setVariable(address, buffer.array())\n\t\t\t\t\t\t.get(1, TimeUnit.SECONDS);\n\t\t\t}\n\t\t\tcatch (InterruptedException | ExecutionException | TimeoutException e) {\n\t\t\t\tthrow new ByteBlockAccessException(\"Could not set target memory\", e);\n\t\t\t}\n\t\t}\n\n\t\t@Override\n\t\tpublic void setByte(BigInteger index, byte value) throws ByteBlockAccessException {\n\t\t\tdoSet(getAddress(index), alloc(Byte.BYTES).put(value));\n\t\t}\n\n\t\t@Override\n\t\tpublic void setShort(BigInteger index, short value) throws ByteBlockAccessException {\n\t\t\tdoSet(getAddress(index), alloc(Short.BYTES).putShort(value));\n\t\t}\n\n\t\t@Override\n\t\tpublic void setInt(BigInteger index, int value) throws ByteBlockAccessException {\n\t\t\tdoSet(getAddress(index), alloc(Integer.BYTES).putInt(value));\n\t\t}\n","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryBytesProvider.java#L348-L384","documentation":"Thrown by DebuggerMemoryBytesProvider.doSet when an asynchronous write to target memory via controlService.createStateEditor(...).setVariable(...) fails. The ByteBlockAccessException wraps any InterruptedException, ExecutionException, or TimeoutException (1-second deadline) from the future.","triggerScenarios":"Editing a byte in the Memory Bytes provider while the control service's state editor future times out (>1s), is interrupted, or the underlying target/emu write raises an ExecutionException.","commonSituations":"Target connection lost or unresponsive; emulator stalled; heavy I/O making the 1-second timeout too tight; writing to read-only or unmapped target memory that the backend rejects; concurrent close of the trace during edit.","solutions":["Confirm the target/emulator is alive and responsive, then retry the edit.","Verify the address being written is writable and mapped in the current coordinates.","If timeouts recur, check for a blocked target agent or a locked trace; restart the debug session.","Ensure no other transaction holds the trace open in a way that stalls the state editor."],"exampleFix":"// before\ncontrolService.createStateEditor(current)\n    .setVariable(address, buffer.array())\n    .get(1, TimeUnit.SECONDS); // may throw on timeout\n\n// after - separate the failure modes\ntry {\n    editor.setVariable(address, buffer.array()).get(1, TimeUnit.SECONDS);\n} catch (TimeoutException te) {\n    throw new ByteBlockAccessException(\"Timed out writing target memory; is the target alive?\", te);\n} catch (ExecutionException ee) {\n    throw new ByteBlockAccessException(\"Target rejected memory write\", ee.getCause());\n}","handlingStrategy":"try-catch","validationCode":"boolean writable = controlService != null && current != null;\n// also confirm address is mapped/writable via editor.isVariableWritable where available","typeGuard":null,"tryCatchPattern":"try {\n    provider.setByte(index, value);\n} catch (ByteBlockAccessException e) {\n    Throwable root = e.getCause();\n    if (root instanceof TimeoutException) { /* target slow/dead */ }\n    Msg.showError(this, null, \"Write failed\", e.getMessage(), root);\n}","preventionTips":["Confirm the target is responsive before bulk edits.","Avoid editing while the trace is being closed/switched."],"tags":["memory","target","async","timeout","write"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}