简体   繁体   中英

Debug a process started by the current project

My Visual studio solution contains two C++ console projects, 'A' and 'B', where 'A' programmatically starts B (using CreateProcess()).

If I start stepping through 'A' after the point where 'B' has been created, how can I have breakpoints in the 'B' project be detected and stopped at?

Currently I just stick a "DebugBreak()" at specific points in 'B', but this is rather annoying as it usually takes a while for that window to pop up that allows you to debug the app with a VS instance, and often it won't show up the current instance, so I have to start another that takes even longer.

I can't use attach to process, as 'B' starts up, does its thing and then closes too quick.

Is there any of marking a project to be automatically attached, enabling me for example to have a breakpoint right at the beginning of main (similar to DebugBreak at the beginning of main)?

I found this note on MSDN:

The debugger does not automatically attach to a child process that is started by a debugged process, even if the child project is in the same solution. To debug a child process:

  • Attach to the child process after it has been started.
  • -or-
  • Configure Windows to automatically start the child process in a new instance of the debugger.

The latter of which can apparently be accomplished by some registry meddling: Automatically start a process in the debugger

The Visual Studio team has released a Visual Studio extension that allows automatically attaching child processes to the current debugger: Introducing the Child Process Debugging Power Tool .

It is available on the Gallery for Visual Studio 2013 and above.

So you can start your Project B from Project A with Process.Start and it will automatically attach the debugger to this second process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM