-1

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

phuclv
  • 37,963
  • 15
  • 156
  • 475

1 Answers1

0

Attach to a process B programatically

Method 1: Using VS

  1. Open B.vcxproj and not your solution (.sln containning projects A and B)
  2. Put your breakpoints

enter image description here

  1. Run this dos command from your project A via system() (or other variant):

    devenv /nosplash /run "G:\Logiciels\B\B.vcxproj" /nosplash /debugexe

  2. devenv is a command in your VS path. In my case it in:

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC

  3. When you run this command, B project is opened and break point reached.

Method 2: Using Windbg

Just call this command:

windbg -p ProcessID

Attach to a process B graphically

Open your B project in another instance, and attach to it like this :

enter image description here

And select your B.exe:

enter image description here

Landstalker
  • 1,368
  • 8
  • 9