1<html lang="en"> 2<head> 3<title>Frames - Debugging with GDB</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Debugging with GDB"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Stack.html#Stack" title="Stack"> 9<link rel="next" href="Backtrace.html#Backtrace" title="Backtrace"> 10<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 11<!-- 12Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 131998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 14Free Software Foundation, Inc. 15 16Permission is granted to copy, distribute and/or modify this document 17under the terms of the GNU Free Documentation License, Version 1.3 or 18any later version published by the Free Software Foundation; with the 19Invariant Sections being ``Free Software'' and ``Free Software Needs 20Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' 21and with the Back-Cover Texts as in (a) below. 22 23(a) The FSF's Back-Cover Text is: ``You are free to copy and modify 24this GNU Manual. Buying copies from GNU Press supports the FSF in 25developing GNU and promoting software freedom.''--> 26<meta http-equiv="Content-Style-Type" content="text/css"> 27<style type="text/css"><!-- 28 pre.display { font-family:inherit } 29 pre.format { font-family:inherit } 30 pre.smalldisplay { font-family:inherit; font-size:smaller } 31 pre.smallformat { font-family:inherit; font-size:smaller } 32 pre.smallexample { font-size:smaller } 33 pre.smalllisp { font-size:smaller } 34 span.sc { font-variant:small-caps } 35 span.roman { font-family:serif; font-weight:normal; } 36 span.sansserif { font-family:sans-serif; font-weight:normal; } 37--></style> 38<link rel="stylesheet" type="text/css" href="../cs.css"> 39</head> 40<body> 41<div class="node"> 42<a name="Frames"></a> 43<p> 44Next: <a rel="next" accesskey="n" href="Backtrace.html#Backtrace">Backtrace</a>, 45Up: <a rel="up" accesskey="u" href="Stack.html#Stack">Stack</a> 46<hr> 47</div> 48 49<h3 class="section">8.1 Stack Frames</h3> 50 51<p><a name="index-frame_002c-definition-398"></a><a name="index-stack-frame-399"></a>The call stack is divided up into contiguous pieces called <dfn>stack 52frames</dfn>, or <dfn>frames</dfn> for short; each frame is the data associated 53with one call to one function. The frame contains the arguments given 54to the function, the function's local variables, and the address at 55which the function is executing. 56 57 <p><a name="index-initial-frame-400"></a><a name="index-outermost-frame-401"></a><a name="index-innermost-frame-402"></a>When your program is started, the stack has only one frame, that of the 58function <code>main</code>. This is called the <dfn>initial</dfn> frame or the 59<dfn>outermost</dfn> frame. Each time a function is called, a new frame is 60made. Each time a function returns, the frame for that function invocation 61is eliminated. If a function is recursive, there can be many frames for 62the same function. The frame for the function in which execution is 63actually occurring is called the <dfn>innermost</dfn> frame. This is the most 64recently created of all the stack frames that still exist. 65 66 <p><a name="index-frame-pointer-403"></a>Inside your program, stack frames are identified by their addresses. A 67stack frame consists of many bytes, each of which has its own address; each 68kind of computer has a convention for choosing one byte whose 69address serves as the address of the frame. Usually this address is kept 70in a register called the <dfn>frame pointer register</dfn> 71(see <a href="Registers.html#Registers">$fp</a>) while execution is going on in that frame. 72 73 <p><a name="index-frame-number-404"></a><span class="sc">gdb</span> assigns numbers to all existing stack frames, starting with 74zero for the innermost frame, one for the frame that called it, 75and so on upward. These numbers do not really exist in your program; 76they are assigned by <span class="sc">gdb</span> to give you a way of designating stack 77frames in <span class="sc">gdb</span> commands. 78 79<!-- The -fomit-frame-pointer below perennially causes hbox overflow --> 80<!-- underflow problems. --> 81 <p><a name="index-frameless-execution-405"></a>Some compilers provide a way to compile functions so that they operate 82without stack frames. (For example, the <span class="sc">gcc</span> option 83<pre class="smallexample"> ‘<samp><span class="samp">-fomit-frame-pointer</span></samp>’ 84</pre> 85 <p>generates functions without a frame.) 86This is occasionally done with heavily used library functions to save 87the frame setup time. <span class="sc">gdb</span> has limited facilities for dealing 88with these function invocations. If the innermost function invocation 89has no stack frame, <span class="sc">gdb</span> nevertheless regards it as though 90it had a separate frame, which is numbered zero as usual, allowing 91correct tracing of the function call chain. However, <span class="sc">gdb</span> has 92no provision for frameless functions elsewhere in the stack. 93 94 95<a name="index-frame_0040r_007b_002c-command_007d-406"></a> 96<a name="index-current-stack-frame-407"></a> 97<dl><dt><code>frame </code><var>args</var><dd>The <code>frame</code> command allows you to move from one stack frame to another, 98and to print the stack frame you select. <var>args</var> may be either the 99address of the frame or the stack frame number. Without an argument, 100<code>frame</code> prints the current stack frame. 101 102 <p><a name="index-select_002dframe-408"></a><a name="index-selecting-frame-silently-409"></a><br><dt><code>select-frame</code><dd>The <code>select-frame</code> command allows you to move from one stack frame 103to another without printing the frame. This is the silent version of 104<code>frame</code>. 105</dl> 106 107 </body></html> 108 109