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-2021 Free Software Foundation, Inc. 4 5Permission is granted to copy, distribute and/or modify this document 6under the terms of the GNU Free Documentation License, Version 1.3 or 7any later version published by the Free Software Foundation; with the 8Invariant Sections being "Free Software" and "Free Software Needs 9Free Documentation", with the Front-Cover Texts being "A GNU Manual," 10and with the Back-Cover Texts as in (a) below. 11 12(a) The FSF's Back-Cover Text is: "You are free to copy and modify 13this GNU Manual. Buying copies from GNU Press supports the FSF in 14developing GNU and promoting software freedom." --> 15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 16<head> 17<title>Debugging with GDB: Aliases</title> 18 19<meta name="description" content="Debugging with GDB: Aliases"> 20<meta name="keywords" content="Debugging with GDB: Aliases"> 21<meta name="resource-type" content="document"> 22<meta name="distribution" content="global"> 23<meta name="Generator" content="makeinfo"> 24<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 25<link href="index.html#Top" rel="start" title="Top"> 26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> 27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 28<link href="Extending-GDB.html#Extending-GDB" rel="up" title="Extending GDB"> 29<link href="Interpreters.html#Interpreters" rel="next" title="Interpreters"> 30<link href="Multiple-Extension-Languages.html#Multiple-Extension-Languages" rel="previous" title="Multiple Extension Languages"> 31<style type="text/css"> 32<!-- 33a.summary-letter {text-decoration: none} 34blockquote.smallquotation {font-size: smaller} 35div.display {margin-left: 3.2em} 36div.example {margin-left: 3.2em} 37div.indentedblock {margin-left: 3.2em} 38div.lisp {margin-left: 3.2em} 39div.smalldisplay {margin-left: 3.2em} 40div.smallexample {margin-left: 3.2em} 41div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 42div.smalllisp {margin-left: 3.2em} 43kbd {font-style:oblique} 44pre.display {font-family: inherit} 45pre.format {font-family: inherit} 46pre.menu-comment {font-family: serif} 47pre.menu-preformatted {font-family: serif} 48pre.smalldisplay {font-family: inherit; font-size: smaller} 49pre.smallexample {font-size: smaller} 50pre.smallformat {font-family: inherit; font-size: smaller} 51pre.smalllisp {font-size: smaller} 52span.nocodebreak {white-space:nowrap} 53span.nolinebreak {white-space:nowrap} 54span.roman {font-family:serif; font-weight:normal} 55span.sansserif {font-family:sans-serif; font-weight:normal} 56ul.no-bullet {list-style: none} 57--> 58</style> 59 60 61</head> 62 63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 64<a name="Aliases"></a> 65<div class="header"> 66<p> 67Previous: <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> [<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> 68</div> 69<hr> 70<a name="Creating-New-Spellings-of-Existing-Commands"></a> 71<h3 class="section">23.6 Creating New Spellings of Existing Commands</h3> 72<a name="index-aliases-for-commands"></a> 73 74<p>It is often useful to define alternate spellings of existing commands. 75For example, if a new <small>GDB</small> command defined in Python has 76a long name to type, it is handy to have an abbreviated version of it 77that involves less typing. 78</p> 79<p><small>GDB</small> itself uses aliases. For example ‘<samp>s</samp>’ is an alias 80of the ‘<samp>step</samp>’ command even though it is otherwise an ambiguous 81abbreviation of other commands like ‘<samp>set</samp>’ and ‘<samp>show</samp>’. 82</p> 83<p>Aliases are also used to provide shortened or more common versions 84of multi-word commands. For example, <small>GDB</small> provides the 85‘<samp>tty</samp>’ alias of the ‘<samp>set inferior-tty</samp>’ command. 86</p> 87<p>You can define a new alias with the ‘<samp>alias</samp>’ command. 88</p> 89<dl compact="compact"> 90<dd> 91<a name="index-alias"></a> 92</dd> 93<dt><code>alias [-a] [--] <var>ALIAS</var> = <var>COMMAND</var> [DEFAULT-ARGS...]</code></dt> 94</dl> 95 96<p><var>ALIAS</var> specifies the name of the new alias. 97Each word of <var>ALIAS</var> must consist of letters, numbers, dashes and 98underscores. 99</p> 100<p><var>COMMAND</var> specifies the name of an existing command 101that is being aliased. 102</p> 103<p><var>COMMAND</var> can also be the name of an existing alias. In this case, 104<var>COMMAND</var> cannot be an alias that has default arguments. 105</p> 106<p>The ‘<samp>-a</samp>’ option specifies that the new alias is an abbreviation 107of the command. Abbreviations are not used in command completion. 108</p> 109<p>The ‘<samp>--</samp>’ option specifies the end of options, 110and is useful when <var>ALIAS</var> begins with a dash. 111</p> 112<p>You can specify <var>default-args</var> for your alias. 113These <var>default-args</var> will be automatically added before the alias 114arguments typed explicitly on the command line. 115</p> 116<p>For example, the below defines an alias <code>btfullall</code> that shows all local 117variables and all frame arguments: 118</p><div class="smallexample"> 119<pre class="smallexample">(gdb) alias btfullall = backtrace -full -frame-arguments all 120</pre></div> 121 122<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>. 123</p> 124<p>Here is a simple example showing how to make an abbreviation 125of a command so that there is less to type. 126Suppose you were tired of typing ‘<samp>disas</samp>’, the current 127shortest unambiguous abbreviation of the ‘<samp>disassemble</samp>’ command 128and you wanted an even shorter version named ‘<samp>di</samp>’. 129The following will accomplish this. 130</p> 131<div class="smallexample"> 132<pre class="smallexample">(gdb) alias -a di = disas 133</pre></div> 134 135<p>Note that aliases are different from user-defined commands. 136With a user-defined command, you also need to write documentation 137for it with the ‘<samp>document</samp>’ command. 138An alias automatically picks up the documentation of the existing command. 139</p> 140<p>Here is an example where we make ‘<samp>elms</samp>’ an abbreviation of 141‘<samp>elements</samp>’ in the ‘<samp>set print elements</samp>’ command. 142This is to show that you can make an abbreviation of any part 143of a command. 144</p> 145<div class="smallexample"> 146<pre class="smallexample">(gdb) alias -a set print elms = set print elements 147(gdb) alias -a show print elms = show print elements 148(gdb) set p elms 20 149(gdb) show p elms 150Limit on string chars or array elements to print is 200. 151</pre></div> 152 153<p>Note that if you are defining an alias of a ‘<samp>set</samp>’ command, 154and you want to have an alias for the corresponding ‘<samp>show</samp>’ 155command, then you need to define the latter separately. 156</p> 157<p>Unambiguously abbreviated commands are allowed in <var>COMMAND</var> and 158<var>ALIAS</var>, just as they are normally. 159</p> 160<div class="smallexample"> 161<pre class="smallexample">(gdb) alias -a set pr elms = set p ele 162</pre></div> 163 164<p>Finally, here is an example showing the creation of a one word 165alias for a more complex command. 166This creates alias ‘<samp>spe</samp>’ of the command ‘<samp>set print elements</samp>’. 167</p> 168<div class="smallexample"> 169<pre class="smallexample">(gdb) alias spe = set print elements 170(gdb) spe 20 171</pre></div> 172 173<hr> 174<div class="header"> 175<p> 176Previous: <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> [<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> 177</div> 178 179 180 181</body> 182</html> 183