protected override void WriteReportTypeSpecificSection(XmlWriter reportFile)
 {
     using (new SafeXmlTag(reportFile, "exception-report").WithAttribute("is-clr-terminating", base.IsFlagSet(ReportOptions.ReportTerminateAfterSend) ? "1" : "0"))
     {
         using (new SafeXmlTag(reportFile, "application").WithAttribute("name", base.AppName).WithAttribute("version", WatsonReport.ExchangeFormattedVersion(base.AppVersion)))
         {
         }
         using (new SafeXmlTag(reportFile, "assembly").WithAttribute("name", base.BucketingParameter <WatsonExceptionReport.BucketParamId>(WatsonExceptionReport.BucketParamId.AssemblyName)).WithAttribute("version", base.BucketingParameter <WatsonExceptionReport.BucketParamId>(WatsonExceptionReport.BucketParamId.AssemblyVer)))
         {
         }
         using (SafeXmlTag safeXmlTag4 = new SafeXmlTag(reportFile, "exception"))
         {
             safeXmlTag4.SetContent(WatsonReport.SanitizeException(this.exception.ToString()));
         }
         using (new SafeXmlTag(reportFile, "base-exception").WithAttribute("target-site", this.baseExceptionTargetSite).WithAttribute("assembly-name", this.baseExceptionAssemblyName).WithAttribute("method-name", this.baseExceptionMethodName))
         {
         }
         using (SafeXmlTag safeXmlTag6 = new SafeXmlTag(reportFile, "process").WithAttribute("eip", "0x" + ((IntPtr.Size == 4) ? this.exceptionEIP.ToString("x8") : this.exceptionEIP.ToString("x16"))).WithAttribute("bitness", (IntPtr.Size * 8).ToString()).WithAttribute("pid", base.ProcessId.ToString()))
         {
             if (base.ProcessId == DiagnosticsNativeMethods.GetCurrentProcessId())
             {
                 safeXmlTag6.WithAttribute("managed-tid", Environment.CurrentManagedThreadId.ToString()).WithAttribute("native-tid", DiagnosticsNativeMethods.GetCurrentThreadId().ToString());
             }
         }
         if (this.lids != null)
         {
             using (SafeXmlTag safeXmlTag7 = new SafeXmlTag(reportFile, "location-ids"))
             {
                 safeXmlTag7.SetContent(this.lids);
             }
         }
     }
 }
Пример #2
0
 private uint TraceControlCallback(int requestCode, IntPtr context, IntPtr reserved, IntPtr buffer)
 {
     if (requestCode == 4)
     {
         try
         {
             this.session = DiagnosticsNativeMethods.CriticalTraceHandle.Attach(buffer);
         }
         catch (Win32Exception)
         {
             return(0U);
         }
         if (DiagnosticsNativeMethods.ControlTrace(this.session.DangerousGetHandle(), null, ref EtwSessionInfo.properties, 0U) == 0U)
         {
             this.tracingEnabled = true;
             this.InvokeOnTraceStateChange();
             return(0U);
         }
         return(0U);
     }
     if (requestCode == 5)
     {
         this.tracingEnabled = false;
         if (this.session != null)
         {
             this.session.Dispose();
         }
         this.InvokeOnTraceStateChange();
     }
     return(0U);
 }
        public WatsonExceptionReport(string eventType, Process process, Exception exception, ReportOptions reportOptions) : base(eventType, process)
        {
            this.exception     = exception;
            base.ReportOptions = reportOptions;
            IntPtr exceptionPointers = Marshal.GetExceptionPointers();

            if ((base.ReportOptions & ReportOptions.DoNotLogProcessAndThreadIds) == ReportOptions.None)
            {
                base.LogExtraData("Process ID=" + base.ProcessId);
                if (!base.TargetExternalProcess)
                {
                    base.LogExtraData(string.Concat(new object[]
                    {
                        "Managed Thread ID=",
                        Environment.CurrentManagedThreadId,
                        Environment.NewLine,
                        "Native Thread ID=",
                        DiagnosticsNativeMethods.GetCurrentThreadId()
                    }));
                }
            }
            if (exceptionPointers == IntPtr.Zero)
            {
                this.exceptionInfo = null;
                this.exceptionEIP  = IntPtr.Zero;
                return;
            }
            this.exceptionInfo = new DiagnosticsNativeMethods.WER_EXCEPTION_INFORMATION();
            this.exceptionInfo.exceptionPointers = exceptionPointers;
            this.exceptionInfo.clientPointers    = false;
            this.exceptionEIP = ((DiagnosticsNativeMethods.ExceptionRecord)Marshal.PtrToStructure(((DiagnosticsNativeMethods.ExceptionPointers)Marshal.PtrToStructure(exceptionPointers, typeof(DiagnosticsNativeMethods.ExceptionPointers))).ExceptionRecord, typeof(DiagnosticsNativeMethods.ExceptionRecord))).ExceptionAddress;
        }
