问题
I'm attempting to debug an ASP.NET application. It's particularly difficult as the bug only occurs in the released code deployed to production. It cannot be reproduced in the development or test environments.
I'd like to investigate further by creating a dump file at a particular line in the code where the problem is happening. However the production environment cannot be taken down at any point due to business requirements. That's also why remote debugging can't be used.
Does anyone know how I can force a dump file to be created for w3wp.exe at a certain point in the managed code, yet still allow the rest of the application to operate normally?
回答1:
If the web-app has the access rights to do so and you can deploy new code the environment, then you can manually create the dump file with the use of the DbgHelp API:
[DllImport("DbgHelp.dll", SetLastError = true)]
static extern bool MiniDumpWriteDump(IntPtr ProcessHandle, int ProcId, IntPtr FileHandle, int DumpType, IntPtr ExcpInfo, IntPtr UserInfo, IntPtr ExtInfo);
private static void DumpIt()
{
string outputFileName = "c:\\mem.dmp";
using (FileStream stream = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite))
{
using (Process proc = Process.GetCurrentProcess())
{
MiniDumpWriteDump(proc.Handle, proc.Id, stream.SafeFileHandle.DangerousGetHandle(), (int)0x00000306, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
}
}
}
回答2:
Just to add to Frederik's post, have a look a Tee's blog, but focus on using AdPlus which is command line tool that will help you create dump files for running processes. Tess has a number of examples of how to use this tool for collecting dump files to debug with.
来源:https://stackoverflow.com/questions/1181536/how-to-create-a-dump-of-the-current-asp-net-managed-process-for-debugging