views:

511

answers:

4

I have a multi-threaded Windows application that occasionally deadlocks. Inevitably this happens on a customer system and not when the software is in test. What is the easiest way of getting a Windows Minidump of the current state of the application? If it could also terminate the application so the user can restart it and continue using the system that would be great.

+2  A: 

See the Microsoft support article How to use ADPlus to troubleshoot "hangs" and "crashes", as well as the helpful blog post Debugging Production Applications using ADPlus.

Both of these articles are about "ADPlus", a VBScript tool supplied with Debugging Tools for Windows that can be used to generate minidumps from a production environment (which can later be loaded up with WinDbg on your development machine). ADPlus has a lot of functionality and a lot of options, so it may take some reading, experimentation, and practice to find the best way to use it in your environment.

Bradley Grainger
The snag with ADPlus is that it requires software to be installed on the end user machine. A common scenario I have is remote customers with sensitive data and a business critical service on their Windows Servers. They are somewhat reluctant to install additional software.
davefiddes
From http://support.microsoft.com/kb/286350: "ADPlus supports XCOPY deployment. ... Additionally, ADPlus does not require that you register any custom Component Object Model (COM) components on the system. Because of this, you can use ADPlus on production servers that have a locked-down software configuration."I haven't tried, but you could probably even run it off a flash drive.
Bradley Grainger
+1  A: 

I know how to achieve this. It's just my technique is a bit clunky. All Windows 2000 and later systems have a basic command line debugger as part of the default install called NTSD. What I do at the moment is run:

ntsd -pn MyApp.exe

When the debugger console appears I can then type the following into the debugger console:

.dump c:\my-deadlock.mdmp
.kill

What I'm looking for is something that's a little bit cleaner and easier to put in an email to customers to just run. I've seen it alluded to somewhere (that google can't find for now) that you can use drwtsn32.exe to extract a crash dump and terminate an application.

Edit: It is possible to streamline the command somewhat:

ntsd -pn MyApp.exe -c ".dump c:\my-deadlock.mdmp; .kill"

The command .detach can be given if the process has not terminally hung (e.g. a long network timeout) and you want the process to keep going.

davefiddes
ntsd is no longer installed by default in Vista
Rob Walker
+1  A: 

In Vista you can create a dump file directly from task manager. Right click on a process in the processes tab and choose 'create dump file'.

Prior to Vista I prefer the ntsd route, since although it is not totally user friendly it works without the user installing any other software and the instructions are actually fairly easy to follow.

Rob Walker
A: 

What that dump file will contain ?

Are you sure that it contains enough information to debug the problem ?

Kulvinder Singh
A mini dump will contain stack traces from all of the threads in the process. For a straight forward deadlock this is usually sufficient to figure out where it got stuck. You're right it will not always tell you how you got there.
davefiddes