{"record":{"id":"2e2db58f7f1aa670","repo":"NationalSecurityAgency/ghidra","slug":"no-context-register-element-or-global-element-in-g","errorCode":null,"errorMessage":"No context_register element or global element in gdis options file","messagePattern":"No context_register element or global element in gdis options file","errorType":"exception","errorClass":"JDOMException","httpStatus":null,"severity":"warning","filePath":"Ghidra/Extensions/SleighDevTools/src/main/java/ghidra/app/util/disassemble/GNUExternalDisassembler.java","lineNumber":225,"sourceCode":"\t\t\ttry (InputStream fis = gdisOpts.getInputStream()) {\n\t\t\t\tDocument doc = sax.build(fis);\n\t\t\t\tElement rootElem = doc.getRootElement();\n\t\t\t\tElement globalElement = rootElem.getChild(\"global\");\n\t\t\t\tif (globalElement != null) {\n\t\t\t\t\tglobalDisassemblerOptions = globalElement.getAttributeValue(\"optstring\");\n\t\t\t\t}\n\t\t\t\tElement contextRegisterElement = rootElem.getChild(\"context_register\");\n\t\t\t\tif (contextRegisterElement == null) {\n\t\t\t\t\t//no context_register element found in the xml file \n\t\t\t\t\t//this is not necessarily an error - might only be a global optstring\n\t\t\t\t\t//global optstring has already been parsed, so we're done\n\t\t\t\t\tif (globalElement != null) {\n\t\t\t\t\t\tMsg.info(this,\n\t\t\t\t\t\t\t\"no context register element in \" + gdisOpts.getAbsolutePath());\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\t//no context register element or global element, error\n\t\t\t\t\tthrow new JDOMException(\n\t\t\t\t\t\t\"No context_register element or global element in gdis options file\");\n\t\t\t\t}\n\t\t\t\tif (contextRegisterElement.getContentSize() == 0) {\n\t\t\t\t\tthrow new JDOMException(\"No context register name provided.\");\n\t\t\t\t}\n\t\t\t\tString contextRegisterName = contextRegisterElement.getContent(0).getValue();\n\t\t\t\tcontextRegister = lang.getRegister(contextRegisterName);\n\t\t\t\tif (contextRegister == null) {\n\t\t\t\t\t//the context register named in the xml file does not exist in the sleigh language\n\t\t\t\t\t//this is an error\n\t\t\t\t\tthrow new JDOMException(\"Unknown context register \" + contextRegisterName +\n\t\t\t\t\t\t\" for language \" + lang.getLanguageID().getIdAsString());\n\t\t\t\t}\n\t\t\t\tvalueToOptionString = new HashMap<>();\n\t\t\t\tvalueToDisplayPrefix = new HashMap<>();\n\t\t\t\tElement options = rootElem.getChild(\"options\");\n\t\t\t\tList<Element> optList = options.getChildren(\"option\");\n\t\t\t\tfor (Element opt : optList) {","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Extensions/SleighDevTools/src/main/java/ghidra/app/util/disassemble/GNUExternalDisassembler.java#L207-L243","documentation":"Thrown by parseGdisOptionsFile() as a JDOMException when the gdis options XML file has neither a <context_register> element nor a <global> element under the root. A <global> alone is acceptable (optstring-only); a <context_register> alone is acceptable; but the complete absence of both means the file carries no usable configuration. (This is caught internally and logged; config fields are reset.)","triggerScenarios":"A language's gdis options file (.gdis or named options file next to the .slaspec) that is empty, has only an unrelated root, or is a stub missing both required elements.","commonSituations":"Hand-editing a gdis options file and deleting both elements; a newly added language whose options file was created as a placeholder; corruption during an upgrade that stripped elements.","solutions":["Add at least a <global optstring=\"...\"/> or a properly populated <context_register> element to the options XML.","Validate the options file against a known-good one from a working language (e.g. an x86 gdis options file).","If external disassembly isn't needed for this language, remove the options file so the integration is not attempted."],"exampleFix":"<!-- before -->\n<gdis>\n</gdis>\n\n<!-- after -->\n<gdis>\n  <global optstring=\"-M\"/>\n</gdis>","handlingStrategy":"validation","validationCode":"import org.jdom2.Element;\nElement root = doc.getRootElement();\nboolean hasGlobal = root.getChild(\"global\") != null;\nboolean hasCtx = root.getChild(\"context_register\") != null;\nif (!hasGlobal && !hasCtx) {\n    // options file is empty of usable config; add one before relying on it\n}","typeGuard":"public boolean gdisOptionsHasUsableConfig(Element root) {\n    return root.getChild(\"global\") != null || root.getChild(\"context_register\") != null;\n}","tryCatchPattern":"try {\n    config.parseGdisOptionsFile(fileName);\n} catch (JDOMException e) {\n    if (e.getMessage().contains(\"context_register element or global element\")) {\n        // external disassembler disabled for this language; degrade gracefully\n    } else throw e;\n}","preventionTips":["Author gdis options files with at least a <global> or <context_register> block.","Validate the XML structure against a working language's options file.","Remove the options file if external disassembly is not required for the language."],"tags":["sleigh-devtools","external-disassembler","configuration","xml"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}