42.windbg-调试技巧(定长、不定长参数thiscall平衡堆栈方式不同)
2013-05-13 17:46
211 查看
C++程序的成员函数默认使用的调用约定是thiscall,这种约定是把this指针放到ECX寄存器中.This调用协定也是要求被调用函数负责清理栈,因此不支持可变数时的参数,当我们在C++类中定义了可变数量参数的成员函数时,偏译器会自动改为使用C调用约定,当这种调用时,编译器会将所有参数压入栈中,再将this指针压入栈:
关键两点:1.this时,是被调用函灵敏清理栈 2.如果可变参数,则使用C约定,由调用者来清理
写个小demo测试:
关键两点:1.this时,是被调用函灵敏清理栈 2.如果可变参数,则使用C约定,由调用者来清理
写个小demo测试:
#include "stdafx.h" #include <stdio.h> enum MEAL {BREAKFAST, LUNCH, SUPPER}; class Cat { public: MEAL Fun0(MEAL i) { return i; } char* Fun1(MEAL i, ...) { return 0; } }; int main(int argc, char* argv[]) { Cat cat; cat.Fun0(BREAKFAST); cat.Fun1(BREAKFAST, "meat", "beaf", "rice"); return 0; }
0:000> x ThisCall!Cat::* 00401060 ThisCall!Cat::Fun0 (MEAL) 00401090 ThisCall!Cat::Fun1 (MEAL) 0:000> x ThisCall!main 00401000 ThisCall!main (int, char **) 0:000> bp 00401000先在main处下断点:
ThisCall!main: 00401000 55 push ebp 00401001 8bec mov ebp,esp 00401003 83ec44 sub esp,44h 00401006 53 push ebx 00401007 56 push esi 00401008 57 push edi 00401009 8d7dbc lea edi,[ebp-44h] 0040100c b911000000 mov ecx,11h 00401011 b8cccccccc mov eax,0CCCCCCCCh 00401016 f3ab rep stos dword ptr es:[edi] 00401018 6a00 push 0//入值BREAKFAST 0040101a 8d4dfc lea ecx,[ebp-4]//这地方明显ebp-4为Cat cat这个局部变量,也就是把this赋给ECX 0040101d e83e000000 call ThisCall!Cat::Fun0 (00401060)//Fun0后调用者不用清栈 00401022 68fce04000 push offset ThisCall!`string' (0040e0fc) 00401027 68f4e04000 push offset ThisCall!`string' (0040e0f4) 0040102c 68ece04000 push offset ThisCall!`string' (0040e0ec) 00401031 6a00 push 0 00401033 8d45fc lea eax,[ebp-4] 00401036 50 push eax 00401037 e854000000 call ThisCall!Cat::Fun1 (00401090) 0040103c 83c414 add esp,14h//Fun1后调用者需要清栈这样就看得很清楚了.
相关文章推荐
- windbg-调试技巧(定长、不定长参数thiscall平衡堆栈方式不同)
- 不同页面之间实现参数传递的几种方式
- java中不同的ORM框架实现对数据库批量插入数据库的方式与技巧
- Sharepoint学习笔记—Debug&TroubleShooting--不同调试对象的Attach方式
- 设计技巧20:建造模式:Builder 分不同的步骤创建复杂的对象,支持可变参数
- Flash Builder 4的快捷方式和调试技巧
- 不同页面之间实现参数传递的几种方式
- 【转载】Flash Builder 4的快捷方式和调试技巧
- C# 同一应用程序域不同线程之间的参数传递方式
- C技巧:结构体参数转成不定参数
- 以不同方式向Shell函数传递数组参数
- Ruby on Rails,通过页面链接向Controller中传递参数,附赠调试技巧
- OJ 调试技巧:VS2010 中 通过设置编译参数定义宏,无需修改源文件重定向标准输入输出
- eclispe技巧全解(包括代码重构,调试,快捷方式)
- 关于不同页面之间实现参数传递的几种方式讨论
- Ruby on Rails,通过页面链接向Controller中传递参数,附赠调试技巧
- 4.windbg-调试技巧(函数参数的入栈顺序)
- 不同场景下JVM参数的配置方式
- C技巧:结构体参数转成不定参数
- Java中不定项参数(可变参数)的作用和使用方式