Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

260 Zeilen
10KB

  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>Define (Debugging with GDB)</title>
  17. <meta name="description" content="Define (Debugging with GDB)">
  18. <meta name="keywords" content="Define (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="Hooks.html#Hooks" rel="next" title="Hooks">
  27. <link href="Sequences.html#Sequences" rel="prev" title="Sequences">
  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="Define"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Hooks.html#Hooks" accesskey="n" rel="next">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="User_002ddefined-Commands"></a>
  64. <h4 class="subsection">23.1.1 User-defined Commands</h4>
  65. <a name="index-user_002ddefined-command"></a>
  66. <a name="index-arguments_002c-to-user_002ddefined-commands"></a>
  67. <p>A <em>user-defined command</em> is a sequence of <small>GDB</small> commands to
  68. which you assign a new name as a command. This is done with the
  69. <code>define</code> command. User commands may accept an unlimited number of arguments
  70. separated by whitespace. Arguments are accessed within the user command
  71. via <code>$arg0&hellip;$argN</code>. A trivial example:
  72. </p>
  73. <div class="smallexample">
  74. <pre class="smallexample">define adder
  75. print $arg0 + $arg1 + $arg2
  76. end
  77. </pre></div>
  78. <p>To execute the command use:
  79. </p>
  80. <div class="smallexample">
  81. <pre class="smallexample">adder 1 2 3
  82. </pre></div>
  83. <p>This defines the command <code>adder</code>, which prints the sum of
  84. its three arguments. Note the arguments are text substitutions, so they may
  85. reference variables, use complex expressions, or even perform inferior
  86. functions calls.
  87. </p>
  88. <a name="index-argument-count-in-user_002ddefined-commands"></a>
  89. <a name="index-how-many-arguments-_0028user_002ddefined-commands_0029"></a>
  90. <p>In addition, <code>$argc</code> may be used to find out how many arguments have
  91. been passed.
  92. </p>
  93. <div class="smallexample">
  94. <pre class="smallexample">define adder
  95. if $argc == 2
  96. print $arg0 + $arg1
  97. end
  98. if $argc == 3
  99. print $arg0 + $arg1 + $arg2
  100. end
  101. end
  102. </pre></div>
  103. <p>Combining with the <code>eval</code> command (see <a href="Output.html#eval">eval</a>) makes it easier
  104. to process a variable number of arguments:
  105. </p>
  106. <div class="smallexample">
  107. <pre class="smallexample">define adder
  108. set $i = 0
  109. set $sum = 0
  110. while $i &lt; $argc
  111. eval &quot;set $sum = $sum + $arg%d&quot;, $i
  112. set $i = $i + 1
  113. end
  114. print $sum
  115. end
  116. </pre></div>
  117. <dl compact="compact">
  118. <dd>
  119. <a name="index-define"></a>
  120. </dd>
  121. <dt><code>define <var>commandname</var></code></dt>
  122. <dd><p>Define a command named <var>commandname</var>. If there is already a command
  123. by that name, you are asked to confirm that you want to redefine it.
  124. The argument <var>commandname</var> may be a bare command name consisting of letters,
  125. numbers, dashes, dots, and underscores. It may also start with any
  126. predefined or user-defined prefix command.
  127. For example, &lsquo;<samp>define target my-target</samp>&rsquo; creates
  128. a user-defined &lsquo;<samp>target my-target</samp>&rsquo; command.
  129. </p>
  130. <p>The definition of the command is made up of other <small>GDB</small> command lines,
  131. which are given following the <code>define</code> command. The end of these
  132. commands is marked by a line containing <code>end</code>.
  133. </p>
  134. <a name="index-document"></a>
  135. <a name="index-end-_0028user_002ddefined-commands_0029"></a>
  136. </dd>
  137. <dt><code>document <var>commandname</var></code></dt>
  138. <dd><p>Document the user-defined command <var>commandname</var>, so that it can be
  139. accessed by <code>help</code>. The command <var>commandname</var> must already be
  140. defined. This command reads lines of documentation just as <code>define</code>
  141. reads the lines of the command definition, ending with <code>end</code>.
  142. After the <code>document</code> command is finished, <code>help</code> on command
  143. <var>commandname</var> displays the documentation you have written.
  144. </p>
  145. <p>You may use the <code>document</code> command again to change the
  146. documentation of a command. Redefining the command with <code>define</code>
  147. does not change the documentation.
  148. </p>
  149. <a name="index-define_002dprefix"></a>
  150. </dd>
  151. <dt><code>define-prefix <var>commandname</var></code></dt>
  152. <dd><p>Define or mark the command <var>commandname</var> as a user-defined prefix
  153. command. Once marked, <var>commandname</var> can be used as prefix command
  154. by the <code>define</code> command.
  155. Note that <code>define-prefix</code> can be used with a not yet defined
  156. <var>commandname</var>. In such a case, <var>commandname</var> is defined as
  157. an empty user-defined command.
  158. In case you redefine a command that was marked as a user-defined
  159. prefix command, the subcommands of the redefined command are kept
  160. (and <small>GDB</small> indicates so to the user).
  161. </p>
  162. <p>Example:
  163. </p><div class="example">
  164. <pre class="example">(gdb) define-prefix abc
  165. (gdb) define-prefix abc def
  166. (gdb) define abc def
  167. Type commands for definition of &quot;abc def&quot;.
  168. End with a line saying just &quot;end&quot;.
  169. &gt;echo command initial def\n
  170. &gt;end
  171. (gdb) define abc def ghi
  172. Type commands for definition of &quot;abc def ghi&quot;.
  173. End with a line saying just &quot;end&quot;.
  174. &gt;echo command ghi\n
  175. &gt;end
  176. (gdb) define abc def
  177. Keeping subcommands of prefix command &quot;def&quot;.
  178. Redefine command &quot;def&quot;? (y or n) y
  179. Type commands for definition of &quot;abc def&quot;.
  180. End with a line saying just &quot;end&quot;.
  181. &gt;echo command def\n
  182. &gt;end
  183. (gdb) abc def ghi
  184. command ghi
  185. (gdb) abc def
  186. command def
  187. (gdb)
  188. </pre></div>
  189. <a name="index-dont_002drepeat-1"></a>
  190. <a name="index-don_0027t-repeat-command"></a>
  191. </dd>
  192. <dt><code>dont-repeat</code></dt>
  193. <dd><p>Used inside a user-defined command, this tells <small>GDB</small> that this
  194. command should not be repeated when the user hits <tt class="key">RET</tt>
  195. (see <a href="Command-Syntax.html#Command-Syntax">repeat last command</a>).
  196. </p>
  197. <a name="index-help-user_002ddefined"></a>
  198. </dd>
  199. <dt><code>help user-defined</code></dt>
  200. <dd><p>List all user-defined commands and all python commands defined in class
  201. COMMAND_USER. The first line of the documentation or docstring is
  202. included (if any).
  203. </p>
  204. <a name="index-show-user"></a>
  205. </dd>
  206. <dt><code>show user</code></dt>
  207. <dt><code>show user <var>commandname</var></code></dt>
  208. <dd><p>Display the <small>GDB</small> commands used to define <var>commandname</var> (but
  209. not its documentation). If no <var>commandname</var> is given, display the
  210. definitions for all user-defined commands.
  211. This does not work for user-defined python commands.
  212. </p>
  213. <a name="index-infinite-recursion-in-user_002ddefined-commands"></a>
  214. <a name="index-show-max_002duser_002dcall_002ddepth"></a>
  215. <a name="index-set-max_002duser_002dcall_002ddepth"></a>
  216. </dd>
  217. <dt><code>show max-user-call-depth</code></dt>
  218. <dt><code>set max-user-call-depth</code></dt>
  219. <dd><p>The value of <code>max-user-call-depth</code> controls how many recursion
  220. levels are allowed in user-defined commands before <small>GDB</small> suspects an
  221. infinite recursion and aborts the command.
  222. This does not apply to user-defined python commands.
  223. </p></dd>
  224. </dl>
  225. <p>In addition to the above commands, user-defined commands frequently
  226. use control flow commands, described in <a href="Command-Files.html#Command-Files">Command Files</a>.
  227. </p>
  228. <p>When user-defined commands are executed, the
  229. commands of the definition are not printed. An error in any command
  230. stops execution of the user-defined command.
  231. </p>
  232. <p>If used interactively, commands that would ask for confirmation proceed
  233. without asking when used inside a user-defined command. Many <small>GDB</small>
  234. commands that normally print messages to say what they are doing omit the
  235. messages when used in a user-defined command.
  236. </p>
  237. <hr>
  238. <div class="header">
  239. <p>
  240. Next: <a href="Hooks.html#Hooks" accesskey="n" rel="next">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>
  241. </div>
  242. </body>
  243. </html>