private void FillFaultingThreadAndModuleInformation(CommandExecutionContext context) { UnifiedStackTrace stackTrace = new UnifiedStackTrace(_dbgEngTarget.DebuggerInterface, context); _triageInformation.TotalThreadCount = (int)stackTrace.NumThreads; _triageInformation.ManagedThreadCount = stackTrace.Threads.Count(t => t.IsManagedThread); LastEventInformation lastEventInformation = _dbgEngTarget.GetLastEventInformation(); if (lastEventInformation == null) { return; } ThreadInfo faultingThread = stackTrace.Threads.SingleOrDefault(t => t.OSThreadId == lastEventInformation.OSThreadId); if (faultingThread == null) { return; } _triageInformation.FaultingThreadOSID = faultingThread.OSThreadId; _triageInformation.IsFaultingThreadManaged = faultingThread.IsManagedThread; _triageInformation.EventDescription = lastEventInformation.EventDescription; if (lastEventInformation.ExceptionRecord.HasValue) { _triageInformation.ExceptionCode = lastEventInformation.ExceptionRecord.Value.ExceptionCode; } if (faultingThread.IsManagedThread && faultingThread.ManagedThread.CurrentException != null) { _triageInformation.ManagedExceptionType = faultingThread.ManagedThread.CurrentException.Type.Name; } var frames = stackTrace.GetStackTrace(faultingThread.Index); UnifiedStackFrame faultingFrame = frames.FirstOrDefault(f => f.Module != null && !WellKnownMicrosoftModules.Contains(f.Module)); if (faultingFrame != null) { _triageInformation.FaultingModule = faultingFrame.Module; _triageInformation.FaultingMethod = faultingFrame.Method; } if (ShowFaultingStack) { context.WriteLine("Faulting call stack:"); stackTrace.PrintStackTrace(context, frames); } }
public static LastEventInformation GetLastEventInformation(this DataTarget target) { var control = (IDebugControl)target.DebuggerInterface; DEBUG_EVENT eventType; uint procId, threadId; StringBuilder description = new StringBuilder(2048); uint unused; uint descriptionSize; if (0 != control.GetLastEventInformation( out eventType, out procId, out threadId, IntPtr.Zero, 0, out unused, description, description.Capacity, out descriptionSize)) { return(null); } var osThreadIds = target.GetOSThreadIds(); var eventInformation = new LastEventInformation { OSThreadId = (int)osThreadIds[threadId], EventType = eventType, EventDescription = description.ToString() }; IDebugAdvanced2 debugAdvanced = (IDebugAdvanced2)target.DebuggerInterface; int outSize; byte[] buffer = new byte[Marshal.SizeOf(typeof(EXCEPTION_RECORD64))]; int hr = debugAdvanced.Request(DEBUG_REQUEST.TARGET_EXCEPTION_RECORD, null, 0, buffer, buffer.Length, out outSize); if (hr == 0) { GCHandle gch = GCHandle.Alloc(buffer, GCHandleType.Pinned); try { eventInformation.ExceptionRecord = (EXCEPTION_RECORD64)Marshal.PtrToStructure(gch.AddrOfPinnedObject(), typeof(EXCEPTION_RECORD64)); } finally { gch.Free(); } } return(eventInformation); }
public static LastEventInformation GetLastEventInformation(this DataTarget target) { var control = (IDebugControl)target.DebuggerInterface; DEBUG_EVENT eventType; uint procId, threadId; StringBuilder description = new StringBuilder(2048); uint unused; uint descriptionSize; if (0 != control.GetLastEventInformation( out eventType, out procId, out threadId, IntPtr.Zero, 0, out unused, description, description.Capacity, out descriptionSize)) { return null; } var osThreadIds = target.GetOSThreadIds(); var eventInformation = new LastEventInformation { OSThreadId = (int)osThreadIds[threadId], EventType = eventType, EventDescription = description.ToString() }; IDebugAdvanced2 debugAdvanced = (IDebugAdvanced2)target.DebuggerInterface; int outSize; byte[] buffer = new byte[Marshal.SizeOf(typeof(EXCEPTION_RECORD64))]; int hr = debugAdvanced.Request(DEBUG_REQUEST.TARGET_EXCEPTION_RECORD, null, 0, buffer, buffer.Length, out outSize); if (hr == 0) { GCHandle gch = GCHandle.Alloc(buffer, GCHandleType.Pinned); try { eventInformation.ExceptionRecord = (EXCEPTION_RECORD64)Marshal.PtrToStructure(gch.AddrOfPinnedObject(), typeof(EXCEPTION_RECORD64)); } finally { gch.Free(); } } return eventInformation; }
public void Execute(CommandExecutionContext context) { using (var target = context.CreateTemporaryDbgEngTarget()) { LastEventInformation lastEventInformation = target.GetLastEventInformation(); if (lastEventInformation == null) { context.WriteLine("Last event information is not available"); return; } context.Write("Thread OSID = {0} ", lastEventInformation.OSThreadId); var managedThread = context.Runtime.Threads.SingleOrDefault(t => t.OSThreadId == lastEventInformation.OSThreadId); if (managedThread != null) { context.WriteLine("(managed id = {0})", managedThread.ManagedThreadId); } else { context.WriteLine("(unmanaged)"); } context.WriteLine("{0} - {1}", lastEventInformation.EventType, lastEventInformation.EventDescription); } }
public static LastEventInformation GetLastEventInformation(this DataTarget target) { var control = (IDebugControl)target.DebuggerInterface; DEBUG_EVENT eventType; uint procId, threadId; StringBuilder description = new StringBuilder(2048); uint unused; uint descriptionSize; if (HR.Failed(control.GetLastEventInformation( out eventType, out procId, out threadId, IntPtr.Zero, 0, out unused, description, description.Capacity, out descriptionSize))) { return(null); } var osThreadIds = target.GetOSThreadIds(); var eventInformation = new LastEventInformation { OSThreadId = (int)osThreadIds[threadId], EventType = eventType, EventDescription = description.ToString() }; IDebugAdvanced2 debugAdvanced = (IDebugAdvanced2)target.DebuggerInterface; int outSize; byte[] buffer = new byte[Marshal.SizeOf(typeof(EXCEPTION_RECORD64))]; int hr = debugAdvanced.Request(DEBUG_REQUEST.TARGET_EXCEPTION_RECORD, null, 0, buffer, buffer.Length, out outSize); if (HR.Succeeded(hr)) { GCHandle gch = GCHandle.Alloc(buffer, GCHandleType.Pinned); try { eventInformation.ExceptionRecord = (EXCEPTION_RECORD64)Marshal.PtrToStructure(gch.AddrOfPinnedObject(), typeof(EXCEPTION_RECORD64)); } finally { gch.Free(); } } buffer = new byte[Marshal.SizeOf(typeof(uint))]; hr = debugAdvanced.Request(DEBUG_REQUEST.TARGET_EXCEPTION_THREAD, null, 0, buffer, buffer.Length, out outSize); if (HR.Succeeded(hr)) { // If there is a stored exception event with a thread id, use that instead // of what GetLastEventInformation returns, because it might be different. eventInformation.OSThreadId = (int)BitConverter.ToUInt32(buffer, 0); } buffer = new byte[Marshal.SizeOf(typeof(CONTEXT))]; hr = debugAdvanced.Request(DEBUG_REQUEST.TARGET_EXCEPTION_CONTEXT, null, 0, buffer, buffer.Length, out outSize); if (HR.Succeeded(hr)) { var gch = GCHandle.Alloc(buffer, GCHandleType.Pinned); try { eventInformation.ExceptionContext = (CONTEXT)Marshal.PtrToStructure( gch.AddrOfPinnedObject(), typeof(CONTEXT)); } finally { gch.Free(); } } return(eventInformation); }
public static LastEventInformation GetLastEventInformation(this DataTarget target) { var control = (IDebugControl)target.DebuggerInterface; DEBUG_EVENT eventType; uint procId, threadId; StringBuilder description = new StringBuilder(2048); uint unused; uint descriptionSize; if (HR.Failed(control.GetLastEventInformation( out eventType, out procId, out threadId, IntPtr.Zero, 0, out unused, description, description.Capacity, out descriptionSize))) { return null; } var osThreadIds = target.GetOSThreadIds(); var eventInformation = new LastEventInformation { OSThreadId = (int)osThreadIds[threadId], EventType = eventType, EventDescription = description.ToString() }; IDebugAdvanced2 debugAdvanced = (IDebugAdvanced2)target.DebuggerInterface; int outSize; byte[] buffer = new byte[Marshal.SizeOf(typeof(EXCEPTION_RECORD64))]; int hr = debugAdvanced.Request(DEBUG_REQUEST.TARGET_EXCEPTION_RECORD, null, 0, buffer, buffer.Length, out outSize); if (HR.Succeeded(hr)) { GCHandle gch = GCHandle.Alloc(buffer, GCHandleType.Pinned); try { eventInformation.ExceptionRecord = (EXCEPTION_RECORD64)Marshal.PtrToStructure(gch.AddrOfPinnedObject(), typeof(EXCEPTION_RECORD64)); } finally { gch.Free(); } } buffer = new byte[Marshal.SizeOf(typeof(uint))]; hr = debugAdvanced.Request(DEBUG_REQUEST.TARGET_EXCEPTION_THREAD, null, 0, buffer, buffer.Length, out outSize); if (HR.Succeeded(hr)) { // If there is a stored exception event with a thread id, use that instead // of what GetLastEventInformation returns, because it might be different. eventInformation.OSThreadId = (int)BitConverter.ToUInt32(buffer, 0); } buffer = new byte[Marshal.SizeOf(typeof(CONTEXT))]; hr = debugAdvanced.Request(DEBUG_REQUEST.TARGET_EXCEPTION_CONTEXT, null, 0, buffer, buffer.Length, out outSize); if (HR.Succeeded(hr)) { var gch = GCHandle.Alloc(buffer, GCHandleType.Pinned); try { eventInformation.ExceptionContext = (CONTEXT)Marshal.PtrToStructure( gch.AddrOfPinnedObject(), typeof(CONTEXT)); } finally { gch.Free(); } } return eventInformation; }