Fix MethodMirror.GetCustomAttributes ().
authorZoltan Varga <vargaz@gmail.com>
Sun, 5 Aug 2012 00:29:31 +0000 (20:29 -0400)
committerZoltan Varga <vargaz@gmail.com>
Sun, 5 Aug 2012 00:29:40 +0000 (20:29 -0400)
mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs
mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/MethodMirror.cs
mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs
mcs/class/Mono.Debugger.Soft/Test/dtest.cs
mono/mini/debugger-agent.c

index 319a92bfdfe9e61e5af79d564edb7e6034be9d69..942c08366c7349dc970def4c538ac66781bb8b2e 100644 (file)
@@ -395,7 +395,7 @@ namespace Mono.Debugger.Soft
                 * with newer runtimes, and vice versa.
                 */
                internal const int MAJOR_VERSION = 2;
-               internal const int MINOR_VERSION = 20;
+               internal const int MINOR_VERSION = 21;
 
                enum WPSuspendPolicy {
                        NONE = 0,
@@ -517,7 +517,8 @@ namespace Mono.Debugger.Soft
                        GET_LOCALS_INFO = 5,
                        GET_INFO = 6,
                        GET_BODY = 7,
-                       RESOLVE_TOKEN = 8
+                       RESOLVE_TOKEN = 8,
+                       GET_CATTRS = 9
                }
 
                enum CmdType {
@@ -1824,6 +1825,11 @@ namespace Mono.Debugger.Soft
                        }
                }
 
+               internal CattrInfo[] Method_GetCustomAttributes (long id, long attr_type_id, bool inherit) {
+                       PacketReader r = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_CATTRS, new PacketWriter ().WriteId (id).WriteId (attr_type_id));
+                       return ReadCattrs (r);
+               }
+
                /*
                 * THREAD
                 */
index 0b2ddaf5f61549f7e4ef67ca88a328807c051881..a7a698dfdc31b9c00c94ba92a6561de7e4b80d8b 100644 (file)
@@ -77,11 +77,13 @@ namespace Mono.Debugger.Soft
                 * Creating the custom attributes themselves could modify the behavior of the
                 * debuggee, so we return objects similar to the CustomAttributeData objects
                 * used by the reflection-only functionality on .net.
+                * Since protocol version 2.21
                 */
                public CustomAttributeDataMirror[] GetCustomAttributes (bool inherit) {
                        return GetCAttrs (null, inherit);
                }
 
+               /* Since protocol version 2.21 */
                public CustomAttributeDataMirror[] GetCustomAttributes (TypeMirror attributeType, bool inherit) {
                        if (attributeType == null)
                                throw new ArgumentNullException ("attributeType");
@@ -89,12 +91,12 @@ namespace Mono.Debugger.Soft
                }
 
                CustomAttributeDataMirror[] GetCAttrs (TypeMirror type, bool inherit) {
-                       if (cattrs == null && Metadata != null && !Metadata.HasCustomAttributes)
+                       if (cattrs == null && meta != null && !Metadata.HasCustomAttributes)
                                cattrs = new CustomAttributeDataMirror [0];
 
                        // FIXME: Handle inherit
                        if (cattrs == null) {
-                               CattrInfo[] info = vm.conn.Type_GetCustomAttributes (id, 0, false);
+                               CattrInfo[] info = vm.conn.Method_GetCustomAttributes (id, 0, false);
                                cattrs = CustomAttributeDataMirror.Create (vm, info);
                        }
                        var res = new List<CustomAttributeDataMirror> ();
index d0b6c668f57dfdbc351d7053a18042bbddcdde2d..a5b663b1cd0aa74fd6f2c1b3f7bd51ab9aec0f3c 100644 (file)
@@ -512,6 +512,7 @@ public class Tests : TestsBase
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       [StateMachine (typeof (int))]
        public static void locals2<T> (string[] args, int arg, T t, ref string rs) {
                long i = 42;
                string s = "AB";
index 53c3b3764117b2e8b5cd6872cedd5b7b1cce2f62..b46f9106c21b5116f933ed27f4b85f846b322f60 100644 (file)
@@ -3019,6 +3019,10 @@ public class DebuggerTests
                args = gmd.GetGenericArguments ();
                Assert.AreEqual (1, args.Length);
                Assert.AreEqual ("T", args [0].Name);
+
+               var attrs = m.GetCustomAttributes (true);
+               Assert.AreEqual (1, attrs.Length);
+               Assert.AreEqual ("StateMachineAttribute", attrs [0].Constructor.DeclaringType.Name);
        }
 
        [Test]
index f787a0dba86bd55100338d62d5ab884e8d3a9430..ffcbccf60eb81ad9a2a38c405b15384e07ac435d 100644 (file)
@@ -276,7 +276,7 @@ typedef struct {
 #define HEADER_LENGTH 11
 
 #define MAJOR_VERSION 2
-#define MINOR_VERSION 20
+#define MINOR_VERSION 21
 
 typedef enum {
        CMD_SET_VM = 1,
@@ -456,6 +456,7 @@ typedef enum {
        CMD_METHOD_GET_INFO = 6,
        CMD_METHOD_GET_BODY = 7,
        CMD_METHOD_RESOLVE_TOKEN = 8,
+       CMD_METHOD_GET_CATTRS = 9,
 } CmdMethod;
 
 typedef enum {
@@ -7565,6 +7566,7 @@ static ErrorCode
 method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, guint8 *p, guint8 *end, Buffer *buf)
 {
        MonoMethodHeader *header;
+       int err;
 
        switch (command) {
        case CMD_METHOD_GET_NAME: {
@@ -7884,6 +7886,20 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
                }
                break;
        }
+       case CMD_METHOD_GET_CATTRS: {
+               MonoClass *attr_klass;
+               MonoCustomAttrInfo *cinfo;
+
+               attr_klass = decode_typeid (p, &p, end, NULL, &err);
+               /* attr_klass can be NULL */
+               if (err)
+                       return err;
+
+               cinfo = mono_custom_attrs_from_method (method);
+
+               buffer_add_cattrs (buf, domain, method->klass->image, attr_klass, cinfo);
+               break;
+       }
        default:
                return ERR_NOT_IMPLEMENTED;
        }