diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/hooks.py b/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/hooks.py index 7f04b7784b..b1f8fb82f9 100644 --- a/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/hooks.py +++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/hooks.py @@ -546,19 +546,7 @@ def install_hooks(): if HOOK_STATE.mem_catchpoint is not None: HOOK_STATE.mem_catchpoint.enabled = True else: - breaks_before = set(gdb.breakpoints()) - try: - gdb.execute(""" - catch syscall group:memory - commands - silent - hooks-ghidra event-memory - cont - end - """) - HOOK_STATE.mem_catchpoint = (set(gdb.breakpoints()) - breaks_before).pop() - except Exception as e: - print(f"Error setting memory catchpoint: {e}") + HOOK_STATE.mem_catchpoint = util.MEM_CATCHPOINT_SETTER.install_catchpoint() gdb.events.cont.connect(on_cont) gdb.events.stop.connect(on_stop) diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/util.py b/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/util.py index dc85fc987d..33f96466d5 100644 --- a/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/util.py +++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/util.py @@ -344,6 +344,41 @@ def _choose_breakpoint_location_info_reader(): BREAKPOINT_LOCATION_INFO_READER = _choose_breakpoint_location_info_reader() +class MemCatchpointSetterV8(object): + def install_catchpoint(self): + return object() + + +class MemCatchpointSetterV11(object): + def install_catchpoint(self): + breaks_before = set(gdb.breakpoints()) + try: + gdb.execute(""" + catch syscall group:memory + commands + silent + hooks-ghidra event-memory + cont + end + """) + return (set(gdb.breakpoints()) - breaks_before).pop() + except Exception as e: + print(f"Error setting memory catchpoint: {e}") + return object() + + +def _choose_mem_catchpoint_setter(): + if GDB_VERSION.major >= 11: + return MemCatchpointSetterV11() + if GDB_VERSION.major >= 8: + return MemCatchpointSetterV8() + else: + raise gdb.GdbError( + "GDB version not recognized by ghidragdb: " + GDB_VERSION.full) + + +MEM_CATCHPOINT_SETTER = _choose_mem_catchpoint_setter() + def set_bool_param_by_api(name, value): gdb.set_parameter(name, value)