4

Code:

using System.Diagnostics;
using System.Linq;
using Microsoft.Diagnostics.Runtime;
using Microsoft.Diagnostics.Runtime.Utilities;
using Microsoft.Diagnostics.Runtime.Utilities.Pdb;

namespace myDiagnostics
{
    public class myStackTraceInfo
    {
        public void Atach()
        {
            using (DataTarget target = DataTarget.AttachToProcess(Process.GetCurrentProcess().Id, 5000, AttachFlag.Passive))
            {
                ClrRuntime runtime = target.ClrVersions.First().CreateRuntime();
                foreach (ClrThread thread in runtime.Threads)
                {
                    foreach (ClrStackFrame frame in thread.StackTrace)
                        Console.Write(frame.Method.ToString());
                }
            }
        }
    }
}

As a result, I get instead of method names - "UNKNOWN". But the in method is the field "InstructionPointer", maybe it will give more information?

4

1 回答 1

1

UNKNOWN 表示该方法没有与之关联的托管方法。尝试将它附加到其他进程,也可以在所有堆栈中的所有框架上行走,我相信你会找到一些东西。

在这里,您可以找到转储堆栈(包括堆栈对象)的工作示例。

转储堆栈示例

于 2016-10-26T08:45:20.000 回答