Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically attach vs2005 debugger to a child processes

I have a main C++ app built in Visual Studio 2005, called A.exe. It spawns a child process, B.exe. I run process A in the debugger by hitting F5 -- the only way I know to hit breakpoints in process B is to wait for A to kick it off, then run Debug -> Attach to Process, and manually select B.exe. This doesn't work very well if I need to debug initialization code in process B -- I have to start putting in 10 second sleeps at the beginning.

Is there some trick in the vs2005 GUI that I'm missing?

I'm using native code, by the way.

Thanks, Nathan

like image 983
Nathan Monteleone Avatar asked Jan 15 '09 19:01

Nathan Monteleone


People also ask

How do I debug child processes?

There is an alternative way of debugging the child process. After fork() is executed, put a sleep() call in the code where the child executes, get the PID of the child using the ps utility, then attach the PID. Now, you can debug the child process, like any other process.

What does it mean to attach a debugger?

That means to attach a debugger (i.e visual studio's integrated debugger) to the process so you can pause it and inspect variables at runtime. This happens when you hit F5 automatically, or can be done manually using the debug menu. Follow this answer to receive notifications.


2 Answers

You can tell Windows to automatically attach the debugger when a certain process is started (by specifying the process name in a registry setting).

The details are here: http://msdn.microsoft.com/en-us/library/a329t4ed(v=vs.100).aspx

like image 114
zah Avatar answered Sep 21 '22 02:09

zah


You'd be hard pushed to make use of the debugbreak command in the child process as the debug process is not yet attached.

However, there is another that may be of use. Seeing as your creating the process, you'll have the handle to it. So give the DebugBreakProcess function a whirl.

like image 40
Simon Hughes Avatar answered Sep 21 '22 02:09

Simon Hughes