I have 2 projects in the solution that compile to A.exe and B.exe
A will start B and connect to it through a named pipe. I want to test the connection between them so I'd like to attach to both at the same time. Doing that manually every time is very tedious and inconvenient, especially when B will close after a timeout if it doesn't receive any data from A. Therefore I tried this
if (IsDebuggerPresent())
DebugActiveProcess(processId);
However it seems B is attached to A's debugger instead of Visual Studio's. So how can I attach B to VS debugger automatically?
I have windbg at hand for debugging crash dumps so it may also be a solution, as long as it can be done without multiple user interactions
Attach to a process
BprogramaticallyMethod 1: Using VS
B.vcxprojand not your solution (.slncontainning projectsAandB)Run this dos command from your project A via
system()(or other variant):devenv /nosplash /run "G:\Logiciels\B\B.vcxproj" /nosplash /debugexe
devenvis a command in your VS path. In my case it in:C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC
When you run this command, B project is opened and break point reached.
Method 2: Using Windbg
Just call this command:
Attach to a process
BgraphicallyOpen your B project in another instance, and attach to it like this :
And select your B.exe: