none
The simplest way to generate minidump for mixed managed & unmanaged stack?

    Question

  • I am looking for ways of generating minidump for mixed managed & unmanaged stack.

    dgbhelp.dll provides functions for writing minidumps, but I didn't see any evidence about it  could still work for my case.  And some other ways go so complex.

      Any guys who know how to write such a minidump by using managed code?

     

     Thanks.

    Saturday, May 19, 2007 8:56 AM

Answers

  • Hi Buddhist,

       I wrote a sample of how to use minidump in C#, I think it can help you.

    Code Snippet

            public class MiniDumpDemo
            {

                internal enum MINIDUMP_TYPE
                {
                    MiniDumpNormal = 0x00000000,
                    MiniDumpWithDataSegs = 0x00000001,
                    MiniDumpWithFullMemory = 0x00000002,
                    MiniDumpWithHandleData = 0x00000004,
                    MiniDumpFilterMemory = 0x00000008,
                    MiniDumpScanMemory = 0x00000010,
                    MiniDumpWithUnloadedModules = 0x00000020,
                    MiniDumpWithIndirectlyReferencedMemory = 0x00000040,
                    MiniDumpFilterModulePaths = 0x00000080,
                    MiniDumpWithProcessThreadData = 0x00000100,
                    MiniDumpWithPrivateReadWriteMemory = 0x00000200,
                    MiniDumpWithoutOptionalData = 0x00000400,
                    MiniDumpWithFullMemoryInfo = 0x00000800,
                    MiniDumpWithThreadInfo = 0x00001000,
                    MiniDumpWithCodeSegs = 0x00002000
                }
                [DllImport( "dbghelp.dll" )]
                static extern bool MiniDumpWriteDump (
                    IntPtr hProcess,
                    Int32 ProcessId,
                    IntPtr hFile,
                    MINIDUMP_TYPE DumpType,
                    IntPtr ExceptionParam,
                    IntPtr UserStreamParam,
                    IntPtr CallackParam );

                public static void MiniDumpToFile ( String fileToDump )
                {
                    FileStream fsToDump = null;
                    if ( File.Exists( fileToDump ) )
                        fsToDump = File.Open( fileToDump, FileMode.Append );
                    else
                        fsToDump = File.Create( fileToDump );
                    Process thisProcess = Process.GetCurrentProcess( );
                    MiniDumpWriteDump( thisProcess.Handle, thisProcess.Id,
                        fsToDump.SafeFileHandle.DangerousGetHandle( ), MINIDUMP_TYPE.MiniDumpNormal,
                        IntPtr.Zero, IntPtr.Zero, IntPtr.Zero );
                    fsToDump.Close( );
                }
            };

     

    And you can use it like this:

    Code Snippet
                String fileToDump = @"D:\test.dat";
                Program.MiniDumpDemo.MiniDumpToFile( fileToDump );

     

    Hope this can help you.

     

    Thanks!

     

    Thursday, May 24, 2007 3:13 AM

All replies

  • This post explains how to take minidumps it for managed code:

     

    http://voneinem-windbg.blogspot.com/2007/03/creating-and-analyzing-minidumps-in-net.html

     

    Yours,

       Alois Kraus

     

    Monday, May 21, 2007 6:27 AM
  • Thx. I'm testing it.

     

    Besides, do you know just using dbghelp.dll could satisfy my req?

    Monday, May 21, 2007 11:10 AM
  • You write in C++ right?  Why don't you just call MiniDumpWriteDump()?
    Monday, May 21, 2007 4:39 PM
  • No, I use C#, have to P/Invoke.
    Tuesday, May 22, 2007 12:14 AM
  • Hi Buddhist,

       I wrote a sample of how to use minidump in C#, I think it can help you.

    Code Snippet

            public class MiniDumpDemo
            {

                internal enum MINIDUMP_TYPE
                {
                    MiniDumpNormal = 0x00000000,
                    MiniDumpWithDataSegs = 0x00000001,
                    MiniDumpWithFullMemory = 0x00000002,
                    MiniDumpWithHandleData = 0x00000004,
                    MiniDumpFilterMemory = 0x00000008,
                    MiniDumpScanMemory = 0x00000010,
                    MiniDumpWithUnloadedModules = 0x00000020,
                    MiniDumpWithIndirectlyReferencedMemory = 0x00000040,
                    MiniDumpFilterModulePaths = 0x00000080,
                    MiniDumpWithProcessThreadData = 0x00000100,
                    MiniDumpWithPrivateReadWriteMemory = 0x00000200,
                    MiniDumpWithoutOptionalData = 0x00000400,
                    MiniDumpWithFullMemoryInfo = 0x00000800,
                    MiniDumpWithThreadInfo = 0x00001000,
                    MiniDumpWithCodeSegs = 0x00002000
                }
                [DllImport( "dbghelp.dll" )]
                static extern bool MiniDumpWriteDump (
                    IntPtr hProcess,
                    Int32 ProcessId,
                    IntPtr hFile,
                    MINIDUMP_TYPE DumpType,
                    IntPtr ExceptionParam,
                    IntPtr UserStreamParam,
                    IntPtr CallackParam );

                public static void MiniDumpToFile ( String fileToDump )
                {
                    FileStream fsToDump = null;
                    if ( File.Exists( fileToDump ) )
                        fsToDump = File.Open( fileToDump, FileMode.Append );
                    else
                        fsToDump = File.Create( fileToDump );
                    Process thisProcess = Process.GetCurrentProcess( );
                    MiniDumpWriteDump( thisProcess.Handle, thisProcess.Id,
                        fsToDump.SafeFileHandle.DangerousGetHandle( ), MINIDUMP_TYPE.MiniDumpNormal,
                        IntPtr.Zero, IntPtr.Zero, IntPtr.Zero );
                    fsToDump.Close( );
                }
            };

     

    And you can use it like this:

    Code Snippet
                String fileToDump = @"D:\test.dat";
                Program.MiniDumpDemo.MiniDumpToFile( fileToDump );

     

    Hope this can help you.

     

    Thanks!

     

    Thursday, May 24, 2007 3:13 AM
  • thx.

     

    It works!

    Thursday, May 24, 2007 2:30 PM
  • How would a user specifcy a process?
    Port of Seattle
    Sunday, December 27, 2009 12:25 AM
  • I


    ...

    My problem is that the .net compact framework does not support Process.Handle or
    FileStream.SafeFileHandle . I've looked at the docs and there is a Process.MainWindowHandle ,
    which might work, but there appears to be no way to get a handle to the FileStream .

    Any help would be appreciated.

    Cesar
    Wednesday, July 14, 2010 8:18 PM
  • Extra info. If you are in Window 7 and framework 4 Windows Error Reporting (WER) can be configured so that full user-mode dumps are collected and stored locally after a user-mode application crashes

    see for details: http://msdn.microsoft.com/en-us/library/bb787181(VS.85).aspx


    http://nicogis.blogspot.com

    Thursday, February 09, 2012 8:32 PM
  • Hello,

    I'm having an issue.

    The .dmp is created but when I load it in visual studio, it does open my process information; I see all the dependencies etc.

    But when I try to load symbol, it doesn’t find it. I’ve set the symbol path on a path that contains my pdb. (Same than the executable.) It says that my executable in a native exec, for me it should be managed as I’m using  C# and .Net 4 framework (running in x86 mode on a Win7 x64).

    Maybe I’m missing an option?

    Thanks for your help.

     


    • Edited by Vincss Thursday, December 27, 2012 4:36 PM
    Thursday, December 27, 2012 4:34 PM