【问题标题】:Reading objects from memory with MDbgEng使用 MDbgEng 从内存中读取对象
【发布时间】:2016-06-03 23:27:48
【问题描述】:

我想帮助@mark 解决他在哪里asking for an API to dump many objects from a .NET crash dump file 的问题。

所以我使用mdbgeng 编写了以下代码,但不幸的是它在尝试枚举内存中的对象时失败并返回NotImplementedException

using System;
using System.Runtime.InteropServices;
using Microsoft.Samples.Debugging.CorDebug;
using Microsoft.Samples.Debugging.CorDebug.Utility;
using Microsoft.Samples.Debugging.MdbgEngine;
using Microsoft.Samples.Debugging.Native;

namespace DumpHeapFromDotNet
{
    class Program
    {
        static void Main(string[] args)
        {
            var libraryProvider =  new LibraryProvider();
            var dumpReader = new DumpReader(args[0]);
            var dataTarget = new DumpDataTarget(dumpReader);
            foreach (var module in dumpReader.EnumerateModules())
            {
                var clrDebugging = new CLRDebugging();
                Version actualVersion;
                ClrDebuggingProcessFlags flags;
                CorProcess proc;
                var hr = (HResult) clrDebugging.TryOpenVirtualProcess(module.BaseAddress, dataTarget, libraryProvider,
                    new Version(4, 6, int.MaxValue, int.MaxValue), out actualVersion, out flags, out proc);

                if (hr < 0)
                {
                    switch (hr)
                    {
                        case HResult.CORDBG_E_NOT_CLR:
                            Console.WriteLine(module.FullName + " is not a .NET module");
                            break;
                        case HResult.CORDBG_E_LIBRARY_PROVIDER_ERROR:
                            Console.WriteLine(module.FullName + " could not provide library");
                            break;
                        case HResult.CORDBG_E_UNSUPPORTED_DEBUGGING_MODEL:
                        case HResult.CORDBG_E_UNSUPPORTED_FORWARD_COMPAT:
                            break;
                        default:
                            Marshal.ThrowExceptionForHR((int)hr);
                            break;
                    }
                }
                else
                {
                    var objects = proc.Objects; // NotImplementedException
                    foreach (CorObjectValue o in objects)
                    {
                        // TODO: Write details of object to file here
                    }
                }
            }
            Console.ReadLine();
        }
    }
}

我使用的转储是具有完整内存的 .NET 4.6.1076.0 转储(您可以将文件名作为参数传递):

0:000> lm vm clr
[...]
ProductVersion:   4.6.1076.0
FileVersion:      4.6.1076.0 built by: NETFXREL3STAGE

0:000> .dumpdebug
----- User Mini Dump Analysis

MINIDUMP_HEADER:
Version         A793 (61B1)
NumberOfStreams 11
Flags           1806
                0002 MiniDumpWithFullMemory
                0004 MiniDumpWithHandleData
                0800 MiniDumpWithFullMemoryInfo
                1000 MiniDumpWithThreadInfo

我怀疑这与缺少 mscordacwks 或类似情况有关,因为我刚刚在同一台机器上创建了转储,使用的 .NET 框架与我用于此示例的相同。

真的还没有实现,还是我做错了什么?

【问题讨论】:

    标签: debugging windbg crash-dumps mdbg


    【解决方案1】:

    我目前正在搞乱 MDBG,我试图在实际应用程序上检查所描述的行为,而不是在转储上。我收到了完全相同的未实现异常。在 MSDN 上查找文档时,我发现了 method is not implemented 的确认。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 2013-11-18
      • 2023-03-23
      • 2012-01-13
      • 1970-01-01
      • 2021-02-15
      • 2010-11-19
      相关资源
      最近更新 更多