Add a GetTypes() method to VirtualMachine to search for types with a given name in...
authorZoltan Varga <vargaz@gmail.com>
Tue, 25 Oct 2011 17:09:43 +0000 (19:09 +0200)
committerZoltan Varga <vargaz@gmail.com>
Tue, 25 Oct 2011 17:37:40 +0000 (19:37 +0200)
mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs
mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs
mcs/class/Mono.Debugger.Soft/Test/dtest.cs
mono/mini/debugger-agent.c

index 4cb37fc0e2898f32ea4464ec9f807344c5888fe3..6e6726f15d54e8c6a3a1e135e7dd149517dd8ddc 100644 (file)
@@ -347,7 +347,7 @@ namespace Mono.Debugger.Soft
                 * with newer runtimes, and vice versa.
                 */
                internal const int MAJOR_VERSION = 2;
-               internal const int MINOR_VERSION = 8;
+               internal const int MINOR_VERSION = 9;
 
                enum WPSuspendPolicy {
                        NONE = 0,
@@ -412,7 +412,8 @@ namespace Mono.Debugger.Soft
                        SET_PROTOCOL_VERSION = 8,
                        ABORT_INVOKE = 9,
                        SET_KEEPALIVE = 10,
-                       GET_TYPES_FOR_SOURCE_FILE = 11
+                       GET_TYPES_FOR_SOURCE_FILE = 11,
+                       GET_TYPES = 12
                }
 
                enum CmdEvent {
@@ -1540,6 +1541,15 @@ namespace Mono.Debugger.Soft
                        return types;
                }
 
+               internal long[] VM_GetTypes (string name, bool ignoreCase) {
+                       var res = SendReceive (CommandSet.VM, (int)CmdVM.GET_TYPES, new PacketWriter ().WriteString (name).WriteBool (ignoreCase));
+                       int count = res.ReadInt ();
+                       long[] types = new long [count];
+                       for (int i = 0; i < count; ++i)
+                               types [i] = res.ReadId ();
+                       return types;
+               }
+
                /*
                 * DOMAIN
                 */
index a2dd70b563c5d220d2803b189c5fdeb509f6577f..0a19a7f717e252dd69066fc4e4700c7b45d0ff86 100644 (file)
@@ -251,6 +251,19 @@ namespace Mono.Debugger.Soft
                                res [i] = GetType (ids [i]);
                        return res;
                }
+
+               //
+               // Return a list of TypeMirror objects for all loaded types named 'NAME'.
+               // NAME should be in the the same for as with Assembly.GetType ().
+               // Since protocol version 2.9.
+               //
+               public IList<TypeMirror> GetTypes (string name, bool ignoreCase) {
+                       long[] ids = conn.VM_GetTypes (name, ignoreCase);
+                       var res = new TypeMirror [ids.Length];
+                       for (int i = 0; i < ids.Length; ++i)
+                               res [i] = GetType (ids [i]);
+                       return res;
+               }
                
                internal void queue_event_set (EventSet es) {
                        lock (queue_monitor) {
index a2d9806c222bba7e5c85ee400a09b3bee5ed454d..7595620f28b812ba142b02b02f623c882f8a17a6 100644 (file)
@@ -2737,4 +2737,17 @@ public class DebuggerTests
                Assert.IsTrue (types.Any (t => t.FullName == "Tests"));
                Assert.IsFalse (types.Any (t => t.FullName == "System.Int32"));
        }
+
+       [Test]
+       public void GetTypesNamed () {
+               run_until ("user");
+
+               var types = vm.GetTypes ("Tests", false);
+               Assert.AreEqual (1, types.Count);
+               Assert.AreEqual ("Tests", types [0].FullName);
+
+               types = vm.GetTypes ("System.Exception", false);
+               Assert.AreEqual (1, types.Count);
+               Assert.AreEqual ("System.Exception", types [0].FullName);
+       }
 }
index a03795ce2c447f05511f88f1fc8931f2370984d1..135ba52c9fbd39137a66e29011b07ba13e83ac0a 100644 (file)
@@ -270,7 +270,7 @@ typedef struct {
 #define HEADER_LENGTH 11
 
 #define MAJOR_VERSION 2
-#define MINOR_VERSION 8
+#define MINOR_VERSION 9
 
 typedef enum {
        CMD_SET_VM = 1,
@@ -387,7 +387,8 @@ typedef enum {
        CMD_VM_SET_PROTOCOL_VERSION = 8,
        CMD_VM_ABORT_INVOKE = 9,
        CMD_VM_SET_KEEPALIVE = 10,
-       CMD_VM_GET_TYPES_FOR_SOURCE_FILE = 11
+       CMD_VM_GET_TYPES_FOR_SOURCE_FILE = 11,
+       CMD_VM_GET_TYPES = 12
 } CmdVM;
 
 typedef enum {
@@ -6217,6 +6218,62 @@ vm_commands (int command, int id, guint8 *p, guint8 *end, Buffer *buf)
                g_ptr_array_free (res_domains, TRUE);
                break;
        }
+       case CMD_VM_GET_TYPES: {
+               GHashTableIter iter;
+               MonoDomain *domain;
+               int i;
+               char *name;
+               gboolean ignore_case;
+               GPtrArray *res_classes, *res_domains;
+               MonoTypeNameParse info;
+
+               name = decode_string (p, &p, end);
+               ignore_case = decode_byte (p, &p, end);
+
+               if (!mono_reflection_parse_type (name, &info)) {
+                       g_free (name);
+                       mono_reflection_free_type_info (&info);
+                       return ERR_INVALID_ARGUMENT;
+               }
+
+               res_classes = g_ptr_array_new ();
+               res_domains = g_ptr_array_new ();
+
+               mono_loader_lock ();
+               g_hash_table_iter_init (&iter, domains);
+               while (g_hash_table_iter_next (&iter, NULL, (void**)&domain)) {
+                       MonoAssembly *ass;
+                       gboolean type_resolve;
+                       MonoType *t;
+                       GSList *tmp;
+
+                       mono_domain_assemblies_lock (domain);
+                       for (tmp = domain->domain_assemblies; tmp; tmp = tmp->next) {
+                               ass = tmp->data;
+
+                               if (ass->image) {
+                                       type_resolve = TRUE;
+                                       t = mono_reflection_get_type (ass->image, &info, ignore_case, &type_resolve);
+                                       if (t) {
+                                               g_ptr_array_add (res_classes, mono_type_get_class (t));
+                                               g_ptr_array_add (res_domains, domain);
+                                       }
+                               }
+                       }
+                       mono_domain_assemblies_unlock (domain);
+               }
+               mono_loader_unlock ();
+
+               g_free (name);
+               mono_reflection_free_type_info (&info);
+
+               buffer_add_int (buf, res_classes->len);
+               for (i = 0; i < res_classes->len; ++i)
+                       buffer_add_typeid (buf, g_ptr_array_index (res_domains, i), g_ptr_array_index (res_classes, i));
+               g_ptr_array_free (res_classes, TRUE);
+               g_ptr_array_free (res_domains, TRUE);
+               break;
+       }
 
        default:
                return ERR_NOT_IMPLEMENTED;