Visual Studio: auto attach to a process when the process is spawned

Viewed 49378

I want to attach to a process(a.exe) as soon as it is spawned, is it doable with VS? I only know the name of the process. Actually what I want to accomplish is set a breakpoint in c# code, but the code is belonging to another executable which will be launched by current running application(c.exe). The code is inside the initialize period so it is impossible for me to do the attach manually.

10 Answers

When I've faced this situation before (and I controlled both processes), I found a decent workaround is to put a call to Debugger.Launch() in the spawning process' entry point. VS will then pop up a dialog box and let you attach to the process.

How about this: open project for a.exe in VS, set the breakpoints etc. Then open Project Properties for a.exe, Debugging tab, and set Command to c.exe. Then just hit Debug.

Unfortunately I never did this with managed projects, so I can be off the mark here. However, that's how I would do it with unmanaged (C++) projects. I think managed debugger should support it too.

If C# code being launched by unmanaged code then make sure you check "Unmanaged code debugging" @Project properties --> debug options..

As of VS 2013 SP2, there's a free tool from Microsoft, which does the same as "Spawned Process Catcher" mentioned before - attaching all processes, which are started by a process already in debugging. Note: I have only tested this with unmanaged C++ (this works flawlessly).

Microsoft Child Process Debugging Power Tool

MSDN Blog entry

Related