Debugger late attaching

I often want to debug processes launched by another process. Somehow I usually find myself interested in the early part of the launched process. Problem is, the interesting bit has often passed before I manage to attach. In these scenarios it’s useful to temporarily add these 3 lines of code before the interesting bit.

while (!IsDebuggerPresent())
    Sleep(50);
__debugbreak();

// interesting bit

I often use this trick to launch processes from a CLI instead of via Visual Studio, just to avoid having to copy paste and alter arguments in project properties. On that note, if someone knows of a good command-line / debug arguments plugin for Visual Studio, please leave a comment below! I use Martin Ridger’s excellent clink to get bash style ctrl+r searchable history on Windows btw.

3 thoughts on “Debugger late attaching”

Leave a Reply