1

I have a program running which loads up a separate program to do some work for it. That separate program is run from the first, using Process.Start() and I need it to load into the Visual Studio debugger to single step through it.

Unfortunately, though I can run the first program in a debugger session, it still starts the second as a "proper" process. I need to have this second program open up in a debugger session. Normally I would just attach a debugger to the process once it's started but, in this case, I need it to breakpoint very early on (in the CInitDialog() function) and, as fast as I am, I can't outrun the code in this case.

A solution I found right here on Stack Overflow said to use Debugger.Launch() but that appears to be specific to C#.

I also thought of trying to cause a crash in the code (such as with a null pointer reference) to load up the debugger but I suspect this would mean single stepping would then be unavailable to me.

How can I do this?

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • http://blogs.msdn.com/b/visualstudioalm/archive/2014/11/24/introducing-the-child-process-debugging-power-tool.aspx – Cody Gray - on strike Jan 18 '16 at 06:36
  • Cody, you should make that an answer so I can upvote it. It's no good for me since I'm running VS2010 but it's still useful for others. – paxdiablo Jan 19 '16 at 04:31
  • Same for me, I just remembered hearing about it and thinking it was interesting looking. I couldn't justify making it any more than a comment because I'd never used it myself. – Cody Gray - on strike Jan 19 '16 at 05:28

1 Answers1

0

Visual C++ has a similar feature to the C# Debugger.Launch(), it's called DebugBreak(). This actually breaks the application and it will present you with a dialog box asking how you want to handle it:

enter image description here

If you select Debug the program at that point, it will then ask you whether you want to do it in a new Visual Studio session or an existing one. I tend to have the solution already open so I can effectively attach to that one - opening a new instance gives you just the file rather than the entire solution.

So you can simply insert that call in your code where you want to break, and allow the first program to run it as per normal. The second program will start up and break where you've placed the statement and you can then single-step and do all the other wondrous things a debugger allows.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953