Пример #4
0
        public static void Write(EtwSessionInfo sessionInfo, int lid, TraceType traceType, Guid component, int traceTag, long id, string message)
        {
            int num  = (message.Length + 1) * 2;
            int num2 = 16;
            int num3 = 8064;
            int val  = (num3 - num2) / 2 - 1;

            if (num2 + num < num3)
            {
                uint num4 = DiagnosticsNativeMethods.TraceMessage(sessionInfo.Session.DangerousGetHandle(), 43U, ref component, (ushort)traceType | 32, ref traceTag, 4, message, num, ref id, 8, ref lid, 4, IntPtr.Zero, 0);
                if (num4 != 0U)
                {
                    return;
                }
            }
            else
            {
                int num5 = 0;
                int i    = message.Length;
                while (i > 0)
                {
                    int  num6 = Math.Min(i, val);
                    uint num7 = DiagnosticsNativeMethods.TraceMessage(sessionInfo.Session.DangerousGetHandle(), 43U, ref component, (ushort)traceType | 32, ref traceTag, 4, message.Substring(num5, num6), (num6 + 1) * 2, ref id, 8, ref lid, 4, IntPtr.Zero, 0);
                    i    -= num6;
                    num5 += num6;
                }
            }
        }
Пример #5
0
        public static bool WriteBinary(TraceType traceType, Guid component, int traceTag, byte[] message, out int maxBytes)
        {
            maxBytes = 0;
            int num = message.Length;

            if (traceTag > 255)
            {
                throw new ArgumentException("Maximum allowed tag-value is 255 for binary traces", "traceTag");
            }
            if (num > 8064)
            {
                maxBytes = 8064;
                return(false);
            }
            GCHandle?gchandle = null;
            uint     num2     = 0U;

            try
            {
                DiagnosticsNativeMethods.BinaryEventTrace binaryEventTrace = new DiagnosticsNativeMethods.BinaryEventTrace(component, (byte)traceTag, message, ref gchandle);
                num2 = DiagnosticsNativeMethods.TraceEvent(ETWTrace.ComponentSession.Session.DangerousGetHandle(), ref binaryEventTrace);
            }
            finally
            {
                if (gchandle != null && gchandle.Value.IsAllocated)
                {
                    gchandle.Value.Free();
                }
            }
            return(num2 == 0U);
        }
Пример #6
0
 public MemoryTraceBuilder(int maximumEntries, int maximumBufferSize)
 {
     this.traceBuffer = new char[maximumBufferSize + 1];
     this.entries = new TraceEntry[maximumEntries + 1];
     this.bufferLength = maximumBufferSize + 1;
     this.entryArrayLength = maximumEntries + 1;
     this.nativeThreadId = DiagnosticsNativeMethods.GetCurrentThreadId();
 }
Пример #7
0
 protected override bool ReleaseHandle()
 {
     if (this.handle != (IntPtr)(-1))
     {
         DiagnosticsNativeMethods.CloseHandle(this.handle);
     }
     return(true);
 }
Пример #8
0
 public static uint ExmonTaskTraceEventInstance(byte[] buffer, ref DiagnosticsNativeMethods.EventInstanceInfo instanceInfo, ref DiagnosticsNativeMethods.EventInstanceInfo parentInstanceInfo)
 {
     DiagnosticsNativeMethods.CriticalTraceHandle session = ETWTrace.ExmonTaskSession.Session;
     if (session != null)
     {
         return(DiagnosticsNativeMethods.TraceEventInstance(session.DangerousGetHandle(), buffer, ref instanceInfo, ref parentInstanceInfo));
     }
     return(87U);
 }
 public override void Send()
 {
     if (base.IsFlagSet(ReportOptions.DoNotFreezeThreads) || base.IsFlagSet(ReportOptions.DoNotCollectDumps))
     {
         base.Send();
         return;
     }
     lock (WatsonReport.HeapDumpReportLockObject)
     {
         if (!ExWatson.ReaperThreadAllowed)
         {
             base.Send();
         }
         else
         {
             Thread thread = null;
             try
             {
                 ManualResetEvent reaperThreadIsRunning = new ManualResetEvent(false);
                 thread = new Thread(delegate()
                 {
                     try
                     {
                         WatsonExceptionReport.nativeReaperThreadId = DiagnosticsNativeMethods.GetCurrentThreadId();
                         reaperThreadIsRunning.Set();
                         Thread.Sleep(ExWatson.CrashReportTimeout);
                         ExWatson.TerminateCurrentProcess();
                     }
                     catch
                     {
                     }
                 });
                 thread.Start();
                 reaperThreadIsRunning.WaitOne();
                 base.Send();
             }
             catch
             {
             }
             finally
             {
                 if (thread != null)
                 {
                     thread.Abort();
                     WatsonExceptionReport.nativeReaperThreadId = -1;
                 }
             }
         }
     }
 }
 protected override void BeforeSubmit()
 {
     if (base.ProcessId != DiagnosticsNativeMethods.GetCurrentProcessId())
     {
         try
         {
             this.debugPrivilege = new Privilege("SeDebugPrivilege");
             this.debugPrivilege.Enable();
         }
         catch
         {
         }
     }
     base.IsFlagSet(ReportOptions.DoNotFreezeThreads);
 }
