4 using System.Net.Sockets;
5 using System.Threading;
6 using System.Collections.Generic;
8 using System.Diagnostics;
9 using Mono.Cecil.Metadata;
11 namespace Mono.Debugger.Soft
13 public class VersionInfo {
14 public string VMVersion {
18 public int MajorVersion {
22 public int MinorVersion {
27 * Check that this version is at least major:minor
29 public bool AtLeast (int major, int minor) {
30 if ((MajorVersion > major) || ((MajorVersion == major && MinorVersion >= minor)))
38 public string source_file;
39 public byte[] guid, hash;
43 public int max_il_offset;
44 public int[] il_offsets;
45 public int[] line_numbers;
46 public int[] column_numbers;
47 public int[] end_line_numbers;
48 public int[] end_column_numbers;
49 public SourceInfo[] source_files;
56 public StackFrameFlags flags;
60 public string ns, name, full_name;
61 public long assembly, module, base_type, element_type;
62 public int token, rank, attributes;
63 public bool is_byref, is_pointer, is_primitive, is_valuetype, is_enum;
64 public bool is_gtd, is_generic_type;
67 public long[] type_args;
72 public long[] iface_methods;
73 public long[] target_methods;
77 public int attributes, iattributes, token;
78 public bool is_gmd, is_generic_method;
80 public long[] type_args;
83 class MethodBodyInfo {
85 public ExceptionClauseInfo[] clauses;
88 struct ExceptionClauseInfo {
89 public ExceptionClauseFlags flags;
90 public int try_offset;
91 public int try_length;
92 public int handler_offset;
93 public int handler_length;
94 public int filter_offset;
95 public long catch_type_id;
99 enum ExceptionClauseFlags {
107 public int call_conv;
108 public int param_count;
109 public int generic_param_count;
110 public long ret_type;
111 public long[] param_types;
112 public string[] param_names;
117 public string[] names;
118 public int[] live_range_start;
119 public int[] live_range_end;
120 public int[] scopes_start;
121 public int[] scopes_end;
127 public long get_method, set_method;
131 class CattrNamedArgInfo {
132 public bool is_property;
134 public ValueImpl value;
139 public ValueImpl[] ctor_args;
140 public CattrNamedArgInfo[] named_args;
144 public bool is_thread_pool;
147 struct ObjectRefInfo {
149 public long domain_id;
153 VALUE_TYPE_ID_NULL = 0xf0,
154 VALUE_TYPE_ID_TYPE = 0xf1,
155 VALUE_TYPE_ID_PARENT_VTYPE = 0xf2
161 DISABLE_BREAKPOINTS = 1,
211 public ElementType Type; /* or one of the VALUE_TYPE_ID constants */
214 public long Klass; // For ElementType.ValueType
215 public ValueImpl[] Fields; // for ElementType.ValueType
216 public bool IsEnum; // For ElementType.ValueType
217 public long Id; /* For VALUE_TYPE_ID_TYPE */
218 public int Index; /* For VALUE_TYPE_PARENT_VTYPE */
222 public string Name, ScopeName, FQName, Guid;
223 public long Assembly;
226 class FieldMirrorInfo {
228 public long Parent, TypeId;
241 enum StackFrameFlags {
244 NATIVE_TRANSITION = 2
247 class ResolvedToken {
248 public TokenType Type;
256 class CountModifier : Modifier {
262 class LocationModifier : Modifier {
267 public long Location {
272 class StepModifier : Modifier {
290 class ThreadModifier : Modifier {
296 class ExceptionModifier : Modifier {
303 public bool Uncaught {
306 public bool Subclasses {
311 class AssemblyModifier : Modifier {
312 public long[] Assemblies {
317 class SourceFileModifier : Modifier {
318 public string[] SourceFiles {
323 class TypeNameModifier : Modifier {
324 public string[] TypeNames {
330 public EventType EventType {
338 public SuspendPolicy SuspendPolicy {
342 public long ThreadId {
350 public long Location {
358 public string Category {
362 public string Message {
366 public int ExitCode {
370 public EventInfo (EventType type, int req_id) {
376 public enum ErrorCode {
379 INVALID_FIELDID = 25,
380 INVALID_FRAMEID = 30,
381 NOT_IMPLEMENTED = 100,
383 INVALID_ARGUMENT = 102,
385 ERR_NO_INVOCATION = 104,
386 ABSENT_INFORMATION = 105,
387 NO_SEQ_POINT_AT_IL_OFFSET = 106,
391 public class ErrorHandlerEventArgs : EventArgs {
393 public ErrorCode ErrorCode {
399 * Represents the connection to the debuggee
401 public abstract class Connection
404 * The protocol and the packet format is based on JDWP, the differences
405 * are in the set of supported events, and the commands.
407 internal const string HANDSHAKE_STRING = "DWP-Handshake";
409 internal const int HEADER_LENGTH = 11;
411 static readonly bool EnableConnectionLogging = !String.IsNullOrEmpty (Environment.GetEnvironmentVariable ("MONO_SDB_LOG"));
412 static int ConnectionId;
413 readonly StreamWriter LoggingStream;
416 * Th version of the wire-protocol implemented by the library. The library
417 * and the debuggee can communicate if they implement the same major version.
418 * If they implement a different minor version, they can communicate, but some
419 * features might not be available. This allows older clients to communicate
420 * with newer runtimes, and vice versa.
422 internal const int MAJOR_VERSION = 2;
423 internal const int MINOR_VERSION = 44;
425 enum WPSuspendPolicy {
453 APPDOMAIN_CREATE = 4, // Not in JDI
454 APPDOMAIN_UNLOAD = 5, // Not in JDI
475 SOURCE_FILE_ONLY = 12,
487 SET_PROTOCOL_VERSION = 8,
490 GET_TYPES_FOR_SOURCE_FILE = 11,
493 START_BUFFERING = 14,
506 /* FIXME: Merge into GET_INFO when the major protocol version is increased */
513 enum CmdEventRequest {
516 CLEAR_ALL_BREAKPOINTS = 3
521 GET_FRIENDLY_NAME = 2,
523 GET_ENTRY_ASSEMBLY = 4,
526 CREATE_BOXED_VALUE = 7
532 GET_MANIFEST_MODULE = 3,
544 GET_DECLARING_TYPE = 2,
552 MAKE_GENERIC_METHOD = 10
561 GET_SOURCE_FILES = 6,
563 IS_ASSIGNABLE_FROM = 8,
566 GET_FIELD_CATTRS = 11,
567 GET_PROPERTY_CATTRS = 12,
568 /* FIXME: Merge into GET_SOURCE_FILES when the major protocol version is increased */
569 GET_SOURCE_FILES_2 = 13,
570 /* FIXME: Merge into GET_VALUES when the major protocol version is increased */
572 CMD_TYPE_GET_METHODS_BY_NAME_FLAGS = 15,
574 GET_INTERFACE_MAP = 17,
584 enum BindingFlagsExtensions {
585 BINDING_FLAGS_IGNORE_CASE = 0x70000000,
620 public int command_set;
625 internal static int GetPacketLength (byte[] header) {
627 return decode_int (header, ref offset);
630 internal static bool IsReplyPacket (byte[] packet) {
632 return decode_byte (packet, ref offset) == 0x80;
635 internal static int GetPacketId (byte[] packet) {
637 return decode_int (packet, ref offset);
640 static int decode_byte (byte[] packet, ref int offset) {
641 return packet [offset++];
644 static int decode_short (byte[] packet, ref int offset) {
645 int res = ((int)packet [offset] << 8) | (int)packet [offset + 1];
650 static int decode_int (byte[] packet, ref int offset) {
651 int res = ((int)packet [offset] << 24) | ((int)packet [offset + 1] << 16) | ((int)packet [offset + 2] << 8) | (int)packet [offset + 3];
656 static long decode_id (byte[] packet, ref int offset) {
657 return decode_int (packet, ref offset);
660 static long decode_long (byte[] packet, ref int offset) {
661 uint high = (uint)decode_int (packet, ref offset);
662 uint low = (uint)decode_int (packet, ref offset);
664 return (long)(((ulong)high << 32) | (ulong)low);
667 internal static SuspendPolicy decode_suspend_policy (int suspend_policy) {
668 switch ((WPSuspendPolicy)suspend_policy) {
669 case WPSuspendPolicy.NONE:
670 return SuspendPolicy.None;
671 case WPSuspendPolicy.EVENT_THREAD:
672 return SuspendPolicy.EventThread;
673 case WPSuspendPolicy.ALL:
674 return SuspendPolicy.All;
676 throw new NotImplementedException ();
680 static Header decode_command_header (byte[] packet) {
682 Header res = new Header ();
684 decode_int (packet, ref offset);
685 res.id = decode_int (packet, ref offset);
686 res.flags = decode_byte (packet, ref offset);
687 res.command_set = decode_byte (packet, ref offset);
688 res.command = decode_byte (packet, ref offset);
693 static void encode_byte (byte[] buf, int b, ref int offset) {
694 buf [offset] = (byte)b;
698 static void encode_int (byte[] buf, int i, ref int offset) {
699 buf [offset] = (byte)((i >> 24) & 0xff);
700 buf [offset + 1] = (byte)((i >> 16) & 0xff);
701 buf [offset + 2] = (byte)((i >> 8) & 0xff);
702 buf [offset + 3] = (byte)((i >> 0) & 0xff);
706 static void encode_id (byte[] buf, long id, ref int offset) {
707 encode_int (buf, (int)id, ref offset);
710 static void encode_long (byte[] buf, long l, ref int offset) {
711 encode_int (buf, (int)((l >> 32) & 0xffffffff), ref offset);
712 encode_int (buf, (int)(l & 0xffffffff), ref offset);
715 internal static byte[] EncodePacket (int id, int commandSet, int command, byte[] data, int dataLen) {
716 byte[] buf = new byte [dataLen + 11];
719 encode_int (buf, buf.Length, ref offset);
720 encode_int (buf, id, ref offset);
721 encode_byte (buf, 0, ref offset);
722 encode_byte (buf, commandSet, ref offset);
723 encode_byte (buf, command, ref offset);
725 for (int i = 0; i < dataLen; ++i)
726 buf [offset + i] = data [i];
735 public PacketReader (byte[] packet) {
736 this.packet = packet;
739 Header header = decode_command_header (packet);
740 CommandSet = (CommandSet)header.command_set;
741 Command = header.command;
745 ReadInt (); // length
747 ReadByte (); // flags
748 ErrorCode = ReadShort ();
751 public CommandSet CommandSet {
759 public int ErrorCode {
769 public int ReadByte () {
770 return decode_byte (packet, ref offset);
773 public int ReadShort () {
774 return decode_short (packet, ref offset);
777 public int ReadInt () {
778 return decode_int (packet, ref offset);
781 public long ReadId () {
782 return decode_id (packet, ref offset);
785 public long ReadLong () {
786 return decode_long (packet, ref offset);
789 public float ReadFloat () {
790 float f = DataConverter.FloatFromBE (packet, offset);
795 public double ReadDouble () {
796 double d = DataConverter.DoubleFromBE (packet, offset);
801 public string ReadString () {
802 int len = decode_int (packet, ref offset);
803 string res = new String (Encoding.UTF8.GetChars (packet, offset, len));
808 public string ReadUTF16String () {
809 int len = decode_int (packet, ref offset);
810 string res = new String (Encoding.Unicode.GetChars (packet, offset, len));
815 public ValueImpl ReadValue () {
816 ElementType etype = (ElementType)ReadByte ();
819 case ElementType.Void:
820 return new ValueImpl { Type = etype };
822 return new ValueImpl { Type = etype, Value = (sbyte)ReadInt () };
824 return new ValueImpl { Type = etype, Value = (byte)ReadInt () };
825 case ElementType.Boolean:
826 return new ValueImpl { Type = etype, Value = ReadInt () != 0 };
828 return new ValueImpl { Type = etype, Value = (short)ReadInt () };
830 return new ValueImpl { Type = etype, Value = (ushort)ReadInt () };
831 case ElementType.Char:
832 return new ValueImpl { Type = etype, Value = (char)ReadInt () };
834 return new ValueImpl { Type = etype, Value = ReadInt () };
836 return new ValueImpl { Type = etype, Value = (uint)ReadInt () };
838 return new ValueImpl { Type = etype, Value = ReadLong () };
840 return new ValueImpl { Type = etype, Value = (ulong)ReadLong () };
842 return new ValueImpl { Type = etype, Value = ReadFloat () };
844 return new ValueImpl { Type = etype, Value = ReadDouble () };
847 case ElementType.Ptr:
848 // FIXME: The client and the debuggee might have different word sizes
849 return new ValueImpl { Type = etype, Value = ReadLong () };
850 case ElementType.String:
851 case ElementType.SzArray:
852 case ElementType.Class:
853 case ElementType.Array:
854 case ElementType.Object:
855 long objid = ReadId ();
856 return new ValueImpl () { Type = etype, Objid = objid };
857 case ElementType.ValueType:
858 bool is_enum = ReadByte () == 1;
859 long klass = ReadId ();
860 long nfields = ReadInt ();
861 ValueImpl[] fields = new ValueImpl [nfields];
862 for (int i = 0; i < nfields; ++i)
863 fields [i] = ReadValue ();
864 return new ValueImpl () { Type = etype, Klass = klass, Fields = fields, IsEnum = is_enum };
865 case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
866 return new ValueImpl { Type = etype };
867 case (ElementType)ValueTypeId.VALUE_TYPE_ID_TYPE:
868 return new ValueImpl () { Type = etype, Id = ReadId () };
869 case (ElementType)ValueTypeId.VALUE_TYPE_ID_PARENT_VTYPE:
870 return new ValueImpl () { Type = etype, Index = ReadInt () };
872 throw new NotImplementedException ("Unable to handle type " + etype);
876 public long[] ReadIds (int n) {
877 long[] res = new long [n];
878 for (int i = 0; i < n; ++i)
889 public PacketWriter () {
890 data = new byte [1024];
894 void MakeRoom (int size) {
895 if (offset + size >= data.Length) {
896 int new_len = data.Length * 2;
897 while (new_len < offset + size) {
900 byte[] new_data = new byte [new_len];
901 Array.Copy (data, new_data, data.Length);
906 public PacketWriter WriteByte (byte val) {
908 encode_byte (data, val, ref offset);
912 public PacketWriter WriteInt (int val) {
914 encode_int (data, val, ref offset);
918 public PacketWriter WriteId (long id) {
920 encode_id (data, id, ref offset);
924 public PacketWriter WriteLong (long val) {
926 encode_long (data, val, ref offset);
930 public PacketWriter WriteFloat (float f) {
932 byte[] b = DataConverter.GetBytesBE (f);
933 for (int i = 0; i < 4; ++i)
934 data [offset + i] = b [i];
939 public PacketWriter WriteDouble (double d) {
941 byte[] b = DataConverter.GetBytesBE (d);
942 for (int i = 0; i < 8; ++i)
943 data [offset + i] = b [i];
948 public PacketWriter WriteInts (int[] ids) {
949 for (int i = 0; i < ids.Length; ++i)
954 public PacketWriter WriteIds (long[] ids) {
955 for (int i = 0; i < ids.Length; ++i)
960 public PacketWriter WriteString (string s) {
962 return WriteInt (-1);
964 byte[] b = Encoding.UTF8.GetBytes (s);
966 encode_int (data, b.Length, ref offset);
968 Buffer.BlockCopy (b, 0, data, offset, b.Length);
973 public PacketWriter WriteBool (bool val) {
974 WriteByte (val ? (byte)1 : (byte)0);
978 public PacketWriter WriteValue (ValueImpl v) {
982 t = TypeCodeToElementType (Type.GetTypeCode (v.Value.GetType ()));
987 case ElementType.Boolean:
988 WriteInt ((bool)v.Value ? 1 : 0);
990 case ElementType.Char:
991 WriteInt ((int)(char)v.Value);
994 WriteInt ((int)(sbyte)v.Value);
997 WriteInt ((int)(byte)v.Value);
1000 WriteInt ((int)(short)v.Value);
1002 case ElementType.U2:
1003 WriteInt ((int)(ushort)v.Value);
1005 case ElementType.I4:
1006 WriteInt ((int)(int)v.Value);
1008 case ElementType.U4:
1009 WriteInt ((int)(uint)v.Value);
1011 case ElementType.I8:
1012 WriteLong ((long)(long)v.Value);
1014 case ElementType.U8:
1015 WriteLong ((long)(ulong)v.Value);
1017 case ElementType.R4:
1018 WriteFloat ((float)v.Value);
1020 case ElementType.R8:
1021 WriteDouble ((double)v.Value);
1023 case ElementType.String:
1024 case ElementType.SzArray:
1025 case ElementType.Class:
1026 case ElementType.Array:
1027 case ElementType.Object:
1030 case ElementType.ValueType:
1033 throw new NotImplementedException ();
1036 WriteInt (v.Fields.Length);
1037 for (int i = 0; i < v.Fields.Length; ++i)
1038 WriteValue (v.Fields [i]);
1040 case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
1043 throw new NotImplementedException ();
1049 public PacketWriter WriteValues (ValueImpl[] values) {
1050 for (int i = 0; i < values.Length; ++i)
1051 WriteValue (values [i]);
1055 public byte[] Data {
1068 delegate void ReplyCallback (int packet_id, byte[] packet);
1071 Thread receiver_thread;
1072 Dictionary<int, byte[]> reply_packets;
1073 Dictionary<int, ReplyCallback> reply_cbs;
1074 Dictionary<int, int> reply_cb_counts;
1075 object reply_packets_monitor;
1077 internal event EventHandler<ErrorHandlerEventArgs> ErrorHandler;
1079 protected Connection () {
1081 reply_packets = new Dictionary<int, byte[]> ();
1082 reply_cbs = new Dictionary<int, ReplyCallback> ();
1083 reply_cb_counts = new Dictionary<int, int> ();
1084 reply_packets_monitor = new Object ();
1085 if (EnableConnectionLogging) {
1086 var path = Environment.GetEnvironmentVariable ("MONO_SDB_LOG");
1087 if (path.Contains ("{0}")) {
1088 //C:\SomeDir\sdbLog{0}.txt -> C:\SomeDir\sdbLog1.txt
1089 LoggingStream = new StreamWriter (string.Format (path, ConnectionId++), false);
1090 } else if (Path.HasExtension (path)) {
1091 //C:\SomeDir\sdbLog.txt -> C:\SomeDir\sdbLog1.txt
1092 LoggingStream = new StreamWriter (Path.GetDirectoryName (path) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension (path) + ConnectionId++ + "." + Path.GetExtension (path), false);
1094 //C:\SomeDir\sdbLog -> C:\SomeDir\sdbLog1
1095 LoggingStream = new StreamWriter (path + ConnectionId++, false);
1100 protected abstract int TransportReceive (byte[] buf, int buf_offset, int len);
1101 protected abstract int TransportSend (byte[] buf, int buf_offset, int len);
1102 protected abstract void TransportSetTimeouts (int send_timeout, int receive_timeout);
1103 protected abstract void TransportClose ();
1105 internal VersionInfo Version;
1107 int Receive (byte[] buf, int buf_offset, int len) {
1110 while (offset < len) {
1111 int n = TransportReceive (buf, buf_offset + offset, len - offset);
1121 // Do the wire protocol handshake
1122 internal void Connect () {
1123 byte[] buf = new byte [HANDSHAKE_STRING.Length];
1124 char[] cbuf = new char [buf.Length];
1126 // FIXME: Add a timeout
1127 int n = Receive (buf, 0, buf.Length);
1129 throw new IOException ("DWP Handshake failed.");
1130 for (int i = 0; i < buf.Length; ++i)
1131 cbuf [i] = (char)buf [i];
1133 if (new String (cbuf) != HANDSHAKE_STRING)
1134 throw new IOException ("DWP Handshake failed.");
1136 TransportSend (buf, 0, buf.Length);
1138 receiver_thread = new Thread (new ThreadStart (receiver_thread_main));
1139 receiver_thread.Name = "SDB Receiver";
1140 receiver_thread.IsBackground = true;
1141 receiver_thread.Start ();
1143 Version = VM_GetVersion ();
1146 // Tell the debuggee our protocol version, so newer debuggees can work
1147 // with older clients
1151 // Older debuggees might not support this request
1152 EventHandler<ErrorHandlerEventArgs> OrigErrorHandler = ErrorHandler;
1153 ErrorHandler = null;
1154 ErrorHandler += delegate (object sender, ErrorHandlerEventArgs args) {
1155 throw new NotSupportedException ();
1158 VM_SetProtocolVersion (MAJOR_VERSION, MINOR_VERSION);
1159 } catch (NotSupportedException) {
1161 ErrorHandler = OrigErrorHandler;
1164 internal byte[] ReadPacket () {
1165 // FIXME: Throw ClosedConnectionException () if the connection is closed
1166 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1168 byte[] header = new byte [HEADER_LENGTH];
1170 int len = Receive (header, 0, header.Length);
1172 return new byte [0];
1173 if (len != HEADER_LENGTH) {
1175 throw new IOException ("Packet of length " + len + " is read.");
1178 int packetLength = GetPacketLength (header);
1179 if (packetLength < 11)
1180 throw new IOException ("Invalid packet length.");
1182 if (packetLength == 11) {
1185 byte[] buf = new byte [packetLength];
1186 for (int i = 0; i < header.Length; ++i)
1187 buf [i] = header [i];
1188 len = Receive (buf, header.Length, packetLength - header.Length);
1189 if (len != packetLength - header.Length)
1190 throw new IOException ();
1195 internal void WritePacket (byte[] packet) {
1196 // FIXME: Throw ClosedConnectionException () if the connection is closed
1197 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1199 TransportSend (packet, 0, packet.Length);
1202 internal void WritePackets (List<byte[]> packets) {
1203 // FIXME: Throw ClosedConnectionException () if the connection is closed
1204 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1207 for (int i = 0; i < packets.Count; ++i)
1208 len += packets [i].Length;
1209 byte[] data = new byte [len];
1211 for (int i = 0; i < packets.Count; ++i) {
1212 Buffer.BlockCopy (packets [i], 0, data, pos, packets [i].Length);
1213 pos += packets [i].Length;
1215 TransportSend (data, 0, data.Length);
1218 internal void Close () {
1222 internal bool IsClosed {
1230 internal ManualResetEvent DisconnectedEvent = new ManualResetEvent (false);
1232 void receiver_thread_main () {
1235 bool res = ReceivePacket ();
1238 } catch (Exception ex) {
1240 Console.WriteLine (ex);
1246 lock (reply_packets_monitor) {
1247 disconnected = true;
1248 DisconnectedEvent.Set ();
1249 Monitor.PulseAll (reply_packets_monitor);
1252 EventHandler.VMDisconnect (0, 0, null);
1255 bool ReceivePacket () {
1256 byte[] packet = ReadPacket ();
1258 if (packet.Length == 0) {
1262 if (IsReplyPacket (packet)) {
1263 int id = GetPacketId (packet);
1264 ReplyCallback cb = null;
1265 lock (reply_packets_monitor) {
1266 reply_cbs.TryGetValue (id, out cb);
1268 reply_packets [id] = packet;
1269 Monitor.PulseAll (reply_packets_monitor);
1271 int c = reply_cb_counts [id];
1274 reply_cbs.Remove (id);
1275 reply_cb_counts.Remove (id);
1281 cb.Invoke (id, packet);
1283 PacketReader r = new PacketReader (packet);
1285 if (r.CommandSet == CommandSet.EVENT && r.Command == (int)CmdEvent.COMPOSITE) {
1286 int spolicy = r.ReadByte ();
1287 int nevents = r.ReadInt ();
1289 SuspendPolicy suspend_policy = decode_suspend_policy (spolicy);
1291 EventInfo[] events = new EventInfo [nevents];
1293 for (int i = 0; i < nevents; ++i) {
1294 EventKind kind = (EventKind)r.ReadByte ();
1295 int req_id = r.ReadInt ();
1297 EventType etype = (EventType)kind;
1299 long thread_id = r.ReadId ();
1300 if (kind == EventKind.VM_START) {
1301 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id };
1302 //EventHandler.VMStart (req_id, thread_id, null);
1303 } else if (kind == EventKind.VM_DEATH) {
1305 if (Version.AtLeast (2, 27))
1306 exit_code = r.ReadInt ();
1307 //EventHandler.VMDeath (req_id, 0, null);
1308 events [i] = new EventInfo (etype, req_id) { ExitCode = exit_code };
1309 } else if (kind == EventKind.THREAD_START) {
1310 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = thread_id };
1311 //EventHandler.ThreadStart (req_id, thread_id, thread_id);
1312 } else if (kind == EventKind.THREAD_DEATH) {
1313 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = thread_id };
1314 //EventHandler.ThreadDeath (req_id, thread_id, thread_id);
1315 } else if (kind == EventKind.ASSEMBLY_LOAD) {
1316 long id = r.ReadId ();
1317 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1318 //EventHandler.AssemblyLoad (req_id, thread_id, id);
1319 } else if (kind == EventKind.ASSEMBLY_UNLOAD) {
1320 long id = r.ReadId ();
1321 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1322 //EventHandler.AssemblyUnload (req_id, thread_id, id);
1323 } else if (kind == EventKind.TYPE_LOAD) {
1324 long id = r.ReadId ();
1325 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1326 //EventHandler.TypeLoad (req_id, thread_id, id);
1327 } else if (kind == EventKind.METHOD_ENTRY) {
1328 long id = r.ReadId ();
1329 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1330 //EventHandler.MethodEntry (req_id, thread_id, id);
1331 } else if (kind == EventKind.METHOD_EXIT) {
1332 long id = r.ReadId ();
1333 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1334 //EventHandler.MethodExit (req_id, thread_id, id);
1335 } else if (kind == EventKind.BREAKPOINT) {
1336 long id = r.ReadId ();
1337 long loc = r.ReadLong ();
1338 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1339 //EventHandler.Breakpoint (req_id, thread_id, id, loc);
1340 } else if (kind == EventKind.STEP) {
1341 long id = r.ReadId ();
1342 long loc = r.ReadLong ();
1343 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1344 //EventHandler.Step (req_id, thread_id, id, loc);
1345 } else if (kind == EventKind.EXCEPTION) {
1346 long id = r.ReadId ();
1347 long loc = 0; // FIXME
1348 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1349 //EventHandler.Exception (req_id, thread_id, id, loc);
1350 } else if (kind == EventKind.APPDOMAIN_CREATE) {
1351 long id = r.ReadId ();
1352 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1353 //EventHandler.AppDomainCreate (req_id, thread_id, id);
1354 } else if (kind == EventKind.APPDOMAIN_UNLOAD) {
1355 long id = r.ReadId ();
1356 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1357 //EventHandler.AppDomainUnload (req_id, thread_id, id);
1358 } else if (kind == EventKind.USER_BREAK) {
1361 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1362 //EventHandler.Exception (req_id, thread_id, id, loc);
1363 } else if (kind == EventKind.USER_LOG) {
1364 int level = r.ReadInt ();
1365 string category = r.ReadString ();
1366 string message = r.ReadString ();
1367 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Level = level, Category = category, Message = message };
1368 //EventHandler.Exception (req_id, thread_id, id, loc);
1369 } else if (kind == EventKind.KEEPALIVE) {
1370 events [i] = new EventInfo (etype, req_id) { };
1372 throw new NotImplementedException ("Unknown event kind: " + kind);
1376 EventHandler.Events (suspend_policy, events);
1383 internal IEventHandler EventHandler {
1387 static String CommandString (CommandSet command_set, int command)
1390 switch (command_set) {
1392 cmd = ((CmdVM)command).ToString ();
1394 case CommandSet.OBJECT_REF:
1395 cmd = ((CmdObjectRef)command).ToString ();
1397 case CommandSet.STRING_REF:
1398 cmd = ((CmdStringRef)command).ToString ();
1400 case CommandSet.THREAD:
1401 cmd = ((CmdThread)command).ToString ();
1403 case CommandSet.ARRAY_REF:
1404 cmd = ((CmdArrayRef)command).ToString ();
1406 case CommandSet.EVENT_REQUEST:
1407 cmd = ((CmdEventRequest)command).ToString ();
1409 case CommandSet.STACK_FRAME:
1410 cmd = ((CmdStackFrame)command).ToString ();
1412 case CommandSet.APPDOMAIN:
1413 cmd = ((CmdAppDomain)command).ToString ();
1415 case CommandSet.ASSEMBLY:
1416 cmd = ((CmdAssembly)command).ToString ();
1418 case CommandSet.METHOD:
1419 cmd = ((CmdMethod)command).ToString ();
1421 case CommandSet.TYPE:
1422 cmd = ((CmdType)command).ToString ();
1424 case CommandSet.MODULE:
1425 cmd = ((CmdModule)command).ToString ();
1427 case CommandSet.FIELD:
1428 cmd = ((CmdField)command).ToString ();
1430 case CommandSet.EVENT:
1431 cmd = ((CmdEvent)command).ToString ();
1434 cmd = command.ToString ();
1437 return string.Format ("[{0} {1}]", command_set, cmd);
1440 long total_protocol_ticks;
1442 void LogPacket (int packet_id, byte[] encoded_packet, byte[] reply_packet, CommandSet command_set, int command, Stopwatch watch) {
1444 total_protocol_ticks += watch.ElapsedTicks;
1445 var ts = TimeSpan.FromTicks (total_protocol_ticks);
1446 string msg = string.Format ("Packet: {0} sent: {1} received: {2} ms: {3} total ms: {4} {5}",
1447 packet_id, encoded_packet.Length, reply_packet.Length, watch.ElapsedMilliseconds,
1448 (ts.Seconds * 1000) + ts.Milliseconds,
1449 CommandString (command_set, command));
1451 LoggingStream.WriteLine (msg);
1452 LoggingStream.Flush ();
1455 bool buffer_packets;
1456 List<byte[]> buffered_packets = new List<byte[]> ();
1459 // Start buffering request/response packets on both the client and the debuggee side.
1460 // Packets sent between StartBuffering ()/StopBuffering () must be async, i.e. sent
1461 // using Send () and not SendReceive ().
1463 public void StartBuffering () {
1464 buffer_packets = true;
1465 if (Version.AtLeast (2, 34))
1466 VM_StartBuffering ();
1469 public void StopBuffering () {
1470 if (Version.AtLeast (2, 34))
1471 VM_StopBuffering ();
1472 buffer_packets = false;
1474 WritePackets (buffered_packets);
1475 if (EnableConnectionLogging) {
1476 LoggingStream.WriteLine (String.Format ("Sent {0} packets.", buffered_packets.Count));
1477 LoggingStream.Flush ();
1479 buffered_packets.Clear ();
1482 /* Send a request and call cb when a result is received */
1483 int Send (CommandSet command_set, int command, PacketWriter packet, Action<PacketReader> cb, int count) {
1484 int id = IdGenerator;
1486 Stopwatch watch = null;
1487 if (EnableConnectionLogging)
1488 watch = Stopwatch.StartNew ();
1490 byte[] encoded_packet;
1492 encoded_packet = EncodePacket (id, (int)command_set, command, null, 0);
1494 encoded_packet = EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset);
1497 lock (reply_packets_monitor) {
1498 reply_cbs [id] = delegate (int packet_id, byte[] p) {
1499 if (EnableConnectionLogging)
1500 LogPacket (packet_id, encoded_packet, p, command_set, command, watch);
1501 /* Run the callback on a tp thread to avoid blocking the receive thread */
1502 PacketReader r = new PacketReader (p);
1503 cb.BeginInvoke (r, null, null);
1505 reply_cb_counts [id] = count;
1510 buffered_packets.Add (encoded_packet);
1512 WritePacket (encoded_packet);
1517 // Send a request without waiting for an answer
1518 void Send (CommandSet command_set, int command) {
1519 Send (command_set, command, null, null, 0);
1522 PacketReader SendReceive (CommandSet command_set, int command, PacketWriter packet) {
1523 int id = IdGenerator;
1524 Stopwatch watch = null;
1527 throw new VMDisconnectedException ();
1529 if (EnableConnectionLogging)
1530 watch = Stopwatch.StartNew ();
1532 byte[] encoded_packet;
1535 encoded_packet = EncodePacket (id, (int)command_set, command, null, 0);
1537 encoded_packet = EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset);
1539 WritePacket (encoded_packet);
1543 /* Wait for the reply packet */
1545 lock (reply_packets_monitor) {
1546 if (reply_packets.ContainsKey (packetId)) {
1547 byte[] reply = reply_packets [packetId];
1548 reply_packets.Remove (packetId);
1549 PacketReader r = new PacketReader (reply);
1551 if (EnableConnectionLogging)
1552 LogPacket (packetId, encoded_packet, reply, command_set, command, watch);
1553 if (r.ErrorCode != 0) {
1554 if (ErrorHandler != null)
1555 ErrorHandler (this, new ErrorHandlerEventArgs () { ErrorCode = (ErrorCode)r.ErrorCode });
1556 throw new NotImplementedException ("No error handler set.");
1562 throw new VMDisconnectedException ();
1563 Monitor.Wait (reply_packets_monitor);
1569 PacketReader SendReceive (CommandSet command_set, int command) {
1570 return SendReceive (command_set, command, null);
1573 int packet_id_generator;
1577 return Interlocked.Increment (ref packet_id_generator);
1581 CattrInfo[] ReadCattrs (PacketReader r) {
1582 CattrInfo[] res = new CattrInfo [r.ReadInt ()];
1583 for (int i = 0; i < res.Length; ++i) {
1584 CattrInfo info = new CattrInfo ();
1585 info.ctor_id = r.ReadId ();
1586 info.ctor_args = new ValueImpl [r.ReadInt ()];
1587 for (int j = 0; j < info.ctor_args.Length; ++j) {
1588 info.ctor_args [j] = r.ReadValue ();
1590 info.named_args = new CattrNamedArgInfo [r.ReadInt ()];
1591 for (int j = 0; j < info.named_args.Length; ++j) {
1592 CattrNamedArgInfo arg = new CattrNamedArgInfo ();
1593 int arg_type = r.ReadByte ();
1594 arg.is_property = arg_type == 0x54;
1595 arg.id = r.ReadId ();
1596 arg.value = r.ReadValue ();
1597 info.named_args [j] = arg;
1604 static ElementType TypeCodeToElementType (TypeCode c) {
1606 case TypeCode.Boolean:
1607 return ElementType.Boolean;
1609 return ElementType.Char;
1610 case TypeCode.SByte:
1611 return ElementType.I1;
1613 return ElementType.U1;
1614 case TypeCode.Int16:
1615 return ElementType.I2;
1616 case TypeCode.UInt16:
1617 return ElementType.U2;
1618 case TypeCode.Int32:
1619 return ElementType.I4;
1620 case TypeCode.UInt32:
1621 return ElementType.U4;
1622 case TypeCode.Int64:
1623 return ElementType.I8;
1624 case TypeCode.UInt64:
1625 return ElementType.U8;
1626 case TypeCode.Single:
1627 return ElementType.R4;
1628 case TypeCode.Double:
1629 return ElementType.R8;
1631 throw new NotImplementedException ();
1636 * Implementation of debugger commands
1639 internal VersionInfo VM_GetVersion () {
1640 var res = SendReceive (CommandSet.VM, (int)CmdVM.VERSION, null);
1641 VersionInfo info = new VersionInfo ();
1642 info.VMVersion = res.ReadString ();
1643 info.MajorVersion = res.ReadInt ();
1644 info.MinorVersion = res.ReadInt ();
1648 internal void VM_SetProtocolVersion (int major, int minor) {
1649 SendReceive (CommandSet.VM, (int)CmdVM.SET_PROTOCOL_VERSION, new PacketWriter ().WriteInt (major).WriteInt (minor));
1652 internal void VM_GetThreads (Action<long[]> resultCallaback) {
1653 Send (CommandSet.VM, (int)CmdVM.ALL_THREADS, null, (res) => {
1654 int len = res.ReadInt ();
1655 long[] arr = new long [len];
1656 for (int i = 0; i < len; ++i)
1657 arr [i] = res.ReadId ();
1658 resultCallaback(arr);
1662 internal void VM_Suspend () {
1663 SendReceive (CommandSet.VM, (int)CmdVM.SUSPEND);
1666 internal void VM_Resume () {
1667 SendReceive (CommandSet.VM, (int)CmdVM.RESUME);
1670 internal void VM_Exit (int exitCode) {
1671 SendReceive (CommandSet.VM, (int)CmdVM.EXIT, new PacketWriter ().WriteInt (exitCode));
1674 internal void VM_Dispose () {
1675 SendReceive (CommandSet.VM, (int)CmdVM.DISPOSE);
1678 internal ValueImpl VM_InvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, out ValueImpl exc) {
1680 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));
1681 if (r.ReadByte () == 0) {
1682 exc = r.ReadValue ();
1685 return r.ReadValue ();
1689 internal delegate void InvokeMethodCallback (ValueImpl v, ValueImpl exc, ValueImpl out_this, ValueImpl[] out_args, ErrorCode error, object state);
1691 void read_invoke_res (PacketReader r, out ValueImpl v, out ValueImpl exc, out ValueImpl out_this, out ValueImpl[] out_args) {
1692 int resflags = r.ReadByte ();
1697 if (resflags == 0) {
1698 exc = r.ReadValue ();
1701 if ((resflags & 2) != 0)
1702 out_this = r.ReadValue ();
1703 if ((resflags & 4) != 0) {
1704 int nargs = r.ReadInt ();
1705 out_args = new ValueImpl [nargs];
1706 for (int i = 0; i < nargs; ++i)
1707 out_args [i] = r.ReadValue ();
1712 internal int VM_BeginInvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, InvokeMethodCallback callback, object state) {
1713 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) {
1714 ValueImpl v, exc, out_this = null;
1715 ValueImpl[] out_args = null;
1717 if (r.ErrorCode != 0) {
1718 callback (null, null, null, null, (ErrorCode)r.ErrorCode, state);
1720 read_invoke_res (r, out v, out exc, out out_this, out out_args);
1721 callback (v, exc, out_this, out_args, 0, state);
1726 internal int VM_BeginInvokeMethods (long thread, long[] methods, ValueImpl this_arg, List<ValueImpl[]> arguments, InvokeFlags flags, InvokeMethodCallback callback, object state) {
1727 // FIXME: Merge this with INVOKE_METHOD
1728 var w = new PacketWriter ();
1730 w.WriteInt ((int)flags);
1731 w.WriteInt (methods.Length);
1732 for (int i = 0; i < methods.Length; ++i) {
1733 w.WriteId (methods [i]);
1734 w.WriteValue (this_arg);
1735 w.WriteInt (arguments [i].Length);
1736 w.WriteValues (arguments [i]);
1738 return Send (CommandSet.VM, (int)CmdVM.INVOKE_METHODS, w, delegate (PacketReader r) {
1739 ValueImpl v, exc, out_this = null;
1740 ValueImpl[] out_args = null;
1742 if (r.ErrorCode != 0) {
1743 callback (null, null, null, null, (ErrorCode)r.ErrorCode, state);
1745 read_invoke_res (r, out v, out exc, out out_this, out out_args);
1746 callback (v, exc, out_this, out_args, 0, state);
1751 internal void VM_AbortInvoke (long thread, int id)
1753 SendReceive (CommandSet.VM, (int)CmdVM.ABORT_INVOKE, new PacketWriter ().WriteId (thread).WriteInt (id));
1756 internal void SetSocketTimeouts (int send_timeout, int receive_timeout, int keepalive_interval)
1758 TransportSetTimeouts (send_timeout, receive_timeout);
1759 SendReceive (CommandSet.VM, (int)CmdVM.SET_KEEPALIVE, new PacketWriter ().WriteId (keepalive_interval));
1762 internal long[] VM_GetTypesForSourceFile (string fname, bool ignoreCase) {
1763 var res = SendReceive (CommandSet.VM, (int)CmdVM.GET_TYPES_FOR_SOURCE_FILE, new PacketWriter ().WriteString (fname).WriteBool (ignoreCase));
1764 int count = res.ReadInt ();
1765 long[] types = new long [count];
1766 for (int i = 0; i < count; ++i)
1767 types [i] = res.ReadId ();
1771 internal long[] VM_GetTypes (string name, bool ignoreCase) {
1772 var res = SendReceive (CommandSet.VM, (int)CmdVM.GET_TYPES, new PacketWriter ().WriteString (name).WriteBool (ignoreCase));
1773 int count = res.ReadInt ();
1774 long[] types = new long [count];
1775 for (int i = 0; i < count; ++i)
1776 types [i] = res.ReadId ();
1780 internal void VM_StartBuffering () {
1781 Send (CommandSet.VM, (int)CmdVM.START_BUFFERING);
1784 internal void VM_StopBuffering () {
1785 Send (CommandSet.VM, (int)CmdVM.STOP_BUFFERING);
1792 internal long RootDomain {
1794 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ROOT_DOMAIN, null).ReadId ();
1798 internal string Domain_GetName (long id) {
1799 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_FRIENDLY_NAME, new PacketWriter ().WriteId (id)).ReadString ();
1802 internal long[] Domain_GetAssemblies (long id) {
1803 var res = SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ASSEMBLIES, new PacketWriter ().WriteId (id));
1804 int count = res.ReadInt ();
1805 long[] assemblies = new long [count];
1806 for (int i = 0; i < count; ++i)
1807 assemblies [i] = res.ReadId ();
1811 internal long Domain_GetEntryAssembly (long id) {
1812 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ENTRY_ASSEMBLY, new PacketWriter ().WriteId (id)).ReadId ();
1815 internal long Domain_GetCorlib (long id) {
1816 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_CORLIB, new PacketWriter ().WriteId (id)).ReadId ();
1819 internal long Domain_CreateString (long id, string s) {
1820 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.CREATE_STRING, new PacketWriter ().WriteId (id).WriteString (s)).ReadId ();
1823 internal long Domain_CreateBoxedValue (long id, long type_id, ValueImpl v) {
1824 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.CREATE_BOXED_VALUE, new PacketWriter ().WriteId (id).WriteId (type_id).WriteValue (v)).ReadId ();
1831 internal string Method_GetName (long id) {
1832 return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
1835 internal long Method_GetDeclaringType (long id) {
1836 return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DECLARING_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
1839 internal DebugInfo Method_GetDebugInfo (long id) {
1840 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DEBUG_INFO, new PacketWriter ().WriteId (id));
1842 DebugInfo info = new DebugInfo ();
1843 info.max_il_offset = res.ReadInt ();
1845 SourceInfo[] sources = null;
1846 if (Version.AtLeast (2, 13)) {
1847 int n = res.ReadInt ();
1848 sources = new SourceInfo [n];
1849 for (int i = 0; i < n; ++i) {
1850 sources [i].source_file = res.ReadString ();
1851 if (Version.AtLeast (2, 14)) {
1852 sources [i].hash = new byte [16];
1853 for (int j = 0; j < 16; ++j)
1854 sources [i].hash [j] = (byte)res.ReadByte ();
1858 sources = new SourceInfo [1];
1859 sources [0].source_file = res.ReadString ();
1862 int n_il_offsets = res.ReadInt ();
1863 info.il_offsets = new int [n_il_offsets];
1864 info.line_numbers = new int [n_il_offsets];
1865 info.source_files = new SourceInfo [n_il_offsets];
1866 info.column_numbers = new int [n_il_offsets];
1867 info.end_line_numbers = new int [n_il_offsets];
1868 info.end_column_numbers = new int [n_il_offsets];
1869 for (int i = 0; i < n_il_offsets; ++i) {
1870 info.il_offsets [i] = res.ReadInt ();
1871 info.line_numbers [i] = res.ReadInt ();
1872 if (Version.AtLeast (2, 12)) {
1873 int idx = res.ReadInt ();
1874 info.source_files [i] = idx >= 0 ? sources [idx] : default (SourceInfo);
1876 info.source_files [i] = sources [0];
1878 if (Version.AtLeast (2, 19))
1879 info.column_numbers [i] = res.ReadInt ();
1881 info.column_numbers [i] = 0;
1882 if (Version.AtLeast (2, 32)) {
1883 info.end_line_numbers [i] = res.ReadInt ();
1884 info.end_column_numbers [i] = res.ReadInt ();
1886 info.end_column_numbers [i] = -1;
1887 info.end_column_numbers [i] = -1;
1894 internal ParamInfo Method_GetParamInfo (long id) {
1895 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_PARAM_INFO, new PacketWriter ().WriteId (id));
1897 ParamInfo info = new ParamInfo ();
1898 info.call_conv = res.ReadInt ();
1899 info.param_count = res.ReadInt ();
1900 info.generic_param_count = res.ReadInt ();
1901 info.ret_type = res.ReadId ();
1902 info.param_types = new long [info.param_count];
1903 for (int i = 0; i < info.param_count; ++i)
1904 info.param_types [i] = res.ReadId ();
1905 info.param_names = new string [info.param_count];
1906 for (int i = 0; i < info.param_count; ++i)
1907 info.param_names [i] = res.ReadString ();
1912 internal LocalsInfo Method_GetLocalsInfo (long id) {
1913 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_LOCALS_INFO, new PacketWriter ().WriteId (id));
1915 LocalsInfo info = new LocalsInfo ();
1917 if (Version.AtLeast (2, 43)) {
1918 int nscopes = res.ReadInt ();
1919 info.scopes_start = new int [nscopes];
1920 info.scopes_end = new int [nscopes];
1922 for (int i = 0; i < nscopes; ++i) {
1923 info.scopes_start [i] = last_start + res.ReadInt ();
1924 info.scopes_end [i] = info.scopes_start [i] + res.ReadInt ();
1925 last_start = info.scopes_start [i];
1929 int nlocals = res.ReadInt ();
1930 info.types = new long [nlocals];
1931 for (int i = 0; i < nlocals; ++i)
1932 info.types [i] = res.ReadId ();
1933 info.names = new string [nlocals];
1934 for (int i = 0; i < nlocals; ++i)
1935 info.names [i] = res.ReadString ();
1936 info.live_range_start = new int [nlocals];
1937 info.live_range_end = new int [nlocals];
1938 for (int i = 0; i < nlocals; ++i) {
1939 info.live_range_start [i] = res.ReadInt ();
1940 info.live_range_end [i] = res.ReadInt ();
1946 internal MethodInfo Method_GetInfo (long id) {
1947 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_INFO, new PacketWriter ().WriteId (id));
1949 MethodInfo info = new MethodInfo ();
1950 info.attributes = res.ReadInt ();
1951 info.iattributes = res.ReadInt ();
1952 info.token = res.ReadInt ();
1953 if (Version.AtLeast (2, 12)) {
1954 int attrs = res.ReadByte ();
1955 if ((attrs & (1 << 0)) != 0)
1957 if ((attrs & (1 << 1)) != 0)
1958 info.is_generic_method = true;
1959 info.gmd = res.ReadId ();
1960 if (Version.AtLeast (2, 15)) {
1961 if (info.is_generic_method) {
1962 int n = res.ReadInt ();
1963 info.type_args = res.ReadIds (n);
1970 internal MethodBodyInfo Method_GetBody (long id) {
1971 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_BODY, new PacketWriter ().WriteId (id));
1973 MethodBodyInfo info = new MethodBodyInfo ();
1974 info.il = new byte [res.ReadInt ()];
1975 for (int i = 0; i < info.il.Length; ++i)
1976 info.il [i] = (byte)res.ReadByte ();
1978 if (Version.AtLeast (2, 18)) {
1979 info.clauses = new ExceptionClauseInfo [res.ReadInt ()];
1981 for (int i = 0; i < info.clauses.Length; ++i) {
1982 var clause = new ExceptionClauseInfo {
1983 flags = (ExceptionClauseFlags) res.ReadInt (),
1984 try_offset = res.ReadInt (),
1985 try_length = res.ReadInt (),
1986 handler_offset = res.ReadInt (),
1987 handler_length = res.ReadInt (),
1990 if (clause.flags == ExceptionClauseFlags.None)
1991 clause.catch_type_id = res.ReadId ();
1992 else if (clause.flags == ExceptionClauseFlags.Filter)
1993 clause.filter_offset = res.ReadInt ();
1995 info.clauses [i] = clause;
1998 info.clauses = new ExceptionClauseInfo [0];
2003 internal ResolvedToken Method_ResolveToken (long id, int token) {
2004 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.RESOLVE_TOKEN, new PacketWriter ().WriteId (id).WriteInt (token));
2006 TokenType type = (TokenType)res.ReadByte ();
2008 case TokenType.STRING:
2009 return new ResolvedToken () { Type = type, Str = res.ReadString () };
2010 case TokenType.TYPE:
2011 case TokenType.METHOD:
2012 case TokenType.FIELD:
2013 return new ResolvedToken () { Type = type, Id = res.ReadId () };
2014 case TokenType.UNKNOWN:
2015 return new ResolvedToken () { Type = type };
2017 throw new NotImplementedException ();
2021 internal CattrInfo[] Method_GetCustomAttributes (long id, long attr_type_id, bool inherit) {
2022 PacketReader r = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_CATTRS, new PacketWriter ().WriteId (id).WriteId (attr_type_id));
2023 return ReadCattrs (r);
2026 internal long Method_MakeGenericMethod (long id, long[] args) {
2027 PacketReader r = SendReceive (CommandSet.METHOD, (int)CmdMethod.MAKE_GENERIC_METHOD, new PacketWriter ().WriteId (id).WriteInt (args.Length).WriteIds (args));
2035 internal string Thread_GetName (long id) {
2036 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
2039 internal void Thread_GetFrameInfo (long id, int start_frame, int length, Action<FrameInfo[]> resultCallaback) {
2040 Send (CommandSet.THREAD, (int)CmdThread.GET_FRAME_INFO, new PacketWriter ().WriteId (id).WriteInt (start_frame).WriteInt (length), (res) => {
2041 int count = res.ReadInt ();
2042 var frames = new FrameInfo[count];
2043 for (int i = 0; i < count; ++i) {
2044 var f = new FrameInfo ();
2045 f.id = res.ReadInt ();
2046 f.method = res.ReadId ();
2047 f.il_offset = res.ReadInt ();
2048 f.flags = (StackFrameFlags)res.ReadByte ();
2051 resultCallaback (frames);
2055 internal int Thread_GetState (long id) {
2056 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_STATE, new PacketWriter ().WriteId (id)).ReadInt ();
2059 internal ThreadInfo Thread_GetInfo (long id) {
2060 PacketReader r = SendReceive (CommandSet.THREAD, (int)CmdThread.GET_INFO, new PacketWriter ().WriteId (id));
2062 ThreadInfo res = new ThreadInfo () { is_thread_pool = r.ReadByte () > 0 ? true : false };
2067 internal long Thread_GetId (long id) {
2068 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_ID, new PacketWriter ().WriteId (id)).ReadLong ();
2071 internal long Thread_GetTID (long id) {
2072 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_TID, new PacketWriter ().WriteId (id)).ReadLong ();
2075 internal void Thread_SetIP (long id, long method_id, long il_offset) {
2076 SendReceive (CommandSet.THREAD, (int)CmdThread.SET_IP, new PacketWriter ().WriteId (id).WriteId (method_id).WriteLong (il_offset));
2083 internal ModuleInfo Module_GetInfo (long id) {
2084 PacketReader r = SendReceive (CommandSet.MODULE, (int)CmdModule.GET_INFO, new PacketWriter ().WriteId (id));
2085 ModuleInfo info = new ModuleInfo { Name = r.ReadString (), ScopeName = r.ReadString (), FQName = r.ReadString (), Guid = r.ReadString (), Assembly = r.ReadId () };
2093 internal string Assembly_GetLocation (long id) {
2094 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_LOCATION, new PacketWriter ().WriteId (id)).ReadString ();
2097 internal long Assembly_GetEntryPoint (long id) {
2098 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_ENTRY_POINT, new PacketWriter ().WriteId (id)).ReadId ();
2101 internal long Assembly_GetManifestModule (long id) {
2102 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_MANIFEST_MODULE, new PacketWriter ().WriteId (id)).ReadId ();
2105 internal long Assembly_GetObject (long id) {
2106 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
2109 internal long Assembly_GetType (long id, string name, bool ignoreCase) {
2110 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_TYPE, new PacketWriter ().WriteId (id).WriteString (name).WriteBool (ignoreCase)).ReadId ();
2113 internal string Assembly_GetName (long id) {
2114 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
2121 internal TypeInfo Type_GetInfo (long id) {
2122 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INFO, new PacketWriter ().WriteId (id));
2123 TypeInfo res = new TypeInfo ();
2125 res.ns = r.ReadString ();
2126 res.name = r.ReadString ();
2127 res.full_name = r.ReadString ();
2128 res.assembly = r.ReadId ();
2129 res.module = r.ReadId ();
2130 res.base_type = r.ReadId ();
2131 res.element_type = r.ReadId ();
2132 res.token = r.ReadInt ();
2133 res.rank = r.ReadByte ();
2134 res.attributes = r.ReadInt ();
2135 int b = r.ReadByte ();
2136 res.is_byref = (b & 1) != 0;
2137 res.is_pointer = (b & 2) != 0;
2138 res.is_primitive = (b & 4) != 0;
2139 res.is_valuetype = (b & 8) != 0;
2140 res.is_enum = (b & 16) != 0;
2141 res.is_gtd = (b & 32) != 0;
2142 res.is_generic_type = (b & 64) != 0;
2144 int nested_len = r.ReadInt ();
2145 res.nested = new long [nested_len];
2146 for (int i = 0; i < nested_len; ++i)
2147 res.nested [i] = r.ReadId ();
2149 if (Version.AtLeast (2, 12))
2150 res.gtd = r.ReadId ();
2151 if (Version.AtLeast (2, 15) && res.is_generic_type) {
2152 int n = r.ReadInt ();
2153 res.type_args = r.ReadIds (n);
2159 internal long[] Type_GetMethods (long id) {
2160 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_METHODS, new PacketWriter ().WriteId (id));
2162 int n = r.ReadInt ();
2163 long[] res = new long [n];
2164 for (int i = 0; i < n; ++i)
2165 res [i] = r.ReadId ();
2169 internal long[] Type_GetFields (long id, out string[] names, out long[] types, out int[] attrs) {
2170 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_FIELDS, new PacketWriter ().WriteId (id));
2172 int n = r.ReadInt ();
2173 long[] res = new long [n];
2174 names = new string [n];
2175 types = new long [n];
2176 attrs = new int [n];
2177 for (int i = 0; i < n; ++i) {
2178 res [i] = r.ReadId ();
2179 names [i] = r.ReadString ();
2180 types [i] = r.ReadId ();
2181 attrs [i] = r.ReadInt ();
2186 internal PropInfo[] Type_GetProperties (long id) {
2187 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_PROPERTIES, new PacketWriter ().WriteId (id));
2189 int n = r.ReadInt ();
2190 PropInfo[] res = new PropInfo [n];
2191 for (int i = 0; i < n; ++i) {
2192 res [i] = new PropInfo ();
2193 res [i].id = r.ReadId ();
2194 res [i].name = r.ReadString ();
2195 res [i].get_method = r.ReadId ();
2196 res [i].set_method = r.ReadId ();
2197 res [i].attrs = r.ReadInt ();
2203 internal long Type_GetObject (long id) {
2204 return SendReceive (CommandSet.TYPE, (int)CmdType.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
2207 internal ValueImpl[] Type_GetValues (long id, long[] fields, long thread_id) {
2208 int len = fields.Length;
2211 r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES_2, new PacketWriter ().WriteId (id).WriteId (thread_id).WriteInt (len).WriteIds (fields));
2213 r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));
2215 ValueImpl[] res = new ValueImpl [len];
2216 for (int i = 0; i < len; ++i)
2217 res [i] = r.ReadValue ();
2221 internal void Type_SetValues (long id, long[] fields, ValueImpl[] values) {
2222 SendReceive (CommandSet.TYPE, (int)CmdType.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
2225 internal string[] Type_GetSourceFiles (long id, bool return_full_paths) {
2226 var r = SendReceive (CommandSet.TYPE, return_full_paths ? (int)CmdType.GET_SOURCE_FILES_2 : (int)CmdType.GET_SOURCE_FILES, new PacketWriter ().WriteId (id));
2227 int len = r.ReadInt ();
2228 string[] res = new string [len];
2229 for (int i = 0; i < len; ++i)
2230 res [i] = r.ReadString ();
2234 internal bool Type_IsAssignableFrom (long id, long c_id) {
2235 return SendReceive (CommandSet.TYPE, (int)CmdType.IS_ASSIGNABLE_FROM, new PacketWriter ().WriteId (id).WriteId (c_id)).ReadByte () > 0;
2238 internal CattrInfo[] Type_GetCustomAttributes (long id, long attr_type_id, bool inherit) {
2239 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_CATTRS, new PacketWriter ().WriteId (id).WriteId (attr_type_id));
2240 return ReadCattrs (r);
2243 internal CattrInfo[] Type_GetFieldCustomAttributes (long id, long field_id, long attr_type_id, bool inherit) {
2244 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_FIELD_CATTRS, new PacketWriter ().WriteId (id).WriteId (field_id).WriteId (attr_type_id));
2245 return ReadCattrs (r);
2248 internal CattrInfo[] Type_GetPropertyCustomAttributes (long id, long field_id, long attr_type_id, bool inherit) {
2249 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_PROPERTY_CATTRS, new PacketWriter ().WriteId (id).WriteId (field_id).WriteId (attr_type_id));
2250 return ReadCattrs (r);
2253 public long[] Type_GetMethodsByNameFlags (long id, string name, int flags, bool ignoreCase) {
2254 flags |= ignoreCase ? (int)BindingFlagsExtensions.BINDING_FLAGS_IGNORE_CASE : 0;
2255 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.CMD_TYPE_GET_METHODS_BY_NAME_FLAGS, new PacketWriter ().WriteId (id).WriteString (name).WriteInt (flags));
2256 int len = r.ReadInt ();
2257 long[] res = new long [len];
2258 for (int i = 0; i < len; ++i)
2259 res [i] = r.ReadId ();
2263 internal long[] Type_GetInterfaces (long id) {
2264 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INTERFACES, new PacketWriter ().WriteId (id));
2265 int len = r.ReadInt ();
2266 return r.ReadIds (len);
2269 internal IfaceMapInfo[] Type_GetInterfaceMap (long id, long[] ids) {
2270 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INTERFACE_MAP, new PacketWriter ().WriteId (id).WriteInt (ids.Length).WriteIds (ids));
2271 var res = new IfaceMapInfo [ids.Length];
2272 for (int i = 0; i < ids.Length; ++i) {
2273 int n = r.ReadInt ();
2275 res [i].iface_id = ids [i];
2276 res [i].iface_methods = r.ReadIds (n);
2277 res [i].target_methods = r.ReadIds (n);
2283 internal bool Type_IsInitialized (long id) {
2284 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.IS_INITIALIZED, new PacketWriter ().WriteId (id));
2285 return r.ReadInt () == 1;
2288 internal long Type_CreateInstance (long id) {
2289 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.CREATE_INSTANCE, new PacketWriter ().WriteId (id));
2297 internal FieldMirrorInfo Field_GetInfo (long id) {
2298 PacketReader r = SendReceive (CommandSet.FIELD, (int)CmdField.GET_INFO, new PacketWriter ().WriteId (id));
2299 FieldMirrorInfo info = new FieldMirrorInfo { Name = r.ReadString (), Parent = r.ReadId (), TypeId = r.ReadId (), Attrs = r.ReadInt () };
2307 internal int EnableEvent (EventType etype, SuspendPolicy suspend_policy, List<Modifier> mods) {
2308 var w = new PacketWriter ().WriteByte ((byte)etype).WriteByte ((byte)suspend_policy);
2310 if (mods.Count > 255)
2311 throw new NotImplementedException ();
2312 w.WriteByte ((byte)mods.Count);
2313 foreach (Modifier mod in mods) {
2314 if (mod is CountModifier) {
2315 w.WriteByte ((byte)ModifierKind.COUNT);
2316 w.WriteInt ((mod as CountModifier).Count);
2317 } else if (mod is LocationModifier) {
2318 w.WriteByte ((byte)ModifierKind.LOCATION_ONLY);
2319 w.WriteId ((mod as LocationModifier).Method);
2320 w.WriteLong ((mod as LocationModifier).Location);
2321 } else if (mod is StepModifier) {
2322 w.WriteByte ((byte)ModifierKind.STEP);
2323 w.WriteId ((mod as StepModifier).Thread);
2324 w.WriteInt ((mod as StepModifier).Size);
2325 w.WriteInt ((mod as StepModifier).Depth);
2326 if (Version.AtLeast (2, 16))
2327 w.WriteInt ((mod as StepModifier).Filter);
2328 } else if (mod is ThreadModifier) {
2329 w.WriteByte ((byte)ModifierKind.THREAD_ONLY);
2330 w.WriteId ((mod as ThreadModifier).Thread);
2331 } else if (mod is ExceptionModifier) {
2332 var em = mod as ExceptionModifier;
2333 w.WriteByte ((byte)ModifierKind.EXCEPTION_ONLY);
2334 w.WriteId (em.Type);
2335 if (Version.MajorVersion > 2 || Version.MinorVersion > 0) {
2336 /* This is only supported in protocol version 2.1 */
2337 w.WriteBool (em.Caught);
2338 w.WriteBool (em.Uncaught);
2339 } else if (!em.Caught || !em.Uncaught) {
2340 throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
2342 if (Version.MajorVersion > 2 || Version.MinorVersion > 24) {
2343 w.WriteBool (em.Subclasses);
2344 } else if (!em.Subclasses) {
2345 throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
2347 } else if (mod is AssemblyModifier) {
2348 w.WriteByte ((byte)ModifierKind.ASSEMBLY_ONLY);
2349 var amod = (mod as AssemblyModifier);
2350 w.WriteInt (amod.Assemblies.Length);
2351 foreach (var id in amod.Assemblies)
2353 } else if (mod is SourceFileModifier) {
2354 w.WriteByte ((byte)ModifierKind.SOURCE_FILE_ONLY);
2355 var smod = (mod as SourceFileModifier);
2356 w.WriteInt (smod.SourceFiles.Length);
2357 foreach (var s in smod.SourceFiles)
2359 } else if (mod is TypeNameModifier) {
2360 w.WriteByte ((byte)ModifierKind.TYPE_NAME_ONLY);
2361 var tmod = (mod as TypeNameModifier);
2362 w.WriteInt (tmod.TypeNames.Length);
2363 foreach (var s in tmod.TypeNames)
2366 throw new NotImplementedException ();
2372 return SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.SET, w).ReadInt ();
2375 internal void ClearEventRequest (EventType etype, int req_id) {
2376 SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.CLEAR, new PacketWriter ().WriteByte ((byte)etype).WriteInt (req_id));
2379 internal void ClearAllBreakpoints () {
2380 SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.CLEAR_ALL_BREAKPOINTS, new PacketWriter ());
2386 internal ValueImpl StackFrame_GetThis (long thread_id, long id) {
2387 PacketReader r = SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_THIS, new PacketWriter ().WriteId (thread_id).WriteId (id));
2388 return r.ReadValue ();
2391 internal ValueImpl[] StackFrame_GetValues (long thread_id, long id, int[] pos) {
2392 /* pos < 0 -> argument at pos (-pos) - 1 */
2393 /* pos >= 0 -> local at pos */
2394 int len = pos.Length;
2395 PacketReader r = SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos));
2397 ValueImpl[] res = new ValueImpl [len];
2398 for (int i = 0; i < len; ++i)
2399 res [i] = r.ReadValue ();
2403 internal void StackFrame_SetValues (long thread_id, long id, int[] pos, ValueImpl[] values) {
2404 /* pos < 0 -> argument at pos (-pos) - 1 */
2405 /* pos >= 0 -> local at pos */
2406 int len = pos.Length;
2407 SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.SET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos).WriteValues (values));
2410 internal long StackFrame_GetDomain (long thread_id, long id) {
2411 return SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_DOMAIN, new PacketWriter ().WriteId (thread_id).WriteId (id)).ReadId ();
2414 internal void StackFrame_SetThis (long thread_id, long id, ValueImpl value) {
2415 SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.SET_THIS, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteValue (value));
2421 internal int[] Array_GetLength (long id, out int rank, out int[] lower_bounds) {
2422 var r = SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.GET_LENGTH, new PacketWriter ().WriteId (id));
2423 rank = r.ReadInt ();
2424 int[] res = new int [rank];
2425 lower_bounds = new int [rank];
2426 for (int i = 0; i < rank; ++i) {
2427 res [i] = r.ReadInt ();
2428 lower_bounds [i] = r.ReadInt ();
2433 internal ValueImpl[] Array_GetValues (long id, int index, int len) {
2434 var r = SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (len));
2435 ValueImpl[] res = new ValueImpl [len];
2436 for (int i = 0; i < len; ++i)
2437 res [i] = r.ReadValue ();
2441 internal void Array_SetValues (long id, int index, ValueImpl[] values) {
2442 SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (values.Length).WriteValues (values));
2448 internal string String_GetValue (long id) {
2449 var r = SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_VALUE, new PacketWriter ().WriteId (id));
2451 bool is_utf16 = false;
2452 if (Version.AtLeast (2, 41))
2453 is_utf16 = r.ReadByte () == 1;
2456 return r.ReadUTF16String ();
2458 return r.ReadString ();
2461 internal int String_GetLength (long id) {
2462 return (int)SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_LENGTH, new PacketWriter ().WriteId (id)).ReadLong ();
2465 internal char[] String_GetChars (long id, int index, int length) {
2466 var r = SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_CHARS, new PacketWriter ().WriteId (id).WriteLong (index).WriteLong (length));
2467 var res = new char [length];
2468 for (int i = 0; i < length; ++i)
2469 res [i] = (char)r.ReadShort ();
2476 internal long Object_GetType (long id) {
2477 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
2480 internal long Object_GetDomain (long id) {
2481 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_DOMAIN, new PacketWriter ().WriteId (id)).ReadId ();
2484 internal ValueImpl[] Object_GetValues (long id, long[] fields) {
2485 int len = fields.Length;
2486 PacketReader r = SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));
2488 ValueImpl[] res = new ValueImpl [len];
2489 for (int i = 0; i < len; ++i)
2490 res [i] = r.ReadValue ();
2494 internal void Object_SetValues (long id, long[] fields, ValueImpl[] values) {
2495 SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
2498 internal bool Object_IsCollected (long id) {
2499 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.IS_COLLECTED, new PacketWriter ().WriteId (id)).ReadInt () == 1;
2502 internal long Object_GetAddress (long id) {
2503 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_ADDRESS, new PacketWriter ().WriteId (id)).ReadLong ();
2506 internal ObjectRefInfo Object_GetInfo (long id) {
2507 ObjectRefInfo res = new ObjectRefInfo ();
2508 PacketReader r = SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_INFO, new PacketWriter ().WriteId (id));
2510 res.type_id = r.ReadId ();
2511 res.domain_id = r.ReadId ();
2515 public void ForceDisconnect ()
2518 disconnected = true;
2519 DisconnectedEvent.Set ();
2524 class TcpConnection : Connection
2528 internal TcpConnection (Socket socket)
2530 this.socket = socket;
2531 //socket.SetSocketOption (SocketOptionLevel.IP, SocketOptionName.NoDelay, 1);
2534 internal EndPoint EndPoint {
2536 return socket.RemoteEndPoint;
2540 protected override int TransportSend (byte[] buf, int buf_offset, int len)
2542 return socket.Send (buf, buf_offset, len, SocketFlags.None);
2545 protected override int TransportReceive (byte[] buf, int buf_offset, int len)
2547 return socket.Receive (buf, buf_offset, len, SocketFlags.None);
2550 protected override void TransportSetTimeouts (int send_timeout, int receive_timeout)
2552 socket.SendTimeout = send_timeout;
2553 socket.ReceiveTimeout = receive_timeout;
2556 protected override void TransportClose ()
2562 /* This is the interface exposed by the debugger towards the debugger agent */
2563 interface IEventHandler
2565 void Events (SuspendPolicy suspend_policy, EventInfo[] events);
2567 void VMDisconnect (int req_id, long thread_id, string vm_uri);