'How to hook delete breakpoints command in gdb

GDB supports the hook command function. For example, when GDB executes the delete command, the user-defined hook command can be executed:

define hook-delete
  printf "hook a delete command.\n"
  # do something
end

But how to hook delete breakpoints?

After verification, execute the delete breakpoints command, knowing that the above hook-delete function will not be called.

gdb


Solution 1:[1]

I already know the answer by querying the GDB manual.

The GDB manual reads as follows:

You can hook a multi-word command by adding hook- or hookpost- to the last word of the command, e.g. ‘define target hook-remote’ to add a hook to ‘target remote’.

So, the function to hook delete breakpoints can be defined like this:

define delete hook-breakpoints
  printf "hook a delete breakpoints command.\n"
  # do something
end

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FairyFar