Merge pull request #5010 from Unity-Technologies/boehm-gc-alloc-fixed-sre
[mono.git] / mcs / class / Mono.Debugger.Soft / Mono.Debugger.Soft / Connection.cs
index 5499fef1cf6f3c2e025e5de0b880db253af50393..602c827091dedaa8314bd015dae6c2689616b4b7 100644 (file)
@@ -36,7 +36,7 @@ namespace Mono.Debugger.Soft
 
        struct SourceInfo {
                public string source_file;
-               public byte[] guid, hash;
+               public byte[] hash;
        }
 
        class DebugInfo {
@@ -117,6 +117,8 @@ namespace Mono.Debugger.Soft
                public string[] names;
                public int[] live_range_start;
                public int[] live_range_end;
+               public int[] scopes_start;
+               public int[] scopes_end;
        }
 
        struct PropInfo {
@@ -382,7 +384,8 @@ namespace Mono.Debugger.Soft
                ERR_UNLOADED = 103,
                ERR_NO_INVOCATION = 104,
                ABSENT_INFORMATION = 105,
-               NO_SEQ_POINT_AT_IL_OFFSET = 106
+               NO_SEQ_POINT_AT_IL_OFFSET = 106,
+               INVOKE_ABORTED = 107
        }
 
        public class ErrorHandlerEventArgs : EventArgs {
@@ -417,7 +420,7 @@ namespace Mono.Debugger.Soft
                 * with newer runtimes, and vice versa.
                 */
                internal const int MAJOR_VERSION = 2;
-               internal const int MINOR_VERSION = 39;
+               internal const int MINOR_VERSION = 45;
 
                enum WPSuspendPolicy {
                        NONE = 0,
@@ -529,7 +532,8 @@ namespace Mono.Debugger.Soft
                        GET_MANIFEST_MODULE = 3,
                        GET_OBJECT = 4,
                        GET_TYPE = 5,
-                       GET_NAME = 6
+                       GET_NAME = 6,
+                       GET_DOMAIN = 7
                }
 
                enum CmdModule {
@@ -587,6 +591,7 @@ namespace Mono.Debugger.Soft
                        GET_THIS = 2,
                        SET_VALUES = 3,
                        GET_DOMAIN = 4,
+                       SET_THIS = 5,
                }
 
                enum CmdArrayRef {
@@ -801,6 +806,13 @@ namespace Mono.Debugger.Soft
                                return res;
                        }
 
+                       public string ReadUTF16String () {
+                               int len = decode_int (packet, ref offset);
+                               string res = new String (Encoding.Unicode.GetChars (packet, offset, len));
+                               offset += len;
+                               return res;
+                       }
+
                        public ValueImpl ReadValue () {
                                ElementType etype = (ElementType)ReadByte ();
 
@@ -1224,6 +1236,8 @@ namespace Mono.Debugger.Soft
                                        bool res = ReceivePacket ();
                                        if (!res)
                                                break;
+                               } catch (ThreadAbortException) {
+                                       break;
                                } catch (Exception ex) {
                                        if (!closed) {
                                                Console.WriteLine (ex);
@@ -1638,13 +1652,14 @@ namespace Mono.Debugger.Soft
                        SendReceive (CommandSet.VM, (int)CmdVM.SET_PROTOCOL_VERSION, new PacketWriter ().WriteInt (major).WriteInt (minor));
                }
 
-               internal long[] VM_GetThreads () {
-                       var res = SendReceive (CommandSet.VM, (int)CmdVM.ALL_THREADS, null);
-                       int len = res.ReadInt ();
-                       long[] arr = new long [len];
-                       for (int i = 0; i < len; ++i)
-                               arr [i] = res.ReadId ();
-                       return arr;
+               internal void VM_GetThreads (Action<long[]> resultCallaback) {
+                       Send (CommandSet.VM, (int)CmdVM.ALL_THREADS, null, (res) => {
+                               int len = res.ReadInt ();
+                               long[] arr = new long [len];
+                               for (int i = 0; i < len; ++i)
+                                       arr [i] = res.ReadId ();
+                               resultCallaback(arr);
+                       }, 1);
                }
 
                internal void VM_Suspend () {
@@ -1901,6 +1916,19 @@ namespace Mono.Debugger.Soft
                        var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_LOCALS_INFO, new PacketWriter ().WriteId (id));
 
                        LocalsInfo info = new LocalsInfo ();
+
+                       if (Version.AtLeast (2, 43)) {
+                               int nscopes = res.ReadInt ();
+                               info.scopes_start = new int [nscopes];
+                               info.scopes_end = new int [nscopes];
+                               int last_start = 0;
+                               for (int i = 0; i < nscopes; ++i) {
+                                       info.scopes_start [i] = last_start + res.ReadInt ();
+                                       info.scopes_end [i] = info.scopes_start [i] + res.ReadInt ();
+                                       last_start = info.scopes_start [i];
+                               }
+                       }
+
                        int nlocals = res.ReadInt ();
                        info.types = new long [nlocals];
                        for (int i = 0; i < nlocals; ++i)
@@ -2089,6 +2117,10 @@ namespace Mono.Debugger.Soft
                        return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
                }
 
+               internal long Assembly_GetIdDomain (long id) {
+                       return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_DOMAIN, new PacketWriter ().WriteId (id)).ReadId ();
+               }
+
                /*
                 * TYPE
                 */
@@ -2182,7 +2214,7 @@ namespace Mono.Debugger.Soft
                internal ValueImpl[] Type_GetValues (long id, long[] fields, long thread_id) {
                        int len = fields.Length;
                        PacketReader r;
-                       if (thread_id != 0)
+                       if (thread_id != 0 && Version.AtLeast(2, 3))
                                r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES_2, new PacketWriter ().WriteId (id).WriteId (thread_id).WriteInt (len).WriteIds (fields));
                        else
                                r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));
@@ -2386,6 +2418,10 @@ namespace Mono.Debugger.Soft
                        return SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_DOMAIN, new PacketWriter ().WriteId (thread_id).WriteId (id)).ReadId ();
                }
 
+               internal void StackFrame_SetThis (long thread_id, long id, ValueImpl value) {
+                       SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.SET_THIS, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteValue (value));
+               }
+
                /*
                 * ARRAYS
                 */
@@ -2417,7 +2453,16 @@ namespace Mono.Debugger.Soft
                 * STRINGS
                 */
                internal string String_GetValue (long id) {
-                       return SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_VALUE, new PacketWriter ().WriteId (id)).ReadString ();
+                       var r = SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_VALUE, new PacketWriter ().WriteId (id));
+
+                       bool is_utf16 = false;
+                       if (Version.AtLeast (2, 41))
+                               is_utf16 = r.ReadByte () == 1;
+
+                       if (is_utf16)
+                               return r.ReadUTF16String ();
+                       else
+                               return r.ReadString ();
                }                       
 
                internal int String_GetLength (long id) {