Work around MinGW mangling of "host:/path"
[msysgit/historical-msysgit.git] / mingw / info / gdb / Hooks.html
blob74cd5f8fb9170be528fe2fefa4bffc59cee83275
1 <html lang="en">
2 <head>
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">
8 </head>
9 <body>
10 <div class="node">
11 <p>
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>
16 <hr><br>
17 </div>
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)
24 before that command.
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,
42 you could define:
44 <pre class="example"> define hook-stop
45 handle SIGALRM nopass
46 end
48 define hook-run
49 handle SIGALRM pass
50 end
52 define hook-continue
53 handle SIGLARM pass
54 end
55 </pre>
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,
59 you could define:
61 <pre class="example"> define hook-echo
62 echo &lt;&lt;&lt;---
63 end
65 define hookpost-echo
66 echo ---&gt;&gt;&gt;\n
67 end
69 (gdb) echo Hello World
70 &lt;&lt;&lt;---Hello World---&gt;&gt;&gt;
71 (gdb)
73 </pre>
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.
85 </body></html>