如何调试超出初始断点的子进程

How to debug a child process beyond the initial breakpoint

我的应用有 a.exe,它启动 b.exe 并与之通信。顺序是:

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

我想中断 b.exe 接口方法调用。目前,我是这样做的:

  1. 运行 a.exe windbg下
  2. 输入.childdbg 1
  3. 等到b.exe开始,其初始断点中断。
  4. 在b.exe中设置另一个断点并继续。 必须在10秒内完成,否则a.exe会超时kill b.exe。

我设法做到了,但 10 秒超时有时会过去。有更好的方法吗?

看完我的问题,我找到了答案——让初始断点设置真正的断点:

.childdbg 1
sxe -c "bm b!*MyMethod*;g" ibp
sxd epr
:\>type childproc.cpp
#include<stdio.h>
#include<windows.h>
void main (void)
{
        LPTSTR path2child = "c:\windows\system32\calc.exe[=10=]";
        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>