Windbg查看函数调用过程中的内存布局

文章详细分析了C语言函数调用时的汇编代码和内存布局,展示了参数传递、局部变量存储以及栈帧的变化过程,对调试和理解程序执行有重要参考价值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

     我们在分析问题的时候经常会需要查看进程的栈和帧中的值,下面我们就用一个简单的例子来分析一下这个过程。

源代码:

#include <iostream>
int add(int a, int b)
{
   return a + b;
}


int main()
{
    int a, b;
    a = 3;
    b = 4;
    int ret = add(a, b);
    std::cout << "Result:"<<ret<<"\t\n";
}

生成的汇编代码:

main 函数的汇编代码

 10 004c1000 55              push    ebp
   10 004c1001 8bec            mov     ebp,esp
   10 004c1003 83ec0c          sub     esp,0Ch
   12 004c1006 c745f803000000  mov     dword ptr [ebp-8],3
   13 004c100d c745fc04000000  mov     dword ptr [ebp-4],4
   14 004c1014 8b45fc          mov     eax,dword ptr [ebp-4]
   14 004c1017 50              push    eax
   14 004c1018 8b4df8          mov     ecx,dword ptr [ebp-8]
   14 004c101b 51              push    ecx
   14 004c101c e83f000000      call    statckTest!add (004c1060)
   14 004c1021 83c408          add     esp,8
   14 004c1024 8945f4          mov     dword ptr [ebp-0Ch],eax
   15 004c1027 6840314c00      push    offset statckTest!GS_ExceptionPointers+0x8 (004c3140)
   15 004c102c 8b55f4          mov     edx,dword ptr [ebp-0Ch]
   15 004c102f 52              push    edx
   15 004c1030 6844314c00      push    offset statckTest!std::_Fake_alloc+0x1 (004c3144)
   15 004c1035 a16c304c00      mov     eax,dword ptr [statckTest!_imp_?coutstd (004c306c)]
   15 004c103a 50              push    eax
   15 004c103b e8e0020000      call    statckTest!std::operator<<<std::char_traits<char> > (004c1320)
   15 004c1040 83c408          add     esp,8
   15 004c1043 8bc8            mov     ecx,eax
   15 004c1045 ff1540304c00    call    dword ptr [statckTest!_imp_??6?$basic_ostreamDU?$char_traitsDstdstdQAEAAV01HZ (004c3040)]
   15 004c104b 50              push    eax
   15 004c104c e8cf020000      call    statckTest!std::operator<<<std::char_traits<char> > (004c1320)
   15 004c1051 83c408          add     esp,8
   16 004c1054 33c0            xor     eax,eax
   16 004c1056 8be5            mov     esp,ebp
   16 004c1058 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值