4 using System.Net.Sockets;
5 using System.Threading;
6 using System.Collections.Generic;
8 using Mono.Cecil.Metadata;
10 namespace Mono.Debugger.Soft
12 public class VersionInfo {
13 public string VMVersion {
17 public int MajorVersion {
21 public int MinorVersion {
27 public int max_il_offset;
28 public string filename;
29 public int[] il_offsets;
30 public int[] line_numbers;
37 public StackFrameFlags flags;
41 public string ns, name, full_name;
42 public long assembly, module, base_type, element_type;
43 public int token, rank, attributes;
44 public bool is_byref, is_pointer, is_primitive, is_valuetype, is_enum;
49 public int attributes, iattributes, token;
52 class MethodBodyInfo {
58 public int param_count;
59 public int generic_param_count;
61 public long[] param_types;
62 public string[] param_names;
67 public string[] names;
68 public int[] live_range_start;
69 public int[] live_range_end;
75 public long get_method, set_method;
79 class CattrNamedArgInfo {
80 public bool is_property;
82 public ValueImpl value;
87 public ValueImpl[] ctor_args;
88 public CattrNamedArgInfo[] named_args;
92 public bool is_thread_pool;
96 VALUE_TYPE_ID_NULL = 0xf0,
97 VALUE_TYPE_ID_TYPE = 0xf1
102 DISABLE_BREAKPOINTS = 0x1,
103 SINGLE_THREADED = 0x2
149 public ElementType Type; /* or one of the VALUE_TYPE_ID constants */
152 public long Klass; // For ElementType.ValueType
153 public ValueImpl[] Fields; // for ElementType.ValueType
154 public bool IsEnum; // For ElementType.ValueType
155 public long Id; /* For VALUE_TYPE_ID_TYPE */
159 public string Name, ScopeName, FQName, Guid;
160 public long Assembly;
171 enum StackFrameFlags {
175 class ResolvedToken {
176 public TokenType Type;
184 class CountModifier : Modifier {
190 class LocationModifier : Modifier {
195 public long Location {
200 class StepModifier : Modifier {
214 class ThreadModifier : Modifier {
220 class ExceptionModifier : Modifier {
227 public bool Uncaught {
232 class AssemblyModifier : Modifier {
233 public long[] Assemblies {
239 public EventType EventType {
247 public SuspendPolicy SuspendPolicy {
251 public long ThreadId {
259 public long Location {
263 public EventInfo (EventType type, int req_id) {
269 public enum ErrorCode {
272 INVALID_FIELDID = 25,
273 INVALID_FRAMEID = 30,
274 NOT_IMPLEMENTED = 100,
276 INVALID_ARGUMENT = 102,
278 ERR_NO_INVOCATION = 104,
279 ABSENT_INFORMATION = 105
282 public class ErrorHandlerEventArgs : EventArgs {
284 public ErrorCode ErrorCode {
290 * Represents the connection to the debuggee
295 * The protocol and the packet format is based on JDWP, the differences
296 * are in the set of supported events, and the commands.
298 public const string HANDSHAKE_STRING = "DWP-Handshake";
300 public const int HEADER_LENGTH = 11;
303 * Th version of the wire-protocol implemented by the library. The library
304 * and the debuggee can communicate if they implement the same major version.
305 * If they implement a different minor version, they can communicate, but some
306 * features might not be available. This allows older clients to communicate
307 * with newer runtimes, and vice versa.
309 public const int MAJOR_VERSION = 2;
310 public const int MINOR_VERSION = 2;
312 enum WPSuspendPolicy {
339 APPDOMAIN_CREATE = 4, // Not in JDI
340 APPDOMAIN_UNLOAD = 5, // Not in JDI
368 SET_PROTOCOL_VERSION = 8,
381 /* FIXME: Merge into GET_INFO when the major protocol version is increased */
385 enum CmdEventRequest {
388 CLEAR_ALL_BREAKPOINTS = 3
393 GET_FRIENDLY_NAME = 2,
395 GET_ENTRY_ASSEMBLY = 4,
398 CREATE_BOXED_VALUE = 7
404 GET_MANIFEST_MODULE = 3,
416 GET_DECLARING_TYPE = 2,
431 GET_SOURCE_FILES = 6,
433 IS_ASSIGNABLE_FROM = 8,
436 GET_FIELD_CATTRS = 11,
437 GET_PROPERTY_CATTRS = 12,
438 /* FIXME: Merge into GET_SOURCE_FILES when the major protocol version is increased */
439 GET_SOURCE_FILES_2 = 13
469 public int command_set;
474 public static int GetPacketLength (byte[] header) {
476 return decode_int (header, ref offset);
479 public static bool IsReplyPacket (byte[] packet) {
481 return decode_byte (packet, ref offset) == 0x80;
484 public static int GetPacketId (byte[] packet) {
486 return decode_int (packet, ref offset);
489 static int decode_byte (byte[] packet, ref int offset) {
490 return packet [offset++];
493 static int decode_short (byte[] packet, ref int offset) {
494 int res = ((int)packet [offset] << 8) | (int)packet [offset + 1];
499 static int decode_int (byte[] packet, ref int offset) {
500 int res = ((int)packet [offset] << 24) | ((int)packet [offset + 1] << 16) | ((int)packet [offset + 2] << 8) | (int)packet [offset + 3];
505 static long decode_id (byte[] packet, ref int offset) {
506 return decode_int (packet, ref offset);
509 static long decode_long (byte[] packet, ref int offset) {
510 uint high = (uint)decode_int (packet, ref offset);
511 uint low = (uint)decode_int (packet, ref offset);
513 return (long)(((ulong)high << 32) | (ulong)low);
516 public static SuspendPolicy decode_suspend_policy (int suspend_policy) {
517 switch ((WPSuspendPolicy)suspend_policy) {
518 case WPSuspendPolicy.NONE:
519 return SuspendPolicy.None;
520 case WPSuspendPolicy.EVENT_THREAD:
521 return SuspendPolicy.EventThread;
522 case WPSuspendPolicy.ALL:
523 return SuspendPolicy.All;
525 throw new NotImplementedException ();
529 static Header decode_command_header (byte[] packet) {
531 Header res = new Header ();
533 decode_int (packet, ref offset);
534 res.id = decode_int (packet, ref offset);
535 res.flags = decode_byte (packet, ref offset);
536 res.command_set = decode_byte (packet, ref offset);
537 res.command = decode_byte (packet, ref offset);
542 static void encode_byte (byte[] buf, int b, ref int offset) {
543 buf [offset] = (byte)b;
547 static void encode_int (byte[] buf, int i, ref int offset) {
548 buf [offset] = (byte)((i >> 24) & 0xff);
549 buf [offset + 1] = (byte)((i >> 16) & 0xff);
550 buf [offset + 2] = (byte)((i >> 8) & 0xff);
551 buf [offset + 3] = (byte)((i >> 0) & 0xff);
555 static void encode_id (byte[] buf, long id, ref int offset) {
556 encode_int (buf, (int)id, ref offset);
559 static void encode_long (byte[] buf, long l, ref int offset) {
560 encode_int (buf, (int)((l >> 32) & 0xffffffff), ref offset);
561 encode_int (buf, (int)(l & 0xffffffff), ref offset);
564 public static byte[] EncodePacket (int id, int commandSet, int command, byte[] data, int dataLen) {
565 byte[] buf = new byte [dataLen + 11];
568 encode_int (buf, buf.Length, ref offset);
569 encode_int (buf, id, ref offset);
570 encode_byte (buf, 0, ref offset);
571 encode_byte (buf, commandSet, ref offset);
572 encode_byte (buf, command, ref offset);
574 for (int i = 0; i < dataLen; ++i)
575 buf [offset + i] = data [i];
584 public PacketReader (byte[] packet) {
585 this.packet = packet;
588 Header header = decode_command_header (packet);
589 CommandSet = (CommandSet)header.command_set;
590 Command = header.command;
594 ReadInt (); // length
596 ReadByte (); // flags
597 ErrorCode = ReadShort ();
600 public CommandSet CommandSet {
608 public int ErrorCode {
618 public int ReadByte () {
619 return decode_byte (packet, ref offset);
622 public int ReadShort () {
623 return decode_short (packet, ref offset);
626 public int ReadInt () {
627 return decode_int (packet, ref offset);
630 public long ReadId () {
631 return decode_id (packet, ref offset);
634 public long ReadLong () {
635 return decode_long (packet, ref offset);
638 public float ReadFloat () {
639 float f = DataConverter.FloatFromBE (packet, offset);
644 public double ReadDouble () {
645 double d = DataConverter.DoubleFromBE (packet, offset);
650 public string ReadString () {
651 int len = decode_int (packet, ref offset);
652 string res = new String (Encoding.UTF8.GetChars (packet, offset, len));
657 public ValueImpl ReadValue () {
658 ElementType etype = (ElementType)ReadByte ();
661 case ElementType.Void:
662 return new ValueImpl { Type = etype };
664 return new ValueImpl { Type = etype, Value = (sbyte)ReadInt () };
666 return new ValueImpl { Type = etype, Value = (byte)ReadInt () };
667 case ElementType.Boolean:
668 return new ValueImpl { Type = etype, Value = ReadInt () != 0 };
670 return new ValueImpl { Type = etype, Value = (short)ReadInt () };
672 return new ValueImpl { Type = etype, Value = (ushort)ReadInt () };
673 case ElementType.Char:
674 return new ValueImpl { Type = etype, Value = (char)ReadInt () };
676 return new ValueImpl { Type = etype, Value = ReadInt () };
678 return new ValueImpl { Type = etype, Value = (uint)ReadInt () };
680 return new ValueImpl { Type = etype, Value = ReadLong () };
682 return new ValueImpl { Type = etype, Value = (ulong)ReadLong () };
684 return new ValueImpl { Type = etype, Value = ReadFloat () };
686 return new ValueImpl { Type = etype, Value = ReadDouble () };
689 case ElementType.Ptr:
690 // FIXME: The client and the debuggee might have different word sizes
691 return new ValueImpl { Type = etype, Value = ReadLong () };
692 case ElementType.String:
693 case ElementType.SzArray:
694 case ElementType.Class:
695 case ElementType.Array:
696 case ElementType.Object:
697 long objid = ReadId ();
698 return new ValueImpl () { Type = etype, Objid = objid };
699 case ElementType.ValueType:
700 bool is_enum = ReadByte () == 1;
701 long klass = ReadId ();
702 long nfields = ReadInt ();
703 ValueImpl[] fields = new ValueImpl [nfields];
704 for (int i = 0; i < nfields; ++i)
705 fields [i] = ReadValue ();
706 return new ValueImpl () { Type = etype, Klass = klass, Fields = fields, IsEnum = is_enum };
707 case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
708 return new ValueImpl { Type = etype };
709 case (ElementType)ValueTypeId.VALUE_TYPE_ID_TYPE:
710 return new ValueImpl () { Type = etype, Id = ReadId () };
712 throw new NotImplementedException ("Unable to handle type " + etype);
722 public PacketWriter () {
723 data = new byte [1024];
727 void MakeRoom (int size) {
728 if (offset + size >= data.Length) {
729 int new_len = data.Length * 2;
730 while (new_len < offset + size) {
733 byte[] new_data = new byte [new_len];
734 Array.Copy (data, new_data, data.Length);
739 public PacketWriter WriteByte (byte val) {
741 encode_byte (data, val, ref offset);
745 public PacketWriter WriteInt (int val) {
747 encode_int (data, val, ref offset);
751 public PacketWriter WriteId (long id) {
753 encode_id (data, id, ref offset);
757 public PacketWriter WriteLong (long val) {
759 encode_long (data, val, ref offset);
763 public PacketWriter WriteFloat (float f) {
765 byte[] b = DataConverter.GetBytesBE (f);
766 for (int i = 0; i < 4; ++i)
767 data [offset + i] = b [i];
772 public PacketWriter WriteDouble (double d) {
774 byte[] b = DataConverter.GetBytesBE (d);
775 for (int i = 0; i < 8; ++i)
776 data [offset + i] = b [i];
781 public PacketWriter WriteInts (int[] ids) {
782 for (int i = 0; i < ids.Length; ++i)
787 public PacketWriter WriteIds (long[] ids) {
788 for (int i = 0; i < ids.Length; ++i)
793 public PacketWriter WriteString (string s) {
794 encode_int (data, s.Length, ref offset);
795 byte[] b = Encoding.UTF8.GetBytes (s);
797 Buffer.BlockCopy (b, 0, data, offset, b.Length);
802 public PacketWriter WriteBool (bool val) {
803 WriteByte (val ? (byte)1 : (byte)0);
807 public PacketWriter WriteValue (ValueImpl v) {
811 t = TypeCodeToElementType (Type.GetTypeCode (v.Value.GetType ()));
816 case ElementType.Boolean:
817 WriteInt ((bool)v.Value ? 1 : 0);
819 case ElementType.Char:
820 WriteInt ((int)(char)v.Value);
823 WriteInt ((int)(sbyte)v.Value);
826 WriteInt ((int)(byte)v.Value);
829 WriteInt ((int)(short)v.Value);
832 WriteInt ((int)(ushort)v.Value);
835 WriteInt ((int)(int)v.Value);
838 WriteInt ((int)(uint)v.Value);
841 WriteLong ((long)(long)v.Value);
844 WriteLong ((long)(ulong)v.Value);
847 WriteFloat ((float)v.Value);
850 WriteDouble ((double)v.Value);
852 case ElementType.String:
853 case ElementType.SzArray:
854 case ElementType.Class:
855 case ElementType.Array:
856 case ElementType.Object:
859 case ElementType.ValueType:
862 throw new NotImplementedException ();
865 WriteInt (v.Fields.Length);
866 for (int i = 0; i < v.Fields.Length; ++i)
867 WriteValue (v.Fields [i]);
869 case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
872 throw new NotImplementedException ();
878 public PacketWriter WriteValues (ValueImpl[] values) {
879 for (int i = 0; i < values.Length; ++i)
880 WriteValue (values [i]);
897 delegate void ReplyCallback (int packet_id, byte[] packet);
901 Thread receiver_thread;
902 Dictionary<int, byte[]> reply_packets;
903 Dictionary<int, ReplyCallback> reply_cbs;
904 object reply_packets_monitor;
906 public event EventHandler<ErrorHandlerEventArgs> ErrorHandler;
908 public Connection (Socket socket) {
909 this.socket = socket;
910 //socket.SetSocketOption (SocketOptionLevel.IP, SocketOptionName.NoDelay, 1);
912 reply_packets = new Dictionary<int, byte[]> ();
913 reply_cbs = new Dictionary<int, ReplyCallback> ();
914 reply_packets_monitor = new Object ();
917 int Receive (byte[] buf, int buf_offset, int len) {
920 while (offset < len) {
921 int n = socket.Receive (buf, buf_offset + offset, len - offset, SocketFlags.None);
931 public VersionInfo Version;
933 // Do the wire protocol handshake
934 public void Connect () {
935 byte[] buf = new byte [HANDSHAKE_STRING.Length];
936 char[] cbuf = new char [buf.Length];
938 // FIXME: Add a timeout
939 int n = Receive (buf, 0, buf.Length);
941 throw new IOException ("DWP Handshake failed.");
942 for (int i = 0; i < buf.Length; ++i)
943 cbuf [i] = (char)buf [i];
945 if (new String (cbuf) != HANDSHAKE_STRING)
946 throw new IOException ("DWP Handshake failed.");
950 receiver_thread = new Thread (new ThreadStart (receiver_thread_main));
951 receiver_thread.Start ();
953 Version = VM_GetVersion ();
956 // Tell the debuggee our protocol version, so newer debuggees can work
957 // with older clients
961 // Older debuggees might not support this request
962 EventHandler<ErrorHandlerEventArgs> OrigErrorHandler = ErrorHandler;
964 ErrorHandler += delegate (object sender, ErrorHandlerEventArgs args) {
965 throw new NotSupportedException ();
968 VM_SetProtocolVersion (MAJOR_VERSION, MINOR_VERSION);
969 } catch (NotSupportedException) {
971 ErrorHandler = OrigErrorHandler;
974 public EndPoint EndPoint {
976 return socket.RemoteEndPoint;
980 public byte[] ReadPacket () {
981 // FIXME: Throw ClosedConnectionException () if the connection is closed
982 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
984 byte[] header = new byte [HEADER_LENGTH];
986 int len = Receive (header, 0, header.Length);
989 if (len != HEADER_LENGTH) {
991 throw new IOException ("Packet of length " + len + " is read.");
994 int packetLength = GetPacketLength (header);
995 if (packetLength < 11)
996 throw new IOException ("Invalid packet length.");
998 if (packetLength == 11) {
1001 byte[] buf = new byte [packetLength];
1002 for (int i = 0; i < header.Length; ++i)
1003 buf [i] = header [i];
1004 len = Receive (buf, header.Length, packetLength - header.Length);
1005 if (len != packetLength - header.Length)
1006 throw new IOException ();
1011 public void WritePacket (byte[] packet) {
1012 // FIXME: Throw ClosedConnectionException () if the connection is closed
1013 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1015 socket.Send (packet);
1018 public void Close () {
1022 public bool IsClosed {
1030 void receiver_thread_main () {
1033 bool res = ReceivePacket ();
1036 } catch (Exception ex) {
1037 Console.WriteLine (ex);
1042 lock (reply_packets_monitor) {
1043 disconnected = true;
1044 Monitor.PulseAll (reply_packets_monitor);
1046 EventHandler.VMDisconnect (0, 0, null);
1049 bool ReceivePacket () {
1050 byte[] packet = ReadPacket ();
1052 if (packet.Length == 0) {
1056 if (IsReplyPacket (packet)) {
1057 int id = GetPacketId (packet);
1058 ReplyCallback cb = null;
1059 lock (reply_packets_monitor) {
1060 reply_cbs.TryGetValue (id, out cb);
1062 reply_packets [id] = packet;
1063 Monitor.PulseAll (reply_packets_monitor);
1068 cb.Invoke (id, packet);
1070 PacketReader r = new PacketReader (packet);
1072 if (r.CommandSet == CommandSet.EVENT && r.Command == (int)CmdEvent.COMPOSITE) {
1073 int spolicy = r.ReadByte ();
1074 int nevents = r.ReadInt ();
1076 SuspendPolicy suspend_policy = decode_suspend_policy (spolicy);
1078 EventInfo[] events = new EventInfo [nevents];
1080 for (int i = 0; i < nevents; ++i) {
1081 EventKind kind = (EventKind)r.ReadByte ();
1082 int req_id = r.ReadInt ();
1084 EventType etype = (EventType)kind;
1086 if (kind == EventKind.VM_START) {
1087 long thread_id = r.ReadId ();
1088 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id };
1089 //EventHandler.VMStart (req_id, thread_id, null);
1090 } else if (kind == EventKind.VM_DEATH) {
1091 //EventHandler.VMDeath (req_id, 0, null);
1092 events [i] = new EventInfo (etype, req_id) { };
1093 } else if (kind == EventKind.THREAD_START) {
1094 long thread_id = r.ReadId ();
1095 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = thread_id };
1096 //EventHandler.ThreadStart (req_id, thread_id, thread_id);
1097 } else if (kind == EventKind.THREAD_DEATH) {
1098 long thread_id = r.ReadId ();
1099 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = thread_id };
1100 //EventHandler.ThreadDeath (req_id, thread_id, thread_id);
1101 } else if (kind == EventKind.ASSEMBLY_LOAD) {
1102 long thread_id = r.ReadId ();
1103 long id = r.ReadId ();
1104 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1105 //EventHandler.AssemblyLoad (req_id, thread_id, id);
1106 } else if (kind == EventKind.ASSEMBLY_UNLOAD) {
1107 long thread_id = r.ReadId ();
1108 long id = r.ReadId ();
1109 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1110 //EventHandler.AssemblyUnload (req_id, thread_id, id);
1111 } else if (kind == EventKind.TYPE_LOAD) {
1112 long thread_id = r.ReadId ();
1113 long id = r.ReadId ();
1114 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1115 //EventHandler.TypeLoad (req_id, thread_id, id);
1116 } else if (kind == EventKind.METHOD_ENTRY) {
1117 long thread_id = r.ReadId ();
1118 long id = r.ReadId ();
1119 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1120 //EventHandler.MethodEntry (req_id, thread_id, id);
1121 } else if (kind == EventKind.METHOD_EXIT) {
1122 long thread_id = r.ReadId ();
1123 long id = r.ReadId ();
1124 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1125 //EventHandler.MethodExit (req_id, thread_id, id);
1126 } else if (kind == EventKind.BREAKPOINT) {
1127 long thread_id = r.ReadId ();
1128 long id = r.ReadId ();
1129 long loc = r.ReadLong ();
1130 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1131 //EventHandler.Breakpoint (req_id, thread_id, id, loc);
1132 } else if (kind == EventKind.STEP) {
1133 long thread_id = r.ReadId ();
1134 long id = r.ReadId ();
1135 long loc = r.ReadLong ();
1136 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1137 //EventHandler.Step (req_id, thread_id, id, loc);
1138 } else if (kind == EventKind.EXCEPTION) {
1139 long thread_id = r.ReadId ();
1140 long id = r.ReadId ();
1141 long loc = 0; // FIXME
1142 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1143 //EventHandler.Exception (req_id, thread_id, id, loc);
1144 } else if (kind == EventKind.APPDOMAIN_CREATE) {
1145 long thread_id = r.ReadId ();
1146 long id = r.ReadId ();
1147 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1148 //EventHandler.AppDomainCreate (req_id, thread_id, id);
1149 } else if (kind == EventKind.APPDOMAIN_UNLOAD) {
1150 long thread_id = r.ReadId ();
1151 long id = r.ReadId ();
1152 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1153 //EventHandler.AppDomainUnload (req_id, thread_id, id);
1155 throw new NotImplementedException ("Unknown event kind: " + kind);
1159 EventHandler.Events (suspend_policy, events);
1166 public IEventHandler EventHandler {
1170 /* Send a request and call cb when a result is received */
1171 int Send (CommandSet command_set, int command, PacketWriter packet, Action<PacketReader> cb) {
1172 int id = IdGenerator;
1174 lock (reply_packets_monitor) {
1175 reply_cbs [id] = delegate (int packet_id, byte[] p) {
1176 /* Run the callback on a tp thread to avoid blocking the receive thread */
1177 PacketReader r = new PacketReader (p);
1178 cb.BeginInvoke (r, null, null);
1183 WritePacket (EncodePacket (id, (int)command_set, command, null, 0));
1185 WritePacket (EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset));
1190 PacketReader SendReceive (CommandSet command_set, int command, PacketWriter packet) {
1191 int id = IdGenerator;
1194 WritePacket (EncodePacket (id, (int)command_set, command, null, 0));
1196 WritePacket (EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset));
1200 /* Wait for the reply packet */
1202 lock (reply_packets_monitor) {
1203 if (reply_packets.ContainsKey (packetId)) {
1204 byte[] reply = reply_packets [packetId];
1205 reply_packets.Remove (packetId);
1206 PacketReader r = new PacketReader (reply);
1207 if (r.ErrorCode != 0) {
1208 if (ErrorHandler != null)
1209 ErrorHandler (this, new ErrorHandlerEventArgs () { ErrorCode = (ErrorCode)r.ErrorCode });
1210 throw new NotImplementedException ("No error handler set.");
1216 throw new VMDisconnectedException ();
1217 Monitor.Wait (reply_packets_monitor);
1223 PacketReader SendReceive (CommandSet command_set, int command) {
1224 return SendReceive (command_set, command, null);
1227 int packet_id_generator;
1231 return Interlocked.Increment (ref packet_id_generator);
1235 CattrInfo[] ReadCattrs (PacketReader r) {
1236 CattrInfo[] res = new CattrInfo [r.ReadInt ()];
1237 for (int i = 0; i < res.Length; ++i) {
1238 CattrInfo info = new CattrInfo ();
1239 info.ctor_id = r.ReadId ();
1240 info.ctor_args = new ValueImpl [r.ReadInt ()];
1241 for (int j = 0; j < info.ctor_args.Length; ++j) {
1242 info.ctor_args [j] = r.ReadValue ();
1244 info.named_args = new CattrNamedArgInfo [r.ReadInt ()];
1245 for (int j = 0; j < info.named_args.Length; ++j) {
1246 CattrNamedArgInfo arg = new CattrNamedArgInfo ();
1247 int arg_type = r.ReadByte ();
1248 arg.is_property = arg_type == 0x54;
1249 arg.id = r.ReadId ();
1250 arg.value = r.ReadValue ();
1251 info.named_args [j] = arg;
1258 static ElementType TypeCodeToElementType (TypeCode c) {
1260 case TypeCode.Boolean:
1261 return ElementType.Boolean;
1263 return ElementType.Char;
1264 case TypeCode.SByte:
1265 return ElementType.I1;
1267 return ElementType.U1;
1268 case TypeCode.Int16:
1269 return ElementType.I2;
1270 case TypeCode.UInt16:
1271 return ElementType.U2;
1272 case TypeCode.Int32:
1273 return ElementType.I4;
1274 case TypeCode.UInt32:
1275 return ElementType.U4;
1276 case TypeCode.Int64:
1277 return ElementType.I8;
1278 case TypeCode.UInt64:
1279 return ElementType.U8;
1280 case TypeCode.Single:
1281 return ElementType.R4;
1282 case TypeCode.Double:
1283 return ElementType.R8;
1285 throw new NotImplementedException ();
1290 * Implementation of debugger commands
1293 public VersionInfo VM_GetVersion () {
1294 var res = SendReceive (CommandSet.VM, (int)CmdVM.VERSION, null);
1295 VersionInfo info = new VersionInfo ();
1296 info.VMVersion = res.ReadString ();
1297 info.MajorVersion = res.ReadInt ();
1298 info.MinorVersion = res.ReadInt ();
1302 public void VM_SetProtocolVersion (int major, int minor) {
1303 SendReceive (CommandSet.VM, (int)CmdVM.SET_PROTOCOL_VERSION, new PacketWriter ().WriteInt (major).WriteInt (minor));
1306 public long[] VM_GetThreads () {
1307 var res = SendReceive (CommandSet.VM, (int)CmdVM.ALL_THREADS, null);
1308 int len = res.ReadInt ();
1309 long[] arr = new long [len];
1310 for (int i = 0; i < len; ++i)
1311 arr [i] = res.ReadId ();
1315 public void VM_Suspend () {
1316 SendReceive (CommandSet.VM, (int)CmdVM.SUSPEND);
1319 public void VM_Resume () {
1320 SendReceive (CommandSet.VM, (int)CmdVM.RESUME);
1323 public void VM_Exit (int exitCode) {
1324 SendReceive (CommandSet.VM, (int)CmdVM.EXIT, new PacketWriter ().WriteInt (exitCode));
1327 public void VM_Dispose () {
1328 SendReceive (CommandSet.VM, (int)CmdVM.DISPOSE);
1331 public ValueImpl VM_InvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, out ValueImpl exc) {
1333 PacketReader r = SendReceive (CommandSet.VM, (int)CmdVM.INVOKE_METHOD, new PacketWriter ().WriteId (thread).WriteInt ((int)flags).WriteId (method).WriteValue (this_arg).WriteInt (arguments.Length).WriteValues (arguments));
1334 if (r.ReadByte () == 0) {
1335 exc = r.ReadValue ();
1338 return r.ReadValue ();
1342 public delegate void InvokeMethodCallback (ValueImpl v, ValueImpl exc, ErrorCode error, object state);
1344 public int VM_BeginInvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, InvokeMethodCallback callback, object state) {
1345 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) {
1348 if (r.ErrorCode != 0) {
1349 callback (null, null, (ErrorCode)r.ErrorCode, state);
1351 if (r.ReadByte () == 0) {
1352 exc = r.ReadValue ();
1359 callback (v, exc, 0, state);
1364 public void VM_AbortInvoke (long thread, int id)
1366 SendReceive (CommandSet.VM, (int)CmdVM.ABORT_INVOKE, new PacketWriter ().WriteId (thread).WriteInt (id));
1373 public long RootDomain {
1375 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ROOT_DOMAIN, null).ReadId ();
1379 public string Domain_GetName (long id) {
1380 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_FRIENDLY_NAME, new PacketWriter ().WriteId (id)).ReadString ();
1383 public long[] Domain_GetAssemblies (long id) {
1384 var res = SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ASSEMBLIES, new PacketWriter ().WriteId (id));
1385 int count = res.ReadInt ();
1386 long[] assemblies = new long [count];
1387 for (int i = 0; i < count; ++i)
1388 assemblies [i] = res.ReadId ();
1392 public long Domain_GetEntryAssembly (long id) {
1393 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ENTRY_ASSEMBLY, new PacketWriter ().WriteId (id)).ReadId ();
1396 public long Domain_GetCorlib (long id) {
1397 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_CORLIB, new PacketWriter ().WriteId (id)).ReadId ();
1400 public long Domain_CreateString (long id, string s) {
1401 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.CREATE_STRING, new PacketWriter ().WriteId (id).WriteString (s)).ReadId ();
1404 public long Domain_CreateBoxedValue (long id, long type_id, ValueImpl v) {
1405 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.CREATE_BOXED_VALUE, new PacketWriter ().WriteId (id).WriteId (type_id).WriteValue (v)).ReadId ();
1412 public string Method_GetName (long id) {
1413 return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
1416 public long Method_GetDeclaringType (long id) {
1417 return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DECLARING_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
1420 public DebugInfo Method_GetDebugInfo (long id) {
1421 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DEBUG_INFO, new PacketWriter ().WriteId (id));
1423 DebugInfo info = new DebugInfo ();
1424 info.max_il_offset = res.ReadInt ();
1425 info.filename = res.ReadString ();
1427 int n_il_offsets = res.ReadInt ();
1428 info.il_offsets = new int [n_il_offsets];
1429 info.line_numbers = new int [n_il_offsets];
1430 for (int i = 0; i < n_il_offsets; ++i) {
1431 info.il_offsets [i] = res.ReadInt ();
1432 info.line_numbers [i] = res.ReadInt ();
1438 public ParamInfo Method_GetParamInfo (long id) {
1439 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_PARAM_INFO, new PacketWriter ().WriteId (id));
1441 ParamInfo info = new ParamInfo ();
1442 info.call_conv = res.ReadInt ();
1443 info.param_count = res.ReadInt ();
1444 info.generic_param_count = res.ReadInt ();
1445 info.ret_type = res.ReadId ();
1446 info.param_types = new long [info.param_count];
1447 for (int i = 0; i < info.param_count; ++i)
1448 info.param_types [i] = res.ReadId ();
1449 info.param_names = new string [info.param_count];
1450 for (int i = 0; i < info.param_count; ++i)
1451 info.param_names [i] = res.ReadString ();
1456 public LocalsInfo Method_GetLocalsInfo (long id) {
1457 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_LOCALS_INFO, new PacketWriter ().WriteId (id));
1459 LocalsInfo info = new LocalsInfo ();
1460 int nlocals = res.ReadInt ();
1461 info.types = new long [nlocals];
1462 for (int i = 0; i < nlocals; ++i)
1463 info.types [i] = res.ReadId ();
1464 info.names = new string [nlocals];
1465 for (int i = 0; i < nlocals; ++i)
1466 info.names [i] = res.ReadString ();
1467 info.live_range_start = new int [nlocals];
1468 info.live_range_end = new int [nlocals];
1469 for (int i = 0; i < nlocals; ++i) {
1470 info.live_range_start [i] = res.ReadInt ();
1471 info.live_range_end [i] = res.ReadInt ();
1477 public MethodInfo Method_GetInfo (long id) {
1478 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_INFO, new PacketWriter ().WriteId (id));
1480 MethodInfo info = new MethodInfo ();
1481 info.attributes = res.ReadInt ();
1482 info.iattributes = res.ReadInt ();
1483 info.token = res.ReadInt ();
1488 public MethodBodyInfo Method_GetBody (long id) {
1489 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_BODY, new PacketWriter ().WriteId (id));
1491 MethodBodyInfo info = new MethodBodyInfo ();
1492 info.il = new byte [res.ReadInt ()];
1493 for (int i = 0; i < info.il.Length; ++i)
1494 info.il [i] = (byte)res.ReadByte ();
1499 public ResolvedToken Method_ResolveToken (long id, int token) {
1500 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.RESOLVE_TOKEN, new PacketWriter ().WriteId (id).WriteInt (token));
1502 TokenType type = (TokenType)res.ReadByte ();
1504 case TokenType.STRING:
1505 return new ResolvedToken () { Type = type, Str = res.ReadString () };
1506 case TokenType.TYPE:
1507 case TokenType.METHOD:
1508 case TokenType.FIELD:
1509 return new ResolvedToken () { Type = type, Id = res.ReadId () };
1510 case TokenType.UNKNOWN:
1511 return new ResolvedToken () { Type = type };
1513 throw new NotImplementedException ();
1521 public string Thread_GetName (long id) {
1522 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
1525 public FrameInfo[] Thread_GetFrameInfo (long id, int start_frame, int length) {
1526 var res = SendReceive (CommandSet.THREAD, (int)CmdThread.GET_FRAME_INFO, new PacketWriter ().WriteId (id).WriteInt (start_frame).WriteInt (length));
1527 int count = res.ReadInt ();
1529 var frames = new FrameInfo [count];
1530 for (int i = 0; i < count; ++i) {
1531 frames [i].id = res.ReadInt ();
1532 frames [i].method = res.ReadId ();
1533 frames [i].il_offset = res.ReadInt ();
1534 frames [i].flags = (StackFrameFlags)res.ReadByte ();
1539 public int Thread_GetState (long id) {
1540 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_STATE, new PacketWriter ().WriteId (id)).ReadInt ();
1543 public ThreadInfo Thread_GetInfo (long id) {
1544 PacketReader r = SendReceive (CommandSet.THREAD, (int)CmdThread.GET_INFO, new PacketWriter ().WriteId (id));
1546 ThreadInfo res = new ThreadInfo () { is_thread_pool = r.ReadByte () > 0 ? true : false };
1551 public long Thread_GetId (long id) {
1552 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_ID, new PacketWriter ().WriteId (id)).ReadLong ();
1559 public ModuleInfo Module_GetInfo (long id) {
1560 PacketReader r = SendReceive (CommandSet.MODULE, (int)CmdModule.GET_INFO, new PacketWriter ().WriteId (id));
1561 ModuleInfo info = new ModuleInfo { Name = r.ReadString (), ScopeName = r.ReadString (), FQName = r.ReadString (), Guid = r.ReadString (), Assembly = r.ReadId () };
1569 public string Assembly_GetLocation (long id) {
1570 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_LOCATION, new PacketWriter ().WriteId (id)).ReadString ();
1573 public long Assembly_GetEntryPoint (long id) {
1574 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_ENTRY_POINT, new PacketWriter ().WriteId (id)).ReadId ();
1577 public long Assembly_GetManifestModule (long id) {
1578 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_MANIFEST_MODULE, new PacketWriter ().WriteId (id)).ReadId ();
1581 public long Assembly_GetObject (long id) {
1582 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
1585 public long Assembly_GetType (long id, string name, bool ignoreCase) {
1586 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_TYPE, new PacketWriter ().WriteId (id).WriteString (name).WriteBool (ignoreCase)).ReadId ();
1589 public string Assembly_GetName (long id) {
1590 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
1597 public TypeInfo Type_GetInfo (long id) {
1598 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INFO, new PacketWriter ().WriteId (id));
1599 TypeInfo res = new TypeInfo ();
1601 res.ns = r.ReadString ();
1602 res.name = r.ReadString ();
1603 res.full_name = r.ReadString ();
1604 res.assembly = r.ReadId ();
1605 res.module = r.ReadId ();
1606 res.base_type = r.ReadId ();
1607 res.element_type = r.ReadId ();
1608 res.token = r.ReadInt ();
1609 res.rank = r.ReadByte ();
1610 res.attributes = r.ReadInt ();
1611 int b = r.ReadByte ();
1612 res.is_byref = (b & 1) != 0;
1613 res.is_pointer = (b & 2) != 0;
1614 res.is_primitive = (b & 4) != 0;
1615 res.is_valuetype = (b & 8) != 0;
1616 res.is_enum = (b & 16) != 0;
1618 int nested_len = r.ReadInt ();
1619 res.nested = new long [nested_len];
1620 for (int i = 0; i < nested_len; ++i)
1621 res.nested [i] = r.ReadId ();
1626 public long[] Type_GetMethods (long id) {
1627 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_METHODS, new PacketWriter ().WriteId (id));
1629 int n = r.ReadInt ();
1630 long[] res = new long [n];
1631 for (int i = 0; i < n; ++i)
1632 res [i] = r.ReadId ();
1636 public long[] Type_GetFields (long id, out string[] names, out long[] types, out int[] attrs) {
1637 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_FIELDS, new PacketWriter ().WriteId (id));
1639 int n = r.ReadInt ();
1640 long[] res = new long [n];
1641 names = new string [n];
1642 types = new long [n];
1643 attrs = new int [n];
1644 for (int i = 0; i < n; ++i) {
1645 res [i] = r.ReadId ();
1646 names [i] = r.ReadString ();
1647 types [i] = r.ReadId ();
1648 attrs [i] = r.ReadInt ();
1653 public PropInfo[] Type_GetProperties (long id) {
1654 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_PROPERTIES, new PacketWriter ().WriteId (id));
1656 int n = r.ReadInt ();
1657 PropInfo[] res = new PropInfo [n];
1658 for (int i = 0; i < n; ++i) {
1659 res [i] = new PropInfo ();
1660 res [i].id = r.ReadId ();
1661 res [i].name = r.ReadString ();
1662 res [i].get_method = r.ReadId ();
1663 res [i].set_method = r.ReadId ();
1664 res [i].attrs = r.ReadInt ();
1670 public long Type_GetObject (long id) {
1671 return SendReceive (CommandSet.TYPE, (int)CmdType.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
1674 public ValueImpl[] Type_GetValues (long id, long[] fields) {
1675 int len = fields.Length;
1676 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));
1678 ValueImpl[] res = new ValueImpl [len];
1679 for (int i = 0; i < len; ++i)
1680 res [i] = r.ReadValue ();
1684 public void Type_SetValues (long id, long[] fields, ValueImpl[] values) {
1685 SendReceive (CommandSet.TYPE, (int)CmdType.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
1688 public string[] Type_GetSourceFiles (long id, bool return_full_paths) {
1689 var r = SendReceive (CommandSet.TYPE, return_full_paths ? (int)CmdType.GET_SOURCE_FILES_2 : (int)CmdType.GET_SOURCE_FILES, new PacketWriter ().WriteId (id));
1690 int len = r.ReadInt ();
1691 string[] res = new string [len];
1692 for (int i = 0; i < len; ++i)
1693 res [i] = r.ReadString ();
1697 public bool Type_IsAssignableFrom (long id, long c_id) {
1698 return SendReceive (CommandSet.TYPE, (int)CmdType.IS_ASSIGNABLE_FROM, new PacketWriter ().WriteId (id).WriteId (c_id)).ReadByte () > 0;
1701 public CattrInfo[] Type_GetCustomAttributes (long id, long attr_type_id, bool inherit) {
1702 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_CATTRS, new PacketWriter ().WriteId (id).WriteId (attr_type_id));
1703 return ReadCattrs (r);
1706 public CattrInfo[] Type_GetFieldCustomAttributes (long id, long field_id, long attr_type_id, bool inherit) {
1707 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_FIELD_CATTRS, new PacketWriter ().WriteId (id).WriteId (field_id).WriteId (attr_type_id));
1708 return ReadCattrs (r);
1711 public CattrInfo[] Type_GetPropertyCustomAttributes (long id, long field_id, long attr_type_id, bool inherit) {
1712 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_PROPERTY_CATTRS, new PacketWriter ().WriteId (id).WriteId (field_id).WriteId (attr_type_id));
1713 return ReadCattrs (r);
1720 public int EnableEvent (EventType etype, SuspendPolicy suspend_policy, List<Modifier> mods) {
1721 var w = new PacketWriter ().WriteByte ((byte)etype).WriteByte ((byte)suspend_policy);
1723 if (mods.Count > 255)
1724 throw new NotImplementedException ();
1725 w.WriteByte ((byte)mods.Count);
1726 foreach (Modifier mod in mods) {
1727 if (mod is CountModifier) {
1728 w.WriteByte ((byte)ModifierKind.COUNT);
1729 w.WriteInt ((mod as CountModifier).Count);
1730 } else if (mod is LocationModifier) {
1731 w.WriteByte ((byte)ModifierKind.LOCATION_ONLY);
1732 w.WriteId ((mod as LocationModifier).Method);
1733 w.WriteLong ((mod as LocationModifier).Location);
1734 } else if (mod is StepModifier) {
1735 w.WriteByte ((byte)ModifierKind.STEP);
1736 w.WriteId ((mod as StepModifier).Thread);
1737 w.WriteInt ((mod as StepModifier).Size);
1738 w.WriteInt ((mod as StepModifier).Depth);
1739 } else if (mod is ThreadModifier) {
1740 w.WriteByte ((byte)ModifierKind.THREAD_ONLY);
1741 w.WriteId ((mod as ThreadModifier).Thread);
1742 } else if (mod is ExceptionModifier) {
1743 var em = mod as ExceptionModifier;
1744 w.WriteByte ((byte)ModifierKind.EXCEPTION_ONLY);
1745 w.WriteId (em.Type);
1746 if (Version.MajorVersion > 2 || Version.MinorVersion > 0) {
1747 /* This is only supported in protocol version 2.1 */
1748 w.WriteBool (em.Caught);
1749 w.WriteBool (em.Uncaught);
1750 } else if (!em.Caught || !em.Uncaught) {
1751 throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
1753 } else if (mod is AssemblyModifier) {
1754 w.WriteByte ((byte)ModifierKind.ASSEMBLY_ONLY);
1755 var amod = (mod as AssemblyModifier);
1756 w.WriteInt (amod.Assemblies.Length);
1757 foreach (var id in amod.Assemblies)
1760 throw new NotImplementedException ();
1766 return SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.SET, w).ReadInt ();
1769 public void ClearEventRequest (EventType etype, int req_id) {
1770 SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.CLEAR, new PacketWriter ().WriteByte ((byte)etype).WriteInt (req_id));
1773 public void ClearAllBreakpoints () {
1774 SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.CLEAR_ALL_BREAKPOINTS, new PacketWriter ());
1780 public ValueImpl StackFrame_GetThis (long thread_id, long id) {
1781 PacketReader r = SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_THIS, new PacketWriter ().WriteId (thread_id).WriteId (id));
1782 return r.ReadValue ();
1785 public ValueImpl[] StackFrame_GetValues (long thread_id, long id, int[] pos) {
1786 /* pos < 0 -> argument at pos (-pos) - 1 */
1787 /* pos >= 0 -> local at pos */
1788 int len = pos.Length;
1789 PacketReader r = SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos));
1791 ValueImpl[] res = new ValueImpl [len];
1792 for (int i = 0; i < len; ++i)
1793 res [i] = r.ReadValue ();
1797 public void StackFrame_SetValues (long thread_id, long id, int[] pos, ValueImpl[] values) {
1798 /* pos < 0 -> argument at pos (-pos) - 1 */
1799 /* pos >= 0 -> local at pos */
1800 int len = pos.Length;
1801 SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.SET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos).WriteValues (values));
1807 public int[] Array_GetLength (long id, out int rank, out int[] lower_bounds) {
1808 var r = SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.GET_LENGTH, new PacketWriter ().WriteId (id));
1809 rank = r.ReadInt ();
1810 int[] res = new int [rank];
1811 lower_bounds = new int [rank];
1812 for (int i = 0; i < rank; ++i) {
1813 res [i] = r.ReadInt ();
1814 lower_bounds [i] = r.ReadInt ();
1819 public ValueImpl[] Array_GetValues (long id, int index, int len) {
1820 var r = SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (len));
1821 ValueImpl[] res = new ValueImpl [len];
1822 for (int i = 0; i < len; ++i)
1823 res [i] = r.ReadValue ();
1827 public void Array_SetValues (long id, int index, ValueImpl[] values) {
1828 SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (values.Length).WriteValues (values));
1834 public string String_GetValue (long id) {
1835 return SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_VALUE, new PacketWriter ().WriteId (id)).ReadString ();
1841 public long Object_GetType (long id) {
1842 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
1845 public long Object_GetDomain (long id) {
1846 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_DOMAIN, new PacketWriter ().WriteId (id)).ReadId ();
1849 public ValueImpl[] Object_GetValues (long id, long[] fields) {
1850 int len = fields.Length;
1851 PacketReader r = SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));
1853 ValueImpl[] res = new ValueImpl [len];
1854 for (int i = 0; i < len; ++i)
1855 res [i] = r.ReadValue ();
1859 public void Object_SetValues (long id, long[] fields, ValueImpl[] values) {
1860 SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
1863 public bool Object_IsCollected (long id) {
1864 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.IS_COLLECTED, new PacketWriter ().WriteId (id)).ReadInt () == 1;
1867 public long Object_GetAddress (long id) {
1868 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_ADDRESS, new PacketWriter ().WriteId (id)).ReadLong ();
1873 /* This is the interface exposed by the debugger towards the debugger agent */
1874 interface IEventHandler
1876 void Events (SuspendPolicy suspend_policy, EventInfo[] events);
1878 void VMDisconnect (int req_id, long thread_id, string vm_uri);