All_002dStop-Mode.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Free Software" and "Free Software Needs
  8. Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
  9. and with the Back-Cover Texts as in (a) below.
  10. (a) The FSF's Back-Cover Text is: "You are free to copy and modify
  11. this GNU Manual. Buying copies from GNU Press supports the FSF in
  12. developing GNU and promoting software freedom." -->
  13. <!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: All-Stop Mode</title>
  16. <meta name="description" content="Debugging with GDB: All-Stop Mode">
  17. <meta name="keywords" content="Debugging with GDB: All-Stop Mode">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Thread-Stops.html#Thread-Stops" rel="up" title="Thread Stops">
  26. <link href="Non_002dStop-Mode.html#Non_002dStop-Mode" rel="next" title="Non-Stop Mode">
  27. <link href="Thread-Stops.html#Thread-Stops" rel="previous" title="Thread Stops">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style:oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="All_002dStop-Mode"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Non_002dStop-Mode.html#Non_002dStop-Mode" accesskey="n" rel="next">Non-Stop Mode</a>, Up: <a href="Thread-Stops.html#Thread-Stops" accesskey="u" rel="up">Thread Stops</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  62. </div>
  63. <hr>
  64. <a name="All_002dStop-Mode-1"></a>
  65. <h4 class="subsection">5.5.1 All-Stop Mode</h4>
  66. <a name="index-all_002dstop-mode"></a>
  67. <p>In all-stop mode, whenever your program stops under <small>GDB</small> for any reason,
  68. <em>all</em> threads of execution stop, not just the current thread. This
  69. allows you to examine the overall state of the program, including
  70. switching between threads, without worrying that things may change
  71. underfoot.
  72. </p>
  73. <p>Conversely, whenever you restart the program, <em>all</em> threads start
  74. executing. <em>This is true even when single-stepping</em> with commands
  75. like <code>step</code> or <code>next</code>.
  76. </p>
  77. <p>In particular, <small>GDB</small> cannot single-step all threads in lockstep.
  78. Since thread scheduling is up to your debugging target&rsquo;s operating
  79. system (not controlled by <small>GDB</small>), other threads may
  80. execute more than one statement while the current thread completes a
  81. single step. Moreover, in general other threads stop in the middle of a
  82. statement, rather than at a clean statement boundary, when the program
  83. stops.
  84. </p>
  85. <p>You might even find your program stopped in another thread after
  86. continuing or even single-stepping. This happens whenever some other
  87. thread runs into a breakpoint, a signal, or an exception before the
  88. first thread completes whatever you requested.
  89. </p>
  90. <a name="index-automatic-thread-selection"></a>
  91. <a name="index-switching-threads-automatically"></a>
  92. <a name="index-threads_002c-automatic-switching"></a>
  93. <p>Whenever <small>GDB</small> stops your program, due to a breakpoint or a
  94. signal, it automatically selects the thread where that breakpoint or
  95. signal happened. <small>GDB</small> alerts you to the context switch with a
  96. message such as &lsquo;<samp>[Switching to Thread <var>n</var>]</samp>&rsquo; to identify the
  97. thread.
  98. </p>
  99. <p>On some OSes, you can modify <small>GDB</small>&rsquo;s default behavior by
  100. locking the OS scheduler to allow only a single thread to run.
  101. </p>
  102. <dl compact="compact">
  103. <dt><code>set scheduler-locking <var>mode</var></code></dt>
  104. <dd><a name="index-scheduler-locking-mode"></a>
  105. <a name="index-lock-scheduler"></a>
  106. <p>Set the scheduler locking mode. It applies to normal execution,
  107. record mode, and replay mode. If it is <code>off</code>, then there is no
  108. locking and any thread may run at any time. If <code>on</code>, then only
  109. the current thread may run when the inferior is resumed. The
  110. <code>step</code> mode optimizes for single-stepping; it prevents other
  111. threads from preempting the current thread while you are stepping, so
  112. that the focus of debugging does not change unexpectedly. Other
  113. threads never get a chance to run when you step, and they are
  114. completely free to run when you use commands like &lsquo;<samp>continue</samp>&rsquo;,
  115. &lsquo;<samp>until</samp>&rsquo;, or &lsquo;<samp>finish</samp>&rsquo;. However, unless another thread hits a
  116. breakpoint during its timeslice, <small>GDB</small> does not change the
  117. current thread away from the thread that you are debugging. The
  118. <code>replay</code> mode behaves like <code>off</code> in record mode and like
  119. <code>on</code> in replay mode.
  120. </p>
  121. </dd>
  122. <dt><code>show scheduler-locking</code></dt>
  123. <dd><p>Display the current scheduler locking mode.
  124. </p></dd>
  125. </dl>
  126. <a name="index-resume-threads-of-multiple-processes-simultaneously"></a>
  127. <p>By default, when you issue one of the execution commands such as
  128. <code>continue</code>, <code>next</code> or <code>step</code>, <small>GDB</small> allows only
  129. threads of the current inferior to run. For example, if <small>GDB</small>
  130. is attached to two inferiors, each with two threads, the
  131. <code>continue</code> command resumes only the two threads of the current
  132. inferior. This is useful, for example, when you debug a program that
  133. forks and you want to hold the parent stopped (so that, for instance,
  134. it doesn&rsquo;t run to exit), while you debug the child. In other
  135. situations, you may not be interested in inspecting the current state
  136. of any of the processes <small>GDB</small> is attached to, and you may want
  137. to resume them all until some breakpoint is hit. In the latter case,
  138. you can instruct <small>GDB</small> to allow all threads of all the
  139. inferiors to run with the <code>set&nbsp;<span class="nolinebreak">schedule-multiple</span></code><!-- /@w --> command.
  140. </p>
  141. <dl compact="compact">
  142. <dd><a name="index-set-schedule_002dmultiple"></a>
  143. </dd>
  144. <dt><code>set schedule-multiple</code></dt>
  145. <dd><p>Set the mode for allowing threads of multiple processes to be resumed
  146. when an execution command is issued. When <code>on</code>, all threads of
  147. all processes are allowed to run. When <code>off</code>, only the threads
  148. of the current process are resumed. The default is <code>off</code>. The
  149. <code>scheduler-locking</code> mode takes precedence when set to <code>on</code>,
  150. or while you are stepping and set to <code>step</code>.
  151. </p>
  152. </dd>
  153. <dt><code>show schedule-multiple</code></dt>
  154. <dd><p>Display the current mode for resuming the execution of threads of
  155. multiple processes.
  156. </p></dd>
  157. </dl>
  158. <hr>
  159. <div class="header">
  160. <p>
  161. Next: <a href="Non_002dStop-Mode.html#Non_002dStop-Mode" accesskey="n" rel="next">Non-Stop Mode</a>, Up: <a href="Thread-Stops.html#Thread-Stops" accesskey="u" rel="up">Thread Stops</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  162. </div>
  163. </body>
  164. </html>