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;
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 = 45;
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,
545 GET_DECLARING_TYPE = 2,
553 MAKE_GENERIC_METHOD = 10
562 GET_SOURCE_FILES = 6,
564 IS_ASSIGNABLE_FROM = 8,
567 GET_FIELD_CATTRS = 11,
568 GET_PROPERTY_CATTRS = 12,
569 /* FIXME: Merge into GET_SOURCE_FILES when the major protocol version is increased */
570 GET_SOURCE_FILES_2 = 13,
571 /* FIXME: Merge into GET_VALUES when the major protocol version is increased */
573 CMD_TYPE_GET_METHODS_BY_NAME_FLAGS = 15,
575 GET_INTERFACE_MAP = 17,
585 enum BindingFlagsExtensions {
586 BINDING_FLAGS_IGNORE_CASE = 0x70000000,
621 public int command_set;
626 internal static int GetPacketLength (byte[] header) {
628 return decode_int (header, ref offset);
631 internal static bool IsReplyPacket (byte[] packet) {
633 return decode_byte (packet, ref offset) == 0x80;
636 internal static int GetPacketId (byte[] packet) {
638 return decode_int (packet, ref offset);
641 static int decode_byte (byte[] packet, ref int offset) {
642 return packet [offset++];
645 static int decode_short (byte[] packet, ref int offset) {
646 int res = ((int)packet [offset] << 8) | (int)packet [offset + 1];
651 static int decode_int (byte[] packet, ref int offset) {
652 int res = ((int)packet [offset] << 24) | ((int)packet [offset + 1] << 16) | ((int)packet [offset + 2] << 8) | (int)packet [offset + 3];
657 static long decode_id (byte[] packet, ref int offset) {
658 return decode_int (packet, ref offset);
661 static long decode_long (byte[] packet, ref int offset) {
662 uint high = (uint)decode_int (packet, ref offset);
663 uint low = (uint)decode_int (packet, ref offset);
665 return (long)(((ulong)high << 32) | (ulong)low);
668 internal static SuspendPolicy decode_suspend_policy (int suspend_policy) {
669 switch ((WPSuspendPolicy)suspend_policy) {
670 case WPSuspendPolicy.NONE:
671 return SuspendPolicy.None;
672 case WPSuspendPolicy.EVENT_THREAD:
673 return SuspendPolicy.EventThread;
674 case WPSuspendPolicy.ALL:
675 return SuspendPolicy.All;
677 throw new NotImplementedException ();
681 static Header decode_command_header (byte[] packet) {
683 Header res = new Header ();
685 decode_int (packet, ref offset);
686 res.id = decode_int (packet, ref offset);
687 res.flags = decode_byte (packet, ref offset);
688 res.command_set = decode_byte (packet, ref offset);
689 res.command = decode_byte (packet, ref offset);
694 static void encode_byte (byte[] buf, int b, ref int offset) {
695 buf [offset] = (byte)b;
699 static void encode_int (byte[] buf, int i, ref int offset) {
700 buf [offset] = (byte)((i >> 24) & 0xff);
701 buf [offset + 1] = (byte)((i >> 16) & 0xff);
702 buf [offset + 2] = (byte)((i >> 8) & 0xff);
703 buf [offset + 3] = (byte)((i >> 0) & 0xff);
707 static void encode_id (byte[] buf, long id, ref int offset) {
708 encode_int (buf, (int)id, ref offset);
711 static void encode_long (byte[] buf, long l, ref int offset) {
712 encode_int (buf, (int)((l >> 32) & 0xffffffff), ref offset);
713 encode_int (buf, (int)(l & 0xffffffff), ref offset);
716 internal static byte[] EncodePacket (int id, int commandSet, int command, byte[] data, int dataLen) {
717 byte[] buf = new byte [dataLen + 11];
720 encode_int (buf, buf.Length, ref offset);
721 encode_int (buf, id, ref offset);
722 encode_byte (buf, 0, ref offset);
723 encode_byte (buf, commandSet, ref offset);
724 encode_byte (buf, command, ref offset);
726 for (int i = 0; i < dataLen; ++i)
727 buf [offset + i] = data [i];
736 public PacketReader (byte[] packet) {
737 this.packet = packet;
740 Header header = decode_command_header (packet);
741 CommandSet = (CommandSet)header.command_set;
742 Command = header.command;
746 ReadInt (); // length
748 ReadByte (); // flags
749 ErrorCode = ReadShort ();
752 public CommandSet CommandSet {
760 public int ErrorCode {
770 public int ReadByte () {
771 return decode_byte (packet, ref offset);
774 public int ReadShort () {
775 return decode_short (packet, ref offset);
778 public int ReadInt () {
779 return decode_int (packet, ref offset);
782 public long ReadId () {
783 return decode_id (packet, ref offset);
786 public long ReadLong () {
787 return decode_long (packet, ref offset);
790 public float ReadFloat () {
791 float f = DataConverter.FloatFromBE (packet, offset);
796 public double ReadDouble () {
797 double d = DataConverter.DoubleFromBE (packet, offset);
802 public string ReadString () {
803 int len = decode_int (packet, ref offset);
804 string res = new String (Encoding.UTF8.GetChars (packet, offset, len));
809 public string ReadUTF16String () {
810 int len = decode_int (packet, ref offset);
811 string res = new String (Encoding.Unicode.GetChars (packet, offset, len));
816 public ValueImpl ReadValue () {
817 ElementType etype = (ElementType)ReadByte ();
820 case ElementType.Void:
821 return new ValueImpl { Type = etype };
823 return new ValueImpl { Type = etype, Value = (sbyte)ReadInt () };
825 return new ValueImpl { Type = etype, Value = (byte)ReadInt () };
826 case ElementType.Boolean:
827 return new ValueImpl { Type = etype, Value = ReadInt () != 0 };
829 return new ValueImpl { Type = etype, Value = (short)ReadInt () };
831 return new ValueImpl { Type = etype, Value = (ushort)ReadInt () };
832 case ElementType.Char:
833 return new ValueImpl { Type = etype, Value = (char)ReadInt () };
835 return new ValueImpl { Type = etype, Value = ReadInt () };
837 return new ValueImpl { Type = etype, Value = (uint)ReadInt () };
839 return new ValueImpl { Type = etype, Value = ReadLong () };
841 return new ValueImpl { Type = etype, Value = (ulong)ReadLong () };
843 return new ValueImpl { Type = etype, Value = ReadFloat () };
845 return new ValueImpl { Type = etype, Value = ReadDouble () };
848 case ElementType.Ptr:
849 // FIXME: The client and the debuggee might have different word sizes
850 return new ValueImpl { Type = etype, Value = ReadLong () };
851 case ElementType.String:
852 case ElementType.SzArray:
853 case ElementType.Class:
854 case ElementType.Array:
855 case ElementType.Object:
856 long objid = ReadId ();
857 return new ValueImpl () { Type = etype, Objid = objid };
858 case ElementType.ValueType:
859 bool is_enum = ReadByte () == 1;
860 long klass = ReadId ();
861 long nfields = ReadInt ();
862 ValueImpl[] fields = new ValueImpl [nfields];
863 for (int i = 0; i < nfields; ++i)
864 fields [i] = ReadValue ();
865 return new ValueImpl () { Type = etype, Klass = klass, Fields = fields, IsEnum = is_enum };
866 case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
867 return new ValueImpl { Type = etype };
868 case (ElementType)ValueTypeId.VALUE_TYPE_ID_TYPE:
869 return new ValueImpl () { Type = etype, Id = ReadId () };
870 case (ElementType)ValueTypeId.VALUE_TYPE_ID_PARENT_VTYPE:
871 return new ValueImpl () { Type = etype, Index = ReadInt () };
873 throw new NotImplementedException ("Unable to handle type " + etype);
877 public long[] ReadIds (int n) {
878 long[] res = new long [n];
879 for (int i = 0; i < n; ++i)
890 public PacketWriter () {
891 data = new byte [1024];
895 void MakeRoom (int size) {
896 if (offset + size >= data.Length) {
897 int new_len = data.Length * 2;
898 while (new_len < offset + size) {
901 byte[] new_data = new byte [new_len];
902 Array.Copy (data, new_data, data.Length);
907 public PacketWriter WriteByte (byte val) {
909 encode_byte (data, val, ref offset);
913 public PacketWriter WriteInt (int val) {
915 encode_int (data, val, ref offset);
919 public PacketWriter WriteId (long id) {
921 encode_id (data, id, ref offset);
925 public PacketWriter WriteLong (long val) {
927 encode_long (data, val, ref offset);
931 public PacketWriter WriteFloat (float f) {
933 byte[] b = DataConverter.GetBytesBE (f);
934 for (int i = 0; i < 4; ++i)
935 data [offset + i] = b [i];
940 public PacketWriter WriteDouble (double d) {
942 byte[] b = DataConverter.GetBytesBE (d);
943 for (int i = 0; i < 8; ++i)
944 data [offset + i] = b [i];
949 public PacketWriter WriteInts (int[] ids) {
950 for (int i = 0; i < ids.Length; ++i)
955 public PacketWriter WriteIds (long[] ids) {
956 for (int i = 0; i < ids.Length; ++i)
961 public PacketWriter WriteString (string s) {
963 return WriteInt (-1);
965 byte[] b = Encoding.UTF8.GetBytes (s);
967 encode_int (data, b.Length, ref offset);
969 Buffer.BlockCopy (b, 0, data, offset, b.Length);
974 public PacketWriter WriteBool (bool val) {
975 WriteByte (val ? (byte)1 : (byte)0);
979 public PacketWriter WriteValue (ValueImpl v) {
983 t = TypeCodeToElementType (Type.GetTypeCode (v.Value.GetType ()));
988 case ElementType.Boolean:
989 WriteInt ((bool)v.Value ? 1 : 0);
991 case ElementType.Char:
992 WriteInt ((int)(char)v.Value);
995 WriteInt ((int)(sbyte)v.Value);
998 WriteInt ((int)(byte)v.Value);
1000 case ElementType.I2:
1001 WriteInt ((int)(short)v.Value);
1003 case ElementType.U2:
1004 WriteInt ((int)(ushort)v.Value);
1006 case ElementType.I4:
1007 WriteInt ((int)(int)v.Value);
1009 case ElementType.U4:
1010 WriteInt ((int)(uint)v.Value);
1012 case ElementType.I8:
1013 WriteLong ((long)(long)v.Value);
1015 case ElementType.U8:
1016 WriteLong ((long)(ulong)v.Value);
1018 case ElementType.R4:
1019 WriteFloat ((float)v.Value);
1021 case ElementType.R8:
1022 WriteDouble ((double)v.Value);
1024 case ElementType.String:
1025 case ElementType.SzArray:
1026 case ElementType.Class:
1027 case ElementType.Array:
1028 case ElementType.Object:
1031 case ElementType.ValueType:
1034 throw new NotImplementedException ();
1037 WriteInt (v.Fields.Length);
1038 for (int i = 0; i < v.Fields.Length; ++i)
1039 WriteValue (v.Fields [i]);
1041 case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
1044 throw new NotImplementedException ();
1050 public PacketWriter WriteValues (ValueImpl[] values) {
1051 for (int i = 0; i < values.Length; ++i)
1052 WriteValue (values [i]);
1056 public byte[] Data {
1069 delegate void ReplyCallback (int packet_id, byte[] packet);
1072 Thread receiver_thread;
1073 Dictionary<int, byte[]> reply_packets;
1074 Dictionary<int, ReplyCallback> reply_cbs;
1075 Dictionary<int, int> reply_cb_counts;
1076 object reply_packets_monitor;
1078 internal event EventHandler<ErrorHandlerEventArgs> ErrorHandler;
1080 protected Connection () {
1082 reply_packets = new Dictionary<int, byte[]> ();
1083 reply_cbs = new Dictionary<int, ReplyCallback> ();
1084 reply_cb_counts = new Dictionary<int, int> ();
1085 reply_packets_monitor = new Object ();
1086 if (EnableConnectionLogging) {
1087 var path = Environment.GetEnvironmentVariable ("MONO_SDB_LOG");
1088 if (path.Contains ("{0}")) {
1089 //C:\SomeDir\sdbLog{0}.txt -> C:\SomeDir\sdbLog1.txt
1090 LoggingStream = new StreamWriter (string.Format (path, ConnectionId++), false);
1091 } else if (Path.HasExtension (path)) {
1092 //C:\SomeDir\sdbLog.txt -> C:\SomeDir\sdbLog1.txt
1093 LoggingStream = new StreamWriter (Path.GetDirectoryName (path) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension (path) + ConnectionId++ + "." + Path.GetExtension (path), false);
1095 //C:\SomeDir\sdbLog -> C:\SomeDir\sdbLog1
1096 LoggingStream = new StreamWriter (path + ConnectionId++, false);
1101 protected abstract int TransportReceive (byte[] buf, int buf_offset, int len);
1102 protected abstract int TransportSend (byte[] buf, int buf_offset, int len);
1103 protected abstract void TransportSetTimeouts (int send_timeout, int receive_timeout);
1104 protected abstract void TransportClose ();
1106 internal VersionInfo Version;
1108 int Receive (byte[] buf, int buf_offset, int len) {
1111 while (offset < len) {
1112 int n = TransportReceive (buf, buf_offset + offset, len - offset);
1122 // Do the wire protocol handshake
1123 internal void Connect () {
1124 byte[] buf = new byte [HANDSHAKE_STRING.Length];
1125 char[] cbuf = new char [buf.Length];
1127 // FIXME: Add a timeout
1128 int n = Receive (buf, 0, buf.Length);
1130 throw new IOException ("DWP Handshake failed.");
1131 for (int i = 0; i < buf.Length; ++i)
1132 cbuf [i] = (char)buf [i];
1134 if (new String (cbuf) != HANDSHAKE_STRING)
1135 throw new IOException ("DWP Handshake failed.");
1137 TransportSend (buf, 0, buf.Length);
1139 receiver_thread = new Thread (new ThreadStart (receiver_thread_main));
1140 receiver_thread.Name = "SDB Receiver";
1141 receiver_thread.IsBackground = true;
1142 receiver_thread.Start ();
1144 Version = VM_GetVersion ();
1147 // Tell the debuggee our protocol version, so newer debuggees can work
1148 // with older clients
1152 // Older debuggees might not support this request
1153 EventHandler<ErrorHandlerEventArgs> OrigErrorHandler = ErrorHandler;
1154 ErrorHandler = null;
1155 ErrorHandler += delegate (object sender, ErrorHandlerEventArgs args) {
1156 throw new NotSupportedException ();
1159 VM_SetProtocolVersion (MAJOR_VERSION, MINOR_VERSION);
1160 } catch (NotSupportedException) {
1162 ErrorHandler = OrigErrorHandler;
1165 internal byte[] ReadPacket () {
1166 // FIXME: Throw ClosedConnectionException () if the connection is closed
1167 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1169 byte[] header = new byte [HEADER_LENGTH];
1171 int len = Receive (header, 0, header.Length);
1173 return new byte [0];
1174 if (len != HEADER_LENGTH) {
1176 throw new IOException ("Packet of length " + len + " is read.");
1179 int packetLength = GetPacketLength (header);
1180 if (packetLength < 11)
1181 throw new IOException ("Invalid packet length.");
1183 if (packetLength == 11) {
1186 byte[] buf = new byte [packetLength];
1187 for (int i = 0; i < header.Length; ++i)
1188 buf [i] = header [i];
1189 len = Receive (buf, header.Length, packetLength - header.Length);
1190 if (len != packetLength - header.Length)
1191 throw new IOException ();
1196 internal void WritePacket (byte[] packet) {
1197 // FIXME: Throw ClosedConnectionException () if the connection is closed
1198 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1200 TransportSend (packet, 0, packet.Length);
1203 internal void WritePackets (List<byte[]> packets) {
1204 // FIXME: Throw ClosedConnectionException () if the connection is closed
1205 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1208 for (int i = 0; i < packets.Count; ++i)
1209 len += packets [i].Length;
1210 byte[] data = new byte [len];
1212 for (int i = 0; i < packets.Count; ++i) {
1213 Buffer.BlockCopy (packets [i], 0, data, pos, packets [i].Length);
1214 pos += packets [i].Length;
1216 TransportSend (data, 0, data.Length);
1219 internal void Close () {
1223 internal bool IsClosed {
1231 internal ManualResetEvent DisconnectedEvent = new ManualResetEvent (false);
1233 void receiver_thread_main () {
1236 bool res = ReceivePacket ();
1239 } catch (Exception ex) {
1241 Console.WriteLine (ex);
1247 lock (reply_packets_monitor) {
1248 disconnected = true;
1249 DisconnectedEvent.Set ();
1250 Monitor.PulseAll (reply_packets_monitor);
1253 EventHandler.VMDisconnect (0, 0, null);
1256 bool ReceivePacket () {
1257 byte[] packet = ReadPacket ();
1259 if (packet.Length == 0) {
1263 if (IsReplyPacket (packet)) {
1264 int id = GetPacketId (packet);
1265 ReplyCallback cb = null;
1266 lock (reply_packets_monitor) {
1267 reply_cbs.TryGetValue (id, out cb);
1269 reply_packets [id] = packet;
1270 Monitor.PulseAll (reply_packets_monitor);
1272 int c = reply_cb_counts [id];
1275 reply_cbs.Remove (id);
1276 reply_cb_counts.Remove (id);
1282 cb.Invoke (id, packet);
1284 PacketReader r = new PacketReader (packet);
1286 if (r.CommandSet == CommandSet.EVENT && r.Command == (int)CmdEvent.COMPOSITE) {
1287 int spolicy = r.ReadByte ();
1288 int nevents = r.ReadInt ();
1290 SuspendPolicy suspend_policy = decode_suspend_policy (spolicy);
1292 EventInfo[] events = new EventInfo [nevents];
1294 for (int i = 0; i < nevents; ++i) {
1295 EventKind kind = (EventKind)r.ReadByte ();
1296 int req_id = r.ReadInt ();
1298 EventType etype = (EventType)kind;
1300 long thread_id = r.ReadId ();
1301 if (kind == EventKind.VM_START) {
1302 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id };
1303 //EventHandler.VMStart (req_id, thread_id, null);
1304 } else if (kind == EventKind.VM_DEATH) {
1306 if (Version.AtLeast (2, 27))
1307 exit_code = r.ReadInt ();
1308 //EventHandler.VMDeath (req_id, 0, null);
1309 events [i] = new EventInfo (etype, req_id) { ExitCode = exit_code };
1310 } else if (kind == EventKind.THREAD_START) {
1311 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = thread_id };
1312 //EventHandler.ThreadStart (req_id, thread_id, thread_id);
1313 } else if (kind == EventKind.THREAD_DEATH) {
1314 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = thread_id };
1315 //EventHandler.ThreadDeath (req_id, thread_id, thread_id);
1316 } else if (kind == EventKind.ASSEMBLY_LOAD) {
1317 long id = r.ReadId ();
1318 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1319 //EventHandler.AssemblyLoad (req_id, thread_id, id);
1320 } else if (kind == EventKind.ASSEMBLY_UNLOAD) {
1321 long id = r.ReadId ();
1322 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1323 //EventHandler.AssemblyUnload (req_id, thread_id, id);
1324 } else if (kind == EventKind.TYPE_LOAD) {
1325 long id = r.ReadId ();
1326 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1327 //EventHandler.TypeLoad (req_id, thread_id, id);
1328 } else if (kind == EventKind.METHOD_ENTRY) {
1329 long id = r.ReadId ();
1330 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1331 //EventHandler.MethodEntry (req_id, thread_id, id);
1332 } else if (kind == EventKind.METHOD_EXIT) {
1333 long id = r.ReadId ();
1334 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1335 //EventHandler.MethodExit (req_id, thread_id, id);
1336 } else if (kind == EventKind.BREAKPOINT) {
1337 long id = r.ReadId ();
1338 long loc = r.ReadLong ();
1339 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1340 //EventHandler.Breakpoint (req_id, thread_id, id, loc);
1341 } else if (kind == EventKind.STEP) {
1342 long id = r.ReadId ();
1343 long loc = r.ReadLong ();
1344 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1345 //EventHandler.Step (req_id, thread_id, id, loc);
1346 } else if (kind == EventKind.EXCEPTION) {
1347 long id = r.ReadId ();
1348 long loc = 0; // FIXME
1349 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1350 //EventHandler.Exception (req_id, thread_id, id, loc);
1351 } else if (kind == EventKind.APPDOMAIN_CREATE) {
1352 long id = r.ReadId ();
1353 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1354 //EventHandler.AppDomainCreate (req_id, thread_id, id);
1355 } else if (kind == EventKind.APPDOMAIN_UNLOAD) {
1356 long id = r.ReadId ();
1357 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1358 //EventHandler.AppDomainUnload (req_id, thread_id, id);
1359 } else if (kind == EventKind.USER_BREAK) {
1362 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1363 //EventHandler.Exception (req_id, thread_id, id, loc);
1364 } else if (kind == EventKind.USER_LOG) {
1365 int level = r.ReadInt ();
1366 string category = r.ReadString ();
1367 string message = r.ReadString ();
1368 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Level = level, Category = category, Message = message };
1369 //EventHandler.Exception (req_id, thread_id, id, loc);
1370 } else if (kind == EventKind.KEEPALIVE) {
1371 events [i] = new EventInfo (etype, req_id) { };
1373 throw new NotImplementedException ("Unknown event kind: " + kind);
1377 EventHandler.Events (suspend_policy, events);
1384 internal IEventHandler EventHandler {
1388 static String CommandString (CommandSet command_set, int command)
1391 switch (command_set) {
1393 cmd = ((CmdVM)command).ToString ();
1395 case CommandSet.OBJECT_REF:
1396 cmd = ((CmdObjectRef)command).ToString ();
1398 case CommandSet.STRING_REF:
1399 cmd = ((CmdStringRef)command).ToString ();
1401 case CommandSet.THREAD:
1402 cmd = ((CmdThread)command).ToString ();
1404 case CommandSet.ARRAY_REF:
1405 cmd = ((CmdArrayRef)command).ToString ();
1407 case CommandSet.EVENT_REQUEST:
1408 cmd = ((CmdEventRequest)command).ToString ();
1410 case CommandSet.STACK_FRAME:
1411 cmd = ((CmdStackFrame)command).ToString ();
1413 case CommandSet.APPDOMAIN:
1414 cmd = ((CmdAppDomain)command).ToString ();
1416 case CommandSet.ASSEMBLY:
1417 cmd = ((CmdAssembly)command).ToString ();
1419 case CommandSet.METHOD:
1420 cmd = ((CmdMethod)command).ToString ();
1422 case CommandSet.TYPE:
1423 cmd = ((CmdType)command).ToString ();
1425 case CommandSet.MODULE:
1426 cmd = ((CmdModule)command).ToString ();
1428 case CommandSet.FIELD:
1429 cmd = ((CmdField)command).ToString ();
1431 case CommandSet.EVENT:
1432 cmd = ((CmdEvent)command).ToString ();
1435 cmd = command.ToString ();
1438 return string.Format ("[{0} {1}]", command_set, cmd);
1441 long total_protocol_ticks;
1443 void LogPacket (int packet_id, byte[] encoded_packet, byte[] reply_packet, CommandSet command_set, int command, Stopwatch watch) {
1445 total_protocol_ticks += watch.ElapsedTicks;
1446 var ts = TimeSpan.FromTicks (total_protocol_ticks);
1447 string msg = string.Format ("Packet: {0} sent: {1} received: {2} ms: {3} total ms: {4} {5}",
1448 packet_id, encoded_packet.Length, reply_packet.Length, watch.ElapsedMilliseconds,
1449 (ts.Seconds * 1000) + ts.Milliseconds,
1450 CommandString (command_set, command));
1452 LoggingStream.WriteLine (msg);
1453 LoggingStream.Flush ();
1456 bool buffer_packets;
1457 List<byte[]> buffered_packets = new List<byte[]> ();
1460 // Start buffering request/response packets on both the client and the debuggee side.
1461 // Packets sent between StartBuffering ()/StopBuffering () must be async, i.e. sent
1462 // using Send () and not SendReceive ().
1464 public void StartBuffering () {
1465 buffer_packets = true;
1466 if (Version.AtLeast (2, 34))
1467 VM_StartBuffering ();
1470 public void StopBuffering () {
1471 if (Version.AtLeast (2, 34))
1472 VM_StopBuffering ();
1473 buffer_packets = false;
1475 WritePackets (buffered_packets);
1476 if (EnableConnectionLogging) {
1477 LoggingStream.WriteLine (String.Format ("Sent {0} packets.", buffered_packets.Count));
1478 LoggingStream.Flush ();
1480 buffered_packets.Clear ();
1483 /* Send a request and call cb when a result is received */
1484 int Send (CommandSet command_set, int command, PacketWriter packet, Action<PacketReader> cb, int count) {
1485 int id = IdGenerator;
1487 Stopwatch watch = null;
1488 if (EnableConnectionLogging)
1489 watch = Stopwatch.StartNew ();
1491 byte[] encoded_packet;
1493 encoded_packet = EncodePacket (id, (int)command_set, command, null, 0);
1495 encoded_packet = EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset);
1498 lock (reply_packets_monitor) {
1499 reply_cbs [id] = delegate (int packet_id, byte[] p) {
1500 if (EnableConnectionLogging)
1501 LogPacket (packet_id, encoded_packet, p, command_set, command, watch);
1502 /* Run the callback on a tp thread to avoid blocking the receive thread */
1503 PacketReader r = new PacketReader (p);
1504 cb.BeginInvoke (r, null, null);
1506 reply_cb_counts [id] = count;
1511 buffered_packets.Add (encoded_packet);
1513 WritePacket (encoded_packet);
1518 // Send a request without waiting for an answer
1519 void Send (CommandSet command_set, int command) {
1520 Send (command_set, command, null, null, 0);
1523 PacketReader SendReceive (CommandSet command_set, int command, PacketWriter packet) {
1524 int id = IdGenerator;
1525 Stopwatch watch = null;
1528 throw new VMDisconnectedException ();
1530 if (EnableConnectionLogging)
1531 watch = Stopwatch.StartNew ();
1533 byte[] encoded_packet;
1536 encoded_packet = EncodePacket (id, (int)command_set, command, null, 0);
1538 encoded_packet = EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset);
1540 WritePacket (encoded_packet);
1544 /* Wait for the reply packet */
1546 lock (reply_packets_monitor) {
1547 if (reply_packets.ContainsKey (packetId)) {
1548 byte[] reply = reply_packets [packetId];
1549 reply_packets.Remove (packetId);
1550 PacketReader r = new PacketReader (reply);
1552 if (EnableConnectionLogging)
1553 LogPacket (packetId, encoded_packet, reply, command_set, command, watch);
1554 if (r.ErrorCode != 0) {
1555 if (ErrorHandler != null)
1556 ErrorHandler (this, new ErrorHandlerEventArgs () { ErrorCode = (ErrorCode)r.ErrorCode });
1557 throw new NotImplementedException ("No error handler set.");
1563 throw new VMDisconnectedException ();
1564 Monitor.Wait (reply_packets_monitor);
1570 PacketReader SendReceive (CommandSet command_set, int command) {
1571 return SendReceive (command_set, command, null);
1574 int packet_id_generator;
1578 return Interlocked.Increment (ref packet_id_generator);
1582 CattrInfo[] ReadCattrs (PacketReader r) {
1583 CattrInfo[] res = new CattrInfo [r.ReadInt ()];
1584 for (int i = 0; i < res.Length; ++i) {
1585 CattrInfo info = new CattrInfo ();
1586 info.ctor_id = r.ReadId ();
1587 info.ctor_args = new ValueImpl [r.ReadInt ()];
1588 for (int j = 0; j < info.ctor_args.Length; ++j) {
1589 info.ctor_args [j] = r.ReadValue ();
1591 info.named_args = new CattrNamedArgInfo [r.ReadInt ()];
1592 for (int j = 0; j < info.named_args.Length; ++j) {
1593 CattrNamedArgInfo arg = new CattrNamedArgInfo ();
1594 int arg_type = r.ReadByte ();
1595 arg.is_property = arg_type == 0x54;
1596 arg.id = r.ReadId ();
1597 arg.value = r.ReadValue ();
1598 info.named_args [j] = arg;
1605 static ElementType TypeCodeToElementType (TypeCode c) {
1607 case TypeCode.Boolean:
1608 return ElementType.Boolean;
1610 return ElementType.Char;
1611 case TypeCode.SByte:
1612 return ElementType.I1;
1614 return ElementType.U1;
1615 case TypeCode.Int16:
1616 return ElementType.I2;
1617 case TypeCode.UInt16:
1618 return ElementType.U2;
1619 case TypeCode.Int32:
1620 return ElementType.I4;
1621 case TypeCode.UInt32:
1622 return ElementType.U4;
1623 case TypeCode.Int64:
1624 return ElementType.I8;
1625 case TypeCode.UInt64:
1626 return ElementType.U8;
1627 case TypeCode.Single:
1628 return ElementType.R4;
1629 case TypeCode.Double:
1630 return ElementType.R8;
1632 throw new NotImplementedException ();
1637 * Implementation of debugger commands
1640 internal VersionInfo VM_GetVersion () {
1641 var res = SendReceive (CommandSet.VM, (int)CmdVM.VERSION, null);
1642 VersionInfo info = new VersionInfo ();
1643 info.VMVersion = res.ReadString ();
1644 info.MajorVersion = res.ReadInt ();
1645 info.MinorVersion = res.ReadInt ();
1649 internal void VM_SetProtocolVersion (int major, int minor) {
1650 SendReceive (CommandSet.VM, (int)CmdVM.SET_PROTOCOL_VERSION, new PacketWriter ().WriteInt (major).WriteInt (minor));
1653 internal void VM_GetThreads (Action<long[]> resultCallaback) {
1654 Send (CommandSet.VM, (int)CmdVM.ALL_THREADS, null, (res) => {
1655 int len = res.ReadInt ();
1656 long[] arr = new long [len];
1657 for (int i = 0; i < len; ++i)
1658 arr [i] = res.ReadId ();
1659 resultCallaback(arr);
1663 internal void VM_Suspend () {
1664 SendReceive (CommandSet.VM, (int)CmdVM.SUSPEND);
1667 internal void VM_Resume () {
1668 SendReceive (CommandSet.VM, (int)CmdVM.RESUME);
1671 internal void VM_Exit (int exitCode) {
1672 SendReceive (CommandSet.VM, (int)CmdVM.EXIT, new PacketWriter ().WriteInt (exitCode));
1675 internal void VM_Dispose () {
1676 SendReceive (CommandSet.VM, (int)CmdVM.DISPOSE);
1679 internal ValueImpl VM_InvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, out ValueImpl exc) {
1681 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));
1682 if (r.ReadByte () == 0) {
1683 exc = r.ReadValue ();
1686 return r.ReadValue ();
1690 internal delegate void InvokeMethodCallback (ValueImpl v, ValueImpl exc, ValueImpl out_this, ValueImpl[] out_args, ErrorCode error, object state);
1692 void read_invoke_res (PacketReader r, out ValueImpl v, out ValueImpl exc, out ValueImpl out_this, out ValueImpl[] out_args) {
1693 int resflags = r.ReadByte ();
1698 if (resflags == 0) {
1699 exc = r.ReadValue ();
1702 if ((resflags & 2) != 0)
1703 out_this = r.ReadValue ();
1704 if ((resflags & 4) != 0) {
1705 int nargs = r.ReadInt ();
1706 out_args = new ValueImpl [nargs];
1707 for (int i = 0; i < nargs; ++i)
1708 out_args [i] = r.ReadValue ();
1713 internal int VM_BeginInvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, InvokeMethodCallback callback, object state) {
1714 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) {
1715 ValueImpl v, exc, out_this = null;
1716 ValueImpl[] out_args = null;
1718 if (r.ErrorCode != 0) {
1719 callback (null, null, null, null, (ErrorCode)r.ErrorCode, state);
1721 read_invoke_res (r, out v, out exc, out out_this, out out_args);
1722 callback (v, exc, out_this, out_args, 0, state);
1727 internal int VM_BeginInvokeMethods (long thread, long[] methods, ValueImpl this_arg, List<ValueImpl[]> arguments, InvokeFlags flags, InvokeMethodCallback callback, object state) {
1728 // FIXME: Merge this with INVOKE_METHOD
1729 var w = new PacketWriter ();
1731 w.WriteInt ((int)flags);
1732 w.WriteInt (methods.Length);
1733 for (int i = 0; i < methods.Length; ++i) {
1734 w.WriteId (methods [i]);
1735 w.WriteValue (this_arg);
1736 w.WriteInt (arguments [i].Length);
1737 w.WriteValues (arguments [i]);
1739 return Send (CommandSet.VM, (int)CmdVM.INVOKE_METHODS, w, delegate (PacketReader r) {
1740 ValueImpl v, exc, out_this = null;
1741 ValueImpl[] out_args = null;
1743 if (r.ErrorCode != 0) {
1744 callback (null, null, null, null, (ErrorCode)r.ErrorCode, state);
1746 read_invoke_res (r, out v, out exc, out out_this, out out_args);
1747 callback (v, exc, out_this, out_args, 0, state);
1752 internal void VM_AbortInvoke (long thread, int id)
1754 SendReceive (CommandSet.VM, (int)CmdVM.ABORT_INVOKE, new PacketWriter ().WriteId (thread).WriteInt (id));
1757 internal void SetSocketTimeouts (int send_timeout, int receive_timeout, int keepalive_interval)
1759 TransportSetTimeouts (send_timeout, receive_timeout);
1760 SendReceive (CommandSet.VM, (int)CmdVM.SET_KEEPALIVE, new PacketWriter ().WriteId (keepalive_interval));
1763 internal long[] VM_GetTypesForSourceFile (string fname, bool ignoreCase) {
1764 var res = SendReceive (CommandSet.VM, (int)CmdVM.GET_TYPES_FOR_SOURCE_FILE, new PacketWriter ().WriteString (fname).WriteBool (ignoreCase));
1765 int count = res.ReadInt ();
1766 long[] types = new long [count];
1767 for (int i = 0; i < count; ++i)
1768 types [i] = res.ReadId ();
1772 internal long[] VM_GetTypes (string name, bool ignoreCase) {
1773 var res = SendReceive (CommandSet.VM, (int)CmdVM.GET_TYPES, new PacketWriter ().WriteString (name).WriteBool (ignoreCase));
1774 int count = res.ReadInt ();
1775 long[] types = new long [count];
1776 for (int i = 0; i < count; ++i)
1777 types [i] = res.ReadId ();
1781 internal void VM_StartBuffering () {
1782 Send (CommandSet.VM, (int)CmdVM.START_BUFFERING);
1785 internal void VM_StopBuffering () {
1786 Send (CommandSet.VM, (int)CmdVM.STOP_BUFFERING);
1793 internal long RootDomain {
1795 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ROOT_DOMAIN, null).ReadId ();
1799 internal string Domain_GetName (long id) {
1800 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_FRIENDLY_NAME, new PacketWriter ().WriteId (id)).ReadString ();
1803 internal long[] Domain_GetAssemblies (long id) {
1804 var res = SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ASSEMBLIES, new PacketWriter ().WriteId (id));
1805 int count = res.ReadInt ();
1806 long[] assemblies = new long [count];
1807 for (int i = 0; i < count; ++i)
1808 assemblies [i] = res.ReadId ();
1812 internal long Domain_GetEntryAssembly (long id) {
1813 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ENTRY_ASSEMBLY, new PacketWriter ().WriteId (id)).ReadId ();
1816 internal long Domain_GetCorlib (long id) {
1817 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_CORLIB, new PacketWriter ().WriteId (id)).ReadId ();
1820 internal long Domain_CreateString (long id, string s) {
1821 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.CREATE_STRING, new PacketWriter ().WriteId (id).WriteString (s)).ReadId ();
1824 internal long Domain_CreateBoxedValue (long id, long type_id, ValueImpl v) {
1825 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.CREATE_BOXED_VALUE, new PacketWriter ().WriteId (id).WriteId (type_id).WriteValue (v)).ReadId ();
1832 internal string Method_GetName (long id) {
1833 return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
1836 internal long Method_GetDeclaringType (long id) {
1837 return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DECLARING_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
1840 internal DebugInfo Method_GetDebugInfo (long id) {
1841 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DEBUG_INFO, new PacketWriter ().WriteId (id));
1843 DebugInfo info = new DebugInfo ();
1844 info.max_il_offset = res.ReadInt ();
1846 SourceInfo[] sources = null;
1847 if (Version.AtLeast (2, 13)) {
1848 int n = res.ReadInt ();
1849 sources = new SourceInfo [n];
1850 for (int i = 0; i < n; ++i) {
1851 sources [i].source_file = res.ReadString ();
1852 if (Version.AtLeast (2, 14)) {
1853 sources [i].hash = new byte [16];
1854 for (int j = 0; j < 16; ++j)
1855 sources [i].hash [j] = (byte)res.ReadByte ();
1859 sources = new SourceInfo [1];
1860 sources [0].source_file = res.ReadString ();
1863 int n_il_offsets = res.ReadInt ();
1864 info.il_offsets = new int [n_il_offsets];
1865 info.line_numbers = new int [n_il_offsets];
1866 info.source_files = new SourceInfo [n_il_offsets];
1867 info.column_numbers = new int [n_il_offsets];
1868 info.end_line_numbers = new int [n_il_offsets];
1869 info.end_column_numbers = new int [n_il_offsets];
1870 for (int i = 0; i < n_il_offsets; ++i) {
1871 info.il_offsets [i] = res.ReadInt ();
1872 info.line_numbers [i] = res.ReadInt ();
1873 if (Version.AtLeast (2, 12)) {
1874 int idx = res.ReadInt ();
1875 info.source_files [i] = idx >= 0 ? sources [idx] : default (SourceInfo);
1877 info.source_files [i] = sources [0];
1879 if (Version.AtLeast (2, 19))
1880 info.column_numbers [i] = res.ReadInt ();
1882 info.column_numbers [i] = 0;
1883 if (Version.AtLeast (2, 32)) {
1884 info.end_line_numbers [i] = res.ReadInt ();
1885 info.end_column_numbers [i] = res.ReadInt ();
1887 info.end_column_numbers [i] = -1;
1888 info.end_column_numbers [i] = -1;
1895 internal ParamInfo Method_GetParamInfo (long id) {
1896 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_PARAM_INFO, new PacketWriter ().WriteId (id));
1898 ParamInfo info = new ParamInfo ();
1899 info.call_conv = res.ReadInt ();
1900 info.param_count = res.ReadInt ();
1901 info.generic_param_count = res.ReadInt ();
1902 info.ret_type = res.ReadId ();
1903 info.param_types = new long [info.param_count];
1904 for (int i = 0; i < info.param_count; ++i)
1905 info.param_types [i] = res.ReadId ();
1906 info.param_names = new string [info.param_count];
1907 for (int i = 0; i < info.param_count; ++i)
1908 info.param_names [i] = res.ReadString ();
1913 internal LocalsInfo Method_GetLocalsInfo (long id) {
1914 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_LOCALS_INFO, new PacketWriter ().WriteId (id));
1916 LocalsInfo info = new LocalsInfo ();
1918 if (Version.AtLeast (2, 43)) {
1919 int nscopes = res.ReadInt ();
1920 info.scopes_start = new int [nscopes];
1921 info.scopes_end = new int [nscopes];
1923 for (int i = 0; i < nscopes; ++i) {
1924 info.scopes_start [i] = last_start + res.ReadInt ();
1925 info.scopes_end [i] = info.scopes_start [i] + res.ReadInt ();
1926 last_start = info.scopes_start [i];
1930 int nlocals = res.ReadInt ();
1931 info.types = new long [nlocals];
1932 for (int i = 0; i < nlocals; ++i)
1933 info.types [i] = res.ReadId ();
1934 info.names = new string [nlocals];
1935 for (int i = 0; i < nlocals; ++i)
1936 info.names [i] = res.ReadString ();
1937 info.live_range_start = new int [nlocals];
1938 info.live_range_end = new int [nlocals];
1939 for (int i = 0; i < nlocals; ++i) {
1940 info.live_range_start [i] = res.ReadInt ();
1941 info.live_range_end [i] = res.ReadInt ();
1947 internal MethodInfo Method_GetInfo (long id) {
1948 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_INFO, new PacketWriter ().WriteId (id));
1950 MethodInfo info = new MethodInfo ();
1951 info.attributes = res.ReadInt ();
1952 info.iattributes = res.ReadInt ();
1953 info.token = res.ReadInt ();
1954 if (Version.AtLeast (2, 12)) {
1955 int attrs = res.ReadByte ();
1956 if ((attrs & (1 << 0)) != 0)
1958 if ((attrs & (1 << 1)) != 0)
1959 info.is_generic_method = true;
1960 info.gmd = res.ReadId ();
1961 if (Version.AtLeast (2, 15)) {
1962 if (info.is_generic_method) {
1963 int n = res.ReadInt ();
1964 info.type_args = res.ReadIds (n);
1971 internal MethodBodyInfo Method_GetBody (long id) {
1972 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_BODY, new PacketWriter ().WriteId (id));
1974 MethodBodyInfo info = new MethodBodyInfo ();
1975 info.il = new byte [res.ReadInt ()];
1976 for (int i = 0; i < info.il.Length; ++i)
1977 info.il [i] = (byte)res.ReadByte ();
1979 if (Version.AtLeast (2, 18)) {
1980 info.clauses = new ExceptionClauseInfo [res.ReadInt ()];
1982 for (int i = 0; i < info.clauses.Length; ++i) {
1983 var clause = new ExceptionClauseInfo {
1984 flags = (ExceptionClauseFlags) res.ReadInt (),
1985 try_offset = res.ReadInt (),
1986 try_length = res.ReadInt (),
1987 handler_offset = res.ReadInt (),
1988 handler_length = res.ReadInt (),
1991 if (clause.flags == ExceptionClauseFlags.None)
1992 clause.catch_type_id = res.ReadId ();
1993 else if (clause.flags == ExceptionClauseFlags.Filter)
1994 clause.filter_offset = res.ReadInt ();
1996 info.clauses [i] = clause;
1999 info.clauses = new ExceptionClauseInfo [0];
2004 internal ResolvedToken Method_ResolveToken (long id, int token) {
2005 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.RESOLVE_TOKEN, new PacketWriter ().WriteId (id).WriteInt (token));
2007 TokenType type = (TokenType)res.ReadByte ();
2009 case TokenType.STRING:
2010 return new ResolvedToken () { Type = type, Str = res.ReadString () };
2011 case TokenType.TYPE:
2012 case TokenType.METHOD:
2013 case TokenType.FIELD:
2014 return new ResolvedToken () { Type = type, Id = res.ReadId () };
2015 case TokenType.UNKNOWN:
2016 return new ResolvedToken () { Type = type };
2018 throw new NotImplementedException ();
2022 internal CattrInfo[] Method_GetCustomAttributes (long id, long attr_type_id, bool inherit) {
2023 PacketReader r = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_CATTRS, new PacketWriter ().WriteId (id).WriteId (attr_type_id));
2024 return ReadCattrs (r);
2027 internal long Method_MakeGenericMethod (long id, long[] args) {
2028 PacketReader r = SendReceive (CommandSet.METHOD, (int)CmdMethod.MAKE_GENERIC_METHOD, new PacketWriter ().WriteId (id).WriteInt (args.Length).WriteIds (args));
2036 internal string Thread_GetName (long id) {
2037 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
2040 internal void Thread_GetFrameInfo (long id, int start_frame, int length, Action<FrameInfo[]> resultCallaback) {
2041 Send (CommandSet.THREAD, (int)CmdThread.GET_FRAME_INFO, new PacketWriter ().WriteId (id).WriteInt (start_frame).WriteInt (length), (res) => {
2042 int count = res.ReadInt ();
2043 var frames = new FrameInfo[count];
2044 for (int i = 0; i < count; ++i) {
2045 var f = new FrameInfo ();
2046 f.id = res.ReadInt ();
2047 f.method = res.ReadId ();
2048 f.il_offset = res.ReadInt ();
2049 f.flags = (StackFrameFlags)res.ReadByte ();
2052 resultCallaback (frames);
2056 internal int Thread_GetState (long id) {
2057 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_STATE, new PacketWriter ().WriteId (id)).ReadInt ();
2060 internal ThreadInfo Thread_GetInfo (long id) {
2061 PacketReader r = SendReceive (CommandSet.THREAD, (int)CmdThread.GET_INFO, new PacketWriter ().WriteId (id));
2063 ThreadInfo res = new ThreadInfo () { is_thread_pool = r.ReadByte () > 0 ? true : false };
2068 internal long Thread_GetId (long id) {
2069 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_ID, new PacketWriter ().WriteId (id)).ReadLong ();
2072 internal long Thread_GetTID (long id) {
2073 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_TID, new PacketWriter ().WriteId (id)).ReadLong ();
2076 internal void Thread_SetIP (long id, long method_id, long il_offset) {
2077 SendReceive (CommandSet.THREAD, (int)CmdThread.SET_IP, new PacketWriter ().WriteId (id).WriteId (method_id).WriteLong (il_offset));
2084 internal ModuleInfo Module_GetInfo (long id) {
2085 PacketReader r = SendReceive (CommandSet.MODULE, (int)CmdModule.GET_INFO, new PacketWriter ().WriteId (id));
2086 ModuleInfo info = new ModuleInfo { Name = r.ReadString (), ScopeName = r.ReadString (), FQName = r.ReadString (), Guid = r.ReadString (), Assembly = r.ReadId () };
2094 internal string Assembly_GetLocation (long id) {
2095 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_LOCATION, new PacketWriter ().WriteId (id)).ReadString ();
2098 internal long Assembly_GetEntryPoint (long id) {
2099 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_ENTRY_POINT, new PacketWriter ().WriteId (id)).ReadId ();
2102 internal long Assembly_GetManifestModule (long id) {
2103 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_MANIFEST_MODULE, new PacketWriter ().WriteId (id)).ReadId ();
2106 internal long Assembly_GetObject (long id) {
2107 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
2110 internal long Assembly_GetType (long id, string name, bool ignoreCase) {
2111 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_TYPE, new PacketWriter ().WriteId (id).WriteString (name).WriteBool (ignoreCase)).ReadId ();
2114 internal string Assembly_GetName (long id) {
2115 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
2118 internal long Assembly_GetIdDomain (long id) {
2119 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_DOMAIN, new PacketWriter ().WriteId (id)).ReadId ();
2126 internal TypeInfo Type_GetInfo (long id) {
2127 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INFO, new PacketWriter ().WriteId (id));
2128 TypeInfo res = new TypeInfo ();
2130 res.ns = r.ReadString ();
2131 res.name = r.ReadString ();
2132 res.full_name = r.ReadString ();
2133 res.assembly = r.ReadId ();
2134 res.module = r.ReadId ();
2135 res.base_type = r.ReadId ();
2136 res.element_type = r.ReadId ();
2137 res.token = r.ReadInt ();
2138 res.rank = r.ReadByte ();
2139 res.attributes = r.ReadInt ();
2140 int b = r.ReadByte ();
2141 res.is_byref = (b & 1) != 0;
2142 res.is_pointer = (b & 2) != 0;
2143 res.is_primitive = (b & 4) != 0;
2144 res.is_valuetype = (b & 8) != 0;
2145 res.is_enum = (b & 16) != 0;
2146 res.is_gtd = (b & 32) != 0;
2147 res.is_generic_type = (b & 64) != 0;
2149 int nested_len = r.ReadInt ();
2150 res.nested = new long [nested_len];
2151 for (int i = 0; i < nested_len; ++i)
2152 res.nested [i] = r.ReadId ();
2154 if (Version.AtLeast (2, 12))
2155 res.gtd = r.ReadId ();
2156 if (Version.AtLeast (2, 15) && res.is_generic_type) {
2157 int n = r.ReadInt ();
2158 res.type_args = r.ReadIds (n);
2164 internal long[] Type_GetMethods (long id) {
2165 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_METHODS, new PacketWriter ().WriteId (id));
2167 int n = r.ReadInt ();
2168 long[] res = new long [n];
2169 for (int i = 0; i < n; ++i)
2170 res [i] = r.ReadId ();
2174 internal long[] Type_GetFields (long id, out string[] names, out long[] types, out int[] attrs) {
2175 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_FIELDS, new PacketWriter ().WriteId (id));
2177 int n = r.ReadInt ();
2178 long[] res = new long [n];
2179 names = new string [n];
2180 types = new long [n];
2181 attrs = new int [n];
2182 for (int i = 0; i < n; ++i) {
2183 res [i] = r.ReadId ();
2184 names [i] = r.ReadString ();
2185 types [i] = r.ReadId ();
2186 attrs [i] = r.ReadInt ();
2191 internal PropInfo[] Type_GetProperties (long id) {
2192 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_PROPERTIES, new PacketWriter ().WriteId (id));
2194 int n = r.ReadInt ();
2195 PropInfo[] res = new PropInfo [n];
2196 for (int i = 0; i < n; ++i) {
2197 res [i] = new PropInfo ();
2198 res [i].id = r.ReadId ();
2199 res [i].name = r.ReadString ();
2200 res [i].get_method = r.ReadId ();
2201 res [i].set_method = r.ReadId ();
2202 res [i].attrs = r.ReadInt ();
2208 internal long Type_GetObject (long id) {
2209 return SendReceive (CommandSet.TYPE, (int)CmdType.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
2212 internal ValueImpl[] Type_GetValues (long id, long[] fields, long thread_id) {
2213 int len = fields.Length;
2216 r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES_2, new PacketWriter ().WriteId (id).WriteId (thread_id).WriteInt (len).WriteIds (fields));
2218 r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));
2220 ValueImpl[] res = new ValueImpl [len];
2221 for (int i = 0; i < len; ++i)
2222 res [i] = r.ReadValue ();
2226 internal void Type_SetValues (long id, long[] fields, ValueImpl[] values) {
2227 SendReceive (CommandSet.TYPE, (int)CmdType.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
2230 internal string[] Type_GetSourceFiles (long id, bool return_full_paths) {
2231 var r = SendReceive (CommandSet.TYPE, return_full_paths ? (int)CmdType.GET_SOURCE_FILES_2 : (int)CmdType.GET_SOURCE_FILES, new PacketWriter ().WriteId (id));
2232 int len = r.ReadInt ();
2233 string[] res = new string [len];
2234 for (int i = 0; i < len; ++i)
2235 res [i] = r.ReadString ();
2239 internal bool Type_IsAssignableFrom (long id, long c_id) {
2240 return SendReceive (CommandSet.TYPE, (int)CmdType.IS_ASSIGNABLE_FROM, new PacketWriter ().WriteId (id).WriteId (c_id)).ReadByte () > 0;
2243 internal CattrInfo[] Type_GetCustomAttributes (long id, long attr_type_id, bool inherit) {
2244 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_CATTRS, new PacketWriter ().WriteId (id).WriteId (attr_type_id));
2245 return ReadCattrs (r);
2248 internal CattrInfo[] Type_GetFieldCustomAttributes (long id, long field_id, long attr_type_id, bool inherit) {
2249 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_FIELD_CATTRS, new PacketWriter ().WriteId (id).WriteId (field_id).WriteId (attr_type_id));
2250 return ReadCattrs (r);
2253 internal CattrInfo[] Type_GetPropertyCustomAttributes (long id, long field_id, long attr_type_id, bool inherit) {
2254 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_PROPERTY_CATTRS, new PacketWriter ().WriteId (id).WriteId (field_id).WriteId (attr_type_id));
2255 return ReadCattrs (r);
2258 public long[] Type_GetMethodsByNameFlags (long id, string name, int flags, bool ignoreCase) {
2259 flags |= ignoreCase ? (int)BindingFlagsExtensions.BINDING_FLAGS_IGNORE_CASE : 0;
2260 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.CMD_TYPE_GET_METHODS_BY_NAME_FLAGS, new PacketWriter ().WriteId (id).WriteString (name).WriteInt (flags));
2261 int len = r.ReadInt ();
2262 long[] res = new long [len];
2263 for (int i = 0; i < len; ++i)
2264 res [i] = r.ReadId ();
2268 internal long[] Type_GetInterfaces (long id) {
2269 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INTERFACES, new PacketWriter ().WriteId (id));
2270 int len = r.ReadInt ();
2271 return r.ReadIds (len);
2274 internal IfaceMapInfo[] Type_GetInterfaceMap (long id, long[] ids) {
2275 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INTERFACE_MAP, new PacketWriter ().WriteId (id).WriteInt (ids.Length).WriteIds (ids));
2276 var res = new IfaceMapInfo [ids.Length];
2277 for (int i = 0; i < ids.Length; ++i) {
2278 int n = r.ReadInt ();
2280 res [i].iface_id = ids [i];
2281 res [i].iface_methods = r.ReadIds (n);
2282 res [i].target_methods = r.ReadIds (n);
2288 internal bool Type_IsInitialized (long id) {
2289 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.IS_INITIALIZED, new PacketWriter ().WriteId (id));
2290 return r.ReadInt () == 1;
2293 internal long Type_CreateInstance (long id) {
2294 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.CREATE_INSTANCE, new PacketWriter ().WriteId (id));
2302 internal FieldMirrorInfo Field_GetInfo (long id) {
2303 PacketReader r = SendReceive (CommandSet.FIELD, (int)CmdField.GET_INFO, new PacketWriter ().WriteId (id));
2304 FieldMirrorInfo info = new FieldMirrorInfo { Name = r.ReadString (), Parent = r.ReadId (), TypeId = r.ReadId (), Attrs = r.ReadInt () };
2312 internal int EnableEvent (EventType etype, SuspendPolicy suspend_policy, List<Modifier> mods) {
2313 var w = new PacketWriter ().WriteByte ((byte)etype).WriteByte ((byte)suspend_policy);
2315 if (mods.Count > 255)
2316 throw new NotImplementedException ();
2317 w.WriteByte ((byte)mods.Count);
2318 foreach (Modifier mod in mods) {
2319 if (mod is CountModifier) {
2320 w.WriteByte ((byte)ModifierKind.COUNT);
2321 w.WriteInt ((mod as CountModifier).Count);
2322 } else if (mod is LocationModifier) {
2323 w.WriteByte ((byte)ModifierKind.LOCATION_ONLY);
2324 w.WriteId ((mod as LocationModifier).Method);
2325 w.WriteLong ((mod as LocationModifier).Location);
2326 } else if (mod is StepModifier) {
2327 w.WriteByte ((byte)ModifierKind.STEP);
2328 w.WriteId ((mod as StepModifier).Thread);
2329 w.WriteInt ((mod as StepModifier).Size);
2330 w.WriteInt ((mod as StepModifier).Depth);
2331 if (Version.AtLeast (2, 16))
2332 w.WriteInt ((mod as StepModifier).Filter);
2333 } else if (mod is ThreadModifier) {
2334 w.WriteByte ((byte)ModifierKind.THREAD_ONLY);
2335 w.WriteId ((mod as ThreadModifier).Thread);
2336 } else if (mod is ExceptionModifier) {
2337 var em = mod as ExceptionModifier;
2338 w.WriteByte ((byte)ModifierKind.EXCEPTION_ONLY);
2339 w.WriteId (em.Type);
2340 if (Version.MajorVersion > 2 || Version.MinorVersion > 0) {
2341 /* This is only supported in protocol version 2.1 */
2342 w.WriteBool (em.Caught);
2343 w.WriteBool (em.Uncaught);
2344 } else if (!em.Caught || !em.Uncaught) {
2345 throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
2347 if (Version.MajorVersion > 2 || Version.MinorVersion > 24) {
2348 w.WriteBool (em.Subclasses);
2349 } else if (!em.Subclasses) {
2350 throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
2352 } else if (mod is AssemblyModifier) {
2353 w.WriteByte ((byte)ModifierKind.ASSEMBLY_ONLY);
2354 var amod = (mod as AssemblyModifier);
2355 w.WriteInt (amod.Assemblies.Length);
2356 foreach (var id in amod.Assemblies)
2358 } else if (mod is SourceFileModifier) {
2359 w.WriteByte ((byte)ModifierKind.SOURCE_FILE_ONLY);
2360 var smod = (mod as SourceFileModifier);
2361 w.WriteInt (smod.SourceFiles.Length);
2362 foreach (var s in smod.SourceFiles)
2364 } else if (mod is TypeNameModifier) {
2365 w.WriteByte ((byte)ModifierKind.TYPE_NAME_ONLY);
2366 var tmod = (mod as TypeNameModifier);
2367 w.WriteInt (tmod.TypeNames.Length);
2368 foreach (var s in tmod.TypeNames)
2371 throw new NotImplementedException ();
2377 return SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.SET, w).ReadInt ();
2380 internal void ClearEventRequest (EventType etype, int req_id) {
2381 SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.CLEAR, new PacketWriter ().WriteByte ((byte)etype).WriteInt (req_id));
2384 internal void ClearAllBreakpoints () {
2385 SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.CLEAR_ALL_BREAKPOINTS, new PacketWriter ());
2391 internal ValueImpl StackFrame_GetThis (long thread_id, long id) {
2392 PacketReader r = SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_THIS, new PacketWriter ().WriteId (thread_id).WriteId (id));
2393 return r.ReadValue ();
2396 internal ValueImpl[] StackFrame_GetValues (long thread_id, long id, int[] pos) {
2397 /* pos < 0 -> argument at pos (-pos) - 1 */
2398 /* pos >= 0 -> local at pos */
2399 int len = pos.Length;
2400 PacketReader r = SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos));
2402 ValueImpl[] res = new ValueImpl [len];
2403 for (int i = 0; i < len; ++i)
2404 res [i] = r.ReadValue ();
2408 internal void StackFrame_SetValues (long thread_id, long id, int[] pos, ValueImpl[] values) {
2409 /* pos < 0 -> argument at pos (-pos) - 1 */
2410 /* pos >= 0 -> local at pos */
2411 int len = pos.Length;
2412 SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.SET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos).WriteValues (values));
2415 internal long StackFrame_GetDomain (long thread_id, long id) {
2416 return SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_DOMAIN, new PacketWriter ().WriteId (thread_id).WriteId (id)).ReadId ();
2419 internal void StackFrame_SetThis (long thread_id, long id, ValueImpl value) {
2420 SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.SET_THIS, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteValue (value));
2426 internal int[] Array_GetLength (long id, out int rank, out int[] lower_bounds) {
2427 var r = SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.GET_LENGTH, new PacketWriter ().WriteId (id));
2428 rank = r.ReadInt ();
2429 int[] res = new int [rank];
2430 lower_bounds = new int [rank];
2431 for (int i = 0; i < rank; ++i) {
2432 res [i] = r.ReadInt ();
2433 lower_bounds [i] = r.ReadInt ();
2438 internal ValueImpl[] Array_GetValues (long id, int index, int len) {
2439 var r = SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (len));
2440 ValueImpl[] res = new ValueImpl [len];
2441 for (int i = 0; i < len; ++i)
2442 res [i] = r.ReadValue ();
2446 internal void Array_SetValues (long id, int index, ValueImpl[] values) {
2447 SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (values.Length).WriteValues (values));
2453 internal string String_GetValue (long id) {
2454 var r = SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_VALUE, new PacketWriter ().WriteId (id));
2456 bool is_utf16 = false;
2457 if (Version.AtLeast (2, 41))
2458 is_utf16 = r.ReadByte () == 1;
2461 return r.ReadUTF16String ();
2463 return r.ReadString ();
2466 internal int String_GetLength (long id) {
2467 return (int)SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_LENGTH, new PacketWriter ().WriteId (id)).ReadLong ();
2470 internal char[] String_GetChars (long id, int index, int length) {
2471 var r = SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_CHARS, new PacketWriter ().WriteId (id).WriteLong (index).WriteLong (length));
2472 var res = new char [length];
2473 for (int i = 0; i < length; ++i)
2474 res [i] = (char)r.ReadShort ();
2481 internal long Object_GetType (long id) {
2482 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
2485 internal long Object_GetDomain (long id) {
2486 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_DOMAIN, new PacketWriter ().WriteId (id)).ReadId ();
2489 internal ValueImpl[] Object_GetValues (long id, long[] fields) {
2490 int len = fields.Length;
2491 PacketReader r = SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));
2493 ValueImpl[] res = new ValueImpl [len];
2494 for (int i = 0; i < len; ++i)
2495 res [i] = r.ReadValue ();
2499 internal void Object_SetValues (long id, long[] fields, ValueImpl[] values) {
2500 SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
2503 internal bool Object_IsCollected (long id) {
2504 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.IS_COLLECTED, new PacketWriter ().WriteId (id)).ReadInt () == 1;
2507 internal long Object_GetAddress (long id) {
2508 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_ADDRESS, new PacketWriter ().WriteId (id)).ReadLong ();
2511 internal ObjectRefInfo Object_GetInfo (long id) {
2512 ObjectRefInfo res = new ObjectRefInfo ();
2513 PacketReader r = SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_INFO, new PacketWriter ().WriteId (id));
2515 res.type_id = r.ReadId ();
2516 res.domain_id = r.ReadId ();
2520 public void ForceDisconnect ()
2523 disconnected = true;
2524 DisconnectedEvent.Set ();
2529 class TcpConnection : Connection
2533 internal TcpConnection (Socket socket)
2535 this.socket = socket;
2536 //socket.SetSocketOption (SocketOptionLevel.IP, SocketOptionName.NoDelay, 1);
2539 internal EndPoint EndPoint {
2541 return socket.RemoteEndPoint;
2545 protected override int TransportSend (byte[] buf, int buf_offset, int len)
2547 return socket.Send (buf, buf_offset, len, SocketFlags.None);
2550 protected override int TransportReceive (byte[] buf, int buf_offset, int len)
2552 return socket.Receive (buf, buf_offset, len, SocketFlags.None);
2555 protected override void TransportSetTimeouts (int send_timeout, int receive_timeout)
2557 socket.SendTimeout = send_timeout;
2558 socket.ReceiveTimeout = receive_timeout;
2561 protected override void TransportClose ()
2567 /* This is the interface exposed by the debugger towards the debugger agent */
2568 interface IEventHandler
2570 void Events (SuspendPolicy suspend_policy, EventInfo[] events);
2572 void VMDisconnect (int req_id, long thread_id, string vm_uri);