The program you are debugging may contain some functions which are
uninteresting to debug. The skip
command lets you tell gdb to
skip a function, all functions in a file or a particular function in
a particular file when stepping.
For example, consider the following C function:
101 int func() 102 { 103 foo(boring()); 104 bar(boring()); 105 }
Suppose you wish to step into the functions foo
and bar
, but you
are not interested in stepping through boring
. If you run step
at line 103, you'll enter boring()
, but if you run next
, you'll
step over both foo
and boring
!
One solution is to step
into boring
and use the finish
command to immediately exit it. But this can become tedious if boring
is called from many places.
A more flexible solution is to execute skip boring. This instructs
gdb never to step into boring
. Now when you execute
step
at line 103, you'll step over boring
and directly into
foo
.
Functions may be skipped by providing either a function name, linespec
(see Specify Location), regular expression that matches the function's
name, file name or a glob
-style pattern that matches the file name.
On Posix systems the form of the regular expression is
“Extended Regular Expressions”. See for example ‘man 7 regex’
on gnu/Linux systems. On non-Posix systems the form of the regular
expression is whatever is provided by the regcomp
function of
the underlying system.
See for example ‘man 7 glob’ on gnu/Linux systems for a
description of glob
-style patterns.
skip
[options]skip
command takes zero or more options
that specify what to skip.
The options argument is any useful combination of the following:
-file
file-fi
file-gfile
file-glob-pattern-gfi
file-glob-pattern(gdb) skip -gfi utils/*.c
-function
linespec-fu
linespec-rfunction
regexp-rfu
regexpThis form is useful for complex function names.
For example, there is generally no need to step into C++ std::string
constructors or destructors. Plus with C++ templates it can be hard to
write out the full name of the function, and often it doesn't matter what
the template arguments are. Specifying the function to be skipped as a
regular expression makes this easier.
(gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
If you want to skip every templated C++ constructor and destructor
in the std
namespace you can do:
(gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
If no options are specified, the function you're currently debugging will be skipped.
skip function
[linespec]If you do not specify linespec, the function you're currently debugging will be skipped.
(If you have a function called file
that you want to skip, use
skip function file.)
skip file
[filename](gdb) skip file boring.c File boring.c will be skipped when stepping.
If you do not specify filename, functions whose source lives in the file you're currently debugging will be skipped.
Skips can be listed, deleted, disabled, and enabled, much like breakpoints. These are the commands for managing your list of skips:
info skip
[range]info skip
prints the following information about each skip:
skip delete
[range]skip enable
[range]skip disable
[range]set debug skip
[on|off
]show debug skip