如何在初始断点之外调试子进程

时间:2016-06-19 11:24:15

标签: windbg breakpoints

我的应用有一个启动b.exe并与之通信的程序。顺序是:

  1. a.exe启动b.exe,并等待b.exe中的事件超时10秒
  2. b.exe启动,注册为COM服务器,并发出事件信号
  3. a.exe调用COM接口中的方法
  4. 调用b.exe接口方法。 <<<<<我想在这里休息
  5. 我想打破b.exe接口方法调用。目前,我这样做:

    1. 在windbg
    2. 下运行a.exe
    3. 输入.childdbg 1
    4. 等到b.exe启动,其初始断点断开。
    5. 在b.exe中设置另一个断点并继续。 我必须在10秒内完成 ,否则a.exe会超时并杀死b.exe。
    6. 我设法做到了,但10秒的超时有时会过去。有没有更好的方法呢?

2 个答案:

答案 0 :(得分:4)

阅读我的问题,我找到了答案 - 让初始断点设置真正的断点:

.childdbg 1
sxe -c "bm b!*MyMethod*;g" ibp
sxd epr

答案 1 :(得分:1)

:\>type childproc.cpp
#include<stdio.h>
#include<windows.h>
void main (void)
{
        LPTSTR path2child = "c:\\windows\\system32\\calc.exe\0";
        PROCESS_INFORMATION pi = {0};
        STARTUPINFO si = {0};
        si.cb = sizeof(STARTUPINFO);
        printf("Creating a Child Process %s\n",path2child);
        CreateProcess(NULL,path2child,NULL,NULL,false,0,NULL,NULL,&si,&pi);
        printf("waiting for the child to %p to exit\n",pi.hProcess);
        WaitForSingleObject(pi.hProcess,INFINITE);
        printf("closing handles and exiting");
        CloseHandle(pi.hProcess);
        CloseHandle(pi.hThread);
}


:\>cat childbrk.txt
sxe -c"bp calc!WinMain;g" cpr;g
$$ set createprocess exception handler to execute commands and continue (go)


:\>cdb -o -c "$$>a< childbrk.txt;g" childproc.exe

Microsoft (R) Windows Debugger Version 10.0.10586.567 X86  
CommandLine: childproc.exe

Breakpoint 0 hit
eip=00071635 
calc!WinMain:
00071635 8bff            mov     edi,edi
1:001>