From 255a36860f77d42216855ea198d782ba4d209128 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Mon, 20 Feb 2012 14:12:05 +0000 Subject: [PATCH] Emit debugger hidden attribute for more compiler generated members --- mcs/mcs/anonymous.cs | 2 +- mcs/mcs/attribute.cs | 38 +++++++++++++++++++++++--------------- mcs/mcs/dmcs.csproj | 12 ++++++------ mcs/mcs/field.cs | 2 ++ mcs/mcs/method.cs | 11 +++++------ mcs/mcs/typemanager.cs | 4 ++++ mcs/tests/test-debug-02-ref.xml | 4 ++-- 7 files changed, 43 insertions(+), 30 deletions(-) diff --git a/mcs/mcs/anonymous.cs b/mcs/mcs/anonymous.cs index 2222e915364..6678566bb27 100644 --- a/mcs/mcs/anonymous.cs +++ b/mcs/mcs/anonymous.cs @@ -1747,7 +1747,7 @@ namespace Mono.CSharp { for (int i = 0; i < parameters.Count; ++i) { AnonymousTypeParameter p = parameters [i]; - Field f = new Field (a_type, t_args [i], Modifiers.PRIVATE | Modifiers.READONLY, + Field f = new Field (a_type, t_args [i], Modifiers.PRIVATE | Modifiers.READONLY | Modifiers.DEBUGGER_HIDDEN, new MemberName ("<" + p.Name + ">", p.Location), null); if (!a_type.AddField (f)) { diff --git a/mcs/mcs/attribute.cs b/mcs/mcs/attribute.cs index 47996afaaaa..44a4b5456ed 100644 --- a/mcs/mcs/attribute.cs +++ b/mcs/mcs/attribute.cs @@ -1647,6 +1647,7 @@ namespace Mono.CSharp { public readonly PredefinedAttribute DebuggerHidden; public readonly PredefinedAttribute UnsafeValueType; public readonly PredefinedAttribute UnmanagedFunctionPointer; + public readonly PredefinedDebuggerBrowsableAttribute DebuggerBrowsable; // New in .NET 3.5 public readonly PredefinedAttribute Extension; @@ -1701,6 +1702,7 @@ namespace Mono.CSharp { DebuggerHidden = new PredefinedAttribute (module, "System.Diagnostics", "DebuggerHiddenAttribute"); UnsafeValueType = new PredefinedAttribute (module, "System.Runtime.CompilerServices", "UnsafeValueTypeAttribute"); UnmanagedFunctionPointer = new PredefinedAttribute (module, "System.Runtime.InteropServices", "UnmanagedFunctionPointerAttribute"); + DebuggerBrowsable = new PredefinedDebuggerBrowsableAttribute (module, "System.Diagnostics", "DebuggerBrowsableAttribute"); Extension = new PredefinedAttribute (module, "System.Runtime.CompilerServices", "ExtensionAttribute"); @@ -1784,22 +1786,12 @@ namespace Mono.CSharp { builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty); } - public void EmitAttribute (FieldBuilder builder, AttributeEncoder argsEncoded) - { - builder.SetCustomAttribute (GetCtorMetaInfo (), argsEncoded.ToArray ()); - } - public void EmitAttribute (TypeBuilder builder) { if (ResolveBuilder ()) builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty); } - public void EmitAttribute (TypeBuilder builder, AttributeEncoder argsEncoded) - { - builder.SetCustomAttribute (GetCtorMetaInfo (), argsEncoded.ToArray ()); - } - public void EmitAttribute (AssemblyBuilder builder) { if (ResolveBuilder ()) @@ -1818,11 +1810,6 @@ namespace Mono.CSharp { builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty); } - public void EmitAttribute (ParameterBuilder builder, AttributeEncoder argsEncoded) - { - builder.SetCustomAttribute (GetCtorMetaInfo (), argsEncoded.ToArray ()); - } - ConstructorInfo GetCtorMetaInfo () { return (ConstructorInfo) ctor.GetMetaInfo (); @@ -1844,6 +1831,27 @@ namespace Mono.CSharp { } } + public class PredefinedDebuggerBrowsableAttribute : PredefinedAttribute + { + public PredefinedDebuggerBrowsableAttribute (ModuleContainer module, string ns, string name) + : base (module, ns, name) + { + } + + public void EmitAttribute (FieldBuilder builder, System.Diagnostics.DebuggerBrowsableState state) + { + var ctor = module.PredefinedMembers.DebuggerBrowsableAttributeCtor.Get (); + if (ctor == null) + return; + + AttributeEncoder encoder = new AttributeEncoder (); + encoder.Encode ((int) state); + encoder.EncodeEmptyNamedArguments (); + + builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), encoder.ToArray ()); + } + } + public class PredefinedDecimalAttribute : PredefinedAttribute { public PredefinedDecimalAttribute (ModuleContainer module, string ns, string name) diff --git a/mcs/mcs/dmcs.csproj b/mcs/mcs/dmcs.csproj index 149c027ef02..b6015c4e882 100644 --- a/mcs/mcs/dmcs.csproj +++ b/mcs/mcs/dmcs.csproj @@ -52,6 +52,9 @@ MonoSymbolWriter.cs + + SourceMethodBuilder.cs + @@ -60,6 +63,7 @@ + @@ -111,6 +115,7 @@ + @@ -126,16 +131,11 @@ - - - - + - - diff --git a/mcs/mcs/field.cs b/mcs/mcs/field.cs index 29d44a446d4..cf854ce196a 100644 --- a/mcs/mcs/field.cs +++ b/mcs/mcs/field.cs @@ -239,6 +239,8 @@ namespace Mono.CSharp if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0 && !Parent.IsCompilerGenerated) Module.PredefinedAttributes.CompilerGenerated.EmitAttribute (FieldBuilder); + if ((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0) + Module.PredefinedAttributes.DebuggerBrowsable.EmitAttribute (FieldBuilder, System.Diagnostics.DebuggerBrowsableState.Never); if (OptAttributes != null) { OptAttributes.Emit (); diff --git a/mcs/mcs/method.cs b/mcs/mcs/method.cs index 4cd097d5f65..f40efb93aa0 100644 --- a/mcs/mcs/method.cs +++ b/mcs/mcs/method.cs @@ -1193,6 +1193,7 @@ namespace Mono.CSharp { } AsyncInitializer.Create (this, block, parameters, Parent.PartialContainer, ReturnType, Location); + ModFlags |= Modifiers.DEBUGGER_HIDDEN; } } @@ -1661,13 +1662,11 @@ namespace Mono.CSharp { if (Initializer != null) { // - // Use location of the constructor to emit sequence point of initializers - // at beginning of constructor name - // - // TODO: Need to extend mdb to support line regions to allow set a breakpoint at - // initializer + // mdb format does not support reqions. Try to workaround this by emitting the + // sequence point at initializer. Any breakpoint at constructor header should + // be adjusted to this sequence point as it's the next one which follows. // - block.AddScopeStatement (new StatementExpression (Initializer, Location)); + block.AddScopeStatement (new StatementExpression (Initializer)); } } diff --git a/mcs/mcs/typemanager.cs b/mcs/mcs/typemanager.cs index b6243c8cea2..14a96b757ce 100644 --- a/mcs/mcs/typemanager.cs +++ b/mcs/mcs/typemanager.cs @@ -322,6 +322,7 @@ namespace Mono.CSharp public readonly PredefinedMember AsyncVoidMethodBuilderCreate; public readonly PredefinedMember AsyncVoidMethodBuilderSetException; public readonly PredefinedMember AsyncVoidMethodBuilderSetResult; + public readonly PredefinedMember DebuggerBrowsableAttributeCtor; public readonly PredefinedMember DecimalCtor; public readonly PredefinedMember DecimalCtorInt; public readonly PredefinedMember DecimalCtorLong; @@ -402,6 +403,9 @@ namespace Mono.CSharp AsyncVoidMethodBuilderSetResult = new PredefinedMember (module, types.AsyncVoidMethodBuilder, MemberFilter.Method ("SetResult", 0, ParametersCompiled.EmptyReadOnlyParameters, btypes.Void)); + DebuggerBrowsableAttributeCtor = new PredefinedMember (module, atypes.DebuggerBrowsable, + MemberFilter.Constructor (null)); + DecimalCtor = new PredefinedMember (module, btypes.Decimal, MemberFilter.Constructor (ParametersCompiled.CreateFullyResolved ( btypes.Int, btypes.Int, btypes.Int, btypes.Bool, btypes.Byte))); diff --git a/mcs/tests/test-debug-02-ref.xml b/mcs/tests/test-debug-02-ref.xml index c3f3e8f8c93..b22032eb28c 100644 --- a/mcs/tests/test-debug-02-ref.xml +++ b/mcs/tests/test-debug-02-ref.xml @@ -33,7 +33,7 @@ @@ -42,7 +42,7 @@ - -- 2.11.4.GIT