/// <summary> /// Initializes a new instance of the <see cref="ClrThread"/> class. /// </summary> /// <param name="thread">The thread.</param> /// <param name="clrThread">The CLR thread.</param> /// <param name="process">The process.</param> internal ClrThread(Thread thread, Microsoft.Diagnostics.Runtime.ClrThread clrThread, Process process) : base(thread != null ? thread.Id : uint.MaxValue, clrThread.OSThreadId, process) { ClrThread = clrThread; runtime = SimpleCache.Create(() => Process.ClrRuntimes.Single(r => r.ClrRuntime == clrThread.Runtime)); appDomain = SimpleCache.Create(() => Runtime.AppDomains.Single(a => a.ClrAppDomain.Address == clrThread.AppDomain)); clrStackTrace = SimpleCache.Create(() => { StackTrace stackTrace = new StackTrace(this); uint frameNumber = 0; stackTrace.Frames = ClrThread.StackTrace.Where(f => f.Method != null).Select(f => { return(new StackFrame(stackTrace, new ThreadContext(f.InstructionPointer, f.StackPointer, ulong.MaxValue)) { FrameNumber = frameNumber++, InstructionOffset = f.InstructionPointer, StackOffset = f.StackPointer, FrameOffset = ulong.MaxValue, ReturnOffset = ulong.MaxValue, ClrStackFrame = f, }); }).ToArray(); return(stackTrace); }); lastThrownException = SimpleCache.Create(() => ClrThread.CurrentException != null ? new ClrException(this, ClrThread.CurrentException) : null); }
/// <summary> /// Initializes a new instance of the <see cref="ClrMdThread"/> class. /// </summary> /// <param name="thread">The thread.</param> /// <param name="clrThread">The CLR thread.</param> /// <param name="process">The process.</param> internal ClrMdThread(Thread thread, Microsoft.Diagnostics.Runtime.ClrThread clrThread, Process process) { Thread = thread; Process = process; ClrThread = clrThread; runtime = SimpleCache.Create(() => Process.ClrRuntimes.Single(r => ((ClrMdRuntime)r).ClrRuntime == clrThread.Runtime)); appDomain = SimpleCache.Create(() => Runtime.AppDomains.Single(a => a.Address == clrThread.AppDomain)); clrStackTrace = SimpleCache.Create(() => { CLR.ClrMdProvider provider = ((ClrMdRuntime)Runtime).Provider; StackTrace stackTrace = new StackTrace(Thread); uint frameNumber = 0; stackTrace.Frames = ClrThread.StackTrace.Where(f => f.Method != null).Select(f => { return(new StackFrame(stackTrace, new ThreadContext(f.InstructionPointer, f.StackPointer, ulong.MaxValue, null)) { FrameNumber = frameNumber++, InstructionOffset = f.InstructionPointer, StackOffset = f.StackPointer, FrameOffset = ulong.MaxValue, ReturnOffset = ulong.MaxValue, ClrStackFrame = new ClrMdStackFrame(provider, f), }); }).ToArray(); return(stackTrace); }); lastThrownException = SimpleCache.Create(() => { if (ClrThread.CurrentException != null) { CLR.ClrMdProvider provider = ((ClrMdRuntime)Runtime).Provider; Microsoft.Diagnostics.Runtime.ClrException clrException = ClrThread.CurrentException; return(Variable.CreatePointer(Process.FromClrType(provider.FromClrType(clrException.Type)), clrException.Address)); } return(null); }); }