Search code examples
windbgdumpmemory-dumpclrmd

ClrMD Get Memory Dump time


I`m playing around with CLR Memory Diagnostics tool in order to analyze memory dumps.

Opening a dump using WinDBG, I am able to use .time command to get the debug session time (when dump was captured).

Does anybody knows the ClrMD API to get the date?


Solution

  • I've found the following way to solve this task, however it restricts us to the DbgEng usage only.

    1. Open dump file and specify DbgEng (so IDebugClient will be used)

      DataTarget.LoadCrashDump(pathToMemoryDumpFile, CrashDumpReader.DbgEng));
      
    2. Use the IDebugControl2 COM interface to get target time (ensure that you perform that on the same thread that started the session):

      uint secondsSinceUnix;
      var dbgCtrl2 = (IDebugControl2)sessionContext.DataTarget.DebuggerInterface;
      dbgCtrl2.GetCurrentTimeDate(out secondsSinceUnix);
      
    3. Convert secondsSinceUnix to DateTime using the approach described here.

    4. As output you will get UTC date time of the memory dump creation (or attaching time).

    It worked well for me :)