{"record":{"id":"4f8bb56b703480e0","repo":"NationalSecurityAgency/ghidra","slug":"cannot-add-trace-to-a-program","errorCode":null,"errorMessage":"Cannot add Trace to a program","messagePattern":"Cannot add Trace to a program","errorType":"exception","errorClass":"LoadException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-importers/src/main/java/ghidra/app/util/opinion/TenetLoader.java","lineNumber":318,"sourceCode":"\t\t\t\t\t.appendMsg(\"%d ms to load trace | %d ms to flush cache | %d ms total time\"\n\t\t\t\t\t\t\t.formatted(loadDone - start, flushDone - loadDone, flushDone - start));\n\n\t\t\treturn new LoadResults<>(new Loaded<>(trace, settings));\n\t\t}\n\t\tcatch (final CancelledException e) {\n\t\t\tthrow e;\n\t\t}\n\t\tfinally {\n\t\t\tif (program != null) {\n\t\t\t\tprogram.release(this);\n\t\t\t}\n\t\t}\n\t}\n\n\t@Override\n\tpublic void loadInto(final Program program, final ImporterSettings settings)\n\t\t\tthrows IOException, LoadException, CancelledException {\n\t\tthrow new LoadException(\"Cannot add Trace to a program\");\n\t}\n\n\tprivate Trace loadTrace(final ByteProvider provider, final String name, final Program program,\n\t\t\tfinal Object consumer, final MessageLog log, final TaskMonitor monitor)\n\t\t\tthrows LanguageNotFoundException, IOException, CancelledException {\n\n\t\tthis.program = program;\n\t\tfinal Language lang = program.getLanguage();\n\t\tthis.defaultSpace = lang.getAddressFactory().getDefaultAddressSpace();\n\n\t\tfinal Trace trace = new DBTrace(name, program.getCompilerSpec(), consumer);\n\t\tfinal TraceObjectManager om = trace.getObjectManager();\n\n\t\ttry (Transaction tx = trace.openTransaction(\"Import Tenet Trace: %s\".formatted(name));\n\t\t\t\tBypassWriteCache bypass = om.withoutWriteCache()) {\n\n\t\t\tom.createRootObject(TENET_SESSION_SCHEMA);\n","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-importers/src/main/java/ghidra/app/util/opinion/TenetLoader.java#L300-L336","documentation":"TenetLoader.loadInto(Program, ImporterSettings) is overridden to unconditionally throw LoadException('Cannot add Trace to a program'). A Tenet trace is itself a separate Trace domain object, not something that can be merged into an existing Program; the API entry point that would imply that is therefore forbidden.","triggerScenarios":"The framework or a caller invokes loadInto(program, settings) on TenetLoader instead of the full load() that creates a new Trace. This is a deliberate API guard: trace loaders do not support adding into a program.","commonSituations":"A generic importer harness that loops over loaders and calls loadInto on each, hitting the trace loader; a script that assumed loadInto was uniformly supported across all loaders.","solutions":["Do not call loadInto on TenetLoader; use load() / loadTrace(...) which produces a new Trace domain object.","If writing a generic loader dispatcher, skip loaders whose loadInto throws this contract violation, or check the loader type first.","Report to the caller that traces are created as new domain objects, not merged into programs."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (loader instanceof TenetLoader) {\n    // use load() to create a new Trace; never loadInto()\n}","typeGuard":null,"tryCatchPattern":"try {\n    loader.loadInto(program, settings);\n} catch (LoadException e) {\n    if (e.getMessage().contains(\"Cannot add Trace to a program\")) {\n        // fall back to load() to create a standalone Trace\n    }\n}","preventionTips":["Never call loadInto on trace loaders; use load() to create a new Trace domain object.","In generic loader dispatchers, skip or special-case trace loaders for the loadInto path.","Remember traces are standalone objects, not merge targets."],"tags":["ghidra","import","loader","trace","api-contract","tenet"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}