cl /Zi /nologo /W4 /analyze %1% /link /RELEASE
在 msvc++2010exp 中 编译的片段
#include <stdio.h>
class MyClass {
int width,length;
public:
void set_val(int,int);
int area();
};
void MyClass::set_val(int x , int y) {
width = x;
length = y;
}
int MyClass::area() {
return width*length;
}
void main(void) {
MyClass foo;
for (int i = 0; i < 10; i++) {
foo.set_val(i,5);
printf("%d\n",foo.area());
}
}
在 windbg 中,在 set_val() 上设置条件断点以在宽度 == 7 时中断
条件断点语法说明
classtest!MyClass::set_val
<module!class::method>
@@c++()
usingc++ expression evaluator
@ecx
保持this pointer
适当的类型转换MyClass *
width
为member of MyClass
我们6
在此演示中用于比较目的,
因为我们正在设置break point prior to execution of set_val()
方法
(请注意在显示 MyClass 后uninitialized garbage
打印go from 条件以中断时first time
gc
if width != 7
.else is implied
width == 7
命令应该在一行
bp classtest!MyClass::set_val
".if( @@c++((((MyClass *) @ecx )->width)) != 6 ) {dt MyClass @ecx ; gc }"
结果
0:000> bp classtest!MyClass::set_val ".if( @@c++((((MyClass *) @ecx )->width)) != 6 ) {dt MyClass @ecx ; gc }"
0:000> bl
0 e 00401000 0001 (0001) 0:**** classtest!MyClass::set_val ".if( @@c++((((MyClass *) @ecx )->width)) != 6 ) {dt MyClass @ecx ; gc }"
0:000> g
ModLoad: 5cb70000 5cb96000 C:\WINDOWS\system32\ShimEng.dll
classtest!MyClass
+0x000 width : 0n4205541
+0x004 length : 0n4208683
classtest!MyClass
+0x000 width : 0n0
+0x004 length : 0n5
classtest!MyClass
+0x000 width : 0n1
+0x004 length : 0n5
classtest!MyClass
+0x000 width : 0n2
+0x004 length : 0n5
classtest!MyClass
+0x000 width : 0n3
+0x004 length : 0n5
classtest!MyClass
+0x000 width : 0n4
+0x004 length : 0n5
classtest!MyClass
+0x000 width : 0n5
+0x004 length : 0n5
eax=00000007 ebx=7ffdf000 ecx=0013ff70 edx=00416680 esi=00000000 edi=0098f6ee
eip=00401000 esp=0013ff60 ebp=0013ff78 iopl=0 nv up ei ng nz ac po cy
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000293
classtest!MyClass::set_val:
00401000 55 push ebp
0:000> dd esp l3
0013ff60 0040106c 00000007 00000005
0:000> x @eip
0:000> ?? @eip
unsigned int 0x401000
0:000> lsa . 0,1
> 8: void MyClass::set_val(int x , int y) {
0:000> dv
this = 0xfffffffe
x = 0n7
y = 0n5