Break-Commands.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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: Break Commands</title>
  16. <meta name="description" content="Debugging with GDB: Break Commands">
  17. <meta name="keywords" content="Debugging with GDB: Break Commands">
  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="Breakpoints.html#Breakpoints" rel="up" title="Breakpoints">
  26. <link href="Dynamic-Printf.html#Dynamic-Printf" rel="next" title="Dynamic Printf">
  27. <link href="Conditions.html#Conditions" rel="previous" title="Conditions">
  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="Break-Commands"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Dynamic-Printf.html#Dynamic-Printf" accesskey="n" rel="next">Dynamic Printf</a>, Previous: <a href="Conditions.html#Conditions" accesskey="p" rel="previous">Conditions</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>
  62. </div>
  63. <hr>
  64. <a name="Breakpoint-Command-Lists"></a>
  65. <h4 class="subsection">5.1.7 Breakpoint Command Lists</h4>
  66. <a name="index-breakpoint-commands"></a>
  67. <p>You can give any breakpoint (or watchpoint or catchpoint) a series of
  68. commands to execute when your program stops due to that breakpoint. For
  69. example, you might want to print the values of certain expressions, or
  70. enable other breakpoints.
  71. </p>
  72. <dl compact="compact">
  73. <dd><a name="index-commands"></a>
  74. <a name="index-end-_0028breakpoint-commands_0029"></a>
  75. </dd>
  76. <dt><code>commands <span class="roman">[</span><var>list</var>&hellip;<span class="roman">]</span></code></dt>
  77. <dt><code>&hellip; <var>command-list</var> &hellip;</code></dt>
  78. <dt><code>end</code></dt>
  79. <dd><p>Specify a list of commands for the given breakpoints. The commands
  80. themselves appear on the following lines. Type a line containing just
  81. <code>end</code> to terminate the commands.
  82. </p>
  83. <p>To remove all commands from a breakpoint, type <code>commands</code> and
  84. follow it immediately with <code>end</code>; that is, give no commands.
  85. </p>
  86. <p>With no argument, <code>commands</code> refers to the last breakpoint,
  87. watchpoint, or catchpoint set (not to the breakpoint most recently
  88. encountered). If the most recent breakpoints were set with a single
  89. command, then the <code>commands</code> will apply to all the breakpoints
  90. set by that command. This applies to breakpoints set by
  91. <code>rbreak</code>, and also applies when a single <code>break</code> command
  92. creates multiple breakpoints (see <a href="Ambiguous-Expressions.html#Ambiguous-Expressions">Ambiguous
  93. Expressions</a>).
  94. </p></dd>
  95. </dl>
  96. <p>Pressing <tt class="key">RET</tt> as a means of repeating the last <small>GDB</small> command is
  97. disabled within a <var>command-list</var>.
  98. </p>
  99. <p>You can use breakpoint commands to start your program up again. Simply
  100. use the <code>continue</code> command, or <code>step</code>, or any other command
  101. that resumes execution.
  102. </p>
  103. <p>Any other commands in the command list, after a command that resumes
  104. execution, are ignored. This is because any time you resume execution
  105. (even with a simple <code>next</code> or <code>step</code>), you may encounter
  106. another breakpoint&mdash;which could have its own command list, leading to
  107. ambiguities about which list to execute.
  108. </p>
  109. <a name="index-silent"></a>
  110. <p>If the first command you specify in a command list is <code>silent</code>, the
  111. usual message about stopping at a breakpoint is not printed. This may
  112. be desirable for breakpoints that are to print a specific message and
  113. then continue. If none of the remaining commands print anything, you
  114. see no sign that the breakpoint was reached. <code>silent</code> is
  115. meaningful only at the beginning of a breakpoint command list.
  116. </p>
  117. <p>The commands <code>echo</code>, <code>output</code>, and <code>printf</code> allow you to
  118. print precisely controlled output, and are often useful in silent
  119. breakpoints. See <a href="Output.html#Output">Commands for Controlled Output</a>.
  120. </p>
  121. <p>For example, here is how you could use breakpoint commands to print the
  122. value of <code>x</code> at entry to <code>foo</code> whenever <code>x</code> is positive.
  123. </p>
  124. <div class="smallexample">
  125. <pre class="smallexample">break foo if x&gt;0
  126. commands
  127. silent
  128. printf &quot;x is %d\n&quot;,x
  129. cont
  130. end
  131. </pre></div>
  132. <p>One application for breakpoint commands is to compensate for one bug so
  133. you can test for another. Put a breakpoint just after the erroneous line
  134. of code, give it a condition to detect the case in which something
  135. erroneous has been done, and give it commands to assign correct values
  136. to any variables that need them. End with the <code>continue</code> command
  137. so that your program does not stop, and start with the <code>silent</code>
  138. command so that no output is produced. Here is an example:
  139. </p>
  140. <div class="smallexample">
  141. <pre class="smallexample">break 403
  142. commands
  143. silent
  144. set x = y + 4
  145. cont
  146. end
  147. </pre></div>
  148. <hr>
  149. <div class="header">
  150. <p>
  151. Next: <a href="Dynamic-Printf.html#Dynamic-Printf" accesskey="n" rel="next">Dynamic Printf</a>, Previous: <a href="Conditions.html#Conditions" accesskey="p" rel="previous">Conditions</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>
  152. </div>
  153. </body>
  154. </html>