Command-Settings.html 7.7 KB

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