CTRL+C Exception Handling Under WinDbg

Last reviewed: December 16, 1996
Article ID: Q97858
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK) versions 3.1, 3.5, 3.51, and 4.0

SUMMARY

An exception is raised for CTRL+C only if the process is being debugged. The purpose is to make it convenient for the debugger to catch CTRL+C in console applications. For the purposes of this article, the debugger is assumed to be WinDbg.

MORE INFORMATION

When the console server detects a CTRL+C, it uses CreateRemoteThread() to create a thread in the client process to handle the event. This new thread then raises an exception IF AND ONLY IF the process is being debugged. At this point, the debugger either handles the exception or it continues the exception unhandled.

The "gh" command marks the exception as having been handled and continues the execution. The application does not notice the CTRL+C, with one exception: CTRL+C causes alertable waits to terminate. This is most noticeable when executing:

   while( (c = getchar()) != EOF )  - or -  while( gets(s) )

It is not possible to get the debugger to stop the wait from terminating.

The "gn" command marks an exception as unhandled and continues the execution. The handler list for the application is searched, as documented for SetConsoleCtrlHandler(). The handler is executed in the thread created by the console server.

After the exception is handled, the thread created to handle the event terminates. The debugger will not continue to execute the application if Go On Thread Termination is not enabled (from the Options menu, choose Debug, and select the Go On Thread Termination check box). The thread and process status indicate that the application is stopped at a debug event. As soon as the debugger is given a go command, the dead thread disappears and the application continues execution.

There are three cases where CTRL+C doesn't cause the program to stop executing (instead it causes a "page down"):

  1. When CTRL+C is already being handled.

  2. When the debugger is in the foreground and a source window has the focus (both must be true).

  3. When the CTRL+C exception is disabled (through the Debugger Exceptions dialog box).

This follows the convention of the WordStar/Turbo C/Turbo Pascal editor commands.


KBCategory: kbtool
KBSubcategory: TlsWindbg BseDebug
Additional reference words: 3.10 3.50 3.51 4.00 95


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 16, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.