NationalSecurityAgency/ghidra · error · JDOMException
Unknown context register
Error message
Unknown context register
What it means
Thrown by GNUExternalDisassembler when parsing the gdis options XML file: the context register named in the XML does not exist in the target Sleigh language's register set. The XML file declares a context_register element whose value is looked up via lang.getRegister(contextRegisterName), and if that returns null the JDOMException is raised. This means the gdis configuration file and the Sleigh processor specification are out of sync.
Source
Thrown at Ghidra/Extensions/SleighDevTools/src/main/java/ghidra/app/util/disassemble/GNUExternalDisassembler.java:236
//global optstring has already been parsed, so we're done
if (globalElement != null) {
Msg.info(this,
"no context register element in " + gdisOpts.getAbsolutePath());
return;
}
//no context register element or global element, error
throw new JDOMException(
"No context_register element or global element in gdis options file");
}
if (contextRegisterElement.getContentSize() == 0) {
throw new JDOMException("No context register name provided.");
}
String contextRegisterName = contextRegisterElement.getContent(0).getValue();
contextRegister = lang.getRegister(contextRegisterName);
if (contextRegister == null) {
//the context register named in the xml file does not exist in the sleigh language
//this is an error
throw new JDOMException("Unknown context register " + contextRegisterName +
" for language " + lang.getLanguageID().getIdAsString());
}
valueToOptionString = new HashMap<>();
valueToDisplayPrefix = new HashMap<>();
Element options = rootElem.getChild("options");
List<Element> optList = options.getChildren("option");
for (Element opt : optList) {
Long value = Long.decode(opt.getAttributeValue("value"));
String optString = opt.getAttributeValue("optstring");
valueToOptionString.put(value, optString);
String displayPrefix = opt.getAttributeValue("display_prefix");
valueToDisplayPrefix.put(value, displayPrefix);
}
}
catch (JDOMException e) {
Msg.error(this, "Error reading " + fileName + ": " + e.getMessage());
contextRegister = null;View on GitHub (pinned to d5f144c24d)
Solutions
- Open the gdis options XML file referenced for this language and verify the context_register element's text matches a register defined in the Sleigh .sla/.ldefs for that language.
- List the registers available via the Sleigh language (lang.getRegisters()) and replace the XML value with the correct register name.
- If the architecture genuinely has no context register, remove or adjust the context_register element so it matches the expected gdis options schema for that processor.
- Ensure the gdis config file version matches the Ghidra/Sleigh version in use — a version mismatch often renames or removes context registers.
Example fix
// before (gdis XML references stale register name) // <context_register>ctx_reg_v1</context_register> // // after — name matches the Sleigh spec's actual register // <context_register>ctx</context_register>
Defensive patterns
Strategy: validation
Validate before calling
// Before parsing the gdis options XML, verify the context register exists
String contextRegisterName = contextRegisterElement.getContent(0).getValue();
Register reg = lang.getRegister(contextRegisterName);
if (reg == null) {
// Log available registers for diagnosis, then skip or use a default
throw new JDOMException("Unknown context register '" + contextRegisterName +
"'. Available: " + lang.getRegisters());
} Try / catch
try {
// parse gdis options XML
} catch (JDOMException e) {
if (e.getMessage().startsWith("Unknown context register")) {
// surface to user: gdis config is out of sync with Sleigh language
Msg.showError(this, null, "Config Error", e.getMessage());
} else {
throw e;
}
} Prevention
- Keep gdis option XML files version-aligned with the Sleigh processor specifications they target.
- Validate the context register name against lang.getRegisters() during config load, not at disassembly time.
- Run a config smoke-test after Sleigh spec updates to catch renamed registers.
When it happens
Trigger: Parsing a gdis options XML file (via the contextRegisterElement branch) where contextRegisterElement.getContent(0).getValue() names a register that lang.getRegister() cannot resolve. The lookup happens immediately after reading the context_register element's text content.
Common situations: The gdis XML config was written for a different processor version or language variant whose register names differ; the context register was renamed in a Sleigh spec update; the XML file is copy-pasted from another architecture without updating the register name; a custom Sleigh language is used but the gdis config still references the stock register name.
Related errors
- Unknown register or label: '{nm}'
- No context_register element or global element in gdis option
- No context register name provided.
- Error: disassemble_fn is NULL. Nothing I can do.\n
- Current trace does not use Sleigh
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/396191f59d0ada5d.
Report an issue: GitHub.