{"record":{"id":"3cca2c6355a228dc","repo":"NationalSecurityAgency/ghidra","slug":"address-address-is-not-in-inferior-inf-num","errorCode":null,"errorMessage":"Address {address} is not in inferior {inf.num}","messagePattern":"Address (.+?) is not in inferior (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/arch.py","lineNumber":235,"sourceCode":"\nclass DefaultMemoryMapper(object):\n\n    def __init__(self, defaultSpace: str) -> None:\n        self.defaultSpace = defaultSpace\n\n    def map(self, inf: gdb.Inferior, offset: int) -> Tuple[str, Address]:\n        if inf.num == 1:\n            space = self.defaultSpace\n        else:\n            space = f'{self.defaultSpace}{inf.num}'\n        return self.defaultSpace, Address(space, offset)\n\n    def map_back(self, inf: gdb.Inferior, address: Address) -> int:\n        if address.space == self.defaultSpace and inf.num == 1:\n            return address.offset\n        if address.space == f'{self.defaultSpace}{inf.num}':\n            return address.offset\n        raise ValueError(f\"Address {address} is not in inferior {inf.num}\")\n\n\nDEFAULT_MEMORY_MAPPER = DefaultMemoryMapper('ram')\n\nmemory_mappers: Dict[str, DefaultMemoryMapper] = {}\n\n\ndef compute_memory_mapper(lang: str) -> DefaultMemoryMapper:\n    if not lang in memory_mappers:\n        return DEFAULT_MEMORY_MAPPER\n    return memory_mappers[lang]\n\n\nclass DefaultRegisterMapper(object):\n\n    def __init__(self, byte_order: str) -> None:\n        if not byte_order in ['big', 'little']:\n            raise ValueError(f\"Invalid byte_order: {byte_order}\")","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/arch.py#L217-L253","documentation":"Thrown as a ValueError by map_back in the gdb agent's DefaultMemoryMapper when the Address's space field does not match either the default space (for inferior #1) or the inferior-specific space (defaultSpace + inf.num). This reverse-mapping function translates a Ghidra Address back to a local offset; a space mismatch means the address belongs to a different inferior's address space.","triggerScenarios":"Calling map_back with an Address whose space is 'ram3' while the current inferior is #2 (expected 'ram2'), or an Address with space 'ram2' while the current inferior is #1 (expected 'ram'). The check is strict: only the exact space for the given inferior number is accepted.","commonSituations":"Cross-inferior address references in multi-process GDB debugging; stale address objects cached from a previous inferior selection; address space naming mismatch after an inferior is added or removed.","solutions":["Ensure the Address object's space matches the current inferior's expected space (defaultSpace for inf 1, defaultSpace+infnum otherwise).","Re-derive the address using map() for the correct inferior before calling map_back().","Verify gdb.selected_inferior().num matches the inferior that produced the Address."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"def validate_address_for_inferior(address: Address, inf: gdb.Inferior, default_space: str) -> bool:\n    expected = default_space if inf.num == 1 else f'{default_space}{inf.num}'\n    return address.space == expected","typeGuard":null,"tryCatchPattern":"try:\n    offset = mapper.map_back(inf, address)\nexcept ValueError as e:\n    if 'is not in inferior' in str(e):\n        print(f'Address space mismatch: {address.space} vs inferior {inf.num}')\n    raise","preventionTips":["Always re-derive addresses with map() for the current inferior before calling map_back().","Do not cache Address objects across inferior selection changes.","In multi-process debugging, track which inferior produced each address."],"tags":["gdb","memory-mapping","multi-process","address-space"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}