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: Command Settings</title>
18
19<meta name="description" content="Debugging with GDB: Command Settings">
20<meta name="keywords" content="Debugging with GDB: Command Settings">
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="Commands.html#Commands" rel="up" title="Commands">
29<link href="Completion.html#Completion" rel="next" title="Completion">
30<link href="Command-Syntax.html#Command-Syntax" rel="previous" title="Command Syntax">
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="Command-Settings"></a>
65<div class="header">
66<p>
67Next: <a href="Completion.html#Completion" accesskey="n" rel="next">Completion</a>, Previous: <a href="Command-Syntax.html#Command-Syntax" accesskey="p" rel="previous">Command Syntax</a>, Up: <a href="Commands.html#Commands" accesskey="u" rel="up">Commands</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="Command-Settings-1"></a>
71<h3 class="section">3.2 Command Settings</h3>
72<a name="index-default-behavior-of-commands_002c-changing"></a>
73<a name="index-default-settings_002c-changing"></a>
74
75<p>Many commands change their behavior according to command-specific
76variables or settings.  These settings can be changed with the
77<code>set</code> subcommands.  For example, the <code>print</code> command
78(see <a href="Data.html#Data">Examining Data</a>) prints arrays differently depending on
79settings changeable with the commands <code>set print elements
80NUMBER-OF-ELEMENTS</code> and <code>set print array-indexes</code>, among others.
81</p>
82<p>You can change these settings to your preference in the gdbinit files
83loaded at <small>GDB</small> startup.  See <a href="Startup.html#Startup">Startup</a>.
84</p>
85<p>The settings can also be changed interactively during the debugging
86session.  For example, to change the limit of array elements to print,
87you can do the following:
88</p><div class="smallexample">
89<pre class="smallexample">(GDB) set print elements 10
90(GDB) print some_array
91$1 = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90...}
92</pre></div>
93
94<p>The above <code>set print elements 10</code> command changes the number of
95elements to print from the default of 200 to 10.  If you only intend
96this limit of 10 to be used for printing <code>some_array</code>, then you
97must restore the limit back to 200, with <code>set print elements
98200</code>.
99</p>
100<p>Some commands allow overriding settings with command options.  For
101example, the <code>print</code> command supports a number of options that
102allow overriding relevant global print settings as set by <code>set
103print</code> subcommands.  See <a href="Data.html#print-options">print options</a>.  The example above could be
104rewritten as:
105</p><div class="smallexample">
106<pre class="smallexample">(GDB) print -elements 10 -- some_array
107$1 = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90...}
108</pre></div>
109
110<p>Alternatively, you can use the <code>with</code> command to change a setting
111temporarily, for the duration of a command invocation.
112</p>
113<dl compact="compact">
114<dd><a name="index-with-command"></a>
115<a name="index-w-_0028with_0029"></a>
116<a name="index-settings"></a>
117<a name="index-temporarily-change-settings"></a>
118</dd>
119<dt><code>with <var>setting</var> [<var>value</var>] [-- <var>command</var>]</code></dt>
120<dt><code>w <var>setting</var> [<var>value</var>] [-- <var>command</var>]</code></dt>
121<dd><p>Temporarily set <var>setting</var> to <var>value</var> for the duration of
122<var>command</var>.
123</p>
124<p><var>setting</var> is any setting you can change with the <code>set</code>
125subcommands.  <var>value</var> is the value to assign to <code>setting</code>
126while running <code>command</code>.
127</p>
128<p>If no <var>command</var> is provided, the last command executed is
129repeated.
130</p>
131<p>If a <var>command</var> is provided, it must be preceded by a double dash
132(<code>--</code>) separator.  This is required because some settings accept
133free-form arguments, such as expressions or filenames.
134</p>
135<p>For example, the command
136</p><div class="smallexample">
137<pre class="smallexample">(GDB) with print array on -- print some_array
138</pre></div>
139<p>is equivalent to the following 3 commands:
140</p><div class="smallexample">
141<pre class="smallexample">(GDB) set print array on
142(GDB) print some_array
143(GDB) set print array off
144</pre></div>
145
146<p>The <code>with</code> command is particularly useful when you want to
147override a setting while running user-defined commands, or commands
148defined in Python or Guile.  See <a href="Extending-GDB.html#Extending-GDB">Extending GDB</a>.
149</p>
150<div class="smallexample">
151<pre class="smallexample">(GDB) with print pretty on -- my_complex_command
152</pre></div>
153
154<p>To change several settings for the same command, you can nest
155<code>with</code> commands.  For example, <code>with language ada -- with
156print elements 10</code> temporarily changes the language to Ada and sets a
157limit of 10 elements to print for arrays and strings.
158</p>
159</dd>
160</dl>
161
162<hr>
163<div class="header">
164<p>
165Next: <a href="Completion.html#Completion" accesskey="n" rel="next">Completion</a>, Previous: <a href="Command-Syntax.html#Command-Syntax" accesskey="p" rel="previous">Command Syntax</a>, Up: <a href="Commands.html#Commands" accesskey="u" rel="up">Commands</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>
166</div>
167
168
169
170</body>
171</html>
172