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-2021 Free Software Foundation, Inc.
4
5Permission is granted to copy, distribute and/or modify this document
6under the terms of the GNU Free Documentation License, Version 1.3 or
7any later version published by the Free Software Foundation; with the
8Invariant Sections being "Free Software" and "Free Software Needs
9Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
10and with the Back-Cover Texts as in (a) below.
11
12(a) The FSF's Back-Cover Text is: "You are free to copy and modify
13this GNU Manual.  Buying copies from GNU Press supports the FSF in
14developing GNU and promoting software freedom." -->
15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
16<head>
17<title>Debugging with GDB: Break Commands</title>
18
19<meta name="description" content="Debugging with GDB: Break Commands">
20<meta name="keywords" content="Debugging with GDB: Break Commands">
21<meta name="resource-type" content="document">
22<meta name="distribution" content="global">
23<meta name="Generator" content="makeinfo">
24<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
25<link href="index.html#Top" rel="start" title="Top">
26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
28<link href="Breakpoints.html#Breakpoints" rel="up" title="Breakpoints">
29<link href="Dynamic-printf.html#Dynamic-printf" rel="next" title="Dynamic printf">
30<link href="Conditions.html#Conditions" rel="previous" title="Conditions">
31<style type="text/css">
32<!--
33a.summary-letter {text-decoration: none}
34blockquote.smallquotation {font-size: smaller}
35div.display {margin-left: 3.2em}
36div.example {margin-left: 3.2em}
37div.indentedblock {margin-left: 3.2em}
38div.lisp {margin-left: 3.2em}
39div.smalldisplay {margin-left: 3.2em}
40div.smallexample {margin-left: 3.2em}
41div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
42div.smalllisp {margin-left: 3.2em}
43kbd {font-style:oblique}
44pre.display {font-family: inherit}
45pre.format {font-family: inherit}
46pre.menu-comment {font-family: serif}
47pre.menu-preformatted {font-family: serif}
48pre.smalldisplay {font-family: inherit; font-size: smaller}
49pre.smallexample {font-size: smaller}
50pre.smallformat {font-family: inherit; font-size: smaller}
51pre.smalllisp {font-size: smaller}
52span.nocodebreak {white-space:nowrap}
53span.nolinebreak {white-space:nowrap}
54span.roman {font-family:serif; font-weight:normal}
55span.sansserif {font-family:sans-serif; font-weight:normal}
56ul.no-bullet {list-style: none}
57-->
58</style>
59
60
61</head>
62
63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
64<a name="Break-Commands"></a>
65<div class="header">
66<p>
67Next: <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>
68</div>
69<hr>
70<a name="Breakpoint-Command-Lists"></a>
71<h4 class="subsection">5.1.7 Breakpoint Command Lists</h4>
72
73<a name="index-breakpoint-commands"></a>
74<p>You can give any breakpoint (or watchpoint or catchpoint) a series of
75commands to execute when your program stops due to that breakpoint.  For
76example, you might want to print the values of certain expressions, or
77enable other breakpoints.
78</p>
79<dl compact="compact">
80<dd><a name="index-commands"></a>
81<a name="index-end-_0028breakpoint-commands_0029"></a>
82</dd>
83<dt><code>commands <span class="roman">[</span><var>list</var>&hellip;<span class="roman">]</span></code></dt>
84<dt><code>&hellip; <var>command-list</var> &hellip;</code></dt>
85<dt><code>end</code></dt>
86<dd><p>Specify a list of commands for the given breakpoints.  The commands
87themselves appear on the following lines.  Type a line containing just
88<code>end</code> to terminate the commands.
89</p>
90<p>To remove all commands from a breakpoint, type <code>commands</code> and
91follow it immediately with <code>end</code>; that is, give no commands.
92</p>
93<p>With no argument, <code>commands</code> refers to the last breakpoint,
94watchpoint, or catchpoint set (not to the breakpoint most recently
95encountered).  If the most recent breakpoints were set with a single
96command, then the <code>commands</code> will apply to all the breakpoints
97set by that command.  This applies to breakpoints set by
98<code>rbreak</code>, and also applies when a single <code>break</code> command
99creates multiple breakpoints (see <a href="Ambiguous-Expressions.html#Ambiguous-Expressions">Ambiguous
100Expressions</a>).
101</p></dd>
102</dl>
103
104<p>Pressing <tt class="key">RET</tt> as a means of repeating the last <small>GDB</small> command is
105disabled within a <var>command-list</var>.
106</p>
107<p>You can use breakpoint commands to start your program up again.  Simply
108use the <code>continue</code> command, or <code>step</code>, or any other command
109that resumes execution.
110</p>
111<p>Any other commands in the command list, after a command that resumes
112execution, are ignored.  This is because any time you resume execution
113(even with a simple <code>next</code> or <code>step</code>), you may encounter
114another breakpoint&mdash;which could have its own command list, leading to
115ambiguities about which list to execute.
116</p>
117<a name="index-silent"></a>
118<p>If the first command you specify in a command list is <code>silent</code>, the
119usual message about stopping at a breakpoint is not printed.  This may
120be desirable for breakpoints that are to print a specific message and
121then continue.  If none of the remaining commands print anything, you
122see no sign that the breakpoint was reached.  <code>silent</code> is
123meaningful only at the beginning of a breakpoint command list.
124</p>
125<p>The commands <code>echo</code>, <code>output</code>, and <code>printf</code> allow you to
126print precisely controlled output, and are often useful in silent
127breakpoints.  See <a href="Output.html#Output">Commands for Controlled Output</a>.
128</p>
129<p>For example, here is how you could use breakpoint commands to print the
130value of <code>x</code> at entry to <code>foo</code> whenever <code>x</code> is positive.
131</p>
132<div class="smallexample">
133<pre class="smallexample">break foo if x&gt;0
134commands
135silent
136printf &quot;x is %d\n&quot;,x
137cont
138end
139</pre></div>
140
141<p>One application for breakpoint commands is to compensate for one bug so
142you can test for another.  Put a breakpoint just after the erroneous line
143of code, give it a condition to detect the case in which something
144erroneous has been done, and give it commands to assign correct values
145to any variables that need them.  End with the <code>continue</code> command
146so that your program does not stop, and start with the <code>silent</code>
147command so that no output is produced.  Here is an example:
148</p>
149<div class="smallexample">
150<pre class="smallexample">break 403
151commands
152silent
153set x = y + 4
154cont
155end
156</pre></div>
157
158<hr>
159<div class="header">
160<p>
161Next: <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>
162</div>
163
164
165
166</body>
167</html>
168