{"record":{"id":"f926d05a09c7b0e9","repo":"NationalSecurityAgency/ghidra","slug":"tool-does-not-have-service-cls-this-script-shou","errorCode":null,"errorMessage":"Tool does not have service {cls}! This script should be run from the Debugger tool","messagePattern":"Tool does not have service (.+?)! This script should be run from the Debugger tool","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/flatapi/FlatDebuggerAPI.java","lineNumber":118,"sourceCode":"\t */\n\tGhidraState getState();\n\n\t/**\n\t * Require a service from the tool\n\t * \n\t * <p>\n\t * If the service is missing, an exception is thrown directing the user to run the script from\n\t * the Debugger tool.\n\t * \n\t * @param <T> the type of the service\n\t * @param cls the class of the service\n\t * @return the service\n\t * @throws IllegalStateException if the service is missing\n\t */\n\tdefault <T> T requireService(Class<T> cls) {\n\t\tT service = getState().getTool().getService(cls);\n\t\tif (service == null) {\n\t\t\tthrow new IllegalStateException(\"Tool does not have service \" + cls +\n\t\t\t\t\"! This script should be run from the Debugger tool\");\n\t\t}\n\t\treturn service;\n\t}\n\n\t/**\n\t * Get the trace manager service\n\t * \n\t * @return the service\n\t */\n\tdefault DebuggerTraceManagerService getTraceManager() {\n\t\treturn requireService(DebuggerTraceManagerService.class);\n\t}\n\n\t/**\n\t * Open the given trace in the UI\n\t * \n\t * @param trace the trace","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/flatapi/FlatDebuggerAPI.java#L100-L136","documentation":"Thrown by FlatDebuggerAPI.requireService() when the requested Ghidra tool service is not registered on the current tool. The Flat Debugger API delegates to several debugger services, all of which only exist in the Debugger tool, not in the standard CodeBrowser tool.","triggerScenarios":"Calling requireService(SomeDebuggerService.class) (or any flat API method like getTraceManager() that calls it) while the script is running under a tool that lacks that service, e.g., the default CodeBrowser tool.","commonSituations":"Running a FlatDebuggerAPI-based GhidraScript from the CodeBrowser tool instead of the Debugger tool; running in headless mode without the debugger tool configured.","solutions":["Run the script from the Debugger tool (Tool -> Run Script), not the CodeBrowser tool.","For headless use, configure the tool to include the Debugger tool, or use the Debugger headless analyzer.","Check getState().getTool() name before calling service-requiring methods to fail with a clearer message."],"exampleFix":"// before\n// script run from CodeBrowser tool -> throws\nDebuggerTraceManagerService tm = getTraceManager();\n\n// after\n// Run the script via the Debugger tool (Tools > Debugger), or:\nif (!\"Debugger\".equals(getState().getTool().getName())) {\n    println(\"Run this script from the Debugger tool\");\n    return;\n}","handlingStrategy":"validation","validationCode":"// Verify the debugger service is available before use:\nClass<?> svc = DebuggerTraceManagerService.class;\nif (getState().getTool().getService(svc) == null) {\n    throw new IllegalStateException(\n        \"Run this script from the Debugger tool, not \"\n            + getState().getTool().getName());\n}","typeGuard":null,"tryCatchPattern":"try {\n    getTraceManager();\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Debugger tool\")) {\n        println(\"Please run from the Debugger tool\");\n    } else throw e;\n}","preventionTips":["Always run FlatDebuggerAPI scripts from the Debugger tool.","For headless runs, configure the Debugger tool layout explicitly."],"tags":["flat-debugger-api","service-lookup","tool-context","debugger"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}