Imported Upstream version 4.6.0.125

Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-08-03 10:59:49 +00:00
parent a569aebcfd
commit e79aa3c0ed
17047 changed files with 3137615 additions and 392334 deletions

View File

@@ -0,0 +1,25 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: ICustomDebuggerNotification
**
** This interface is implemented by classes that support custom debugger notifications.
**
===========================================================*/
namespace System.Diagnostics {
using System;
// Defines an interface indicating that a custom debugger notification is requested under specific
// conditions. Users should implement this interface to be used as an argument to
// System.Diagnostics.Debugger.CustomNotification.
//
// @dbgtodo dlaw: when this goes public, it must be replaced by a custom attribute
internal interface ICustomDebuggerNotification
{
// Interface does not need to be marked with the serializable attribute
}
}

View File

@@ -0,0 +1,127 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
namespace System.Diagnostics {
using System;
using System.Security.Permissions;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Diagnostics.Contracts;
using System.Diagnostics.CodeAnalysis;
// Class which handles code asserts. Asserts are used to explicitly protect
// assumptions made in the code. In general if an assert fails, it indicates
// a program bug so is immediately called to the attention of the user.
// Only static data members, does not need to be marked with the serializable attribute
internal static class Assert
{
internal const int COR_E_FAILFAST = unchecked((int) 0x80131623);
private static AssertFilter Filter;
static Assert()
{
Filter = new DefaultFilter();
}
// Called when an assertion is being made.
//
[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Process, ResourceScope.Process)]
internal static void Check(bool condition, String conditionString, String message)
{
if (!condition)
{
Fail (conditionString, message, null, COR_E_FAILFAST);
}
}
[ResourceConsumption(ResourceScope.Process, ResourceScope.Process)]
internal static void Check(bool condition, String conditionString, String message, int exitCode)
{
if (!condition)
{
Fail(conditionString, message, null, exitCode);
}
}
[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Process, ResourceScope.Process)]
internal static void Fail(String conditionString, String message)
{
Fail(conditionString, message, null, COR_E_FAILFAST);
}
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Process)]
internal static void Fail(String conditionString, String message, String windowTitle, int exitCode)
{
Fail(conditionString, message, windowTitle, exitCode, StackTrace.TraceFormat.Normal, 0);
}
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Process)]
internal static void Fail(String conditionString, String message, int exitCode, StackTrace.TraceFormat stackTraceFormat)
{
Fail(conditionString, message, null, exitCode, stackTraceFormat, 0);
}
[System.Security.SecuritySafeCritical] // auto-generated
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Process)]
internal static void Fail(String conditionString, String message, String windowTitle, int exitCode, StackTrace.TraceFormat stackTraceFormat, int numStackFramesToSkip)
{
// get the stacktrace
StackTrace st = new StackTrace(numStackFramesToSkip, true);
AssertFilters iResult = Filter.AssertFailure (conditionString, message, st, stackTraceFormat, windowTitle);
if (iResult == AssertFilters.FailDebug)
{
if (Debugger.IsAttached == true)
Debugger.Break();
else
{
if (Debugger.Launch() == false)
{
throw new InvalidOperationException(
Environment.GetResourceString("InvalidOperation_DebuggerLaunchFailed"));
}
}
}
else if (iResult == AssertFilters.FailTerminate)
{
#if FEATURE_CORECLR
// We want to exit the Silverlight application, after displaying a message.
// Our best known way to emulate this is to exit the process with a known
// error code. Jolt may not be prepared for an appdomain to be unloaded.
Environment._Exit(exitCode);
#else
// This assert dialog will be common for code contract failures. If a code contract failure
// occurs on an end user machine, we believe the right experience is to do a FailFast, which
// will report this error via Watson, so someone could theoretically fix the bug.
// However, in CLR v4, Environment.FailFast when a debugger is attached gives you an MDA
// saying you've hit a bug in the runtime or unsafe managed code, and this is most likely caused
// by heap corruption or a stack imbalance from COM Interop or P/Invoke. That extremely
// misleading error isn't right, and we can temporarily work around this by using Environment.Exit
// if a debugger is attached. The right fix is to plumb FailFast correctly through our native
// Watson code, adding in a TypeOfReportedError for fatal managed errors.
if (Debugger.IsAttached)
Environment._Exit(exitCode);
else
Environment.FailFast(message, unchecked((uint) exitCode));
#endif
}
}
// Called when an assert happens.
// windowTitle can be null.
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.Process)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static int ShowDefaultAssertDialog(String conditionString, String message, String stackTrace, String windowTitle);
}
}

View File

@@ -0,0 +1,49 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
namespace System.Diagnostics {
using System;
using System.Runtime.Versioning;
// A Filter is used to decide whether an assert failure
// should terminate the program (or invoke the debugger).
// Typically this is done by popping up a dialog & asking the user.
//
// The default filter brings up a simple Win32 dialog with 3 buttons.
[Serializable]
abstract internal class AssertFilter
{
// Called when an assert fails. This should be overridden with logic which
// determines whether the program should terminate or not. Typically this
// is done by asking the user.
//
// The windowTitle can be null.
abstract public AssertFilters AssertFailure(String condition, String message,
StackTrace location, StackTrace.TraceFormat stackTraceFormat, String windowTitle);
}
// No data, does not need to be marked with the serializable attribute
internal class DefaultFilter : AssertFilter
{
internal DefaultFilter()
{
}
[System.Security.SecuritySafeCritical] // auto-generated
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Process)]
public override AssertFilters AssertFailure(String condition, String message,
StackTrace location, StackTrace.TraceFormat stackTraceFormat,
String windowTitle)
{
return (AssertFilters) Assert.ShowDefaultAssertDialog (condition, message, location.ToString(stackTraceFormat), windowTitle);
}
}
}

View File

@@ -0,0 +1,25 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
namespace System.Diagnostics {
/*
* FailDebug indicates the debugger should be invoked
* FailIgnore indicates the failure should be ignored & the
* program continued
* FailTerminate indicates that the program should be terminated
* FailContinue indicates that no decision is made -
* the previous Filter should be invoked
*/
using System;
[Serializable]
internal enum AssertFilters
{
FailDebug = 0,
FailIgnore = 1,
FailTerminate = 2,
FailContinueFilter = 3,
}
}

View File

