Skipping-Over-Functions-and-Files.html 12 KB

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