代碼:如何使用Microsoft.Diagnostics.Runtime獲取有關StackTrace中的方法的信息?
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());
}
}
}
}
}
其結果是,我得到的替代方法的名稱 - 「未知」。但是in方法是「InstructionPointer」字段,也許它會提供更多信息?
這不是ClrMD的有效使用。你正在看自己的線程,而不是凍結過程中的線程。就像你從一個小型轉儲器或一個調試器斷點獲得的一樣。你自己的線程忙於執行代碼,所以他們的堆棧不斷變化。在你使用thread.StackTrace的時候,你的代碼可能在DAC內運行。本機C++代碼,它將是未知的。 –
如果我接近另一個過程,我會得到相同的結果。 –
看看它是否可以幫助你https://github.com/dudikeleti/DumpMiner –