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=
"Set%20Catchpoints">Set Catchpoints
</a>,
13 Next:
<a rel=
"next" accesskey=
"n" href=
"Delete-Breaks.html#Delete%20Breaks">Delete Breaks
</a>,
14 Previous:
<a rel=
"previous" accesskey=
"p" href=
"Set-Watchpoints.html#Set%20Watchpoints">Set Watchpoints
</a>,
15 Up:
<a rel=
"up" accesskey=
"u" href=
"Breakpoints.html#Breakpoints">Breakpoints
</a>
19 <h4 class=
"subsection">Setting catchpoints
</h4>
21 <p>You can use
<dfn>catchpoints
</dfn> to cause the debugger to stop for certain
22 kinds of program events, such as C
<tt>++
</tt> exceptions or the loading of a
23 shared library. Use the
<code>catch
</code> command to set a catchpoint.
26 <dt><code>catch
</code><var>event
</var><code></code>
27 <dd>Stop when
<var>event
</var> occurs.
<var>event
</var> can be any of the following:
29 <dt><code>throw
</code>
30 <dd>The throwing of a C
<tt>++
</tt> exception.
32 <br><dt><code>catch
</code>
33 <dd>The catching of a C
<tt>++
</tt> exception.
35 <br><dt><code>exec
</code>
36 <dd>A call to
<code>exec
</code>. This is currently only available for HP-UX.
38 <br><dt><code>fork
</code>
39 <dd>A call to
<code>fork
</code>. This is currently only available for HP-UX.
41 <br><dt><code>vfork
</code>
42 <dd>A call to
<code>vfork
</code>. This is currently only available for HP-UX.
44 <br><dt><code>load
</code>
45 <dd><dt><code>load
</code><var>libname
</var><code></code>
46 <dd>The dynamic loading of any shared library, or the loading of the library
47 <var>libname
</var>. This is currently only available for HP-UX.
49 <br><dt><code>unload
</code>
50 <dd><dt><code>unload
</code><var>libname
</var><code></code>
51 <dd>The unloading of any dynamically loaded shared library, or the unloading
52 of the library
<var>libname
</var>. This is currently only available for HP-UX.
55 <br><dt><code>tcatch
</code><var>event
</var><code></code>
56 <dd>Set a catchpoint that is enabled only for one stop. The catchpoint is
57 automatically deleted after the first time the event is caught.
61 <p>Use the
<code>info break
</code> command to list the current catchpoints.
63 <p>There are currently some limitations to C
<tt>++
</tt> exception handling
64 (
<code>catch throw
</code> and
<code>catch catch
</code>) in GDB:
67 <li>If you call a function interactively, GDB normally returns
68 control to you when the function has finished executing. If the call
69 raises an exception, however, the call may bypass the mechanism that
70 returns control to you and cause your program either to abort or to
71 simply continue running until it hits a breakpoint, catches a signal
72 that GDB is listening for, or exits. This is the case even if
73 you set a catchpoint for the exception; catchpoints on exceptions are
74 disabled within interactive calls.
76 <li>You cannot raise an exception interactively.
78 <li>You cannot install an exception handler interactively.
81 <p>Sometimes
<code>catch
</code> is not the best way to debug exception handling:
82 if you need to know exactly where an exception is raised, it is better to
83 stop
<em>before
</em> the exception handler is called, since that way you
84 can see the stack before any unwinding takes place. If you set a
85 breakpoint in an exception handler instead, it may not be easy to find
86 out where the exception was raised.
88 <p>To stop just before an exception handler is called, you need some
89 knowledge of the implementation. In the case of
<small>GNU
</small> C
<tt>++
</tt>, exceptions are
90 raised by calling a library function named
<code>__raise_exception
</code>
91 which has the following ANSI C interface:
93 <pre class=
"example"> /*
<var>addr
</var> is where the exception identifier is stored.
94 <var>id
</var> is the exception identifier. */
95 void __raise_exception (void **addr, void *id);
98 <p>To make the debugger catch all exceptions before any stack
99 unwinding takes place, set a breakpoint on
<code>__raise_exception
</code>
100 (see
<a href=
"Breakpoints.html#Breakpoints">Breakpoints; watchpoints; and exceptions
</a>).
102 <p>With a conditional breakpoint (see
<a href=
"Conditions.html#Conditions">Break conditions
</a>)
103 that depends on the value of
<var>id
</var>, you can stop your program when
104 a specific exception is raised. You can use multiple conditional
105 breakpoints to stop your program when any of a number of exceptions are