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-2021 Free Software Foundation, Inc. 4 5Permission is granted to copy, distribute and/or modify this document 6under the terms of the GNU Free Documentation License, Version 1.3 or 7any later version published by the Free Software Foundation; with the 8Invariant Sections being "Free Software" and "Free Software Needs 9Free Documentation", with the Front-Cover Texts being "A GNU Manual," 10and with the Back-Cover Texts as in (a) below. 11 12(a) The FSF's Back-Cover Text is: "You are free to copy and modify 13this GNU Manual. Buying copies from GNU Press supports the FSF in 14developing GNU and promoting software freedom." --> 15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 16<head> 17<title>Debugging with GDB: Frames</title> 18 19<meta name="description" content="Debugging with GDB: Frames"> 20<meta name="keywords" content="Debugging with GDB: Frames"> 21<meta name="resource-type" content="document"> 22<meta name="distribution" content="global"> 23<meta name="Generator" content="makeinfo"> 24<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 25<link href="index.html#Top" rel="start" title="Top"> 26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> 27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 28<link href="Stack.html#Stack" rel="up" title="Stack"> 29<link href="Backtrace.html#Backtrace" rel="next" title="Backtrace"> 30<link href="Stack.html#Stack" rel="previous" title="Stack"> 31<style type="text/css"> 32<!-- 33a.summary-letter {text-decoration: none} 34blockquote.smallquotation {font-size: smaller} 35div.display {margin-left: 3.2em} 36div.example {margin-left: 3.2em} 37div.indentedblock {margin-left: 3.2em} 38div.lisp {margin-left: 3.2em} 39div.smalldisplay {margin-left: 3.2em} 40div.smallexample {margin-left: 3.2em} 41div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 42div.smalllisp {margin-left: 3.2em} 43kbd {font-style:oblique} 44pre.display {font-family: inherit} 45pre.format {font-family: inherit} 46pre.menu-comment {font-family: serif} 47pre.menu-preformatted {font-family: serif} 48pre.smalldisplay {font-family: inherit; font-size: smaller} 49pre.smallexample {font-size: smaller} 50pre.smallformat {font-family: inherit; font-size: smaller} 51pre.smalllisp {font-size: smaller} 52span.nocodebreak {white-space:nowrap} 53span.nolinebreak {white-space:nowrap} 54span.roman {font-family:serif; font-weight:normal} 55span.sansserif {font-family:sans-serif; font-weight:normal} 56ul.no-bullet {list-style: none} 57--> 58</style> 59 60 61</head> 62 63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 64<a name="Frames"></a> 65<div class="header"> 66<p> 67Next: <a href="Backtrace.html#Backtrace" accesskey="n" rel="next">Backtrace</a>, Up: <a href="Stack.html#Stack" accesskey="u" rel="up">Stack</a> [<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> 68</div> 69<hr> 70<a name="Stack-Frames"></a> 71<h3 class="section">8.1 Stack Frames</h3> 72 73<a name="index-frame_002c-definition"></a> 74<a name="index-stack-frame"></a> 75<p>The call stack is divided up into contiguous pieces called <em>stack 76frames</em>, or <em>frames</em> for short; each frame is the data associated 77with one call to one function. The frame contains the arguments given 78to the function, the function’s local variables, and the address at 79which the function is executing. 80</p> 81<a name="index-initial-frame"></a> 82<a name="index-outermost-frame"></a> 83<a name="index-innermost-frame"></a> 84<p>When your program is started, the stack has only one frame, that of the 85function <code>main</code>. This is called the <em>initial</em> frame or the 86<em>outermost</em> frame. Each time a function is called, a new frame is 87made. Each time a function returns, the frame for that function invocation 88is eliminated. If a function is recursive, there can be many frames for 89the same function. The frame for the function in which execution is 90actually occurring is called the <em>innermost</em> frame. This is the most 91recently created of all the stack frames that still exist. 92</p> 93<a name="index-frame-pointer"></a> 94<p>Inside your program, stack frames are identified by their addresses. A 95stack frame consists of many bytes, each of which has its own address; each 96kind of computer has a convention for choosing one byte whose 97address serves as the address of the frame. Usually this address is kept 98in a register called the <em>frame pointer register</em> 99(see <a href="Registers.html#Registers">$fp</a>) while execution is going on in that frame. 100</p> 101<a name="index-frame-level"></a> 102<a name="index-frame-number"></a> 103<p><small>GDB</small> labels each existing stack frame with a <em>level</em>, a 104number that is zero for the innermost frame, one for the frame that 105called it, and so on upward. These level numbers give you a way of 106designating stack frames in <small>GDB</small> commands. The terms 107<em>frame number</em> and <em>frame level</em> can be used interchangeably to 108describe this number. 109</p> 110<a name="index-frameless-execution"></a> 111<p>Some compilers provide a way to compile functions so that they operate 112without stack frames. (For example, the <small>GCC</small> option 113</p><div class="smallexample"> 114<pre class="smallexample">‘<samp>-fomit-frame-pointer</samp>’ 115</pre></div> 116<p>generates functions without a frame.) 117This is occasionally done with heavily used library functions to save 118the frame setup time. <small>GDB</small> has limited facilities for dealing 119with these function invocations. If the innermost function invocation 120has no stack frame, <small>GDB</small> nevertheless regards it as though 121it had a separate frame, which is numbered zero as usual, allowing 122correct tracing of the function call chain. However, <small>GDB</small> has 123no provision for frameless functions elsewhere in the stack. 124</p> 125<hr> 126<div class="header"> 127<p> 128Next: <a href="Backtrace.html#Backtrace" accesskey="n" rel="next">Backtrace</a>, Up: <a href="Stack.html#Stack" accesskey="u" rel="up">Stack</a> [<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> 129</div> 130 131 132 133</body> 134</html> 135