| <html lang="en"> |
| <head> |
| <title>Inline Functions - Debugging with GDB</title> |
| <meta http-equiv="Content-Type" content="text/html"> |
| <meta name="description" content="Debugging with GDB"> |
| <meta name="generator" content="makeinfo 4.13"> |
| <link title="Top" rel="start" href="index.html#Top"> |
| <link rel="up" href="Optimized-Code.html#Optimized-Code" title="Optimized Code"> |
| <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> |
| <!-- |
| Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, |
| 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
| Free Software Foundation, Inc. |
| |
| Permission is granted to copy, distribute and/or modify this document |
| under the terms of the GNU Free Documentation License, Version 1.3 or |
| any later version published by the Free Software Foundation; with the |
| Invariant Sections being ``Free Software'' and ``Free Software Needs |
| Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' |
| and with the Back-Cover Texts as in (a) below. |
| |
| (a) The FSF's Back-Cover Text is: ``You are free to copy and modify |
| this GNU Manual. Buying copies from GNU Press supports the FSF in |
| developing GNU and promoting software freedom.''--> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <style type="text/css"><!-- |
| pre.display { font-family:inherit } |
| pre.format { font-family:inherit } |
| pre.smalldisplay { font-family:inherit; font-size:smaller } |
| pre.smallformat { font-family:inherit; font-size:smaller } |
| pre.smallexample { font-size:smaller } |
| pre.smalllisp { font-size:smaller } |
| span.sc { font-variant:small-caps } |
| span.roman { font-family:serif; font-weight:normal; } |
| span.sansserif { font-family:sans-serif; font-weight:normal; } |
| --></style> |
| <link rel="stylesheet" type="text/css" href="../cs.css"> |
| </head> |
| <body> |
| <div class="node"> |
| <a name="Inline-Functions"></a> |
| <p> |
| Up: <a rel="up" accesskey="u" href="Optimized-Code.html#Optimized-Code">Optimized Code</a> |
| <hr> |
| </div> |
| |
| <h3 class="section">11.1 Inline Functions</h3> |
| |
| <p><a name="index-inline-functions_002c-debugging-663"></a> |
| <dfn>Inlining</dfn> is an optimization that inserts a copy of the function |
| body directly at each call site, instead of jumping to a shared |
| routine. <span class="sc">gdb</span> displays inlined functions just like |
| non-inlined functions. They appear in backtraces. You can view their |
| arguments and local variables, step into them with <code>step</code>, skip |
| them with <code>next</code>, and escape from them with <code>finish</code>. |
| You can check whether a function was inlined by using the |
| <code>info frame</code> command. |
| |
| <p>For <span class="sc">gdb</span> to support inlined functions, the compiler must |
| record information about inlining in the debug information — |
| <span class="sc">gcc</span> using the <span class="sc">dwarf 2</span> format does this, and several |
| other compilers do also. <span class="sc">gdb</span> only supports inlined functions |
| when using <span class="sc">dwarf 2</span>. Versions of <span class="sc">gcc</span> before 4.1 |
| do not emit two required attributes (‘<samp><span class="samp">DW_AT_call_file</span></samp>’ and |
| ‘<samp><span class="samp">DW_AT_call_line</span></samp>’); <span class="sc">gdb</span> does not display inlined |
| function calls with earlier versions of <span class="sc">gcc</span>. It instead |
| displays the arguments and local variables of inlined functions as |
| local variables in the caller. |
| |
| <p>The body of an inlined function is directly included at its call site; |
| unlike a non-inlined function, there are no instructions devoted to |
| the call. <span class="sc">gdb</span> still pretends that the call site and the |
| start of the inlined function are different instructions. Stepping to |
| the call site shows the call site, and then stepping again shows |
| the first line of the inlined function, even though no additional |
| instructions are executed. |
| |
| <p>This makes source-level debugging much clearer; you can see both the |
| context of the call and then the effect of the call. Only stepping by |
| a single instruction using <code>stepi</code> or <code>nexti</code> does not do |
| this; single instruction steps always show the inlined body. |
| |
| <p>There are some ways that <span class="sc">gdb</span> does not pretend that inlined |
| function calls are the same as normal calls: |
| |
| <ul> |
| <li>You cannot set breakpoints on inlined functions. <span class="sc">gdb</span> |
| either reports that there is no symbol with that name, or else sets the |
| breakpoint only on non-inlined copies of the function. This limitation |
| will be removed in a future version of <span class="sc">gdb</span>; until then, |
| set a breakpoint by line number on the first line of the inlined |
| function instead. |
| |
| <li>Setting breakpoints at the call site of an inlined function may not |
| work, because the call site does not contain any code. <span class="sc">gdb</span> |
| may incorrectly move the breakpoint to the next line of the enclosing |
| function, after the call. This limitation will be removed in a future |
| version of <span class="sc">gdb</span>; until then, set a breakpoint on an earlier line |
| or inside the inlined function instead. |
| |
| <li><span class="sc">gdb</span> cannot locate the return value of inlined calls after |
| using the <code>finish</code> command. This is a limitation of compiler-generated |
| debugging information; after <code>finish</code>, you can step to the next line |
| and print a variable where your program stored the return value. |
| |
| </ul> |
| |
| </body></html> |
| |