NationalSecurityAgency/ghidra · error · RuntimeError

Trace already started

Error message

Trace already started

What it means

Raised as RuntimeError by State.require_no_trace() when STATE.trace is already set. ghidra_trace_start() refuses to create a second trace over an existing one; you must stop the current trace first.

Source

Thrown at Ghidra/Debug/Debugger-agent-drgn/src/main/py/src/ghidradrgn/commands.py:123

            raise RuntimeError("Not connected")
        return self.client

    def require_no_client(self) -> None:
        if self.client != None:
            raise RuntimeError("Already connected")

    def reset_client(self) -> None:
        self.client: Optional[Client] = None
        self.reset_trace()

    def require_trace(self) -> Trace[Extra]:
        if self.trace is None:
            raise RuntimeError("No trace active")
        return self.trace

    def require_no_trace(self) -> None:
        if self.trace != None:
            raise RuntimeError("Trace already started")

    def reset_trace(self) -> None:
        self.trace: Optional[Trace[Extra]] = None
        util.set_convenience_variable('_ghidra_tracing', "false")
        self.reset_tx()

    def require_tx(self) -> Tuple[Trace, Transaction]:
        trace = self.require_trace()
        if self.tx is None:
            raise RuntimeError("No transaction")
        return trace, self.tx

    def require_no_tx(self) -> None:
        if self.tx != None:
            raise RuntimeError("Transaction already started")

    def reset_tx(self) -> None:
        self.tx: Optional[Transaction] = None

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Call ghidra_trace_stop() before starting a new trace, or use ghidra_trace_restart().
  2. Guard: if STATE.trace is not None: stop first.
  3. Make start scripts idempotent by stopping any existing trace up front.

Example fix

// before
ghidra_trace_start(name)  # RuntimeError: Trace already started
// after
if STATE.trace is not None:
    ghidra_trace_stop()
ghidra_trace_start(name)
Defensive patterns

Strategy: validation

Validate before calling

if STATE.trace is not None:
    raise RuntimeError('trace already started; call ghidra_trace_stop first')
# or stop first:
if STATE.trace is not None:
    ghidra_trace_stop()

Type guard

def has_no_trace() -> bool:
    return getattr(STATE, 'trace', None) is None

Try / catch

try:
    ghidra_trace_start(name)
except RuntimeError as e:
    if 'Trace already started' in str(e):
        ghidra_trace_stop(); ghidra_trace_start(name)
    else:
        raise

Prevention

When it happens

Trigger: Calling ghidra_trace_start() while a trace is already active.

Common situations: Re-running a start script without stop(); a previous start that left a half-open trace.

Related errors


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