Aliases.html 8.2 KB

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