private bool ExecutePosTest(string testId, string testDesc, string errorNum1, string errorNum2, DebuggableAttribute.DebuggingModes actualModes, MyDebuggingModes expectedModes) { bool retVal = true; string errorDesc; TestLibrary.TestFramework.BeginScenario(testDesc); try { if (actualModes != (DebuggableAttribute.DebuggingModes)expectedModes) { errorDesc = "Value of " + actualModes + " is not the value " + (int)expectedModes + " as expected: Actually(" + (int)actualModes + ")"; TestLibrary.TestFramework.LogError(errorNum1 + " TestId-" + testId, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; TestLibrary.TestFramework.LogError(errorNum2 + " TestId-" + testId, errorDesc); retVal = false; } return(retVal); }
/// <summary> /// Create the single dynamic module that will /// contain all our types and states. /// </summary> /// <remarks> /// Emits the module into the current appdomain. /// This could be improved to use another appdomain so that all /// the types could be unloaded. All locals would have to be /// marshalable in this case. /// </remarks> private static void CreateDynamicModule() { // See http://blogs.msdn.com/jmstall/archive/2005/02/03/366429.aspx for a simple example // of debuggable reflection-emit. ErrorUtilities.VerifyThrow(s_dynamicModule == null, "Already emitted"); // In a later release, this could be changed to use LightweightCodeGen (DynamicMethod instead of AssemblyBuilder); // currently they don't support sequence points, so they can't be debugged in the normal way AssemblyBuilder assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("msbuild"), AssemblyBuilderAccess.Run); // Mark generated code as debuggable. // See http://blogs.msdn.com/rmbyers/archive/2005/06/26/432922.aspx for explanation. ConstructorInfo constructor = typeof(DebuggableAttribute).GetConstructor(new Type[] { typeof(DebuggableAttribute.DebuggingModes) }); DebuggableAttribute.DebuggingModes debuggingMode = DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.Default; CustomAttributeBuilder attribute = new CustomAttributeBuilder(constructor, new object[] { debuggingMode }); assembly.SetCustomAttribute(attribute); // Arbitrary but reasonable name string name = Process.GetCurrentProcess().ProcessName; s_dynamicModule = assembly.DefineDynamicModule(name, true /* track debug information */); }
private void SetDebuggableAttributes() { DebuggableAttribute.DebuggingModes attrs = DebuggableAttribute.DebuggingModes.Default | // Disable optimizations performed by the compiler to make your output file smaller, faster, and more efficient. // Optimizations result in code rearrangement in the output file, which can make debugging difficult. // Typically optimization should be disabled while debugging. DebuggableAttribute.DebuggingModes.DisableOptimizations | // Sequence points are used to indicate locations in the Microsoft intermediate language (MSIL) code that // a debugger user will expect to be able to refer to uniquely, such as for setting a breakpoint. // The JIT compiler ensures it does not compile the MSIL at two different sequence points into a // single native instruction. By default, the JIT compiler examines the symbol store in the program // database (PDB) file for a list of additional sequence points. However, loading the PDB file requires // that the file be available and has a negative performance impact. In version 2.0, compilers can emit // "implicit sequence points" in the MSIL code stream through the use of MSIL "nop" instructions. // Such compilers should set the IgnoreSymbolStoreSequencePoints flag to notify the common language // runtime to not load the PDB file. DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints; Object[] argValues = new Object[] { attrs }; // To suppress optimizations when debugging dynamic modules, apply the DebuggableAttribute attribute // to the dynamic assembly before calling DefineDynamicModule. Create an instance of DebuggableAttribute // with the DisableOptimizations flag and apply it using the SetCustomAttribute method. The attribute // must be applied to the dynamic assembly. It has no effect if applied to the module. this.AssemblyBuilder.SetCustomAttribute(new CustomAttributeBuilder(NativeGenerator.DebuggableAttributeCtor, argValues)); }
/// <summary> /// Determines whether the assembly was compiled without optimizations using the DebuggableAttribute /// </summary> public static bool HasOptimizationsDisabled(this EcmaAssembly assembly) { bool result = false; MetadataReader reader = assembly.MetadataReader; var attributeHandles = assembly.AssemblyDefinition.GetCustomAttributes(); CustomAttributeHandle attributeHandle = reader.GetCustomAttributeHandle(attributeHandles, "System.Diagnostics", "DebuggableAttribute"); if (!attributeHandle.IsNil) { CustomAttribute attribute = reader.GetCustomAttribute(attributeHandle); CustomAttributeValue <TypeDesc> decoded = attribute.DecodeValue(new CustomAttributeTypeProvider(assembly)); if (decoded.FixedArguments.Length == 1) { // DebuggableAttribute( DebuggableAttribute.DebuggingModes modes ) if (!(decoded.FixedArguments[0].Value is int)) { ThrowHelper.ThrowBadImageFormatException(); } DebuggableAttribute.DebuggingModes modes = (DebuggableAttribute.DebuggingModes)decoded.FixedArguments[0].Value; result = modes.HasFlag(DebuggableAttribute.DebuggingModes.DisableOptimizations) && modes.HasFlag(DebuggableAttribute.DebuggingModes.Default); } else if (decoded.FixedArguments.Length == 2) { // DebuggableAttribute( bool isJITTrackingEnabled, bool isJITOptimizerDisabled ) if (!(decoded.FixedArguments[0].Value is bool) || !(decoded.FixedArguments[1].Value is bool)) { ThrowHelper.ThrowBadImageFormatException(); } result = ((bool)decoded.FixedArguments[1].Value); } } return(result); }
public bool PosTest1() { const string c_TEST_ID = "P001"; string testDesc = "PosTest1: value of DebuggableAttribute.DebuggingModes."; DebuggableAttribute.DebuggingModes modes = DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints; testDesc += modes; MyDebuggingModes expectedModes = MyDebuggingModes.IgnoreSymbolStoreSequencePoints; return(ExecutePosTest(c_TEST_ID, testDesc, "001", "002", modes, expectedModes)); }
public bool PosTest1() { const string c_TEST_ID = "P001"; string testDesc = "PosTest1: value of DebuggableAttribute.DebuggingModes."; DebuggableAttribute.DebuggingModes modes = DebuggableAttribute.DebuggingModes.EnableEditAndContinue; testDesc += modes; MyDebuggingModes expectedModes = MyDebuggingModes.EnableEditAndContinue; return(ExecutePosTest(c_TEST_ID, testDesc, "001", "002", modes, expectedModes)); }
public bool PosTest1() { const string c_TEST_ID = "P001"; string testDesc = "PosTest1: value of DebuggableAttribute.DebuggingModes."; DebuggableAttribute.DebuggingModes modes = DebuggableAttribute.DebuggingModes.DisableOptimizations; testDesc += modes; MyDebuggingModes expectedModes = MyDebuggingModes.DisableOptimizations; return(ExecutePosTest(c_TEST_ID, testDesc, "001", "002", modes, expectedModes)); }
private static ModuleBuilder CreateModuleBuilder(string name) { const DebuggableAttribute.DebuggingModes debuggingModes = DebuggableAttribute.DebuggingModes.DisableOptimizations; AssemblyName assemblyName = new AssemblyName(name); AssemblyBuilder assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); // Enable debugging information. var attributeConstructor = typeof(DebuggableAttribute).GetConstructor(new Type[] { typeof(DebuggableAttribute.DebuggingModes) }); var attributeBuilder = new CustomAttributeBuilder(attributeConstructor, new object[] { debuggingModes }); assembly.SetCustomAttribute(attributeBuilder); return(assembly.DefineDynamicModule(name, true)); }
/// <summary>Initializes a new instance of the <see cref="T:System.Diagnostics.DebuggableAttribute" /> class, using the specified tracking and optimization options for the just-in-time (JIT) compiler.</summary> /// <param name="isJITTrackingEnabled">true to enable debugging; otherwise, false. </param> /// <param name="isJITOptimizerDisabled">true to disable the optimizer for execution; otherwise, false. </param> public DebuggableAttribute(bool isJITTrackingEnabled, bool isJITOptimizerDisabled) { this.JITTrackingEnabledFlag = isJITTrackingEnabled; this.JITOptimizerDisabledFlag = isJITOptimizerDisabled; if (isJITTrackingEnabled) { this.debuggingModes |= DebuggableAttribute.DebuggingModes.Default; } if (isJITOptimizerDisabled) { this.debuggingModes |= DebuggableAttribute.DebuggingModes.DisableOptimizations; } }
/// <summary>使用为实时 (JIT) 编译器指定的跟踪和优化选项来初始化 <see cref="T:System.Diagnostics.DebuggableAttribute" /> 类的新实例。</summary> /// <param name="isJITTrackingEnabled">如果启用调试,则为 true;否则为 false。</param> /// <param name="isJITOptimizerDisabled">如果禁用执行的优化程序,则为 true否则为 false。</param> public DebuggableAttribute(bool isJITTrackingEnabled, bool isJITOptimizerDisabled) { this.m_debuggingModes = DebuggableAttribute.DebuggingModes.None; if (isJITTrackingEnabled) { this.m_debuggingModes = this.m_debuggingModes | DebuggableAttribute.DebuggingModes.Default; } if (!isJITOptimizerDisabled) { return; } this.m_debuggingModes = this.m_debuggingModes | DebuggableAttribute.DebuggingModes.DisableOptimizations; }
internal void SetDebuggableAttributes() { DebuggableAttribute.DebuggingModes attrs = DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.DisableOptimizations; Type[] argTypes = new Type[] { typeof(DebuggableAttribute.DebuggingModes) }; Object[] argValues = new Object[] { attrs }; var debuggableCtor = typeof(DebuggableAttribute).GetConstructor(argTypes); _myAssembly.SetCustomAttribute(new CustomAttributeBuilder(debuggableCtor, argValues)); _myModule.SetCustomAttribute(new CustomAttributeBuilder(debuggableCtor, argValues)); }
/// <summary>Initializes a new instance of the <see cref="T:System.Diagnostics.DebuggableAttribute" /> class, using the specified debugging modes for the just-in-time (JIT) compiler. </summary> /// <param name="modes">A bitwise combination of the <see cref="T:System.Diagnostics.DebuggableAttribute.DebuggingModes" /> values specifying the debugging mode for the JIT compiler.</param> public DebuggableAttribute(DebuggableAttribute.DebuggingModes modes) { this.debuggingModes = modes; this.JITTrackingEnabledFlag = ((this.debuggingModes & DebuggableAttribute.DebuggingModes.Default) != DebuggableAttribute.DebuggingModes.None); this.JITOptimizerDisabledFlag = ((this.debuggingModes & DebuggableAttribute.DebuggingModes.DisableOptimizations) != DebuggableAttribute.DebuggingModes.None); }
public DebuggableAttribute(DebuggableAttribute.DebuggingModes modes) { this.m_debuggingModes = modes; }