Jonathan
Jonathan

Reputation: 7551

How to debug a child process beyond the initial breakpoint

My app has a.exe which launches b.exe and communicates with it. The sequence is:

  1. a.exe launches b.exe, and waits on an event from b.exe with a 10-second timeout
  2. b.exe starts, registers as a COM server, and signals the event
  3. a.exe calls a method in the COM interface
  4. b.exe interface method is called. <<<<< I want to break here

I want to break in b.exe interface method call. Currently, I do it like this:

  1. Run a.exe under windbg
  2. Enter .childdbg 1
  3. Wait until b.exe starts, and its initial breakpoint breaks.
  4. Set another breakpoint in b.exe and continue. I must do it within 10 seconds, otherwise a.exe will timeout and kill b.exe.

I managed to do it, but the 10-second timeout sometimes passes. Is there a better way to do it?

Upvotes: 1

Views: 1213

Answers (2)

blabb
blabb

Reputation: 9007

:\>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>

Upvotes: 1

Jonathan
Jonathan

Reputation: 7551

Reading my question, I found the answer - let the initial breakpoint set the real breakpoint:

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

Upvotes: 5

Related Questions