New tests.
[mono.git] / mcs / class / Mono.Debugger.Soft / Mono.Debugger.Soft / Connection.cs
index 21d7067e34701af397c87fab04d40f97d7d4c112..eace25b3cca9268162737291a31f548b110b07e0 100644 (file)
@@ -200,7 +200,9 @@ namespace Mono.Debugger.Soft
                INVALID_FRAMEID = 30,
                NOT_IMPLEMENTED = 100,
                NOT_SUSPENDED = 101,
-               INVALID_ARGUMENT = 102
+               INVALID_ARGUMENT = 102,
+               ERR_UNLOADED = 103,
+               ERR_NO_INVOCATION = 104
        }
 
        public class ErrorHandlerEventArgs : EventArgs {
@@ -225,8 +227,10 @@ namespace Mono.Debugger.Soft
 
                /*
                 * Th version of the wire-protocol implemented by the library. The library
-                * and the debuggee can communicate if they implement the same major version,
-                * and the debuggee's minor version is <= the library's minor version.
+                * and the debuggee can communicate if they implement the same major version.
+                * If they implement a different minor version, they can communicate, but some
+                * features might not be available. This allows older clients to communicate
+                * with newer runtimes, and vice versa.
                 */
                public const int MAJOR_VERSION = 2;
                public const int MINOR_VERSION = 1;
@@ -286,7 +290,9 @@ namespace Mono.Debugger.Soft
                        RESUME = 4,
                        EXIT = 5,
                        DISPOSE = 6,
-                       INVOKE_METHOD = 7
+                       INVOKE_METHOD = 7,
+                       SET_PROTOCOL_VERSION = 8,
+                       ABORT_INVOKE = 9
                }
 
                enum CmdEvent {
@@ -297,7 +303,9 @@ namespace Mono.Debugger.Soft
                        GET_FRAME_INFO = 1,
                        GET_NAME = 2,
                        GET_STATE = 3,
-                       GET_INFO = 4
+                       GET_INFO = 4,
+                       /* FIXME: Merge into GET_INFO when the major protocol version is increased */
+                       GET_ID = 5
                }
 
                enum CmdEventRequest {
@@ -849,6 +857,24 @@ namespace Mono.Debugger.Soft
                        receiver_thread.Start ();
 
                        Version = VM_GetVersion ();
+
+                       //
+                       // Tell the debuggee our protocol version, so newer debuggees can work
+                       // with older clients
+                       //
+
+                       //
+                       // Older debuggees might not support this request
+                       EventHandler<ErrorHandlerEventArgs> OrigErrorHandler = ErrorHandler;
+                       ErrorHandler = null;
+                       ErrorHandler += delegate (object sender, ErrorHandlerEventArgs args) {
+                               throw new NotSupportedException ();
+                       };
+                       try {
+                               VM_SetProtocolVersion (MAJOR_VERSION, MINOR_VERSION);
+                       } catch (NotSupportedException) {
+                       }
+                       ErrorHandler = OrigErrorHandler;
                }
 
                public EndPoint EndPoint {
@@ -1026,7 +1052,7 @@ namespace Mono.Debugger.Soft
                }
 
                /* Send a request and call cb when a result is received */
-               void Send (CommandSet command_set, int command, PacketWriter packet, Action<PacketReader> cb) {
+               int Send (CommandSet command_set, int command, PacketWriter packet, Action<PacketReader> cb) {
                        int id = IdGenerator;
 
                        lock (reply_packets_monitor) {
@@ -1041,6 +1067,8 @@ namespace Mono.Debugger.Soft
                                WritePacket (EncodePacket (id, (int)command_set, command, null, 0));
                        else
                                WritePacket (EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset));
+
+                       return id;
                }
 
                PacketReader SendReceive (CommandSet command_set, int command, PacketWriter packet) {
@@ -1155,6 +1183,10 @@ namespace Mono.Debugger.Soft
                        return info;
                }
 
+               public void VM_SetProtocolVersion (int major, int minor) {
+                       SendReceive (CommandSet.VM, (int)CmdVM.SET_PROTOCOL_VERSION, new PacketWriter ().WriteInt (major).WriteInt (minor));
+               }
+
                public long[] VM_GetThreads () {
                        var res = SendReceive (CommandSet.VM, (int)CmdVM.ALL_THREADS, null);
                        int len = res.ReadInt ();
@@ -1193,8 +1225,8 @@ namespace Mono.Debugger.Soft
 
                public delegate void InvokeMethodCallback (ValueImpl v, ValueImpl exc, ErrorCode error, object state);
 
-               public void VM_BeginInvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, InvokeMethodCallback callback, object state) {
-                       Send (CommandSet.VM, (int)CmdVM.INVOKE_METHOD, new PacketWriter ().WriteId (thread).WriteInt ((int)flags).WriteId (method).WriteValue (this_arg).WriteInt (arguments.Length).WriteValues (arguments), delegate (PacketReader r) {
+               public int VM_BeginInvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, InvokeMethodCallback callback, object state) {
+                       return Send (CommandSet.VM, (int)CmdVM.INVOKE_METHOD, new PacketWriter ().WriteId (thread).WriteInt ((int)flags).WriteId (method).WriteValue (this_arg).WriteInt (arguments.Length).WriteValues (arguments), delegate (PacketReader r) {
                                        ValueImpl v, exc;
 
                                        if (r.ErrorCode != 0) {
@@ -1213,6 +1245,11 @@ namespace Mono.Debugger.Soft
                                });
                }
 
+               public void VM_AbortInvoke (long thread, int id)
+               {
+                       SendReceive (CommandSet.VM, (int)CmdVM.ABORT_INVOKE, new PacketWriter ().WriteId (thread).WriteInt (id));
+               }
+
                /*
                 * DOMAIN
                 */
@@ -1395,6 +1432,10 @@ namespace Mono.Debugger.Soft
                        return res;
                }
 
+               public long Thread_GetId (long id) {
+                       return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_ID, new PacketWriter ().WriteId (id)).ReadLong ();
+               }
+
                /*
                 * MODULE
                 */