Debugging with GDB Manual HP WDB v6.3 (5900-2180, August 2012)

You may use the document command again to change the
documentation of a command. Redefining the command
with define does not change the documentation.
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 documentation). 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 messages 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 associated
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, for example, 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).
If you try to define a hook which does not match any known command, GDB issues a warning
from the define command.
18.3 Command files
A command file for GDB is a file of lines that are GDB commands. Comments (lines starting with
#) may also be included. An empty line in a command file does nothing; it does not mean to repeat
the last command, as it would from the terminal.
When you start GDB, it executes commands from its init files. These are files named .gdbinit
on UNIX. During startup, GDB does the following:
1. Read the init file (if any) in your home directory.
4
2. Process command-line options and operands.
3. Read the init file (if any) in the current working directory,
4. Read the init file (if any) in the /tmp directory if the GDB_PROCESS_TMP_GDBINIT
environment variable is set.
230 Canned Sequences of Commands