From bebdeb0ef467e0ebc4108f1398692e52108bca38 Mon Sep 17 00:00:00 2001 From: Vance Morrison Date: Tue, 31 Jul 2018 11:24:18 -0700 Subject: [PATCH] Fixed from testing --- .../System/Diagnostics/Tracing/EventProvider.cs | 25 ++++------- .../System/Diagnostics/Tracing/EventSource.cs | 52 +++++++++++----------- 2 files changed, 34 insertions(+), 43 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs index 21c2ea0..36b363f 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs @@ -883,25 +883,18 @@ namespace System.Diagnostics.Tracing { if (data is System.Enum) { - Type underlyingType = Enum.GetUnderlyingType(data.GetType()); - if (underlyingType == typeof(int)) + try { -#if !ES_BUILD_PCL - data = ((IConvertible)data).ToInt32(null); -#else - data = (int)data; -#endif - goto Again; - } - else if (underlyingType == typeof(long)) - { -#if !ES_BUILD_PCL - data = ((IConvertible)data).ToInt64(null); -#else - data = (long)data; -#endif + Type underlyingType = Enum.GetUnderlyingType(data.GetType()); + if (underlyingType == typeof(ulong)) + data = (ulong)data; + else if (underlyingType == typeof(long)) + data = (long)data; + else + data = (int)Convert.ToInt64(data); // This handles all int/uint or below (we treat them like 32 bit ints) goto Again; } + catch { } // On wierd cases (e.g. enums of type double), give up and for compat simply tostring. } // To our eyes, everything else is a just a string diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs index 1981dc6..4670cc6 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs @@ -5451,45 +5451,43 @@ namespace System.Diagnostics.Tracing { bool isbitmap = EventSource.GetCustomAttributeHelper(enumType, typeof(FlagsAttribute), flags) != null; string mapKind = isbitmap ? "bitMap" : "valueMap"; + sb.Append(" <").Append(mapKind).Append(" name=\"").Append(enumType.Name).Append("\">").AppendLine(); // write out each enum value FieldInfo[] staticFields = enumType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static); - - // Empty map entries cause Windows to reject the whole manifest. Avoid this by only writting the - // map header and trailer if we have a valid value entry. - bool headerWriten = false; + bool anyValuesWritten = false; foreach (FieldInfo staticField in staticFields) { object constantValObj = staticField.GetRawConstantValue(); if (constantValObj != null) { - try - { - long hexValue = hexValue = Convert.ToInt64(constantValObj); // Handles all integer types. - - // ETW requires all bitmap values to be powers of 2. Skip the ones that are not. - // TODO: Warn people about the dropping of values. - if (isbitmap && ((hexValue & (hexValue - 1)) != 0 || hexValue == 0)) - continue; - - // We have a valid value, write the header if we have not already. - if (!headerWriten) - { - sb.Append(" <").Append(mapKind).Append(" name=\"").Append(enumType.Name).Append("\">").AppendLine(); - headerWriten = true; - } - - sb.Append(" ").AppendLine(); - } - catch { } + ulong hexValue; + if (constantValObj is ulong) + hexValue = (ulong)constantValObj; // This is the only integer type that can't be represented by a long. + else + hexValue = (ulong) Convert.ToInt64(constantValObj); // Handles all integer types except ulong. + + // ETW requires all bitmap values to be powers of 2. Skip the ones that are not. + // TODO: Warn people about the dropping of values. + if (isbitmap && ((hexValue & (hexValue - 1)) != 0 || hexValue == 0)) + continue; + sb.Append(" ").AppendLine(); + anyValuesWritten = true; } } - if (headerWriten) - sb.Append(" ").AppendLine(); + // the OS requrires that bitmaps and valuemaps have at least one value or it reject the whole manifest. + // To avoid that put a 'None' entry if there are no other values. + if (!anyValuesWritten) + { + sb.Append(" ").AppendLine(); + } + sb.Append(" ").AppendLine(); } sb.Append(" ").AppendLine(); } -- 2.7.4