开发者

Get a Win32 program to request a debugger on startup?

We have a C++ Win32 application which spawns, using Qt's QProcess (undoubtedly a wrapper for CreateProcess()), a secondary 'slave' program.

Unfortunately, when debugging the system with Visual Studio 2008, the debugger does not automatically attach to the spawned process.

I know it's possible to programmatically trigger a debugger breakpoint with __debugbreak(), but is it possible for the slave program to throw up the 'Choose a Program to Debug This' window immediat开发者_StackOverflow中文版ely on startup since at the moment we have to race to manually attach to the new process?


Use Image File Execution Options. You can specify the Visual Studio just-in-time debugger as the default debugger to attach to the process.

If you're into using the command-line debuggers, you can use ntsd -o to automatically debug child processes as well.


Another neat trick that I learnt from reading "Programming Applications for Windows" by Jeffrey Richter

  1. Create a DLL with a call to DebugBreak() in DLLMain() inside DLL_PROCESS_ATTACH case
  2. Add path to your new DLL in the registry (it is a comma separated list):
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Windows\AppInit_DLLs

The image loader will create your process and load all DLLs entered in the registry. This will call DLLmain and your breakpoint will get hit.

Note: To avoid debugging all applications, check the process name with "GetModuleBasename" and call the break point only for processes you are interested.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