Initial bulk commit for "Git on MSys"
[msysgit/historical-msysgit.git] / mingw / info / gdb / Thread-Stops.html
blobad25eaae8c069bf76091f9e53f63aa21ffe7c45e
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="Thread%20Stops">Thread Stops</a>,
13 Previous:<a rel="previous" accesskey="p" href="Signals.html#Signals">Signals</a>,
14 Up:<a rel="up" accesskey="u" href="Stopping.html#Stopping">Stopping</a>
15 <hr><br>
16 </div>
18 <h3 class="section">Stopping and starting multi-thread programs</h3>
20 <p>When your program has multiple threads (see <a href="Threads.html#Threads">Debugging programs with multiple threads</a>), you can choose whether to set
21 breakpoints on all threads, or on a particular thread.
23 <dl>
24 <dt><code>break </code><var>linespec</var><code> thread </code><var>threadno</var><code></code>
25 <dd><dt><code>break </code><var>linespec</var><code> thread </code><var>threadno</var><code> if ...</code>
26 <dd><var>linespec</var> specifies source lines; there are several ways of
27 writing them, but the effect is always to specify some source line.
29 <p>Use the qualifier <code>thread </code><var>threadno</var><code></code> with a breakpoint command
30 to specify that you only want GDB to stop the program when a
31 particular thread reaches this breakpoint. <var>threadno</var> is one of the
32 numeric thread identifiers assigned by GDB, shown in the first
33 column of the <code>info threads</code> display.
35 <p>If you do not specify <code>thread </code><var>threadno</var><code></code> when you set a
36 breakpoint, the breakpoint applies to <em>all</em> threads of your
37 program.
39 <p>You can use the <code>thread</code> qualifier on conditional breakpoints as
40 well; in this case, place <code>thread </code><var>threadno</var><code></code> before the
41 breakpoint condition, like this:
43 <pre class="smallexample"> (gdb) break frik.c:13 thread 28 if bartab &gt; lim
44 </pre>
46 </dl>
48 <p>Whenever your program stops under GDB for any reason,
49 <em>all</em> threads of execution stop, not just the current thread. This
50 allows you to examine the overall state of the program, including
51 switching between threads, without worrying that things may change
52 underfoot.
54 <p>Conversely, whenever you restart the program, <em>all</em> threads start
55 executing. <em>This is true even when single-stepping</em> with commands
56 like <code>step</code> or <code>next</code>.
58 <p>In particular, GDB cannot single-step all threads in lockstep.
59 Since thread scheduling is up to your debugging target's operating
60 system (not controlled by GDB), other threads may
61 execute more than one statement while the current thread completes a
62 single step. Moreover, in general other threads stop in the middle of a
63 statement, rather than at a clean statement boundary, when the program
64 stops.
66 <p>You might even find your program stopped in another thread after
67 continuing or even single-stepping. This happens whenever some other
68 thread runs into a breakpoint, a signal, or an exception before the
69 first thread completes whatever you requested.
71 <p>On some OSes, you can lock the OS scheduler and thus allow only a single
72 thread to run.
74 <dl>
75 <dt><code>set scheduler-locking </code><var>mode</var><code></code>
76 <dd>Set the scheduler locking mode. If it is <code>off</code>, then there is no
77 locking and any thread may run at any time. If <code>on</code>, then only the
78 current thread may run when the inferior is resumed. The <code>step</code>
79 mode optimizes for single-stepping. It stops other threads from
80 "seizing the prompt" by preempting the current thread while you are
81 stepping. Other threads will only rarely (or never) get a chance to run
82 when you step. They are more likely to run when you <code>next</code> over a
83 function call, and they are completely free to run when you use commands
84 like <code>continue</code>, <code>until</code>, or <code>finish</code>. However, unless another
85 thread hits a breakpoint during its timeslice, they will never steal the
86 GDB prompt away from the thread that you are debugging.
88 <br><dt><code>show scheduler-locking</code>
89 <dd>Display the current scheduler locking mode.
90 </dl>
92 </body></html>