NationalSecurityAgency/ghidra · error · AccessPcodeExecutionException

Error reading or writing target

Error message

Error reading or writing target

What it means

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.

Source

Thrown at Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationIntegration.java:135

	 * @param access the access shim for loads and stores
	 * @param thread the trace thread for register accesses
	 * @param frame the frame for register accesses, usually 0
	 * @return the callbacks
	 */
	public static PcodeStateCallbacks bytesImmediateWriteTarget(PcodeDebuggerAccess access,
			TraceThread thread, int frame) {
		return bytesWriteMode(access, thread, frame, Mode.RW).wrapFor(null);
	}

	protected static <T> T waitTimeout(CompletableFuture<T> future) {
		try {
			return future.get(1, TimeUnit.SECONDS);
		}
		catch (TimeoutException e) {
			throw new AccessPcodeExecutionException("Timed out reading or writing target", e);
		}
		catch (InterruptedException | ExecutionException e) {
			throw new AccessPcodeExecutionException("Error reading or writing target", e);
		}
	}

	/**
	 * An extension/replacement of the {@link BytesPieceHandler} that may redirect reads and writes
	 * to/from the target.
	 * 
	 * @implNote Because piece handlers are keyed by (address-domain, value-domain), adding this to
	 *           a writer will replace the default handler.
	 */
	public static class TargetBytesPieceHandler extends BytesPieceHandler {
		protected final Mode mode;

		public TargetBytesPieceHandler(Mode mode) {
			this.mode = mode;
		}

		@Override

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Inspect the wrapped cause (getCause()/getExecutionException) to identify the real failure (connection drop, invalid address, target fault).
  2. Reconnect to / re-open the target and retry the emulation step.
  3. Validate the address is mapped and readable on the target before emulating across it.
  4. If interrupted during teardown, treat as cancellation rather than a hard failure.

Example fix

// before
try {
    access.getPcodeExecutor().execute(sleigh);
} catch (AccessPcodeExecutionException e) {
    throw e; // opaque
}

// after
try {
    access.getPcodeExecutor().execute(sleigh);
} catch (AccessPcodeExecutionException e) {
    Throwable cause = e.getCause();
    Msg.error(this, "Target access failed during emulation", cause);
    // reconnect or fall back to cached trace bytes
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate the target and address are usable before emulating across them
if (!targetService.isTargetAlive(target)) {
    throw new IllegalStateException("Target not alive");
}
if (!targetMemory.contains(addr)) {
    throw new IllegalArgumentException("Address not mapped on target: " + addr);
}

Try / catch

try {
    executor.execute(injection);
} catch (AccessPcodeExecutionException e) {
    Throwable cause = e.getCause();
    // cause is InterruptedException or ExecutionException; handle reconnect/cancel
    if (cause instanceof ExecutionException) { /* inspect cause.getCause() */ }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/98e806bbf927cd53. Report an issue: GitHub.