NationalSecurityAgency/ghidra · error · UnsupportedOperationException

Cannot delete an undefined code unit

Error message

Cannot delete an undefined code unit

What it means

Thrown by UndefinedDBTraceData.delete() — always, unconditionally. UndefinedDBTraceData represents an ephemeral, non-persisted code unit that fills gaps in the trace listing where no defined instruction or data exists. Since it is not backed by any database table, there is nothing to delete. Calling delete() is a programming error.

Source

Thrown at Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/UndefinedDBTraceData.java:77

	 */
	public UndefinedDBTraceData(DBTrace trace, long snap, Address address, TraceThread thread,
			int frameLevel) {
		this.trace = trace;
		this.snap = snap;
		this.lifespan = Lifespan.at(snap);
		this.address = address;
		this.thread = thread;
		this.frameLevel = frameLevel;
	}

	@Override
	public AddressSpace getAddressSpace() {
		return address.getAddressSpace();
	}

	@Override
	public void delete() {
		throw new UnsupportedOperationException("Cannot delete an undefined code unit");
	}

	@Override
	public DBTrace getTrace() {
		return trace;
	}

	@Override
	public Language getLanguage() {
		return trace.getBaseLanguage();
	}

	@Override
	public TracePlatform getPlatform() {
		return trace.getPlatformManager().getHostPlatform();
	}

	@Override

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Check the code unit type before calling delete(): use instanceof to verify it is not UndefinedDBTraceData, or check getCodeUnitType() / isDefined().
  2. Only call delete() on DBTraceInstruction or defined DBTraceData instances.
  3. Filter out undefined units before processing a collection.

Example fix

// before
for (CodeUnit cu : codeUnits) {
    cu.delete();
}

// after
for (CodeUnit cu : codeUnits) {
    if (!(cu instanceof UndefinedDBTraceData)) {
        cu.delete();
    }
}
Defensive patterns

Strategy: type-guard

Type guard

// Type guard: check before calling delete()
static boolean isDeletable(CodeUnit cu) {
    return !(cu instanceof UndefinedDBTraceData);
}

// Usage:
if (isDeletable(cu)) {
    cu.delete();
}

Prevention

When it happens

Trigger: Calling delete() on any UndefinedDBTraceData instance, which is returned by the trace listing API for addresses where no defined code unit exists at a given snap. For example, iterating code units and calling delete() on one that happens to be an undefined placeholder.

Common situations: Generic code that iterates over code units and unconditionally calls delete() without checking the concrete type. Migration or cleanup scripts that try to remove all units at an address, including ephemeral ones.

Related errors


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