95 lines
4.9 KiB
HTML
95 lines
4.9 KiB
HTML
|
<html lang="en">
|
||
|
<head>
|
||
|
<title>Frames - 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="Stack.html#Stack" title="Stack">
|
||
|
<link rel="next" href="Backtrace.html#Backtrace" title="Backtrace">
|
||
|
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
|
||
|
<!--
|
||
|
Copyright (C) 1988-2019 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>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div class="node">
|
||
|
<a name="Frames"></a>
|
||
|
<p>
|
||
|
Next: <a rel="next" accesskey="n" href="Backtrace.html#Backtrace">Backtrace</a>,
|
||
|
Up: <a rel="up" accesskey="u" href="Stack.html#Stack">Stack</a>
|
||
|
<hr>
|
||
|
</div>
|
||
|
|
||
|
<h3 class="section">8.1 Stack Frames</h3>
|
||
|
|
||
|
<p><a name="index-frame_002c-definition-504"></a><a name="index-stack-frame-505"></a>The call stack is divided up into contiguous pieces called <dfn>stack
|
||
|
frames</dfn>, or <dfn>frames</dfn> for short; each frame is the data associated
|
||
|
with one call to one function. The frame contains the arguments given
|
||
|
to the function, the function's local variables, and the address at
|
||
|
which the function is executing.
|
||
|
|
||
|
<p><a name="index-initial-frame-506"></a><a name="index-outermost-frame-507"></a><a name="index-innermost-frame-508"></a>When your program is started, the stack has only one frame, that of the
|
||
|
function <code>main</code>. This is called the <dfn>initial</dfn> frame or the
|
||
|
<dfn>outermost</dfn> frame. Each time a function is called, a new frame is
|
||
|
made. Each time a function returns, the frame for that function invocation
|
||
|
is eliminated. If a function is recursive, there can be many frames for
|
||
|
the same function. The frame for the function in which execution is
|
||
|
actually occurring is called the <dfn>innermost</dfn> frame. This is the most
|
||
|
recently created of all the stack frames that still exist.
|
||
|
|
||
|
<p><a name="index-frame-pointer-509"></a>Inside your program, stack frames are identified by their addresses. A
|
||
|
stack frame consists of many bytes, each of which has its own address; each
|
||
|
kind of computer has a convention for choosing one byte whose
|
||
|
address serves as the address of the frame. Usually this address is kept
|
||
|
in a register called the <dfn>frame pointer register</dfn>
|
||
|
(see <a href="Registers.html#Registers">$fp</a>) while execution is going on in that frame.
|
||
|
|
||
|
<p><a name="index-frame-level-510"></a><a name="index-frame-number-511"></a><span class="sc">gdb</span> labels each existing stack frame with a <dfn>level</dfn>, a
|
||
|
number that is zero for the innermost frame, one for the frame that
|
||
|
called it, and so on upward. These level numbers give you a way of
|
||
|
designating stack frames in <span class="sc">gdb</span> commands. The terms
|
||
|
<dfn>frame number</dfn> and <dfn>frame level</dfn> can be used interchangeably to
|
||
|
describe this number.
|
||
|
|
||
|
<!-- The -fomit-frame-pointer below perennially causes hbox overflow -->
|
||
|
<!-- underflow problems. -->
|
||
|
<p><a name="index-frameless-execution-512"></a>Some compilers provide a way to compile functions so that they operate
|
||
|
without stack frames. (For example, the <span class="sc">gcc</span> option
|
||
|
<pre class="smallexample"> ‘<samp><span class="samp">-fomit-frame-pointer</span></samp>’
|
||
|
</pre>
|
||
|
<p>generates functions without a frame.)
|
||
|
This is occasionally done with heavily used library functions to save
|
||
|
the frame setup time. <span class="sc">gdb</span> has limited facilities for dealing
|
||
|
with these function invocations. If the innermost function invocation
|
||
|
has no stack frame, <span class="sc">gdb</span> nevertheless regards it as though
|
||
|
it had a separate frame, which is numbered zero as usual, allowing
|
||
|
correct tracing of the function call chain. However, <span class="sc">gdb</span> has
|
||
|
no provision for frameless functions elsewhere in the stack.
|
||
|
|
||
|
</body></html>
|
||
|
|