{"record":{"id":"b3c633d2406d1922","repo":"NationalSecurityAgency/ghidra","slug":"cannot-add-trace-to-a-program-b3c633","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/TenetPlusPlusLoader.java","lineNumber":346,"sourceCode":"\t\t\tfinal long flushDone = System.currentTimeMillis();\n\n\t\t\tsettings.log()\n\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\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\tdefaultSpace = 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_PLUS_PLUS_SESSION_SCHEMA);\n","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-importers/src/main/java/ghidra/app/util/opinion/TenetPlusPlusLoader.java#L328-L364","documentation":"TenetPlusPlusLoader.loadInto(Program, ImporterSettings) is overridden to always throw LoadException('Cannot add Trace to a program'). A Tenet++ trace becomes its own Trace domain object and cannot be merged into an existing Program; this entry point is intentionally disabled.","triggerScenarios":"A generic importer or script calls loadInto on TenetPlusPlusLoader instead of load(). The override makes the unsupported operation fail fast.","commonSituations":"Loader-dispatch harness that assumes loadInto works for every loader; misusing the trace loader in a merge-into-program workflow.","solutions":["Use load() which creates a new Trace domain object rather than loadInto().","In a generic dispatcher, skip trace loaders for the loadInto path or detect and handle the LoadException contract.","Document that Tenet++ traces are imported as standalone Trace objects."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (loader instanceof TenetPlusPlusLoader) {\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 Tenet++ trace loaders.","Use load() to produce a standalone Trace domain object.","Handle trace loaders specially in generic dispatchers."],"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"}