问题
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 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 inconvenient so I tried this
if(IsDebuggerPresent())
DebugActiveProcess(processId);
However it seems B is attached to A's debugger instead of Visual Studio's debugger. 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
回答1:
Attach to a process B
programatically
Method 1: Using VS
- Open
B.vcxproj
and not your solution (.sln
containning projectsA
andB
) - Put your breakpoints
Run this dos command from your project A via
system()
(or other variant):devenv /nosplash /run "G:\Logiciels\B\B.vcxproj" /nosplash /debugexe
devenv
is 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:
windbg -p ProcessID
Attach to a process B
graphically
Open your B project in another instance, and attach to it like this :
And select your B.exe:
来源:https://stackoverflow.com/questions/60541684/how-to-attach-a-process-to-the-current-debugger-programmatically