Пример #11
0
 public override void Flush()
 {
     lock (this.syncObj)
     {
         if (this.currPos != 0)
         {
             this.wrappedStream.Write(this.buffer, 0, this.currPos);
             this.wrappedStream.Flush();
             if (this.flushToDisk)
             {
                 DiagnosticsNativeMethods.FlushFileBuffers(((FileStream)this.wrappedStream).SafeFileHandle);
             }
             this.currPos = 0;
         }
     }
 }
Пример #12
0
        internal static void WriteCas(CasTraceEventType eventType, CasTraceStartStop traceType, Guid serviceProviderRequestID, int bytesIn, int bytesOut, string serverAddress, string userContext, string spOperation, string spOperationData, string clientOperation)
        {
            int num  = (serverAddress.Length + 1) * 2;
            int num2 = (userContext.Length + 1) * 2;
            int num3 = (spOperation.Length + 1) * 2;
            int num4 = (spOperationData.Length + 1) * 2;
            int num5 = (clientOperation.Length + 1) * 2;
            int num6 = 12 + 2 * ETWTrace.GuidByteLength + num + num2 + num3 + num4 + num5;
            int num7 = 8064;

            if (num6 < num7)
            {
                int  num8       = (int)traceType;
                Guid activityId = ETWTrace.GetActivityId();
                Guid events     = ETWTrace.casPerfGuids.Events;
                uint num9       = DiagnosticsNativeMethods.TraceMessage(ETWTrace.CasPerfSession.Session.DangerousGetHandle(), 43U, ref events, (ushort)eventType, ref num8, 4, activityId.ToByteArray(), ETWTrace.GuidByteLength, serviceProviderRequestID.ToByteArray(), ETWTrace.GuidByteLength, ref bytesIn, 4, ref bytesOut, 4, serverAddress, num, userContext, num2, spOperation, num3, spOperationData, num4, clientOperation, num5, IntPtr.Zero, 0);
            }
        }
