{"record":{"id":"f1c49f306faf91d8","repo":"NationalSecurityAgency/ghidra","slug":"object-is-not-err-msg-f1c49f","errorCode":null,"errorMessage":"{object} is not {err_msg}","messagePattern":"(.+?) is not (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/methods.py","lineNumber":89,"sourceCode":"BREAK_LOC_PATTERN = extre(BREAKPOINT_PATTERN, '\\\\[(?P<locnum>\\\\d*)\\\\]')\nINFERIOR_PATTERN = re.compile('Inferiors\\\\[(?P<infnum>\\\\d*)\\\\]')\nINF_BREAKS_PATTERN = extre(INFERIOR_PATTERN, '\\\\.Breakpoints')\nENV_PATTERN = extre(INFERIOR_PATTERN, '\\\\.Environment')\nTHREADS_PATTERN = extre(INFERIOR_PATTERN, '\\\\.Threads')\nTHREAD_PATTERN = extre(THREADS_PATTERN, '\\\\[(?P<tnum>\\\\d*)\\\\]')\nSTACK_PATTERN = extre(THREAD_PATTERN, '\\\\.Stack')\nFRAME_PATTERN = extre(STACK_PATTERN, '\\\\[(?P<level>\\\\d*)\\\\]')\nREGS_PATTERN = extre(FRAME_PATTERN, '\\\\.Registers')\nMEMORY_PATTERN = extre(INFERIOR_PATTERN, '\\\\.Memory')\nMODULES_PATTERN = extre(INFERIOR_PATTERN, '\\\\.Modules')\nMODULE_PATTERN = extre(MODULES_PATTERN, '\\\\[(?P<modname>.*)\\\\]')\n\n\ndef find_availpid_by_pattern(pattern: re.Pattern, object: TraceObject,\n                             err_msg: str) -> int:\n    mat = pattern.fullmatch(object.path)\n    if mat is None:\n        raise TypeError(f\"{object} is not {err_msg}\")\n    pid = int(mat['pid'])\n    return pid\n\n\ndef find_availpid_by_obj(object: TraceObject) -> int:\n    return find_availpid_by_pattern(AVAILABLE_PATTERN, object, \"an Available\")\n\n\ndef find_inf_by_num(infnum: int) -> gdb.Inferior:\n    for inf in gdb.inferiors():\n        if inf.num == infnum:\n            return inf\n    raise KeyError(f\"Inferiors[{infnum}] does not exist\")\n\n\ndef find_inf_by_pattern(object: TraceObject, pattern: re.Pattern,\n                        err_msg: str) -> gdb.Inferior:\n    mat = pattern.fullmatch(object.path)","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/methods.py#L71-L107","documentation":"Thrown as a TypeError by find_availpid_by_pattern in the gdb agent when a TraceObject's path does not match the AVAILABLE_PATTERN regex. This function extracts a PID from the object's path in the Available processes tree; a non-matching path means the object does not represent an available process.","triggerScenarios":"Passing a TraceObject whose path is an Inferior path ('Inferiors[1]') or a thread path when an Available process path ('Available[1234]') is expected. The regex fullmatch fails and TypeError is raised.","commonSituations":"Using an Inferior object where an Available object is required; the path was constructed from the wrong tree node; Ghidra UI passed the wrong object type.","solutions":["Pass a TraceObject whose path matches the Available pattern, e.g. 'Available[1234]'.","Use find_availpid_by_obj which applies AVAILABLE_PATTERN automatically.","Ensure the path starts with 'Available[' followed by a numeric PID."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import re\nAVAILABLE_PATTERN_TEST = re.compile(r'Available\\[(?P<pid>\\d+)\\]')\n\ndef is_available_path(path: str) -> bool:\n    return AVAILABLE_PATTERN_TEST.fullmatch(path) is not None","typeGuard":"def is_available_object(obj: TraceObject) -> bool:\n    return AVAILABLE_PATTERN_TEST.fullmatch(obj.path) is not None","tryCatchPattern":"try:\n    pid = find_availpid_by_obj(obj)\nexcept TypeError as e:\n    print(f'Object path does not match Available pattern: {obj.path}')\n    raise","preventionTips":["Verify the path matches 'Available[<pid>]' before calling available-process methods.","Distinguish Available objects from Inferior objects by path prefix.","Use find_availpid_by_obj which applies the correct pattern automatically."],"tags":["gdb","type-mismatch","trace-objects","pattern-matching"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}