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: Skipping Over Functions and Files</title>
18
19<meta name="description" content="Debugging with GDB: Skipping Over Functions and Files">
20<meta name="keywords" content="Debugging with GDB: Skipping Over Functions and Files">
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="Stopping.html#Stopping" rel="up" title="Stopping">
29<link href="Signals.html#Signals" rel="next" title="Signals">
30<link href="Continuing-and-Stepping.html#Continuing-and-Stepping" rel="previous" title="Continuing and Stepping">
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="Skipping-Over-Functions-and-Files"></a>
65<div class="header">
66<p>
67Next: <a href="Signals.html#Signals" accesskey="n" rel="next">Signals</a>, Previous: <a href="Continuing-and-Stepping.html#Continuing-and-Stepping" accesskey="p" rel="previous">Continuing and Stepping</a>, Up: <a href="Stopping.html#Stopping" accesskey="u" rel="up">Stopping</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>
68</div>
69<hr>
70<a name="Skipping-over-Functions-and-Files"></a>
71<h3 class="section">5.3 Skipping over Functions and Files</h3>
72<a name="index-skipping-over-functions-and-files"></a>
73
74<p>The program you are debugging may contain some functions which are
75uninteresting to debug.  The <code>skip</code> command lets you tell <small>GDB</small> to
76skip a function, all functions in a file or a particular function in
77a particular file when stepping.
78</p>
79<p>For example, consider the following C function:
80</p>
81<div class="smallexample">
82<pre class="smallexample">101     int func()
83102     {
84103         foo(boring());
85104         bar(boring());
86105     }
87</pre></div>
88
89<p>Suppose you wish to step into the functions <code>foo</code> and <code>bar</code>, but you
90are not interested in stepping through <code>boring</code>.  If you run <code>step</code>
91at line 103, you&rsquo;ll enter <code>boring()</code>, but if you run <code>next</code>, you&rsquo;ll
92step over both <code>foo</code> and <code>boring</code>!
93</p>
94<p>One solution is to <code>step</code> into <code>boring</code> and use the <code>finish</code>
95command to immediately exit it.  But this can become tedious if <code>boring</code>
96is called from many places.
97</p>
98<p>A more flexible solution is to execute <kbd>skip boring</kbd>.  This instructs
99<small>GDB</small> never to step into <code>boring</code>.  Now when you execute
100<code>step</code> at line 103, you&rsquo;ll step over <code>boring</code> and directly into
101<code>foo</code>.
102</p>
103<p>Functions may be skipped by providing either a function name, linespec
104(see <a href="Specify-Location.html#Specify-Location">Specify Location</a>), regular expression that matches the function&rsquo;s
105name, file name or a <code>glob</code>-style pattern that matches the file name.
106</p>
107<p>On Posix systems the form of the regular expression is
108&ldquo;Extended Regular Expressions&rdquo;.  See for example &lsquo;<samp>man 7 regex</samp>&rsquo;
109on <small>GNU</small>/Linux systems.  On non-Posix systems the form of the regular
110expression is whatever is provided by the <code>regcomp</code> function of
111the underlying system.
112See for example &lsquo;<samp>man 7 glob</samp>&rsquo; on <small>GNU</small>/Linux systems for a
113description of <code>glob</code>-style patterns.
114</p>
115<dl compact="compact">
116<dd><a name="index-skip"></a>
117</dd>
118<dt><code>skip <span class="roman">[</span><var>options</var><span class="roman">]</span></code></dt>
119<dd><p>The basic form of the <code>skip</code> command takes zero or more options
120that specify what to skip.
121The <var>options</var> argument is any useful combination of the following:
122</p>
123<dl compact="compact">
124<dt><code>-file <var>file</var></code></dt>
125<dt><code>-fi <var>file</var></code></dt>
126<dd><p>Functions in <var>file</var> will be skipped over when stepping.
127</p>
128</dd>
129<dt><code>-gfile <var>file-glob-pattern</var></code></dt>
130<dt><code>-gfi <var>file-glob-pattern</var></code></dt>
131<dd><a name="index-skipping-over-files-via-glob_002dstyle-patterns"></a>
132<p>Functions in files matching <var>file-glob-pattern</var> will be skipped
133over when stepping.
134</p>
135<div class="smallexample">
136<pre class="smallexample">(gdb) skip -gfi utils/*.c
137</pre></div>
138
139</dd>
140<dt><code>-function <var>linespec</var></code></dt>
141<dt><code>-fu <var>linespec</var></code></dt>
142<dd><p>Functions named by <var>linespec</var> or the function containing the line
143named by <var>linespec</var> will be skipped over when stepping.
144See <a href="Specify-Location.html#Specify-Location">Specify Location</a>.
145</p>
146</dd>
147<dt><code>-rfunction <var>regexp</var></code></dt>
148<dt><code>-rfu <var>regexp</var></code></dt>
149<dd><a name="index-skipping-over-functions-via-regular-expressions"></a>
150<p>Functions whose name matches <var>regexp</var> will be skipped over when stepping.
151</p>
152<p>This form is useful for complex function names.
153For example, there is generally no need to step into C<tt>++</tt> <code>std::string</code>
154constructors or destructors.  Plus with C<tt>++</tt> templates it can be hard to
155write out the full name of the function, and often it doesn&rsquo;t matter what
156the template arguments are.  Specifying the function to be skipped as a
157regular expression makes this easier.
158</p>
159<div class="smallexample">
160<pre class="smallexample">(gdb) skip -rfu ^std::(allocator|basic_string)&lt;.*&gt;::~?\1 *\(
161</pre></div>
162
163<p>If you want to skip every templated C<tt>++</tt> constructor and destructor
164in the <code>std</code> namespace you can do:
165</p>
166<div class="smallexample">
167<pre class="smallexample">(gdb) skip -rfu ^std::([a-zA-z0-9_]+)&lt;.*&gt;::~?\1 *\(
168</pre></div>
169</dd>
170</dl>
171
172<p>If no options are specified, the function you&rsquo;re currently debugging
173will be skipped.
174</p>
175<a name="index-skip-function"></a>
176</dd>
177<dt><code>skip function <span class="roman">[</span><var>linespec</var><span class="roman">]</span></code></dt>
178<dd><p>After running this command, the function named by <var>linespec</var> or the
179function containing the line named by <var>linespec</var> will be skipped over when
180stepping.  See <a href="Specify-Location.html#Specify-Location">Specify Location</a>.
181</p>
182<p>If you do not specify <var>linespec</var>, the function you&rsquo;re currently debugging
183will be skipped.
184</p>
185<p>(If you have a function called <code>file</code> that you want to skip, use
186<kbd>skip function file</kbd>.)
187</p>
188<a name="index-skip-file"></a>
189</dd>
190<dt><code>skip file <span class="roman">[</span><var>filename</var><span class="roman">]</span></code></dt>
191<dd><p>After running this command, any function whose source lives in <var>filename</var>
192will be skipped over when stepping.
193</p>
194<div class="smallexample">
195<pre class="smallexample">(gdb) skip file boring.c
196File boring.c will be skipped when stepping.
197</pre></div>
198
199<p>If you do not specify <var>filename</var>, functions whose source lives in the file
200you&rsquo;re currently debugging will be skipped.
201</p></dd>
202</dl>
203
204<p>Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
205These are the commands for managing your list of skips:
206</p>
207<dl compact="compact">
208<dd><a name="index-info-skip"></a>
209</dd>
210<dt><code>info skip <span class="roman">[</span><var>range</var><span class="roman">]</span></code></dt>
211<dd><p>Print details about the specified skip(s).  If <var>range</var> is not specified,
212print a table with details about all functions and files marked for skipping.
213<code>info skip</code> prints the following information about each skip:
214</p>
215<dl compact="compact">
216<dt><em>Identifier</em></dt>
217<dd><p>A number identifying this skip.
218</p></dd>
219<dt><em>Enabled or Disabled</em></dt>
220<dd><p>Enabled skips are marked with &lsquo;<samp>y</samp>&rsquo;.
221Disabled skips are marked with &lsquo;<samp>n</samp>&rsquo;.
222</p></dd>
223<dt><em>Glob</em></dt>
224<dd><p>If the file name is a &lsquo;<samp>glob</samp>&rsquo; pattern this is &lsquo;<samp>y</samp>&rsquo;.
225Otherwise it is &lsquo;<samp>n</samp>&rsquo;.
226</p></dd>
227<dt><em>File</em></dt>
228<dd><p>The name or &lsquo;<samp>glob</samp>&rsquo; pattern of the file to be skipped.
229If no file is specified this is &lsquo;<samp>&lt;none&gt;</samp>&rsquo;.
230</p></dd>
231<dt><em>RE</em></dt>
232<dd><p>If the function name is a &lsquo;<samp>regular expression</samp>&rsquo; this is &lsquo;<samp>y</samp>&rsquo;.
233Otherwise it is &lsquo;<samp>n</samp>&rsquo;.
234</p></dd>
235<dt><em>Function</em></dt>
236<dd><p>The name or regular expression of the function to skip.
237If no function is specified this is &lsquo;<samp>&lt;none&gt;</samp>&rsquo;.
238</p></dd>
239</dl>
240
241<a name="index-skip-delete"></a>
242</dd>
243<dt><code>skip delete <span class="roman">[</span><var>range</var><span class="roman">]</span></code></dt>
244<dd><p>Delete the specified skip(s).  If <var>range</var> is not specified, delete all
245skips.
246</p>
247<a name="index-skip-enable"></a>
248</dd>
249<dt><code>skip enable <span class="roman">[</span><var>range</var><span class="roman">]</span></code></dt>
250<dd><p>Enable the specified skip(s).  If <var>range</var> is not specified, enable all
251skips.
252</p>
253<a name="index-skip-disable"></a>
254</dd>
255<dt><code>skip disable <span class="roman">[</span><var>range</var><span class="roman">]</span></code></dt>
256<dd><p>Disable the specified skip(s).  If <var>range</var> is not specified, disable all
257skips.
258</p>
259<a name="index-set-debug-skip"></a>
260</dd>
261<dt><code>set debug skip <span class="roman">[</span>on|off<span class="roman">]</span></code></dt>
262<dd><p>Set whether to print the debug output about skipping files and functions.
263</p>
264<a name="index-show-debug-skip"></a>
265</dd>
266<dt><code>show debug skip</code></dt>
267<dd><p>Show whether the debug output about skipping files and functions is printed.
268</p>
269</dd>
270</dl>
271
272<hr>
273<div class="header">
274<p>
275Next: <a href="Signals.html#Signals" accesskey="n" rel="next">Signals</a>, Previous: <a href="Continuing-and-Stepping.html#Continuing-and-Stepping" accesskey="p" rel="previous">Continuing and Stepping</a>, Up: <a href="Stopping.html#Stopping" accesskey="u" rel="up">Stopping</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>
276</div>
277
278
279
280</body>
281</html>
282