代码:
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());
}
}
}
}
}
结果,我得到的不是方法名称 - “UNKNOWN”。但in方法是字段“InstructionPointer”,也许它会提供更多信息?
答案 0 :(得分:1)