NationalSecurityAgency/ghidra · error · IllegalArgumentException

Given reference is not in this trace

Error message

Given reference is not in this trace

What it means

Thrown as IllegalArgumentException by DBTraceReferenceManager.assertIsMine when the given Reference is not a DBTraceReference, or is a DBTraceReference whose backing entry's manager is not this manager. This guarantees a reference belongs to the same trace before mutating or querying it through this manager. Foreign references (from another trace or a flat Program) are rejected.

Source

Thrown at Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/symbol/DBTraceReferenceManager.java:112

		}
		DBTraceReferenceSpace space = getReferenceSpace(entry.toAddrMin.getAddressSpace(), false);
		assert space != null;
		space.doDelXRef(entry);
	}

	protected void doSetXRefLifespan(DBTraceReferenceEntry entry) {
		if (!entry.toAddrMin.isMemoryAddress()) {
			return;
		}
		DBTraceReferenceSpace space = getReferenceSpace(entry.toAddrMin.getAddressSpace(), false);
		assert space != null;
		space.doSetXRefLifespan(entry);
	}

	// Internal
	public DBTraceReference assertIsMine(Reference ref) {
		if (!(ref instanceof DBTraceReference)) {
			throw new IllegalArgumentException("Given reference is not in this trace");
		}
		DBTraceReference dbRef = (DBTraceReference) ref;
		if (dbRef.ent.space.manager != this) {
			throw new IllegalArgumentException("Given reference is not in this trace");
		}
		return dbRef;
	}

	@Override
	public DBTraceReferenceSpace getReferenceSpace(AddressSpace space, boolean createIfAbsent) {
		return getForSpace(space, createIfAbsent);
	}

	@Override
	public DBTraceReferenceSpace getReferenceRegisterSpace(TraceThread thread,
			boolean createIfAbsent) {
		return getForRegisterSpace(thread, 0, createIfAbsent);
	}

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Obtain references only from the same trace's reference manager: trace.getReferenceManager().getReferences(...).
  2. Before asserting ownership, check ref instanceof DBTraceReference and compare its trace to yours.
  3. When copying between traces, recreate the reference on the target rather than reusing the object.

Example fix

// before
otherMgr.assertIsMine(refFromOtherTrace);
// after
Reference mine =
    trace.getReferenceManager().addReference(snap, from, to, refType);
Defensive patterns

Strategy: validation

Validate before calling

if (ref instanceof DBTraceReference) {
    DBTraceReference d = (DBTraceReference) ref;
    if (d.ent.space.manager == myMgr) {
        myMgr.assertIsMine(ref);
    }
}

Type guard

static boolean refBelongsToMgr(Reference r, DBTraceReferenceManager m) {
    return r instanceof DBTraceReference d && d.ent.space.manager == m;
}

Prevention

When it happens

Trigger: Passing a Program-style Reference into a trace reference manager; passing a DBTraceReference from traceA into traceB's manager; passing a custom Reference implementation.

Common situations: Code shared between Program and Trace APIs that forwards a Reference blindly; multi-trace sessions reusing a reference object; cross-trace copy logic.

Related errors


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