Tuesday, February 17, 2009

Windows hangs while debugging - How to regain Windows GUI responsiveness

Following up on the issue I blogged about a while ago about Windows locking up while debugging multithreaded applications under CodeGear RAD Studio, someone from the CodeGear IDE forum suggested that Command Prompt would still work responsively. Some guessed that it could be due to Windows running out of GDI handles (how that is related to the debugger is beyond me, so if someone cares to explain, I'm all ears) and this proves to be quite correct.

Apparently, this problem has been confirmed on Microsoft Visual C++ 6 up to Visual Studio 2003 (have yet to heard anyone commenting about 2005 or 2008, so they could also be affected) and Borland C++ Builder 6 up to CodeGear C++ Builder 2009. So far I've gathered that this happens on both Windows Server 2003 and XP, regardless of the level of service pack installed.

In order to get your machine responsive again, you'd have to kill the debugger (which is BDS.exe / BCB.exe for CodeGear / Borland and MSDEV.exe / DevEnv.exe for Microsoft). The painful way is to bring up Windows Task Manager (Ctrl+Shift+ESC to save you a few minutes of right-clicking on the taskbar and waiting for the GUI to appear) and select the process to terminate. Going through that process will take you somewhere around 5 to 10 minutes. There's a simpler way though (courtesy of Ingo Zettl - thanks!), which requires less than 5 seconds if you have everything setup before starting your debug session:
  • Install SysInternals PsTools which could be found here http://technet.microsoft.com/en-us/sysinternals/bb896649.aspx
  • Start command prompt, go to the PsTools folder and leave the command window open
  • Start debugging
  • Once you hit the OS+debugger bug, Alt+TAB straight to the command window (beware: if you inadvertently Alt+TAB to the wrong window, you'll waste a few minutes waiting for Windows to respond)
  • Run PsList - you should get a list of processes running on your machine
  • Lookup the Pid (Process ID) of your debugger (e.g. BDS.exe)
  • Run PsKill e.g. - pskill -t [pid]
At this point, your machine should regain responsiveness.

We all have Microsoft to thank for this 'little' inconvenience which makes life 'fun' for us Win32 software developers.

2 comments:

Anonymous said...

Thank you so much. I am using visual studio 2008 with Windows server 2003 and while debugging windows hangs very frequently. This is so annoying especially when your boss is holding your neck to deliver.

Anonymous said...

Unfortunately, this solution doesn't work in my case. I'm using Visual Studio 2008 with Windows 7 and OS GUI completely hangs every time when I try to debug my application in unmanaged code. Command window is open but I can't switch to it using Alt+TAB. Previously this bug also occured under Windows XP and Windows Vista on different PC's.
Any ideas?