Search notes:

WaitForDebugEvent

A debugger uses WaitForDebugEvent() to wait for a debugging event in the target process.
After calling WaitForDebugEvent(), the debugger stops executing until such a debugging event occurs in the target process. When it has occurred, all threads in the target process are stopped and execution resumes in the debugger.
The chapter How Debuggers Work (Inside Windows Debugging) lays out pseudo code that roughly explains how WaitForDebugEvent() is used:
CreateProcess("target.exe",… , DEBUG_PROCESS, …);

while (1) {

    WaitForDebugEvent(&event, …);

    switch (event) {

        case ModuleLoad:
            Handle/Ignore;
            break;

        case TerminateProcess:
            Handle/Ignore;
            break;

        case Exception: // (code breakpoint, single step, etc…)
            Handle/Ignore;
            break;
    }

    ContinueDebugEvent(…);
}

See also

Debugging Windows applications

Links

Writing the Debugger's Main Loop

Index