This week I’m working behind the “Great Firewall” in China and Twitter is blocked by the Chinese government, but my blog is not. I would have tweeted this but instead dear reader, you get the complete back story along with the debugging challenge on how I figured out the problem.

While working with a customer we wanted to set up a test machine to get a minidump when anything crashed. That sounds like a job for the awesome ProcDump from Sysinternals; especially now that it can act as the post mortem debugger. In my elevated PowerShell window I typed the following command for ProcDump to set itself up as the debugger.

  1. [C:\WINDOWS\system32]>procdump -i -ma "c:\junk"
  2.  
  3. ProcDump v6.00 – Writes process dump files
  4. Copyright (C) 2009-2013 Mark Russinovich
  5. Sysinternals – www.sysinternals.com
  6. With contributions from Andrew Richards
  7.  
  8. Set:
  9.   HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug
  10.     (REG_SZ) Auto     = 1
  11.     (REG_SZ) Debugger = "C:\Util\procdump.exe" -j "-ma" %ld %ld %p
  12.  
  13.   HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug
  14.     (REG_SZ) Auto     = 1
  15.     (REG_SZ) Debugger = "C:\Util\procdump.exe" -j "-ma" %ld %ld %p
  16.  
  17. ProcDump is now set as the Just-in-time (AeDebug) debugger.

 

I started running tests and had some crashes, but no dumps were created. The ProcDump window appeared, but it opened and closed so fast I couldn’t see what the problem was, which made it hard to diagnose. Before you read on, stop and think how you’d solve this problem because it’s an interesting exercise.

One way I came up with was using screen recording software like Camtasia. That way could could slow down the playback and see if there was anything in the flashing ProcDump window. If the recording software is on the machine, that might work.

As a debugger kind of guy, my second thought was if I could get a debugger on the process, half the battle is won. The challenge is that the process we need to attach to is not under our control for starting and is ending far faster than I can move the mouse to attach using Visual Studio.

The Windows team thought about this problem many years ago and it’s Image File Execution Options (IFEO) to the rescue. This special registry key lets you tell the operating system when a specific EXE starts, run it under the debugger, among many other options. While you can manipulate IFEO with the registry editor, it’s best if you use GFLAGS.EXE that comes with WinDBG (the Debugging Tools for Windows). For more on WinDBG see my WintellectNOW video: http://www.wintellectnow.com/Videos/Watch/windows-debugger-windbg-for-native-debugging.

I need to note that GFLAGS.EXE is a very dangerous program. You can make your computer unbootable with it so be careful.

Below is my GFLAGS.EXE screen shot showing that I set up WinDBG as the debugger. Note that WinDBG is permanently in my path so I don’t need to add the full path when specifying the debugger value.

image

After triggering a crash I got into WinDBG and let ProcDump run to completion because that does not close the program’s console window.  That made it extremely easy to see what the issue happens to be.

  1. Writing dump file C:\WINDOWS\system32\-ma.dmp …
  2. Error creating dump file:
  3. Error 5 (0x5): Access is denied.

That’s a pretty strange filename ProcDump is trying to write and it’s certainly in the C:JUNK directory I wanted. That got me to look closely at the ProcDump command line I used. It looks like ProcDump requires the –i <Directory> to be the last command line argument when setting itself as the post mortem debugger. Sure enough when I reran my ProcDump command like the following, all the crashes were saved as minidumps.

  1. procdump -ma -i "c:\junk"

I hope this helps someone out for figuring out why ProcDump wasn’t working and gave you a trick for getting a debugger on the process even if that process is not under your control.