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.

182 lines
8.1KB

  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>Aliases (Debugging with GDB)</title>
  17. <meta name="description" content="Aliases (Debugging with GDB)">
  18. <meta name="keywords" content="Aliases (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="Extending-GDB.html#Extending-GDB" rel="up" title="Extending GDB">
  26. <link href="Interpreters.html#Interpreters" rel="next" title="Interpreters">
  27. <link href="Multiple-Extension-Languages.html#Multiple-Extension-Languages" rel="prev" title="Multiple Extension Languages">
  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="Aliases"></a>
  58. <div class="header">
  59. <p>
  60. Previous: <a href="Multiple-Extension-Languages.html#Multiple-Extension-Languages" accesskey="p" rel="prev">Multiple Extension Languages</a>, Up: <a href="Extending-GDB.html#Extending-GDB" accesskey="u" rel="up">Extending GDB</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="Creating-new-spellings-of-existing-commands"></a>
  64. <h3 class="section">23.6 Creating new spellings of existing commands</h3>
  65. <a name="index-aliases-for-commands"></a>
  66. <p>It is often useful to define alternate spellings of existing commands.
  67. For example, if a new <small>GDB</small> command defined in Python has
  68. a long name to type, it is handy to have an abbreviated version of it
  69. that involves less typing.
  70. </p>
  71. <p><small>GDB</small> itself uses aliases. For example &lsquo;<samp>s</samp>&rsquo; is an alias
  72. of the &lsquo;<samp>step</samp>&rsquo; command even though it is otherwise an ambiguous
  73. abbreviation of other commands like &lsquo;<samp>set</samp>&rsquo; and &lsquo;<samp>show</samp>&rsquo;.
  74. </p>
  75. <p>Aliases are also used to provide shortened or more common versions
  76. of multi-word commands. For example, <small>GDB</small> provides the
  77. &lsquo;<samp>tty</samp>&rsquo; alias of the &lsquo;<samp>set inferior-tty</samp>&rsquo; command.
  78. </p>
  79. <p>You can define a new alias with the &lsquo;<samp>alias</samp>&rsquo; command.
  80. </p>
  81. <dl compact="compact">
  82. <dd>
  83. <a name="index-alias"></a>
  84. </dd>
  85. <dt><code>alias [-a] [--] <var>ALIAS</var> = <var>COMMAND</var> [DEFAULT-ARGS...]</code></dt>
  86. </dl>
  87. <p><var>ALIAS</var> specifies the name of the new alias.
  88. Each word of <var>ALIAS</var> must consist of letters, numbers, dashes and
  89. underscores.
  90. </p>
  91. <p><var>COMMAND</var> specifies the name of an existing command
  92. that is being aliased.
  93. </p>
  94. <p><var>COMMAND</var> can also be the name of an existing alias. In this case,
  95. <var>COMMAND</var> cannot be an alias that has default arguments.
  96. </p>
  97. <p>The &lsquo;<samp>-a</samp>&rsquo; option specifies that the new alias is an abbreviation
  98. of the command. Abbreviations are not used in command completion.
  99. </p>
  100. <p>The &lsquo;<samp>--</samp>&rsquo; option specifies the end of options,
  101. and is useful when <var>ALIAS</var> begins with a dash.
  102. </p>
  103. <p>You can specify <var>default-args</var> for your alias.
  104. These <var>default-args</var> will be automatically added before the alias
  105. arguments typed explicitly on the command line.
  106. </p>
  107. <p>For example, the below defines an alias <code>btfullall</code> that shows all local
  108. variables and all frame arguments:
  109. </p><div class="smallexample">
  110. <pre class="smallexample">(gdb) alias btfullall = backtrace -full -frame-arguments all
  111. </pre></div>
  112. <p>For more information about <var>default-args</var>, see <a href="Command-aliases-default-args.html#Command-aliases-default-args">Automatically prepend default arguments to user-defined aliases</a>.
  113. </p>
  114. <p>Here is a simple example showing how to make an abbreviation
  115. of a command so that there is less to type.
  116. Suppose you were tired of typing &lsquo;<samp>disas</samp>&rsquo;, the current
  117. shortest unambiguous abbreviation of the &lsquo;<samp>disassemble</samp>&rsquo; command
  118. and you wanted an even shorter version named &lsquo;<samp>di</samp>&rsquo;.
  119. The following will accomplish this.
  120. </p>
  121. <div class="smallexample">
  122. <pre class="smallexample">(gdb) alias -a di = disas
  123. </pre></div>
  124. <p>Note that aliases are different from user-defined commands.
  125. With a user-defined command, you also need to write documentation
  126. for it with the &lsquo;<samp>document</samp>&rsquo; command.
  127. An alias automatically picks up the documentation of the existing command.
  128. </p>
  129. <p>Here is an example where we make &lsquo;<samp>elms</samp>&rsquo; an abbreviation of
  130. &lsquo;<samp>elements</samp>&rsquo; in the &lsquo;<samp>set print elements</samp>&rsquo; command.
  131. This is to show that you can make an abbreviation of any part
  132. of a command.
  133. </p>
  134. <div class="smallexample">
  135. <pre class="smallexample">(gdb) alias -a set print elms = set print elements
  136. (gdb) alias -a show print elms = show print elements
  137. (gdb) set p elms 20
  138. (gdb) show p elms
  139. Limit on string chars or array elements to print is 200.
  140. </pre></div>
  141. <p>Note that if you are defining an alias of a &lsquo;<samp>set</samp>&rsquo; command,
  142. and you want to have an alias for the corresponding &lsquo;<samp>show</samp>&rsquo;
  143. command, then you need to define the latter separately.
  144. </p>
  145. <p>Unambiguously abbreviated commands are allowed in <var>COMMAND</var> and
  146. <var>ALIAS</var>, just as they are normally.
  147. </p>
  148. <div class="smallexample">
  149. <pre class="smallexample">(gdb) alias -a set pr elms = set p ele
  150. </pre></div>
  151. <p>Finally, here is an example showing the creation of a one word
  152. alias for a more complex command.
  153. This creates alias &lsquo;<samp>spe</samp>&rsquo; of the command &lsquo;<samp>set print elements</samp>&rsquo;.
  154. </p>
  155. <div class="smallexample">
  156. <pre class="smallexample">(gdb) alias spe = set print elements
  157. (gdb) spe 20
  158. </pre></div>
  159. <hr>
  160. <div class="header">
  161. <p>
  162. Previous: <a href="Multiple-Extension-Languages.html#Multiple-Extension-Languages" accesskey="p" rel="prev">Multiple Extension Languages</a>, Up: <a href="Extending-GDB.html#Extending-GDB" accesskey="u" rel="up">Extending GDB</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>
  163. </div>
  164. </body>
  165. </html>