Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

209 rindas
10KB

  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 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>Conditions (Debugging with GDB)</title>
  17. <meta name="description" content="Conditions (Debugging with GDB)">
  18. <meta name="keywords" content="Conditions (Debugging with GDB)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  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="Breakpoints.html#Breakpoints" rel="up" title="Breakpoints">
  26. <link href="Break-Commands.html#Break-Commands" rel="next" title="Break Commands">
  27. <link href="Disabling.html#Disabling" rel="prev" title="Disabling">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; font-weight: normal}
  51. span.sansserif {font-family: sans-serif; font-weight: normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en">
  57. <a name="Conditions"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Break-Commands.html#Break-Commands" accesskey="n" rel="next">Break Commands</a>, Previous: <a href="Disabling.html#Disabling" accesskey="p" rel="prev">Disabling</a>, Up: <a href="Breakpoints.html#Breakpoints" accesskey="u" rel="up">Breakpoints</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>
  61. </div>
  62. <hr>
  63. <a name="Break-Conditions"></a>
  64. <h4 class="subsection">5.1.6 Break Conditions</h4>
  65. <a name="index-conditional-breakpoints"></a>
  66. <a name="index-breakpoint-conditions"></a>
  67. <p>The simplest sort of breakpoint breaks every time your program reaches a
  68. specified place. You can also specify a <em>condition</em> for a
  69. breakpoint. A condition is just a Boolean expression in your
  70. programming language (see <a href="Expressions.html#Expressions">Expressions</a>). A breakpoint with
  71. a condition evaluates the expression each time your program reaches it,
  72. and your program stops only if the condition is <em>true</em>.
  73. </p>
  74. <p>This is the converse of using assertions for program validation; in that
  75. situation, you want to stop when the assertion is violated&mdash;that is,
  76. when the condition is false. In C, if you want to test an assertion expressed
  77. by the condition <var>assert</var>, you should set the condition
  78. &lsquo;<samp>! <var>assert</var></samp>&rsquo; on the appropriate breakpoint.
  79. </p>
  80. <p>Conditions are also accepted for watchpoints; you may not need them,
  81. since a watchpoint is inspecting the value of an expression anyhow&mdash;but
  82. it might be simpler, say, to just set a watchpoint on a variable name,
  83. and specify a condition that tests whether the new value is an interesting
  84. one.
  85. </p>
  86. <p>Break conditions can have side effects, and may even call functions in
  87. your program. This can be useful, for example, to activate functions
  88. that log program progress, or to use your own print functions to
  89. format special data structures. The effects are completely predictable
  90. unless there is another enabled breakpoint at the same address. (In
  91. that case, <small>GDB</small> might see the other breakpoint first and stop your
  92. program without checking the condition of this one.) Note that
  93. breakpoint commands are usually more convenient and flexible than break
  94. conditions for the
  95. purpose of performing side effects when a breakpoint is reached
  96. (see <a href="Break-Commands.html#Break-Commands">Breakpoint Command Lists</a>).
  97. </p>
  98. <p>Breakpoint conditions can also be evaluated on the target&rsquo;s side if
  99. the target supports it. Instead of evaluating the conditions locally,
  100. <small>GDB</small> encodes the expression into an agent expression
  101. (see <a href="Agent-Expressions.html#Agent-Expressions">Agent Expressions</a>) suitable for execution on the target,
  102. independently of <small>GDB</small>. Global variables become raw memory
  103. locations, locals become stack accesses, and so forth.
  104. </p>
  105. <p>In this case, <small>GDB</small> will only be notified of a breakpoint trigger
  106. when its condition evaluates to true. This mechanism may provide faster
  107. response times depending on the performance characteristics of the target
  108. since it does not need to keep <small>GDB</small> informed about
  109. every breakpoint trigger, even those with false conditions.
  110. </p>
  111. <p>Break conditions can be specified when a breakpoint is set, by using
  112. &lsquo;<samp>if</samp>&rsquo; in the arguments to the <code>break</code> command. See <a href="Set-Breaks.html#Set-Breaks">Setting Breakpoints</a>. They can also be changed at any time
  113. with the <code>condition</code> command.
  114. </p>
  115. <p>You can also use the <code>if</code> keyword with the <code>watch</code> command.
  116. The <code>catch</code> command does not recognize the <code>if</code> keyword;
  117. <code>condition</code> is the only way to impose a further condition on a
  118. catchpoint.
  119. </p>
  120. <dl compact="compact">
  121. <dd><a name="index-condition"></a>
  122. </dd>
  123. <dt><code>condition <var>bnum</var> <var>expression</var></code></dt>
  124. <dd><p>Specify <var>expression</var> as the break condition for breakpoint,
  125. watchpoint, or catchpoint number <var>bnum</var>. After you set a condition,
  126. breakpoint <var>bnum</var> stops your program only if the value of
  127. <var>expression</var> is true (nonzero, in C). When you use
  128. <code>condition</code>, <small>GDB</small> checks <var>expression</var> immediately for
  129. syntactic correctness, and to determine whether symbols in it have
  130. referents in the context of your breakpoint. If <var>expression</var> uses
  131. symbols not referenced in the context of the breakpoint, <small>GDB</small>
  132. prints an error message:
  133. </p>
  134. <div class="smallexample">
  135. <pre class="smallexample">No symbol &quot;foo&quot; in current context.
  136. </pre></div>
  137. <p><small>GDB</small> does
  138. not actually evaluate <var>expression</var> at the time the <code>condition</code>
  139. command (or a command that sets a breakpoint with a condition, like
  140. <code>break if &hellip;</code>) is given, however. See <a href="Expressions.html#Expressions">Expressions</a>.
  141. </p>
  142. </dd>
  143. <dt><code>condition <var>bnum</var></code></dt>
  144. <dd><p>Remove the condition from breakpoint number <var>bnum</var>. It becomes
  145. an ordinary unconditional breakpoint.
  146. </p></dd>
  147. </dl>
  148. <a name="index-ignore-count-_0028of-breakpoint_0029"></a>
  149. <p>A special case of a breakpoint condition is to stop only when the
  150. breakpoint has been reached a certain number of times. This is so
  151. useful that there is a special way to do it, using the <em>ignore
  152. count</em> of the breakpoint. Every breakpoint has an ignore count, which
  153. is an integer. Most of the time, the ignore count is zero, and
  154. therefore has no effect. But if your program reaches a breakpoint whose
  155. ignore count is positive, then instead of stopping, it just decrements
  156. the ignore count by one and continues. As a result, if the ignore count
  157. value is <var>n</var>, the breakpoint does not stop the next <var>n</var> times
  158. your program reaches it.
  159. </p>
  160. <dl compact="compact">
  161. <dd><a name="index-ignore"></a>
  162. </dd>
  163. <dt><code>ignore <var>bnum</var> <var>count</var></code></dt>
  164. <dd><p>Set the ignore count of breakpoint number <var>bnum</var> to <var>count</var>.
  165. The next <var>count</var> times the breakpoint is reached, your program&rsquo;s
  166. execution does not stop; other than to decrement the ignore count, <small>GDB</small>
  167. takes no action.
  168. </p>
  169. <p>To make the breakpoint stop the next time it is reached, specify
  170. a count of zero.
  171. </p>
  172. <p>When you use <code>continue</code> to resume execution of your program from a
  173. breakpoint, you can specify an ignore count directly as an argument to
  174. <code>continue</code>, rather than using <code>ignore</code>. See <a href="Continuing-and-Stepping.html#Continuing-and-Stepping">Continuing and Stepping</a>.
  175. </p>
  176. <p>If a breakpoint has a positive ignore count and a condition, the
  177. condition is not checked. Once the ignore count reaches zero,
  178. <small>GDB</small> resumes checking the condition.
  179. </p>
  180. <p>You could achieve the effect of the ignore count with a condition such
  181. as &lsquo;<samp><span class="nolinebreak">$foo--</span>&nbsp;&lt;=&nbsp;0</samp>&rsquo;<!-- /@w --> using a debugger convenience variable that
  182. is decremented each time. See <a href="Convenience-Vars.html#Convenience-Vars">Convenience
  183. Variables</a>.
  184. </p></dd>
  185. </dl>
  186. <p>Ignore counts apply to breakpoints, watchpoints, and catchpoints.
  187. </p>
  188. <hr>
  189. <div class="header">
  190. <p>
  191. Next: <a href="Break-Commands.html#Break-Commands" accesskey="n" rel="next">Break Commands</a>, Previous: <a href="Disabling.html#Disabling" accesskey="p" rel="prev">Disabling</a>, Up: <a href="Breakpoints.html#Breakpoints" accesskey="u" rel="up">Breakpoints</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>
  192. </div>
  193. </body>
  194. </html>