Пример #13
0
        public override string Evaluate(WatsonReport watsonReport)
        {
            string result;

            try
            {
                watsonReport.PerformWerOperation(delegate(WerSafeHandle reportHandle)
                {
                    DiagnosticsNativeMethods.WerReportAddFile(reportHandle, base.Expression, DiagnosticsNativeMethods.WER_FILE_TYPE.WerFileTypeOther, (DiagnosticsNativeMethods.WER_FILE_FLAGS) 0U);
                });
                watsonReport.LogExtraFile(base.Expression);
                result = "Attached file \"" + Path.GetFileName(base.Expression) + "\" to report.";
            }
            catch (Exception ex)
            {
                watsonReport.LogExtraFile(this.FormatError(base.Expression, ex));
                result = this.FormatError(base.Expression, ex);
            }
            return(result);
        }
 protected override void AddExtraFiles(WerSafeHandle watsonReportHandle)
 {
     if (base.ReportingAllowed && !base.ProcessHandle.IsInvalid && !base.IsFlagSet(ReportOptions.DoNotCollectDumps))
     {
         if (WatsonExceptionReport.beforeDumpCollectionAction != null)
         {
             WatsonExceptionReport.beforeDumpCollectionAction();
         }
         DiagnosticsNativeMethods.WER_DUMP_CUSTOM_OPTIONS wer_DUMP_CUSTOM_OPTIONS = new DiagnosticsNativeMethods.WER_DUMP_CUSTOM_OPTIONS();
         wer_DUMP_CUSTOM_OPTIONS.size      = Marshal.SizeOf(typeof(DiagnosticsNativeMethods.WER_DUMP_CUSTOM_OPTIONS));
         wer_DUMP_CUSTOM_OPTIONS.mask      = DiagnosticsNativeMethods.WER_DUMP_FLAGS.WER_DUMP_MASK_DUMPTYPE;
         wer_DUMP_CUSTOM_OPTIONS.dumpFlags = (DiagnosticsNativeMethods.MINIDUMP_TYPE.MiniDumpWithDataSegs | DiagnosticsNativeMethods.MINIDUMP_TYPE.MiniDumpWithHandleData | DiagnosticsNativeMethods.MINIDUMP_TYPE.MiniDumpWithUnloadedModules | DiagnosticsNativeMethods.MINIDUMP_TYPE.MiniDumpWithProcessThreadData | DiagnosticsNativeMethods.MINIDUMP_TYPE.MiniDumpWithPrivateReadWriteMemory);
         DiagnosticsNativeMethods.WerReportAddDump(watsonReportHandle, base.ProcessHandle, IntPtr.Zero, DiagnosticsNativeMethods.WER_DUMP_TYPE.WerDumpTypeMiniDump, this.exceptionInfo, wer_DUMP_CUSTOM_OPTIONS, 0U);
         DiagnosticsNativeMethods.WER_DUMP_CUSTOM_OPTIONS wer_DUMP_CUSTOM_OPTIONS2 = new DiagnosticsNativeMethods.WER_DUMP_CUSTOM_OPTIONS();
         wer_DUMP_CUSTOM_OPTIONS2.size      = Marshal.SizeOf(typeof(DiagnosticsNativeMethods.WER_DUMP_CUSTOM_OPTIONS));
         wer_DUMP_CUSTOM_OPTIONS2.mask      = DiagnosticsNativeMethods.WER_DUMP_FLAGS.WER_DUMP_MASK_DUMPTYPE;
         wer_DUMP_CUSTOM_OPTIONS2.dumpFlags = (wer_DUMP_CUSTOM_OPTIONS.dumpFlags | DiagnosticsNativeMethods.MINIDUMP_TYPE.MiniDumpWithFullMemory);
         DiagnosticsNativeMethods.WerReportAddDump(watsonReportHandle, base.ProcessHandle, IntPtr.Zero, DiagnosticsNativeMethods.WER_DUMP_TYPE.WerDumpTypeHeapDump, this.exceptionInfo, wer_DUMP_CUSTOM_OPTIONS2, 0U);
     }
 }
Пример #15
0
 private static DiagnosticsNativeMethods.EventInstanceInfo CreateInstanceId(IntPtr eventHandle)
 {
     DiagnosticsNativeMethods.EventInstanceInfo result = default(DiagnosticsNativeMethods.EventInstanceInfo);
     DiagnosticsNativeMethods.CreateTraceInstanceId(eventHandle, ref result);
     return(result);
 }
Пример #16
0
 protected override void AddExtraFiles(WerSafeHandle watsonReportHandle)
 {
     DiagnosticsNativeMethods.WerReportAddFile(watsonReportHandle, this.traceFileName, DiagnosticsNativeMethods.WER_FILE_TYPE.WerFileTypeOther, (DiagnosticsNativeMethods.WER_FILE_FLAGS) 0U);
 }
        protected override ProcSafeHandle GetProcessHandle()
        {
            ProcSafeHandle procSafeHandle  = new ProcSafeHandle();
            ProcSafeHandle procSafeHandle2 = base.EvaluateOrDefault <ProcSafeHandle>(() => DiagnosticsNativeMethods.OpenProcess(DiagnosticsNativeMethods.ProcessAccess.VmRead | DiagnosticsNativeMethods.ProcessAccess.QueryInformation | DiagnosticsNativeMethods.ProcessAccess.StandardRightsRead, false, base.ProcessId), procSafeHandle);

            if (procSafeHandle2 != procSafeHandle && procSafeHandle != null)
            {
                procSafeHandle.Dispose();
            }
            return(procSafeHandle2);
        }
Пример #18
0
 protected override bool ReleaseHandle()
 {
     DiagnosticsNativeMethods.WerReportCloseHandle(this.handle);
     return(true);
 }
Пример #19
0
 protected override bool ReleaseHandle()
 {
     return(DiagnosticsNativeMethods.CloseHandle(this.handle));
 }
Пример #20
0
 protected override bool ReleaseHandle()
 {
     DiagnosticsNativeMethods.ErrorCode errorCode = DiagnosticsNativeMethods.RegCloseKey(this.handle);
     return(errorCode == DiagnosticsNativeMethods.ErrorCode.Success);
 }