Debugging with GDB (February 2008)

Table Of Contents
256 Debugging with GDB
You may use the document command again to change the documentation of a
command. Redefining the command with define does not change the docu-
mentation.
help user-defined
List all user-defined commands, with the first line of the documentation (if any)
for each.
show user
show user commandname
Display the GDB commands used to define commandname (but not its docu-
mentation). If no commandname is given, display the definitions for all user-
defined commands.
When user-defined commands are executed, the commands of the definition are not
printed. An error in any command stops execution of the user-defined command.
If used interactively, commands that would ask for confirmation proceed without asking
when used inside a user-defined command. Many GDB commands that normally print mes-
sages to say what they are doing omit the messages when used in a user-defined command.
18.2 User-defined command hooks
You may define hooks, which are a special kind of user-defined command. Whenever you
run the command ‘foo’, if the user-defined command ‘hook-foo’ exists, it is executed (with
no arguments) before that command.
In addition, a pseudo-command, stop exists. Defining (‘hook-stop’) makes the asso-
ciated commands execute every time execution stops in your program: before breakpoint
commands are run, displays are printed, or the stack frame is printed.
For example, to ignore SIGALRM signals while single-stepping, and treat them normally
during normal execution, you could define:
define hook-stop
handle SIGALRM nopass
end
define hook-run
handle SIGALRM pass
end
define hook-continue
handle SIGLARM pass
end
You can define a hook for any single-word command in GDB, and not for command
aliases; Also you should define a hook for the basic command name, e.g. backtrace rather
than bt. If an error occurs during the execution of your hook, execution of GDB commands
stops and GDB issues a prompt (before the command that you actually typed had a chance
to run).