{"record":{"id":"f7447aa6bc8ee8ab","repo":"NationalSecurityAgency/ghidra","slug":"trace-already-started-f7447a","errorCode":null,"errorMessage":"Trace already started","messagePattern":"Trace already started","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-drgn/src/main/py/src/ghidradrgn/commands.py","lineNumber":123,"sourceCode":"            raise RuntimeError(\"Not connected\")\n        return self.client\n\n    def require_no_client(self) -> None:\n        if self.client != None:\n            raise RuntimeError(\"Already connected\")\n\n    def reset_client(self) -> None:\n        self.client: Optional[Client] = None\n        self.reset_trace()\n\n    def require_trace(self) -> Trace[Extra]:\n        if self.trace is None:\n            raise RuntimeError(\"No trace active\")\n        return self.trace\n\n    def require_no_trace(self) -> None:\n        if self.trace != None:\n            raise RuntimeError(\"Trace already started\")\n\n    def reset_trace(self) -> None:\n        self.trace: Optional[Trace[Extra]] = None\n        util.set_convenience_variable('_ghidra_tracing', \"false\")\n        self.reset_tx()\n\n    def require_tx(self) -> Tuple[Trace, Transaction]:\n        trace = self.require_trace()\n        if self.tx is None:\n            raise RuntimeError(\"No transaction\")\n        return trace, self.tx\n\n    def require_no_tx(self) -> None:\n        if self.tx != None:\n            raise RuntimeError(\"Transaction already started\")\n\n    def reset_tx(self) -> None:\n        self.tx: Optional[Transaction] = None","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-drgn/src/main/py/src/ghidradrgn/commands.py#L105-L141","documentation":"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.","triggerScenarios":"Calling ghidra_trace_start() while a trace is already active.","commonSituations":"Re-running a start script without stop(); a previous start that left a half-open trace.","solutions":["Call ghidra_trace_stop() before starting a new trace, or use ghidra_trace_restart().","Guard: if STATE.trace is not None: stop first.","Make start scripts idempotent by stopping any existing trace up front."],"exampleFix":"// before\nghidra_trace_start(name)  # RuntimeError: Trace already started\n// after\nif STATE.trace is not None:\n    ghidra_trace_stop()\nghidra_trace_start(name)","handlingStrategy":"validation","validationCode":"if STATE.trace is not None:\n    raise RuntimeError('trace already started; call ghidra_trace_stop first')\n# or stop first:\nif STATE.trace is not None:\n    ghidra_trace_stop()","typeGuard":"def has_no_trace() -> bool:\n    return getattr(STATE, 'trace', None) is None","tryCatchPattern":"try:\n    ghidra_trace_start(name)\nexcept RuntimeError as e:\n    if 'Trace already started' in str(e):\n        ghidra_trace_stop(); ghidra_trace_start(name)\n    else:\n        raise","preventionTips":["Call ghidra_trace_stop() (or ghidra_trace_restart) before starting a new trace.","Make start scripts idempotent: stop-if-trace, then start.","Avoid double-start from nested scripts."],"tags":["drgn","trace","state-machine","precondition"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}