{"record":{"id":"98e806bbf927cd53","repo":"NationalSecurityAgency/ghidra","slug":"error-reading-or-writing-target","errorCode":null,"errorMessage":"Error reading or writing target","messagePattern":"Error reading or writing target","errorType":"exception","errorClass":"AccessPcodeExecutionException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationIntegration.java","lineNumber":135,"sourceCode":"\t * @param access the access shim for loads and stores\n\t * @param thread the trace thread for register accesses\n\t * @param frame the frame for register accesses, usually 0\n\t * @return the callbacks\n\t */\n\tpublic static PcodeStateCallbacks bytesImmediateWriteTarget(PcodeDebuggerAccess access,\n\t\t\tTraceThread thread, int frame) {\n\t\treturn bytesWriteMode(access, thread, frame, Mode.RW).wrapFor(null);\n\t}\n\n\tprotected static <T> T waitTimeout(CompletableFuture<T> future) {\n\t\ttry {\n\t\t\treturn future.get(1, TimeUnit.SECONDS);\n\t\t}\n\t\tcatch (TimeoutException e) {\n\t\t\tthrow new AccessPcodeExecutionException(\"Timed out reading or writing target\", e);\n\t\t}\n\t\tcatch (InterruptedException | ExecutionException e) {\n\t\t\tthrow new AccessPcodeExecutionException(\"Error reading or writing target\", e);\n\t\t}\n\t}\n\n\t/**\n\t * An extension/replacement of the {@link BytesPieceHandler} that may redirect reads and writes\n\t * to/from the target.\n\t * \n\t * @implNote Because piece handlers are keyed by (address-domain, value-domain), adding this to\n\t *           a writer will replace the default handler.\n\t */\n\tpublic static class TargetBytesPieceHandler extends BytesPieceHandler {\n\t\tprotected final Mode mode;\n\n\t\tpublic TargetBytesPieceHandler(Mode mode) {\n\t\t\tthis.mode = mode;\n\t\t}\n\n\t\t@Override","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationIntegration.java#L117-L153","documentation":"The same waitTimeout() wrapper catches InterruptedException and ExecutionException from future.get(1, SECONDS) and rethrows them as AccessPcodeExecutionException(\"Error reading or writing target\"). This means the asynchronous target read/write completed exceptionally (or the thread was interrupted) rather than timing out.","triggerScenarios":"Target memory read/write future completes with an ExecutionException (e.g. the debug connection threw an IOException, the target reported a memory-access error, or the address is unreadable). The emulation thread is interrupted while waiting on the target. The target service rejects the request.","commonSituations":"Debug target disconnected mid-emulation. Reading memory at an invalid/unmapped target address. Connector protocol errors or target faults during memory access. Thread interruption during shutdown of the emulation/trace plugin.","solutions":["Inspect the wrapped cause (getCause()/getExecutionException) to identify the real failure (connection drop, invalid address, target fault).","Reconnect to / re-open the target and retry the emulation step.","Validate the address is mapped and readable on the target before emulating across it.","If interrupted during teardown, treat as cancellation rather than a hard failure."],"exampleFix":"// before\ntry {\n    access.getPcodeExecutor().execute(sleigh);\n} catch (AccessPcodeExecutionException e) {\n    throw e; // opaque\n}\n\n// after\ntry {\n    access.getPcodeExecutor().execute(sleigh);\n} catch (AccessPcodeExecutionException e) {\n    Throwable cause = e.getCause();\n    Msg.error(this, \"Target access failed during emulation\", cause);\n    // reconnect or fall back to cached trace bytes\n}","handlingStrategy":"try-catch","validationCode":"// Validate the target and address are usable before emulating across them\nif (!targetService.isTargetAlive(target)) {\n    throw new IllegalStateException(\"Target not alive\");\n}\nif (!targetMemory.contains(addr)) {\n    throw new IllegalArgumentException(\"Address not mapped on target: \" + addr);\n}","typeGuard":null,"tryCatchPattern":"try {\n    executor.execute(injection);\n} catch (AccessPcodeExecutionException e) {\n    Throwable cause = e.getCause();\n    // cause is InterruptedException or ExecutionException; handle reconnect/cancel\n    if (cause instanceof ExecutionException) { /* inspect cause.getCause() */ }\n}","preventionTips":["Inspect the wrapped cause to distinguish connection loss from invalid addresses.","Reconnect/reopen the target before retrying after an ExecutionException.","Treat InterruptedException during shutdown as cancellation, not a hard error."],"tags":["emulation","target-access","pcode","io","concurrency"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}