递归栈帧分析

来源:互联网 发布:java实现base64加密 编辑:程序博客网 时间:2024/06/03 20:10
<pre name="code" class="cpp">#include <stdio.h>/** * @source : c++ primer plus *        p239 程序清单7.16 recur.cpp */int countdown(int n);int main(){    countdown(4);    return 0;}int countdown(int n){    printf("Counting down ... %d\n", n);    if(n > 0){        countdown(n-1);    }    printf("%d : Kaboom! \n", n);}eip : 当前指令地址  ebp : 栈地址======================================================================Stack level 0, frame at 0xbffff2d0:----------------------------------------------------------------------eip = 0x8048406 in countdown (recur.c:11); saved eip 0x804842ecalled by frame at 0xbffff2f0source language c.Arglist at 0xbffff2c8, args: n=0Locals at 0xbffff2c8, Previous frame's sp is 0xbffff2d0Saved registers:  ebp at 0xbffff2c8, eip at 0xbffff2cc======================================================================Stack level 1, frame at 0xbffff2f0:----------------------------------------------------------------------eip = 0x804842e in countdown (recur.c:13); saved eip 0x804842ecalled by frame at 0xbffff310, caller of frame at 0xbffff2d0source language c.Arglist at 0xbffff2e8, args: n=1Locals at 0xbffff2e8, Previous frame's sp is 0xbffff2f0Saved registers: ebp at 0xbffff2e8, eip at 0xbffff2ec======================================================================Stack level 2, frame at 0xbffff310:----------------------------------------------------------------------eip = 0x804842e in countdown (recur.c:13); saved eip 0x804842ecalled by frame at 0xbffff330, caller of frame at 0xbffff2f0source language c.Arglist at 0xbffff308, args: n=2Locals at 0xbffff308, Previous frame's sp is 0xbffff310Saved registers: ebp at 0xbffff308, eip at 0xbffff30c======================================================================Stack level 3, frame at 0xbffff330:----------------------------------------------------------------------eip = 0x804842e in countdown (recur.c:13); saved eip 0x804842ecalled by frame at 0xbffff350, caller of frame at 0xbffff310source language c.Arglist at 0xbffff328, args: n=3Locals at 0xbffff328, Previous frame's sp is 0xbffff330Saved registers: ebp at 0xbffff328, eip at 0xbffff32c======================================================================Stack level 4, frame at 0xbffff350:----------------------------------------------------------------------eip = 0x804842e in countdown (recur.c:13); saved eip 0x80483f9called by frame at 0xbffff370, caller of frame at 0xbffff330source language c.Arglist at 0xbffff348, args: n=4Locals at 0xbffff348, Previous frame's sp is 0xbffff350Saved registers: ebp at 0xbffff348, eip at 0xbffff34c======================================================================Stack level 5, frame at 0xbffff370:---------------------------------------------------------------------- eip = 0x80483f9 in main (recur.c:6); saved eip 0xb7e394e3 caller of frame at 0xbffff350 source language c. Arglist at 0xbffff368, args:  Locals at 0xbffff368, Previous frame's sp is 0xbffff370 Saved registers: ebp at 0xbffff368, eip at 0xbffff36c======================================================================


参考资料:[1]:<GDB详解> http://www.cnblogs.com/ggjucheng/archive/2011/12/14/2288004.html

                    [2]:<函数调用之-frame>http://blog.csdn.net/yangzhongxuan/article/details/6910402

                    [3]:《c++ primer plus》

         

0 0