To attach a debugger to a specific point, you have several options:
The easiest way is to just call DebugBreak , which is pretty much equivalent to __asm int 3 , but it also works with other architectures (MSVC for x64 does not allow inline assembly, if I remember correctly). This will bring up the debug window just in time, and you can choose from registered debuggers (for example, Visual Studio) to join the process.
Alternatively, you can enter a Sleep call, giving you the option to hook up a debugger. You should use #ifdef _DEBUG around this to make sure you are not really sending this code.
One question: why can't you run code from the IDE? Is this a service or a downloadable IIS DLL or similar?
In this case, you can check the ImageFileExecutionOptions registry ImageFileExecutionOptions , which allows you to attach a debugger at the start of the process.
If you use cdb for this, you can configure it as a server or client for the WinDbg instance and debug this path. I have done this in the past, using WinDbg as a kernel debugger, and using ImageFileExecutionOptions to run ntsd -d using the specified process. This causes WinDbg to enter user mode. This is sometimes a useful method.
Roger Lipscombe
source share