Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
390 views
in Technique[技术] by (71.8m points)

c++ - debugging a process spawned with CreateProcess in Visual Studio

I've created a Windows/C++/WTL application that spawns a child process. The two processes communicate via anonymous pipes.

I'd like to be able to debug the child process.

Since both parent and child projects are in the same solution in Visual Studio 2008, is there any way to tell VS2008 that I'd like the debugger to debug both processes?

When I start the debugger with the parent process, the debugger won't break on any breakpoints in the child process code.

And since the child process is spawned by the parent process, I can't think of an easy way of attaching the child process (maybe via another instance of VS2008) when it's spawned.

Any insights greatly appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Plenty of options:

  • You can debug multiple .exes with one instance of the debugger by using Debug + Attach. I however always use two instances of Visual Studio, use Debug + Attach in the second one.

  • You could put a __debugbreak() in the child's code, the JIT debugger window will prompt you to select a debugger.

  • You can use the "Image File Execution Options" registry key to automatically launch a debugger as soon as the child .exe is started. Add a key named HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution OptionsYourApp.exe, set its "Debugger" value to "vsjitdebugger.exe"

  • There is a VS add-in that makes it easier yet, haven't tried it myself yet.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...