@@ -0,0 +1,78 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SuppressMessageAttribute
**
**
** An attribute to suppress violation messages/warnings
** by static code analysis tools.
**
**
===========================================================*/
using System;
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(
AttributeTargets.All,
Inherited = false,
AllowMultiple = true
)
]
[Conditional("CODE_ANALYSIS")]
public sealed class SuppressMessageAttribute : Attribute
{
private string category;
private string justification;
private string checkId;
private string scope;
private string target;
private string messageId;
public SuppressMessageAttribute(string category, string checkId)
{
this.category = category;
this.checkId = checkId;
}
public string Category
{
get { return category; }
}
public string CheckId
{
get { return checkId; }
}
public string Scope
{
get { return scope; }
set { scope = value; }
}
public string Target
{
get { return target; }
set { target = value; }
}
public string MessageId
{
get { return messageId; }
set { messageId = value; }
}
public string Justification
{
get { return justification; }
set { justification = value; }
}
}
}

View File

@@ -0,0 +1,27 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
namespace System.Diagnostics {
[Serializable]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple=true)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ConditionalAttribute : Attribute
{
public ConditionalAttribute(String conditionString)
{
m_conditionString = conditionString;
}
public String ConditionString {
get {
return m_conditionString;
}
}
private String m_conditionString;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,211 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// The Debugger class is a part of the System.Diagnostics package
// and is used for communicating with a debugger.
namespace System.Diagnostics
{
using System;
using System.IO;
using System.Collections;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Runtime.Versioning;
// No data, does not need to be marked with the serializable attribute
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class Debugger
{
// This should have been a static class, but wasn't as of v3.5. Clearly, this is
// broken. We'll keep this in V4 for binary compat, but marked obsolete as error
// so migrated source code gets fixed.
[Obsolete("Do not create instances of the Debugger class. Call the static methods directly on this type instead", true)]
public Debugger()
{
// Should not have been instantiable - here for binary compatibility in V4.
}
// Break causes a breakpoint to be signalled to an attached debugger. If no debugger
// is attached, the user is asked if he wants to attach a debugger. If yes, then the
// debugger is launched.
[System.Security.SecuritySafeCritical] // auto-generated
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Process)]
public static void Break()
{
if (!Debugger.IsAttached)
{
// Try and demand UnmanagedCodePermission. This is done in a try block because if this
// fails we want to be able to silently eat the exception and just return so
// that the call to Break does not possibly cause an unhandled exception.
// The idea here is that partially trusted code shouldn't be able to launch a debugger
// without the user going through Watson.
try
{
#pragma warning disable 618
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
#pragma warning restore 618
}
// If we enter this block, we do not have permission to break into the debugger
// and so we just return.
catch (SecurityException)
{
return;
}
}
// Causing a break is now allowed.
BreakInternal();
}
[System.Security.SecuritySafeCritical] // auto-generated
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Process)]
static void BreakCanThrow()
{
if (!Debugger.IsAttached)
{
#pragma warning disable 618
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
#pragma warning restore 618
}
// Causing a break is now allowed.
BreakInternal();
}
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.Process)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void BreakInternal();
// Launch launches & attaches a debugger to the process. If a debugger is already attached,
// nothing happens.
//
[System.Security.SecuritySafeCritical] // auto-generated
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
public static bool Launch()
{
if (Debugger.IsAttached)
return (true);
// Try and demand UnmanagedCodePermission. This is done in a try block because if this
// fails we want to be able to silently eat the exception and just return so
// that the call to Break does not possibly cause an unhandled exception.
// The idea here is that partially trusted code shouldn't be able to launch a debugger
// without the user going through Watson.
try
{
#pragma warning disable 618
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
#pragma warning restore 618
}
// If we enter this block, we do not have permission to break into the debugger
// and so we just return.
catch (SecurityException)
{
return (false);
}
// Causing the debugger to launch is now allowed.
return (LaunchInternal());
}
// This class implements code:ICustomDebuggerNotification and provides a type to be used to notify
// the debugger that execution is about to enter a path that involves a cross-thread dependency.
// See code:NotifyOfCrossThreadDependency for more details.
private class CrossThreadDependencyNotification : ICustomDebuggerNotification
{
// constructor
public CrossThreadDependencyNotification()
{
}
}
// Do not inline the slow path
[MethodImplAttribute(MethodImplOptions.NoInlining)]
private static void NotifyOfCrossThreadDependencySlow()
{
CrossThreadDependencyNotification notification = new CrossThreadDependencyNotification();
CustomNotification(notification);
}
// Sends a notification to the debugger to indicate that execution is about to enter a path
// involving a cross thread dependency. A debugger that has opted into this type of notification
// can take appropriate action on receipt. For example, performing a funceval normally requires
// freezing all threads but the one performing the funceval. If the funceval requires execution on
// more than one thread, as might occur in remoting scenarios, the funceval will block. This
// notification will apprise the debugger that it will need to slip a thread or abort the funceval
// in such a situation. The notification is subject to collection after this function returns.
//
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Process)]
[method:System.Runtime.InteropServices.ComVisible(false)]
public static void NotifyOfCrossThreadDependency()
{
if (Debugger.IsAttached)
{
NotifyOfCrossThreadDependencySlow();
}
}
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.Machine)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern bool LaunchInternal();
// Returns whether or not a debugger is attached to the process.
//
public static extern bool IsAttached
{
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Process)]
[System.Security.SecuritySafeCritical] // auto-generated
[MethodImplAttribute(MethodImplOptions.InternalCall)]
get;
}
// Constants representing the importance level of messages to be logged.
//
// An attached debugger can enable or disable which messages will
// actually be reported to the user through the COM+ debugger
// services API. This info is communicated to the runtime so only
// desired events are actually reported to the debugger.
//
// Constant representing the default category
public static readonly String DefaultCategory = null;
// Posts a message for the attached debugger. If there is no
// debugger attached, has no effect. The debugger may or may not
// report the message depending on its settings.
[System.Security.SecuritySafeCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void Log(int level, String category, String message);
// Checks to see if an attached debugger has logging enabled
//
[System.Security.SecuritySafeCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern bool IsLogging();
// Posts a custom notification for the attached debugger. If there is no
// debugger attached, has no effect. The debugger may or may not
// report the notification depending on its settings.
[System.Security.SecuritySafeCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void CustomNotification(ICustomDebuggerNotification data);
}
}

View File

@@ -0,0 +1,380 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: DebuggerAttributes
**
**
** Purpose: Attributes for debugger
**
**
===========================================================*/
namespace System.Diagnostics {
using System;
using System.Runtime.InteropServices;
using System.Diagnostics.Contracts;
[Serializable]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false)]
[ComVisible(true)]
public sealed class DebuggerStepThroughAttribute : Attribute
{
public DebuggerStepThroughAttribute () {}
}
[Serializable]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false)]
[ComVisible(true)]
public sealed class DebuggerStepperBoundaryAttribute : Attribute
{
public DebuggerStepperBoundaryAttribute () {}
}
[Serializable]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor, Inherited = false)]
[ComVisible(true)]
public sealed class DebuggerHiddenAttribute : Attribute
{
public DebuggerHiddenAttribute () {}
}
[Serializable]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor |AttributeTargets.Struct, Inherited = false)]
[ComVisible(true)]
public sealed class DebuggerNonUserCodeAttribute : Attribute
{
public DebuggerNonUserCodeAttribute () {}
}
// Attribute class used by the compiler to mark modules.
// If present, then debugging information for everything in the
// assembly was generated by the compiler, and will be preserved
// by the Runtime so that the debugger can provide full functionality
// in the case of JIT attach. If not present, then the compiler may
// or may not have included debugging information, and the Runtime
// won't preserve the debugging info, which will make debugging after
// a JIT attach difficult.
[AttributeUsage(AttributeTargets.Assembly|AttributeTargets.Module, AllowMultiple = false)]
[ComVisible(true)]
public sealed class DebuggableAttribute : Attribute
{
[Flags]
[ComVisible(true)]
public enum DebuggingModes
{
None = 0x0,
Default = 0x1,
DisableOptimizations = 0x100,
IgnoreSymbolStoreSequencePoints = 0x2,
EnableEditAndContinue = 0x4
}
private DebuggingModes m_debuggingModes;
public DebuggableAttribute(bool isJITTrackingEnabled,
bool isJITOptimizerDisabled)
{
m_debuggingModes = 0;
if (isJITTrackingEnabled)
{
m_debuggingModes |= DebuggingModes.Default;
}
if (isJITOptimizerDisabled)
{
m_debuggingModes |= DebuggingModes.DisableOptimizations;
}
}
public DebuggableAttribute(DebuggingModes modes)
{
m_debuggingModes = modes;
}
public bool IsJITTrackingEnabled
{
get { return ((m_debuggingModes & DebuggingModes.Default) != 0); }
}
public bool IsJITOptimizerDisabled
{
get { return ((m_debuggingModes & DebuggingModes.DisableOptimizations) != 0); }
}
public DebuggingModes DebuggingFlags
{
get { return m_debuggingModes; }
}
}
// DebuggerBrowsableState states are defined as follows:
// Never never show this element
// Expanded expansion of the class is done, so that all visible internal members are shown
// Collapsed expansion of the class is not performed. Internal visible members are hidden
// RootHidden The target element itself should not be shown, but should instead be
// automatically expanded to have its members displayed.
// Default value is collapsed
// Please also change the code which validates DebuggerBrowsableState variable (in this file)
// if you change this enum.
[ComVisible(true)]
public enum DebuggerBrowsableState
{
Never = 0,
//Expanded is not supported in this release
//Expanded = 1,
Collapsed = 2,
RootHidden = 3
}
// the one currently supported with the csee.dat
// (mcee.dat, autoexp.dat) file.
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
[ComVisible(true)]
public sealed class DebuggerBrowsableAttribute: Attribute
{
private DebuggerBrowsableState state;
public DebuggerBrowsableAttribute(DebuggerBrowsableState state)
{
if( state < DebuggerBrowsableState.Never || state > DebuggerBrowsableState.RootHidden)
throw new ArgumentOutOfRangeException("state");
Contract.EndContractBlock();
this.state = state;
}
public DebuggerBrowsableState State
{
get { return state; }
}
}
// DebuggerTypeProxyAttribute
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
[ComVisible(true)]
public sealed class DebuggerTypeProxyAttribute: Attribute
{
private string typeName;
private string targetName;
private Type target;
public DebuggerTypeProxyAttribute(Type type)
{
if (type == null) {
throw new ArgumentNullException("type");
}
Contract.EndContractBlock();
this.typeName = type.AssemblyQualifiedName;
}
public DebuggerTypeProxyAttribute(string typeName)
{
this.typeName = typeName;
}
public string ProxyTypeName
{
get { return typeName; }
}
public Type Target
{
set {
if( value == null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
targetName = value.AssemblyQualifiedName;
target = value;
}
get { return target; }
}
public string TargetTypeName
{
get { return targetName; }
set { targetName = value; }
}
}
// This attribute is used to control what is displayed for the given class or field
// in the data windows in the debugger. The single argument to this attribute is
// the string that will be displayed in the value column for instances of the type.
// This string can include text between { and } which can be either a field,
// property or method (as will be documented in mscorlib). In the C# case,
// a general expression will be allowed which only has implicit access to the this pointer
// for the current instance of the target type. The expression will be limited,
// however: there is no access to aliases, locals, or pointers.
// In addition, attributes on properties referenced in the expression are not processed.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Delegate | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Assembly, AllowMultiple = true)]
[ComVisible(true)]
public sealed class DebuggerDisplayAttribute : Attribute
{
private string name;
private string value;
private string type;
private string targetName;
private Type target;
public DebuggerDisplayAttribute(string value)
{
if( value == null ) {
this.value = "";
}
else {
this.value = value;
}
name = "";
type = "";
}
public string Value
{
get { return this.value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public string Type
{
get { return type; }
set { type = value; }
}
public Type Target
{
set {
if( value == null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
targetName = value.AssemblyQualifiedName;
target = value;
}
get { return target; }
}
public string TargetTypeName
{
get { return targetName; }
set { targetName = value; }
}
}
/// <summary>
/// Signifies that the attributed type has a visualizer which is pointed
/// to by the parameter type name strings.
/// </summary>
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
[ComVisible(true)]
public sealed class DebuggerVisualizerAttribute: Attribute
{
private string visualizerObjectSourceName;
private string visualizerName;
private string description;
private string targetName;
private Type target;
public DebuggerVisualizerAttribute(string visualizerTypeName)
{
this.visualizerName = visualizerTypeName;
}
public DebuggerVisualizerAttribute(string visualizerTypeName, string visualizerObjectSourceTypeName)
{
this.visualizerName = visualizerTypeName;
this.visualizerObjectSourceName = visualizerObjectSourceTypeName;
}
public DebuggerVisualizerAttribute(string visualizerTypeName, Type visualizerObjectSource)
{
if (visualizerObjectSource == null) {
throw new ArgumentNullException("visualizerObjectSource");
}
Contract.EndContractBlock();
this.visualizerName = visualizerTypeName;
this.visualizerObjectSourceName = visualizerObjectSource.AssemblyQualifiedName;
}
public DebuggerVisualizerAttribute(Type visualizer)
{
if (visualizer == null) {
throw new ArgumentNullException("visualizer");
}
Contract.EndContractBlock();
this.visualizerName = visualizer.AssemblyQualifiedName;
}
public DebuggerVisualizerAttribute(Type visualizer, Type visualizerObjectSource)
{
if (visualizer == null) {
throw new ArgumentNullException("visualizer");
}
if (visualizerObjectSource == null) {
throw new ArgumentNullException("visualizerObjectSource");
}
Contract.EndContractBlock();
this.visualizerName = visualizer.AssemblyQualifiedName;
this.visualizerObjectSourceName = visualizerObjectSource.AssemblyQualifiedName;
}
public DebuggerVisualizerAttribute(Type visualizer, string visualizerObjectSourceTypeName)
{
if (visualizer == null) {
throw new ArgumentNullException("visualizer");
}
Contract.EndContractBlock();
this.visualizerName = visualizer.AssemblyQualifiedName;
this.visualizerObjectSourceName = visualizerObjectSourceTypeName;
}
public string VisualizerObjectSourceTypeName
{
get { return visualizerObjectSourceName; }
}
public string VisualizerTypeName
{
get { return visualizerName; }
}
public string Description
{
get { return description; }
set { description = value; }
}
public Type Target
{
set {
if( value == null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
targetName = value.AssemblyQualifiedName;
target = value;
}
get { return target; }
}
public string TargetTypeName
{
set { targetName = value; }
get { return targetName; }
}
}
}

View File

@@ -0,0 +1,31 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*=============================================================================
**
** Class: EditAndContinueHelper
**
**
** Purpose: Helper for EditAndContinue
**
**
=============================================================================*/
namespace System.Diagnostics {
using System;
#if !FEATURE_PAL
[Serializable]
internal sealed class EditAndContinueHelper
{
#pragma warning disable 169
#pragma warning disable 414 // Field is not used from managed.
private Object _objectReference;
#pragma warning restore 414
#pragma warning restore 169
}
#endif // !FEATURE_PAL
}

View File

@@ -0,0 +1,350 @@
// Copyright (c) Microsoft Corporation. All rights reserved
using System;
using System.Collections.Generic;
#if ES_BUILD_STANDALONE
namespace Microsoft.Diagnostics.Tracing.Internal
#else
namespace System.Diagnostics.Tracing.Internal
#endif
{
#if ES_BUILD_AGAINST_DOTNET_V35
using Microsoft.Internal;
#endif
using Microsoft.Reflection;
using System.Reflection;
internal static class Environment
{
public static readonly string NewLine = System.Environment.NewLine;
public static int TickCount
{ get { return System.Environment.TickCount; } }
public static string GetResourceString(string key, params object[] args)
{
string fmt = rm.GetString(key);
if (fmt != null)
return string.Format(fmt, args);
string sargs = String.Empty;
foreach(var arg in args)
{
if (sargs != String.Empty)
sargs += ", ";
sargs += arg.ToString();
}
return key + " (" + sargs + ")";
}
public static string GetRuntimeResourceString(string key, params object[] args)
{
return GetResourceString(key, args);
}
private static System.Resources.ResourceManager rm = new System.Resources.ResourceManager("Microsoft.Diagnostics.Tracing.Messages", typeof(Environment).Assembly());
}
}
#if ES_BUILD_AGAINST_DOTNET_V35
namespace Microsoft.Diagnostics.Contracts.Internal
{
internal class Contract
{
public static void Assert(bool invariant)
{
Assert(invariant, string.Empty);
}
public static void Assert(bool invariant, string message)
{
if (!invariant)
{
if (System.Diagnostics.Debugger.IsAttached)
System.Diagnostics.Debugger.Break();
throw new Exception("Assertion failed: " + message);
}
}
public static void EndContractBlock()
{ }
}
}
namespace Microsoft.Internal
{
using System.Text;
internal static class Tuple
{
public static Tuple<T1> Create<T1>(T1 item1)
{
return new Tuple<T1>(item1);
}
public static Tuple<T1, T2> Create<T1, T2>(T1 item1, T2 item2)
{
return new Tuple<T1, T2>(item1, item2);
}
}
[Serializable]
internal class Tuple<T1>
{
private readonly T1 m_Item1;
public T1 Item1 { get { return m_Item1; } }
public Tuple(T1 item1)
{
m_Item1 = item1;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("(");
sb.Append(m_Item1);
sb.Append(")");
return sb.ToString();
}
int Size
{
get
{
return 1;
}
}
}
[Serializable]
public class Tuple<T1, T2>
{
private readonly T1 m_Item1;
private readonly T2 m_Item2;
public T1 Item1 { get { return m_Item1; } }
public T2 Item2 { get { return m_Item2; } }
public Tuple(T1 item1, T2 item2)
{
m_Item1 = item1;
m_Item2 = item2;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("(");
sb.Append(m_Item1);
sb.Append(", ");
sb.Append(m_Item2);
sb.Append(")");
return sb.ToString();
}
int Size
{
get
{
return 2;
}
}
}
}
#endif
namespace Microsoft.Reflection
{
using System.Reflection;
#if ES_BUILD_PCL
[Flags]
public enum BindingFlags
{
DeclaredOnly = 0x02, // Only look at the members declared on the Type
Instance = 0x04, // Include Instance members in search
Static = 0x08, // Include Static members in search
Public = 0x10, // Include Public members in search
NonPublic = 0x20, // Include Non-Public members in search
}
public enum TypeCode {
Empty = 0, // Null reference
Object = 1, // Instance that isn't a value
DBNull = 2, // Database null value
Boolean = 3, // Boolean
Char = 4, // Unicode character
SByte = 5, // Signed 8-bit integer
Byte = 6, // Unsigned 8-bit integer
Int16 = 7, // Signed 16-bit integer
UInt16 = 8, // Unsigned 16-bit integer
Int32 = 9, // Signed 32-bit integer
UInt32 = 10, // Unsigned 32-bit integer
Int64 = 11, // Signed 64-bit integer
UInt64 = 12, // Unsigned 64-bit integer
Single = 13, // IEEE 32-bit float
Double = 14, // IEEE 64-bit double
Decimal = 15, // Decimal
DateTime = 16, // DateTime
String = 18, // Unicode character string
}
#endif
static class ReflectionExtensions
{
#if !ES_BUILD_PCL
//
// Type extension methods
//
public static bool IsEnum(this Type type) { return type.IsEnum; }
public static bool IsAbstract(this Type type) { return type.IsAbstract; }
public static bool IsSealed(this Type type) { return type.IsSealed; }
public static Type BaseType(this Type type) { return type.BaseType; }
public static Assembly Assembly(this Type type) { return type.Assembly; }
public static TypeCode GetTypeCode(this Type type) { return Type.GetTypeCode(type); }
public static bool ReflectionOnly(this Assembly assm) { return assm.ReflectionOnly; }
#else // ES_BUILD_PCL
//
// Type extension methods
//
public static bool IsEnum(this Type type) { return type.GetTypeInfo().IsEnum; }
public static bool IsAbstract(this Type type) { return type.GetTypeInfo().IsAbstract; }
public static bool IsSealed(this Type type) { return type.GetTypeInfo().IsSealed; }
public static Type BaseType(this Type type) { return type.GetTypeInfo().BaseType; }
public static Assembly Assembly(this Type type) { return type.GetTypeInfo().Assembly; }
public static MethodInfo[] GetMethods(this Type type, BindingFlags flags)
{
// Minimal implementation to cover only the cases we need
System.Diagnostics.Debug.Assert((flags & BindingFlags.DeclaredOnly) != 0);
System.Diagnostics.Debug.Assert((flags & ~(BindingFlags.DeclaredOnly|BindingFlags.Instance|BindingFlags.Static|BindingFlags.Public|BindingFlags.NonPublic)) == 0);
Func<MethodInfo, bool> visFilter;
Func<MethodInfo, bool> instFilter;
switch (flags & (BindingFlags.Public | BindingFlags.NonPublic))
{
case 0: visFilter = mi => false; break;
case BindingFlags.Public: visFilter = mi => mi.IsPublic; break;
case BindingFlags.NonPublic: visFilter = mi => !mi.IsPublic; break;
default: visFilter = mi => true; break;
}
switch (flags & (BindingFlags.Instance | BindingFlags.Static))
{
case 0: instFilter = mi => false; break;
case BindingFlags.Instance: instFilter = mi => !mi.IsStatic; break;
case BindingFlags.Static: instFilter = mi => mi.IsStatic; break;
default: instFilter = mi => true; break;
}
List<MethodInfo> methodInfos = new List<MethodInfo>();
foreach (var declaredMethod in type.GetTypeInfo().DeclaredMethods)
{
if (visFilter(declaredMethod) && instFilter(declaredMethod))
methodInfos.Add(declaredMethod);
}
return methodInfos.ToArray();
}
public static FieldInfo[] GetFields(this Type type, BindingFlags flags)
{
// Minimal implementation to cover only the cases we need
System.Diagnostics.Debug.Assert((flags & BindingFlags.DeclaredOnly) != 0);
System.Diagnostics.Debug.Assert((flags & ~(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) == 0);
Func<FieldInfo, bool> visFilter;
Func<FieldInfo, bool> instFilter;
switch (flags & (BindingFlags.Public | BindingFlags.NonPublic))
{
case 0: visFilter = fi => false; break;
case BindingFlags.Public: visFilter = fi => fi.IsPublic; break;
case BindingFlags.NonPublic: visFilter = fi => !fi.IsPublic; break;
default: visFilter = fi => true; break;
}
switch (flags & (BindingFlags.Instance | BindingFlags.Static))
{
case 0: instFilter = fi => false; break;
case BindingFlags.Instance: instFilter = fi => !fi.IsStatic; break;
case BindingFlags.Static: instFilter = fi => fi.IsStatic; break;
default: instFilter = fi => true; break;
}
List<FieldInfo> fieldInfos = new List<FieldInfo>();
foreach (var declaredField in type.GetTypeInfo().DeclaredFields)
{
if (visFilter(declaredField) && instFilter(declaredField))
fieldInfos.Add(declaredField);
}
return fieldInfos.ToArray();
}
public static Type GetNestedType(this Type type, string nestedTypeName)
{
TypeInfo ti = null;
foreach(var nt in type.GetTypeInfo().DeclaredNestedTypes)
{
if (nt.Name == nestedTypeName)
{
ti = nt;
break;
}
}
return ti == null ? null : ti.AsType();
}
public static TypeCode GetTypeCode(this Type type)
{
if (type == typeof(bool)) return TypeCode.Boolean;
else if (type == typeof(byte)) return TypeCode.Byte;
else if (type == typeof(char)) return TypeCode.Char;
else if (type == typeof(ushort)) return TypeCode.UInt16;
else if (type == typeof(uint)) return TypeCode.UInt32;
else if (type == typeof(ulong)) return TypeCode.UInt64;
else if (type == typeof(sbyte)) return TypeCode.SByte;
else if (type == typeof(short)) return TypeCode.Int16;
else if (type == typeof(int)) return TypeCode.Int32;
else if (type == typeof(long)) return TypeCode.Int64;
else if (type == typeof(string)) return TypeCode.String;
else if (type == typeof(float)) return TypeCode.Single;
else if (type == typeof(double)) return TypeCode.Double;
else if (type == typeof(DateTime)) return TypeCode.DateTime;
else if (type == (typeof(Decimal))) return TypeCode.Decimal;
else return TypeCode.Object;
}
//
// FieldInfo extension methods
//
public static object GetRawConstantValue(this FieldInfo fi)
{ return fi.GetValue(null); }
//
// Assembly extension methods
//
public static bool ReflectionOnly(this Assembly assm)
{
// In PCL we can't load in reflection-only context
return false;
}
#endif
}
}
// Defining some no-ops in PCL builds
#if ES_BUILD_PCL
namespace System.Security
{
class SuppressUnmanagedCodeSecurityAttribute : Attribute { }
enum SecurityAction { Demand }
}
namespace System.Security.Permissions
{
class HostProtectionAttribute : Attribute { public bool MayLeakOnAbort { get; set; } }
class PermissionSetAttribute : Attribute
{
public PermissionSetAttribute(System.Security.SecurityAction action) { }
public bool Unrestricted { get; set; }
}
}
#endif

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
#if ES_BUILD_STANDALONE
namespace Microsoft.Diagnostics.Tracing
#else
namespace System.Diagnostics.Tracing
#endif
{
internal sealed class ArrayTypeInfo<ElementType>
: TraceLoggingTypeInfo<ElementType[]>
{
private readonly TraceLoggingTypeInfo<ElementType> elementInfo;
public ArrayTypeInfo(TraceLoggingTypeInfo<ElementType> elementInfo)
{
this.elementInfo = elementInfo;
}
public override void WriteMetadata(
TraceLoggingMetadataCollector collector,
string name,
EventFieldFormat format)
{
collector.BeginBufferedArray();
this.elementInfo.WriteMetadata(collector, name, format);
collector.EndBufferedArray();
}
public override void WriteData(
TraceLoggingDataCollector collector,
ref ElementType[] value)
{
var bookmark = collector.BeginBufferedArray();
var count = 0;
if (value != null)
{
count = value.Length;
for (int i = 0; i < value.Length; i++)
{
this.elementInfo.WriteData(collector, ref value[i]);
}
}
collector.EndBufferedArray(bookmark, count);
}
public override object GetData(object value)
{
var array = (ElementType[])value;
var serializedArray = new object[array.Length];
for (int i = 0; i < array.Length; i++)
{
serializedArray[i] = this.elementInfo.GetData(array[i]);
}
return serializedArray;
}
}
}

View File

@@ -0,0 +1,123 @@
using System;
using Interlocked = System.Threading.Interlocked;
#if ES_BUILD_STANDALONE
namespace Microsoft.Diagnostics.Tracing
#else
namespace System.Diagnostics.Tracing
#endif
{
/// <summary>
/// TraceLogging: A very simple lock-free add-only dictionary.
/// Warning: this is a copy-by-value type. Copying performs a snapshot.
/// Accessing a readonly field always makes a copy of the field, so the
/// GetOrAdd method will not work as expected if called on a readonly field.
/// </summary>
/// <typeparam name="KeyType">
/// The type of the key, used for TryGet.
/// </typeparam>
/// <typeparam name="ItemType">
/// The type of the item, used for GetOrAdd.
/// </typeparam>
internal struct ConcurrentSet<KeyType, ItemType>
where ItemType : ConcurrentSetItem<KeyType, ItemType>
{
private ItemType[] items;
public ItemType TryGet(KeyType key)
{
ItemType item;
var oldItems = this.items;
if (oldItems != null)
{
var lo = 0;
var hi = oldItems.Length;
do
{
int i = (lo + hi) / 2;
item = oldItems[i];
int cmp = item.Compare(key);
if (cmp == 0)
{
goto Done;
}
else if (cmp < 0)
{
lo = i + 1;
}
else
{
hi = i;
}
}
while (lo != hi);
}
item = null;
Done:
return item;
}
public ItemType GetOrAdd(ItemType newItem)
{
ItemType item;
var oldItems = this.items;
ItemType[] newItems;
Retry:
if (oldItems == null)
{
newItems = new ItemType[] { newItem };
}
else
{
var lo = 0;
var hi = oldItems.Length;
do
{
int i = (lo + hi) / 2;
item = oldItems[i];
int cmp = item.Compare(newItem);
if (cmp == 0)
{
goto Done;
}
else if (cmp < 0)
{
lo = i + 1;
}
else
{
hi = i;
}
}
while (lo != hi);
int oldLength = oldItems.Length;
newItems = new ItemType[oldLength + 1];
Array.Copy(oldItems, 0, newItems, 0, lo);
newItems[lo] = newItem;
Array.Copy(oldItems, lo, newItems, lo + 1, oldLength - lo);
}
newItems = Interlocked.CompareExchange(ref this.items, newItems, oldItems);
if (oldItems != newItems)
{
oldItems = newItems;
goto Retry;
}
item = newItem;
Done:
return item;
}
}
}

View File

@@ -0,0 +1,21 @@
using System;
#if ES_BUILD_STANDALONE
namespace Microsoft.Diagnostics.Tracing
#else
namespace System.Diagnostics.Tracing
#endif
{
/// <summary>
/// TraceLogging: Abstract base class that must be inherited by items in a
/// ConcurrentSet.
/// </summary>
/// <typeparam name="KeyType">Type of the set's key.</typeparam>
/// <typeparam name="ItemType">Type of the derived class.</typeparam>
internal abstract class ConcurrentSetItem<KeyType, ItemType>
where ItemType : ConcurrentSetItem<KeyType, ItemType>
{
public abstract int Compare(ItemType other);
public abstract int Compare(KeyType key);
}
}

View File

@@ -0,0 +1,315 @@
using System;
using System.Runtime.InteropServices;
using System.Security;
#if ES_BUILD_STANDALONE
using Environment = Microsoft.Diagnostics.Tracing.Internal.Environment;
namespace Microsoft.Diagnostics.Tracing
#else
namespace System.Diagnostics.Tracing
#endif
{
/// <summary>
/// TraceLogging: This is the implementation of the DataCollector
/// functionality. To enable safe access to the DataCollector from
/// untrusted code, there is one thread-local instance of this structure
/// per thread. The instance must be Enabled before any data is written to
/// it. The instance must be Finished before the data is passed to
/// EventWrite. The instance must be Disabled before the arrays referenced
/// by the pointers are freed or unpinned.
/// </summary>
[SecurityCritical]
internal unsafe struct DataCollector
{
[ThreadStatic]
internal static DataCollector ThreadInstance;
private byte* scratchEnd;
private EventSource.EventData* datasEnd;
private GCHandle* pinsEnd;
private EventSource.EventData* datasStart;
private byte* scratch;
private EventSource.EventData* datas;
private GCHandle* pins;
private byte[] buffer;
private int bufferPos;
private int bufferNesting; // We may merge many fields int a single blob. If we are doing this we increment this.
private bool writingScalars;
internal void Enable(
byte* scratch,
int scratchSize,
EventSource.EventData* datas,
int dataCount,
GCHandle* pins,
int pinCount)
{
this.datasStart = datas;
this.scratchEnd = scratch + scratchSize;
this.datasEnd = datas + dataCount;
this.pinsEnd = pins + pinCount;
this.scratch = scratch;
this.datas = datas;
this.pins = pins;
this.writingScalars = false;
}
internal void Disable()
{
this = new DataCollector();
}
/// <summary>
/// Completes the list of scalars. Finish must be called before the data
/// descriptor array is passed to EventWrite.
/// </summary>
/// <returns>
/// A pointer to the next unused data descriptor, or datasEnd if they were
/// all used. (Descriptors may be unused if a string or array was null.)
/// </returns>
internal EventSource.EventData* Finish()
{
this.ScalarsEnd();
return this.datas;
}
internal void AddScalar(void* value, int size)
{
var pb = (byte*)value;
if (this.bufferNesting == 0)
{
var scratchOld = this.scratch;
var scratchNew = scratchOld + size;
if (this.scratchEnd < scratchNew)
{
throw new IndexOutOfRangeException(Environment.GetResourceString("EventSource_AddScalarOutOfRange"));
}
this.ScalarsBegin();
this.scratch = scratchNew;
for (int i = 0; i != size; i++)
{
scratchOld[i] = pb[i];
}
}
else
{
var oldPos = this.bufferPos;
this.bufferPos = checked(this.bufferPos + size);
this.EnsureBuffer();
for (int i = 0; i != size; i++, oldPos++)
{
this.buffer[oldPos] = pb[i];
}
}
}
internal void AddBinary(string value, int size)
{
if (size > ushort.MaxValue)
{
size = ushort.MaxValue - 1;
}
if (this.bufferNesting != 0)
{
this.EnsureBuffer(size + 2);
}
this.AddScalar(&size, 2);
if (size != 0)
{
if (this.bufferNesting == 0)
{
this.ScalarsEnd();
this.PinArray(value, size);
}
else
{
var oldPos = this.bufferPos;
this.bufferPos = checked(this.bufferPos + size);
this.EnsureBuffer();
fixed (void* p = value)
{
Marshal.Copy((IntPtr)p, this.buffer, oldPos, size);
}
}
}
}
internal void AddBinary(Array value, int size)
{
this.AddArray(value, size, 1);
}
internal void AddArray(Array value, int length, int itemSize)
{
if (length > ushort.MaxValue)
{
length = ushort.MaxValue;
}
var size = length * itemSize;
if (this.bufferNesting != 0)
{
this.EnsureBuffer(size + 2);
}
this.AddScalar(&length, 2);
if (length != 0)
{
if (this.bufferNesting == 0)
{
this.ScalarsEnd();
this.PinArray(value, size);
}
else
{
var oldPos = this.bufferPos;
this.bufferPos = checked(this.bufferPos + size);
this.EnsureBuffer();
Buffer.BlockCopy(value, 0, this.buffer, oldPos, size);
}
}
}
/// <summary>
/// Marks the start of a non-blittable array or enumerable.
/// </summary>
/// <returns>Bookmark to be passed to EndBufferedArray.</returns>
internal int BeginBufferedArray()
{
this.BeginBuffered();
this.bufferPos += 2; // Reserve space for the array length (filled in by EndEnumerable)
return this.bufferPos;
}
/// <summary>
/// Marks the end of a non-blittable array or enumerable.
/// </summary>
/// <param name="bookmark">The value returned by BeginBufferedArray.</param>
/// <param name="count">The number of items in the array.</param>
internal void EndBufferedArray(int bookmark, int count)
{
this.EnsureBuffer();
this.buffer[bookmark - 2] = unchecked((byte)count);
this.buffer[bookmark - 1] = unchecked((byte)(count >> 8));
this.EndBuffered();
}
/// <summary>
/// Marks the start of dynamically-buffered data.
/// </summary>
internal void BeginBuffered()
{
this.ScalarsEnd();
this.bufferNesting += 1;
}
/// <summary>
/// Marks the end of dynamically-buffered data.
/// </summary>
internal void EndBuffered()
{
this.bufferNesting -= 1;
if (this.bufferNesting == 0)
{
/*
*/
this.EnsureBuffer();
this.PinArray(this.buffer, this.bufferPos);
this.buffer = null;
this.bufferPos = 0;
}
}
private void EnsureBuffer()
{
var required = this.bufferPos;
if (this.buffer == null || this.buffer.Length < required)
{
this.GrowBuffer(required);
}
}
private void EnsureBuffer(int additionalSize)
{
var required = this.bufferPos + additionalSize;
if (this.buffer == null || this.buffer.Length < required)
{
this.GrowBuffer(required);
}
}
private void GrowBuffer(int required)
{
var newSize = this.buffer == null ? 64 : this.buffer.Length;
do
{
newSize *= 2;
}
while (newSize < required);
Array.Resize(ref this.buffer, newSize);
}
private void PinArray(object value, int size)
{
var pinsTemp = this.pins;
if (this.pinsEnd <= pinsTemp)
{
throw new IndexOutOfRangeException(Environment.GetResourceString("EventSource_PinArrayOutOfRange"));
}
var datasTemp = this.datas;
if (this.datasEnd <= datasTemp)
{
throw new IndexOutOfRangeException(Environment.GetResourceString("EventSource_DataDescriptorsOutOfRange"));
}
this.pins = pinsTemp + 1;
this.datas = datasTemp + 1;
*pinsTemp = GCHandle.Alloc(value, GCHandleType.Pinned);
datasTemp->m_Ptr = (long)(ulong)(UIntPtr)(void*)pinsTemp->AddrOfPinnedObject();
datasTemp->m_Size = size;
}
private void ScalarsBegin()
{
if (!this.writingScalars)
{
var datasTemp = this.datas;
if (this.datasEnd <= datasTemp)
{
throw new IndexOutOfRangeException(Environment.GetResourceString("EventSource_DataDescriptorsOutOfRange"));
}
datasTemp->m_Ptr = (long)(ulong)(UIntPtr)this.scratch;
this.writingScalars = true;
}
}
private void ScalarsEnd()
{
if (this.writingScalars)
{
var datasTemp = this.datas;
datasTemp->m_Size = checked((int)(this.scratch - (byte*)datasTemp->m_Ptr));
this.datas = datasTemp + 1;
this.writingScalars = false;
}
}
}
}

View File

@@ -0,0 +1,13 @@
#if ES_BUILD_STANDALONE
namespace Microsoft.Diagnostics.Tracing
#else
namespace System.Diagnostics.Tracing
#endif
{
/// <summary>
/// TraceLogging: Empty struct indicating no payload data.
/// </summary>
internal struct EmptyStruct
{
}
}

View File

@@ -0,0 +1,42 @@
using System;
using System.Reflection;
#if ES_BUILD_STANDALONE
namespace Microsoft.Diagnostics.Tracing
#else
namespace System.Diagnostics.Tracing
#endif
{
/// <summary>
/// Provides support for casting enums to their underlying type
/// from within generic context.
/// </summary>
/// <typeparam name="UnderlyingType">
/// The underlying type of the enum.
/// </typeparam>
internal static class EnumHelper<UnderlyingType>
{
private delegate UnderlyingType Transformer<ValueType>(ValueType value);
private static readonly MethodInfo IdentityInfo =
Statics.GetDeclaredStaticMethod(typeof(EnumHelper<UnderlyingType>), "Identity");
public static UnderlyingType Cast<ValueType>(ValueType value)
{
return Caster<ValueType>.Instance(value);
}
internal static UnderlyingType Identity(UnderlyingType value)
{
return value;
}
private static class Caster<ValueType>
{
public static readonly Transformer<ValueType> Instance =
(Transformer<ValueType>)Statics.CreateDelegate(
typeof(Transformer<ValueType>),
IdentityInfo);
}
}
}

View File

@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
#if ES_BUILD_STANDALONE
namespace Microsoft.Diagnostics.Tracing
#else
namespace System.Diagnostics.Tracing
#endif
{
internal sealed class EnumerableTypeInfo<IterableType, ElementType>
: TraceLoggingTypeInfo<IterableType>
where IterableType : IEnumerable<ElementType>
{
private readonly TraceLoggingTypeInfo<ElementType> elementInfo;
public EnumerableTypeInfo(TraceLoggingTypeInfo<ElementType> elementInfo)
{
this.elementInfo = elementInfo;
}
public override void WriteMetadata(
TraceLoggingMetadataCollector collector,
string name,
EventFieldFormat format)
{
collector.BeginBufferedArray();
this.elementInfo.WriteMetadata(collector, name, format);
collector.EndBufferedArray();
}
public override void WriteData(
TraceLoggingDataCollector collector,
ref IterableType value)
{
var bookmark = collector.BeginBufferedArray();
var count = 0;
if (value != null)
{
foreach (var element in value)
{
var el = element;
this.elementInfo.WriteData(collector, ref el);
count++;
}
}
collector.EndBufferedArray(bookmark, count);
}
public override object GetData(object value)
{
var iterType = (IterableType)value;
List<object> serializedEnumerable = new List<object>();
foreach (var element in iterType)
{
serializedEnumerable.Add(elementInfo.GetData(element));
}
return serializedEnumerable.ToArray();
}
}
}

View File

@@ -0,0 +1,142 @@
using System;
#if ES_BUILD_STANDALONE
namespace Microsoft.Diagnostics.Tracing
#else
namespace System.Diagnostics.Tracing
#endif
{
/// <summary>
/// Used when authoring types that will be passed to EventSource.Write.
/// EventSource.Write&lt;T> only works when T is either an anonymous type
/// or a type with an [EventData] attribute. In addition, the properties
/// of T must be supported property types. Supported property types include
/// simple built-in types (int, string, Guid, DateTime, DateTimeOffset,
/// KeyValuePair, etc.), anonymous types that only contain supported types,
/// types with an [EventData] attribute, arrays of the above, and IEnumerable
/// of the above.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)]
public class EventDataAttribute
: Attribute
{
private EventLevel level = (EventLevel)(-1);
private EventOpcode opcode = (EventOpcode)(-1);
/// <summary>
/// Gets or sets the name to use if this type is used for an
/// implicitly-named event or an implicitly-named property.
///
/// Example 1:
///
/// EventSource.Write(null, new T()); // implicitly-named event
///
/// The name of the event will be determined as follows:
///
/// if (T has an EventData attribute and attribute.Name != null)
/// eventName = attribute.Name;
/// else
/// eventName = typeof(T).Name;
///
/// Example 2:
///
/// EventSource.Write(name, new { _1 = new T() }); // implicitly-named field
///
/// The name of the field will be determined as follows:
///
/// if (T has an EventData attribute and attribute.Name != null)
/// fieldName = attribute.Name;
/// else
/// fieldName = typeof(T).Name;
/// </summary>
public string Name
{
get;
set;
}
/// <summary>
/// Gets or sets the level to use for the event.
/// Invalid levels (outside the range 0..255) are treated as unset.
/// Note that the Level attribute can bubble-up, i.e. if a type contains
/// a sub-object (a field or property), and the sub-object's type has a
/// TraceLoggingEvent attribute, the Level from the sub-object's attribute
/// can affect the event's level.
///
/// Example: for EventSource.Write(name, options, data), the level of the
/// event will be determined as follows:
///
/// if (options.Level has been set)
/// eventLevel = options.Level;
/// else if (data.GetType() has a TraceLoggingEvent attribute and attribute.Level has been set)
/// eventLevel = attribute.Level;
/// else if (a field/property contained in data has a TraceLoggingEvent attribute and attribute.Level has been set)
/// eventLevel = attribute.Level;
/// else
/// eventLevel = EventLevel.LogAlways;
/// </summary>
internal EventLevel Level
{
get { return this.level; }
set { this.level = value; }
}
/// <summary>
/// Gets or sets the opcode to use for the event.
/// Invalid opcodes (outside the range 0..255) are treated as unset.
/// Note that the Opcode attribute can bubble-up, i.e. if a type contains
/// a sub-object (a field or property), and the sub-object's type has a
/// TraceLoggingEvent attribute, the Opcode from the sub-object's attribute
/// can affect the event's opcode.
///
/// Example: for EventSource.Write(name, options, data), the opcode of the
/// event will be determined as follows:
///
/// if (options.Opcode has been set)
/// eventOpcode = options.Opcode;
/// else if (data.GetType() has a TraceLoggingEvent attribute and attribute.Opcode has been set)
/// eventOpcode = attribute.Opcode;
/// else if (a field/property contained in data has a TraceLoggingEvent attribute and attribute.Opcode has been set)
/// eventOpcode = attribute.Opcode;
/// else
/// eventOpcode = EventOpcode.Info;
/// </summary>
internal EventOpcode Opcode
{
get { return this.opcode; }
set { this.opcode = value; }
}
/// <summary>
/// Gets or sets the keywords to use for the event.
/// Note that the Keywords attribute can bubble-up, i.e. if a type contains
/// a sub-object (a field or property), and the sub-object's type has a
/// TraceLoggingEvent attribute, the Keywords from the sub-object's attribute
/// can affect the event's keywords.
///
/// Example: for EventSource.Write(name, options, data), the keywords of the
/// event will be determined as follows:
///
/// eventKeywords = options.Keywords;
/// if (data.GetType() has a TraceLoggingEvent attribute)
/// eventKeywords |= attribute.Keywords;
/// if (a field/property contained in data has a TraceLoggingEvent attribute)
/// eventKeywords |= attribute.Keywords;
/// </summary>
internal EventKeywords Keywords
{
get;
set;
}
/// <summary>
/// Gets or sets the flags for an event. These flags are ignored by ETW,
/// but can have meaning to the event consumer.
/// </summary>
internal EventTags Tags
{
get;
set;
}
}
}

Some files were not shown because too many files have changed in this diff Show More