views:

924

answers:

3

I'm currently developing an application that is comprised of five separate executables that communicate via ActiveMQ. I have a Visual Studio Solution that contains the five executable projects. One of the projects (the launcher.exe) launches the other four projects from their local folders as separate processes. As such, the launcher project is set as the "Startup Project" and, as a result, it's the only one I can set break points in and debug due to my limited knowledge of VS2005.

Is there a way to set multiple breakpoints across my five c++ projects in my single VS solution and debug them at the same time if the launcher project is the only project executed from VS?

Note: Manually starting new instances of each project via Visual Studio is not an option since their execution needs to be synchronized by the launcher.exe.

I apologize if this is convoluted, it's the best I can explain it. Thanks in advance for your help!

+5  A: 

What you need is in the Tools menu: Attach to Process. This gives you a list of running processes and allows you to attach your debugger to those processes.

For local debugging, Transport and Qualifier should keep their default values. The Attach To value just above the list determines which type of debugging you'll be doing (native or managed are the most common types), and normally the debugger can figure out a good default here as well.

The main interesting part is the list of processes - look in this list for the sub-processes you want to debug. Once you've found and selected the process, click Attach in the lower right corner (or just double-click the process), and the debugger will attach to that process and start debugging it.

You'll probably also want to enable the Debug Location toolbar, which provides a way to change the focus of the debugger to the various processes and threads you're attached to. Multi-process debugging within one Visual Studio instance can be tricky, so you can always consider starting separate instances to debug each different process.

Another tricky aspect of this can be debugging the initial startup of the sub-processes. Often the thing you want to debug happens before you can get the debugger attached, so you need some way to cause the process to wait for you to be ready. An easy way to do this in C++ is to use the IsDebuggerPresent function. Try adding this code to the very beginning of your main() function (or equivalent):

while( !IsDebuggerPresent() )
    Sleep( 500 );

Or try this code for C#:

while( !System.Diagnostics.Debugger.IsAttached )
    System.Threading.Thread.Sleep( 500 );
Charlie
A perfect answer! Thank you.
BeachRunnerJoe
+1  A: 

You can pick one at a time by running launcher manually (outside of visual studio, or with <ctrl-f5>) and then attaching to the process you want to debug once it's started. If it's one of the projects in your solution, you can set breakpoints and they'll get picked up when you attach the debugger.

Eclipse
+1  A: 

Did you know… You can start debugging multiple projects? - #268

Joel Lucsy
Now there's a cool tip!
Eclipse