Windbg条件断点不会中断?

时间:2019-01-27 20:07:31

标签: c debugging windbg

使用 Windbg ,我尝试使用以下src文件有条件地中断: basic_thread.cpp

9:  void __stdcall process()
10: {
11:    unsigned int count = 100000000;
12:    unsigned int hits = 0;
13:    for(unsigned int i = 0; i < count; i++)
14:    {
15:        // Not much to look at.
16:        hits++;
17:    }
18: }

我的断点设置如下:

bu `basic_thread.cpp:12` 
    ".if (poi(count)==0n100000000){.echo 'count==100000000'} .else {gc}"
bu `basic_thread.cpp:16` 
    ".if (poi(hits)==0n500){.echo 'hits==500'} .else {gc}"

设置它们之后,我重新启动程序并运行,但是断点从未实现?

.restart

g

我的断点怎么了?

修改

我已经阅读了官方文档here,断点看上去很准确,但是它们仍然没有中断。

1 个答案:

答案 0 :(得分:3)

您失败了,因为您将c ++表达式与MASM表达式混合在一起。 MASM引擎无法理解您的hitscounts。您必须使用@@c++()语法对它们进行限定。

我刚刚编译并运行了一个简单的测试来模拟您想要的问题:

:\>ls
windbp.cpp

:\>cl /Zi /W4 /Od /analyze /EHsc /nologo windbp.cpp /link /release /nologo
windbp.cpp

:\>cdb -c ".lines;bp `windbp.cpp:16` \".if( @@c++(hits) != 500 ) { gc }\";g" windbp.exe

结果是:

Microsoft (R) Windows Debugger Version 10.0.17763.132 X86

ntdll!LdrpDoDebuggerBreak+0x2c:
773005a6 cc              int     3

0:000> cdb: Reading initial command '.lines;bp `windbp.cpp:16` ".if( @@c++(hits) != 500 ) { gc }";g'
Line number information will be loaded
ModLoad: 6d300000 6d303000   C:\Windows\system32\api-ms-win-core-synch-l1-2-0.DLL
eax=00000500 ebx=7ffd6000 ecx=00000500 edx=00000500 esi=009c8648 edi=00349098
eip=0098102e esp=0028f838 ebp=0028f844 iopl=0         nv up ei ng nz na pe cy
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000287
windbp!process+0x2e:
0098102e 8b55f8          mov     edx,dword ptr [ebp-8] ss:0023:0028f83c=00000500
0:000> ?? hits
unsigned int 0x500
0:000>

这是我的样本src:

0:000> lsa .
     8: //space filler
     9: void __stdcall process()
    10: {
    11:    unsigned int count = 100000000;
    12:    unsigned int hits = 0;
    13:    for(unsigned int i = 0; i < count; i++)
    14:    {
    15:        // Not much to look at.
>   16:        hits++;
    17:    }
    18: }
    19:
    20: int main(void) {
    21:     process();
    22:     return 0;
    23: }
0:000>