{"record":{"id":"57abf33336cd16cb","repo":"NationalSecurityAgency/ghidra","slug":"events-eventnum-does-not-exist","errorCode":null,"errorMessage":"Events[{eventnum}] does not exist","messagePattern":"Events\\[(.+?)\\] does not exist","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/methods.py","lineNumber":204,"sourceCode":"\ndef find_bpt_by_pattern(pattern: re.Pattern, object: TraceObject,\n                        err_msg: str) -> DbgEng.IDebugBreakpoint:\n    mat = pattern.fullmatch(object.path)\n    if mat is None:\n        raise TypeError(f\"{object} is not {err_msg}\")\n    breaknum = int(mat['breaknum'])\n    return find_bpt_by_number(breaknum)\n\n\ndef find_bpt_by_obj(object: TraceObject) -> DbgEng.IDebugBreakpoint:\n    return find_bpt_by_pattern(PROC_BREAKBPT_PATTERN, object, \"a BreakpointSpec\")\n\n\ndef find_evt_by_number(eventnum: int) -> DbgEng._DEBUG_SPECIFIC_FILTER_PARAMETERS:\n    try:\n        return util.GetSpecificFilterParameters(eventnum, 1)\n    except exception.E_NOINTERFACE_Error:\n        raise KeyError(f\"Events[{eventnum}] does not exist\")\n\n\ndef find_evt_by_pattern(pattern: re.Pattern, object: TraceObject,\n                        err_msg: str) -> DbgEng._DEBUG_SPECIFIC_FILTER_PARAMETERS:\n    mat = pattern.fullmatch(object.path)\n    if mat is None:\n        raise TypeError(f\"{object} is not {err_msg}\")\n    eventnum = int(mat['eventnum'])\n    return (eventnum, find_evt_by_number(eventnum))\n\n\ndef find_evt_cont_by_obj(object: TraceObject) -> DbgEng._DEBUG_SPECIFIC_FILTER_PARAMETERS:\n    return find_evt_by_pattern(PROC_EVENT_CONT_PATTERN, object, \"as Event\")\n\n\ndef find_evt_exec_by_obj(object: TraceObject) -> DbgEng._DEBUG_SPECIFIC_FILTER_PARAMETERS:\n    return find_evt_by_pattern(PROC_EVENT_EXEC_PATTERN, object, \"as Event\")\n","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/methods.py#L186-L222","documentation":"Raised by find_evt_by_number() (methods.py:203-204) as a KeyError when util.GetSpecificFilterParameters(eventnum, 1) raises E_NOINTERFACE_Error — dbgeng has no specific event filter at that index. dbgeng distinguishes specific filters (indexed) from arbitrary exception filters; this lookup is for the specific-filter table only.","triggerScenarios":"Referencing a specific event filter index that does not exist (>= GetSpecificFilterParameters count); stale event index after the filter table changed; confusing specific-filter index with exception-filter index (see find_exc_by_number which uses a different offset).","commonSituations":"Hard-coded event filter index from a different target/debugger configuration; off-by-one between 0-based and 1-based numbering; index captured before new filters were added/removed.","solutions":["Query the current specific-filter count (GetNumberEventFilters) and confirm eventnum is in range before lookup.","Distinguish specific filters (Events[n]) from exception filters (Exceptions[n]) — they use separate index spaces and separate find_*_by_number functions.","Wrap in try/except KeyError if a missing filter is a recoverable condition."],"exampleFix":"// before\nparams = find_evt_by_number(stale_index)   # KeyError: Events[5] does not exist\n\n// after\nn_specific = util.GetNumberEventFilters()[1]   # specific-filter count\nif 0 <= stale_index < n_specific:\n    params = find_evt_by_number(stale_index)\nelse:\n    # handle missing filter\n    pass","handlingStrategy":"try-catch","validationCode":"def event_filter_exists(eventnum) -> bool:\n    try:\n        util.GetSpecificFilterParameters(eventnum, 1)\n        return True\n    except Exception:\n        return False\n\n# get the specific-filter count first\n_, n_specific, _ = util.GetNumberEventFilters()\nif not (0 <= eventnum < n_specific):\n    raise KeyError(f'Events[{eventnum}] out of range; only {n_specific} specific filters')","typeGuard":"def event_filter_in_range(eventnum) -> bool:\n    try:\n        _, n_specific, _ = util.GetNumberEventFilters()\n        return 0 <= eventnum < n_specific\n    except Exception:\n        return False","tryCatchPattern":"try:\n    params = find_evt_by_number(eventnum)\nexcept KeyError as e:\n    if 'does not exist' in str(e):\n        raise KeyError(f'stale event index {eventnum}; refresh from the Events container') from e\n    raise","preventionTips":["Query GetNumberEventFilters and range-check before lookup.","Do not confuse specific-filter indices with exception-filter indices.","Refresh indices after the filter table changes."],"tags":["event-filter","com","lookup","ghidra"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}