3 <title>Debugging with GDB
</title>
4 <meta http-equiv=
"Content-Type" content=
"text/html">
5 <meta name=
"description" content=
"Debugging with GDB">
6 <meta name=
"generator" content=
"makeinfo 4.3">
7 <link href=
"http://www.gnu.org/software/texinfo/" rel=
"generator-home">
12 Node:
<a name=
"Hooks">Hooks
</a>,
13 Next:
<a rel=
"next" accesskey=
"n" href=
"Command-Files.html#Command%20Files">Command Files
</a>,
14 Previous:
<a rel=
"previous" accesskey=
"p" href=
"Define.html#Define">Define
</a>,
15 Up:
<a rel=
"up" accesskey=
"u" href=
"Sequences.html#Sequences">Sequences
</a>
19 <h3 class=
"section">User-defined command hooks
</h3>
21 <p>You may define
<dfn>hooks
</dfn>, which are a special kind of user-defined
22 command. Whenever you run the command
<code>foo
</code>, if the user-defined
23 command
<code>hook-foo
</code> exists, it is executed (with no arguments)
26 <p>A hook may also be defined which is run after the command you executed.
27 Whenever you run the command
<code>foo
</code>, if the user-defined command
28 <code>hookpost-foo
</code> exists, it is executed (with no arguments) after
29 that command. Post-execution hooks may exist simultaneously with
30 pre-execution hooks, for the same command.
32 <p>It is valid for a hook to call the command which it hooks. If this
33 occurs, the hook is not re-executed, thereby avoiding infinte recursion.
35 <p>In addition, a pseudo-command,
<code>stop
</code> exists. Defining
36 (
<code>hook-stop
</code>) makes the associated commands execute every time
37 execution stops in your program: before breakpoint commands are run,
38 displays are printed, or the stack frame is printed.
40 <p>For example, to ignore
<code>SIGALRM
</code> signals while
41 single-stepping, but treat them normally during normal execution,
44 <pre class=
"example"> define hook-stop
57 <p>As a further example, to hook at the begining and end of the
<code>echo
</code>
58 command, and to add extra text to the beginning and end of the message,
61 <pre class=
"example"> define hook-echo
66 echo ---
>>>\n
69 (gdb) echo Hello World
70 <<<---Hello World---
>>>
75 <p>You can define a hook for any single-word command in GDB, but
76 not for command aliases; you should define a hook for the basic command
77 name, e.g.
<code>backtrace
</code> rather than
<code>bt
</code>.
78 If an error occurs during the execution of your hook, execution of
79 GDB commands stops and GDB issues a prompt
80 (before the command that you actually typed had a chance to run).
82 <p>If you try to define a hook which does not match any known command, you
83 get a warning from the
<code>define
</code> command.