{"record":{"id":"2f82a36b351d044a","repo":"NationalSecurityAgency/ghidra","slug":"given-platform-is-not-from-the-current-trace","errorCode":null,"errorMessage":"Given platform is not from the current trace","messagePattern":"Given platform is not from the current trace","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/flatapi/FlatDebuggerAPI.java","lineNumber":1104,"sourceCode":"\t * @return the list of register values, or null on error\n\t * @throws IllegalArgumentException if any name is invalid\n\t * @see #readRegisters(TracePlatform, TraceThread, int, long, Collection)\n\t */\n\tdefault List<RegisterValue> readRegistersNamed(Collection<String> names) {\n\t\treturn readRegisters(validateRegisterNames(requireCurrentTrace().getBaseLanguage(), names));\n\t}\n\n\t/**\n\t * Read a register from the current context, refreshing from the target if needed\n\t * \n\t * @param platform the platform whose language defines the register\n\t * @param register the register\n\t * @return the value, or null on error\n\t */\n\tdefault RegisterValue readRegister(TracePlatform platform, Register register) {\n\t\tDebuggerCoordinates current = getCurrentDebuggerCoordinates();\n\t\tif (platform.getTrace() != current.getTrace()) {\n\t\t\tthrow new IllegalArgumentException(\"Given platform is not from the current trace\");\n\t\t}\n\t\tLanguage language = platform.getLanguage();\n\t\tif (!register.equals(language.getRegister(register.getName()))) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\"Register \" + register + \" is not in language \" + language);\n\t\t}\n\t\treturn readRegister(platform, requireThread(current.getThread()), current.getFrame(),\n\t\t\tcurrent.getSnap(), register);\n\t}\n\n\t/**\n\t * Read a register from the current context, refreshing from the target if needed\n\t * \n\t * @param register the register\n\t * @return the value, or null on error\n\t */\n\tdefault RegisterValue readRegister(Register register) {\n\t\treturn readRegister(requireCurrentPlatform(), register);","sourceCodeStart":1086,"sourceCodeEnd":1122,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/flatapi/FlatDebuggerAPI.java#L1086-L1122","documentation":"Thrown by FlatDebuggerAPI.readRegister(platform, register) when the supplied platform's trace does not match the current trace. Register reads operate on the current debugger coordinates, so the platform must belong to that trace.","triggerScenarios":"Calling readRegister(platform, register) where platform.getTrace() differs from getCurrentDebuggerCoordinates().getTrace().","commonSituations":"Caching a platform object from a previous trace and reusing it after switching targets; passing a platform from a stale trace after a target restart.","solutions":["Obtain the platform from the current trace via getCurrentPlatform().","Before calling readRegister(), assert platform.getTrace() equals the current trace.","Discard cached platform references when the active trace changes."],"exampleFix":"// before\nTracePlatform stale = cachedPlatform;\nRegisterValue v = readRegister(stale, reg); // throws if trace changed\n\n// after\nTracePlatform platform = getCurrentPlatform();\nRegisterValue v = readRegister(platform, reg);","handlingStrategy":"validation","validationCode":"DebuggerCoordinates cur = getCurrentDebuggerCoordinates();\nif (platform.getTrace() != cur.getTrace()) {\n    throw new IllegalStateException(\n        \"Platform is not from the current trace\");\n}","typeGuard":"static boolean platformFromCurrentTrace(FlatDebuggerAPI api,\n        TracePlatform platform) {\n    return platform.getTrace() == api.getCurrentDebuggerCoordinates().getTrace();\n}","tryCatchPattern":"try {\n    RegisterValue v = readRegister(platform, reg);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"current trace\")) {\n        platform = getCurrentPlatform(); // refresh and retry\n    } else throw e;\n}","preventionTips":["Always obtain the platform via getCurrentPlatform() at call time.","Discard cached platform references when the active trace changes."],"tags":["flat-debugger-api","register","platform","trace-mismatch","debugger"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}