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