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: Command aliases default args</title> 18 19<meta name="description" content="Debugging with GDB: Command aliases default args"> 20<meta name="keywords" content="Debugging with GDB: Command aliases default args"> 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="Commands.html#Commands" rel="up" title="Commands"> 29<link href="Help.html#Help" rel="next" title="Help"> 30<link href="Command-Options.html#Command-Options" rel="previous" title="Command Options"> 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="Command-aliases-default-args"></a> 65<div class="header"> 66<p> 67Next: <a href="Help.html#Help" accesskey="n" rel="next">Help</a>, Previous: <a href="Command-Options.html#Command-Options" accesskey="p" rel="previous">Command Options</a>, Up: <a href="Commands.html#Commands" accesskey="u" rel="up">Commands</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="Automatically-Prepend-Default-Arguments-to-User_002dDefined-Aliases"></a> 71<h3 class="section">3.5 Automatically Prepend Default Arguments to User-Defined Aliases</h3> 72 73<p>You can tell <small>GDB</small> to always prepend some default arguments to 74the list of arguments provided explicitly by the user when using a 75user-defined alias. 76</p> 77<p>If you repeatedly use the same arguments or options for a command, you 78can define an alias for this command and tell <small>GDB</small> to 79automatically prepend these arguments or options to the list of 80arguments you type explicitly when using the alias<a name="DOCF3" href="#FOOT3"><sup>3</sup></a>. 81</p> 82<p>For example, if you often use the command <code>thread apply all</code> 83specifying to work on the threads in ascending order and to continue in case it 84encounters an error, you can tell <small>GDB</small> to automatically preprend 85the <code>-ascending</code> and <code>-c</code> options by using: 86</p> 87<div class="smallexample"> 88<pre class="smallexample">(gdb) alias thread apply asc-all = thread apply all -ascending -c 89</pre></div> 90 91<p>Once you have defined this alias with its default args, any time you type 92the <code>thread apply asc-all</code> followed by <code>some arguments</code>, 93<small>GDB</small> will execute <code>thread apply all -ascending -c some arguments</code>. 94</p> 95<p>To have even less to type, you can also define a one word alias: 96</p><div class="smallexample"> 97<pre class="smallexample">(gdb) alias t_a_c = thread apply all -ascending -c 98</pre></div> 99 100<p>As usual, unambiguous abbreviations can be used for <var>alias</var> 101and <var>default-args</var>. 102</p> 103<p>The different aliases of a command do not share their default args. 104For example, you define a new alias <code>bt_ALL</code> showing all possible 105information and another alias <code>bt_SMALL</code> showing very limited information 106using: 107</p><div class="smallexample"> 108<pre class="smallexample">(gdb) alias bt_ALL = backtrace -entry-values both -frame-arg all \ 109 -past-main -past-entry -full 110(gdb) alias bt_SMALL = backtrace -entry-values no -frame-arg none \ 111 -past-main off -past-entry off 112</pre></div> 113 114<p>(For more on using the <code>alias</code> command, see <a href="Aliases.html#Aliases">Aliases</a>.) 115</p> 116<p>Default args are not limited to the arguments and options of <var>command</var>, 117but can specify nested commands if <var>command</var> accepts such a nested command 118as argument. 119For example, the below defines <code>faalocalsoftype</code> that lists the 120frames having locals of a certain type, together with the matching 121local vars: 122</p><div class="smallexample"> 123<pre class="smallexample">(gdb) alias faalocalsoftype = frame apply all info locals -q -t 124(gdb) faalocalsoftype int 125#1 0x55554f5e in sleeper_or_burner (v=0xdf50) at sleepers.c:86 126i = 0 127ret = 21845 128</pre></div> 129 130<p>This is also very useful to define an alias for a set of nested <code>with</code> 131commands to have a particular combination of temporary settings. For example, 132the below defines the alias <code>pp10</code> that pretty prints an expression 133argument, with a maximum of 10 elements if the expression is a string or 134an array: 135</p><div class="smallexample"> 136<pre class="smallexample">(gdb) alias pp10 = with print pretty -- with print elements 10 -- print 137</pre></div> 138<p>This defines the alias <code>pp10</code> as being a sequence of 3 commands. 139The first part <code>with print pretty --</code> temporarily activates the setting 140<code>set print pretty</code>, then launches the command that follows the separator 141<code>--</code>. 142The command following the first part is also a <code>with</code> command that 143temporarily changes the setting <code>set print elements</code> to 10, then 144launches the command that follows the second separator <code>--</code>. 145The third part <code>print</code> is the command the <code>pp10</code> alias will launch, 146using the temporary values of the settings and the arguments explicitly given 147by the user. 148For more information about the <code>with</code> command usage, 149see <a href="Command-Settings.html#Command-Settings">Command Settings</a>. 150</p> 151<div class="footnote"> 152<hr> 153<h4 class="footnotes-heading">Footnotes</h4> 154 155<h3><a name="FOOT3" href="#DOCF3">(3)</a></h3> 156<p><small>GDB</small> 157could easily accept default arguments for pre-defined commands and aliases, 158but it was deemed this would be confusing, and so is not allowed.</p> 159</div> 160<hr> 161<div class="header"> 162<p> 163Next: <a href="Help.html#Help" accesskey="n" rel="next">Help</a>, Previous: <a href="Command-Options.html#Command-Options" accesskey="p" rel="previous">Command Options</a>, Up: <a href="Commands.html#Commands" accesskey="u" rel="up">Commands</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> 164</div> 165 166 167 168</body> 169</html> 170