You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Command-Files.html 9.8KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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>Command Files (Debugging with GDB)</title>
  17. <meta name="description" content="Command Files (Debugging with GDB)">
  18. <meta name="keywords" content="Command Files (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="Sequences.html#Sequences" rel="up" title="Sequences">
  26. <link href="Output.html#Output" rel="next" title="Output">
  27. <link href="Hooks.html#Hooks" rel="prev" title="Hooks">
  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="Command-Files"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Output.html#Output" accesskey="n" rel="next">Output</a>, Previous: <a href="Hooks.html#Hooks" accesskey="p" rel="prev">Hooks</a>, Up: <a href="Sequences.html#Sequences" accesskey="u" rel="up">Sequences</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="Command-Files-1"></a>
  64. <h4 class="subsection">23.1.3 Command Files</h4>
  65. <a name="index-command-files"></a>
  66. <a name="index-scripting-commands"></a>
  67. <p>A command file for <small>GDB</small> is a text file made of lines that are
  68. <small>GDB</small> commands. Comments (lines starting with <kbd>#</kbd>) may
  69. also be included. An empty line in a command file does nothing; it
  70. does not mean to repeat the last command, as it would from the
  71. terminal.
  72. </p>
  73. <p>You can request the execution of a command file with the <code>source</code>
  74. command. Note that the <code>source</code> command is also used to evaluate
  75. scripts that are not Command Files. The exact behavior can be configured
  76. using the <code>script-extension</code> setting.
  77. See <a href="Extending-GDB.html#Extending-GDB">Extending GDB</a>.
  78. </p>
  79. <dl compact="compact">
  80. <dd><a name="index-source"></a>
  81. <a name="index-execute-commands-from-a-file"></a>
  82. </dd>
  83. <dt><code>source [-s] [-v] <var>filename</var></code></dt>
  84. <dd><p>Execute the command file <var>filename</var>.
  85. </p></dd>
  86. </dl>
  87. <p>The lines in a command file are generally executed sequentially,
  88. unless the order of execution is changed by one of the
  89. <em>flow-control commands</em> described below. The commands are not
  90. printed as they are executed. An error in any command terminates
  91. execution of the command file and control is returned to the console.
  92. </p>
  93. <p><small>GDB</small> first searches for <var>filename</var> in the current directory.
  94. If the file is not found there, and <var>filename</var> does not specify a
  95. directory, then <small>GDB</small> also looks for the file on the source search path
  96. (specified with the &lsquo;<samp>directory</samp>&rsquo; command);
  97. except that <samp>$cdir</samp> is not searched because the compilation directory
  98. is not relevant to scripts.
  99. </p>
  100. <p>If <code>-s</code> is specified, then <small>GDB</small> searches for <var>filename</var>
  101. on the search path even if <var>filename</var> specifies a directory.
  102. The search is done by appending <var>filename</var> to each element of the
  103. search path. So, for example, if <var>filename</var> is <samp>mylib/myscript</samp>
  104. and the search path contains <samp>/home/user</samp> then <small>GDB</small> will
  105. look for the script <samp>/home/user/mylib/myscript</samp>.
  106. The search is also done if <var>filename</var> is an absolute path.
  107. For example, if <var>filename</var> is <samp>/tmp/myscript</samp> and
  108. the search path contains <samp>/home/user</samp> then <small>GDB</small> will
  109. look for the script <samp>/home/user/tmp/myscript</samp>.
  110. For DOS-like systems, if <var>filename</var> contains a drive specification,
  111. it is stripped before concatenation. For example, if <var>filename</var> is
  112. <samp>d:myscript</samp> and the search path contains <samp>c:/tmp</samp> then <small>GDB</small>
  113. will look for the script <samp>c:/tmp/myscript</samp>.
  114. </p>
  115. <p>If <code>-v</code>, for verbose mode, is given then <small>GDB</small> displays
  116. each command as it is executed. The option must be given before
  117. <var>filename</var>, and is interpreted as part of the filename anywhere else.
  118. </p>
  119. <p>Commands that would ask for confirmation if used interactively proceed
  120. without asking when used in a command file. Many <small>GDB</small> commands that
  121. normally print messages to say what they are doing omit the messages
  122. when called from command files.
  123. </p>
  124. <p><small>GDB</small> also accepts command input from standard input. In this
  125. mode, normal output goes to standard output and error output goes to
  126. standard error. Errors in a command file supplied on standard input do
  127. not terminate execution of the command file&mdash;execution continues with
  128. the next command.
  129. </p>
  130. <div class="smallexample">
  131. <pre class="smallexample">gdb &lt; cmds &gt; log 2&gt;&amp;1
  132. </pre></div>
  133. <p>(The syntax above will vary depending on the shell used.) This example
  134. will execute commands from the file <samp>cmds</samp>. All output and errors
  135. would be directed to <samp>log</samp>.
  136. </p>
  137. <p>Since commands stored on command files tend to be more general than
  138. commands typed interactively, they frequently need to deal with
  139. complicated situations, such as different or unexpected values of
  140. variables and symbols, changes in how the program being debugged is
  141. built, etc. <small>GDB</small> provides a set of flow-control commands to
  142. deal with these complexities. Using these commands, you can write
  143. complex scripts that loop over data structures, execute commands
  144. conditionally, etc.
  145. </p>
  146. <dl compact="compact">
  147. <dd><a name="index-if"></a>
  148. <a name="index-else"></a>
  149. </dd>
  150. <dt><code>if</code></dt>
  151. <dt><code>else</code></dt>
  152. <dd><p>This command allows to include in your script conditionally executed
  153. commands. The <code>if</code> command takes a single argument, which is an
  154. expression to evaluate. It is followed by a series of commands that
  155. are executed only if the expression is true (its value is nonzero).
  156. There can then optionally be an <code>else</code> line, followed by a series
  157. of commands that are only executed if the expression was false. The
  158. end of the list is marked by a line containing <code>end</code>.
  159. </p>
  160. <a name="index-while"></a>
  161. </dd>
  162. <dt><code>while</code></dt>
  163. <dd><p>This command allows to write loops. Its syntax is similar to
  164. <code>if</code>: the command takes a single argument, which is an expression
  165. to evaluate, and must be followed by the commands to execute, one per
  166. line, terminated by an <code>end</code>. These commands are called the
  167. <em>body</em> of the loop. The commands in the body of <code>while</code> are
  168. executed repeatedly as long as the expression evaluates to true.
  169. </p>
  170. <a name="index-loop_005fbreak"></a>
  171. </dd>
  172. <dt><code>loop_break</code></dt>
  173. <dd><p>This command exits the <code>while</code> loop in whose body it is included.
  174. Execution of the script continues after that <code>while</code>s <code>end</code>
  175. line.
  176. </p>
  177. <a name="index-loop_005fcontinue"></a>
  178. </dd>
  179. <dt><code>loop_continue</code></dt>
  180. <dd><p>This command skips the execution of the rest of the body of commands
  181. in the <code>while</code> loop in whose body it is included. Execution
  182. branches to the beginning of the <code>while</code> loop, where it evaluates
  183. the controlling expression.
  184. </p>
  185. <a name="index-end-_0028if_002felse_002fwhile-commands_0029"></a>
  186. </dd>
  187. <dt><code>end</code></dt>
  188. <dd><p>Terminate the block of commands that are the body of <code>if</code>,
  189. <code>else</code>, or <code>while</code> flow-control commands.
  190. </p></dd>
  191. </dl>
  192. <hr>
  193. <div class="header">
  194. <p>
  195. Next: <a href="Output.html#Output" accesskey="n" rel="next">Output</a>, Previous: <a href="Hooks.html#Hooks" accesskey="p" rel="prev">Hooks</a>, Up: <a href="Sequences.html#Sequences" accesskey="u" rel="up">Sequences</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>
  196. </div>
  197. </body>
  198. </html>