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;
125 public long get_method, set_method;
129 class CattrNamedArgInfo {
130 public bool is_property;
132 public ValueImpl value;
137 public ValueImpl[] ctor_args;
138 public CattrNamedArgInfo[] named_args;
142 public bool is_thread_pool;
145 struct ObjectRefInfo {
147 public long domain_id;
151 VALUE_TYPE_ID_NULL = 0xf0,
152 VALUE_TYPE_ID_TYPE = 0xf1,
153 VALUE_TYPE_ID_PARENT_VTYPE = 0xf2
159 DISABLE_BREAKPOINTS = 1,
209 public ElementType Type; /* or one of the VALUE_TYPE_ID constants */
212 public long Klass; // For ElementType.ValueType
213 public ValueImpl[] Fields; // for ElementType.ValueType
214 public bool IsEnum; // For ElementType.ValueType
215 public long Id; /* For VALUE_TYPE_ID_TYPE */
216 public int Index; /* For VALUE_TYPE_PARENT_VTYPE */
220 public string Name, ScopeName, FQName, Guid;
221 public long Assembly;
224 class FieldMirrorInfo {
226 public long Parent, TypeId;
239 enum StackFrameFlags {
242 NATIVE_TRANSITION = 2
245 class ResolvedToken {
246 public TokenType Type;
254 class CountModifier : Modifier {
260 class LocationModifier : Modifier {
265 public long Location {
270 class StepModifier : Modifier {
288 class ThreadModifier : Modifier {
294 class ExceptionModifier : Modifier {
301 public bool Uncaught {
304 public bool Subclasses {
309 class AssemblyModifier : Modifier {
310 public long[] Assemblies {
315 class SourceFileModifier : Modifier {
316 public string[] SourceFiles {
321 class TypeNameModifier : Modifier {
322 public string[] TypeNames {
328 public EventType EventType {
336 public SuspendPolicy SuspendPolicy {
340 public long ThreadId {
348 public long Location {
356 public string Category {
360 public string Message {
364 public int ExitCode {
368 public EventInfo (EventType type, int req_id) {
374 public enum ErrorCode {
377 INVALID_FIELDID = 25,
378 INVALID_FRAMEID = 30,
379 NOT_IMPLEMENTED = 100,
381 INVALID_ARGUMENT = 102,
383 ERR_NO_INVOCATION = 104,
384 ABSENT_INFORMATION = 105,
385 NO_SEQ_POINT_AT_IL_OFFSET = 106,
389 public class ErrorHandlerEventArgs : EventArgs {
391 public ErrorCode ErrorCode {
397 * Represents the connection to the debuggee
399 public abstract class Connection
402 * The protocol and the packet format is based on JDWP, the differences
403 * are in the set of supported events, and the commands.
405 internal const string HANDSHAKE_STRING = "DWP-Handshake";
407 internal const int HEADER_LENGTH = 11;
409 static readonly bool EnableConnectionLogging = !String.IsNullOrEmpty (Environment.GetEnvironmentVariable ("MONO_SDB_LOG"));
410 static int ConnectionId;
411 readonly StreamWriter LoggingStream;
414 * Th version of the wire-protocol implemented by the library. The library
415 * and the debuggee can communicate if they implement the same major version.
416 * If they implement a different minor version, they can communicate, but some
417 * features might not be available. This allows older clients to communicate
418 * with newer runtimes, and vice versa.
420 internal const int MAJOR_VERSION = 2;
421 internal const int MINOR_VERSION = 42;
423 enum WPSuspendPolicy {
451 APPDOMAIN_CREATE = 4, // Not in JDI
452 APPDOMAIN_UNLOAD = 5, // Not in JDI
473 SOURCE_FILE_ONLY = 12,
485 SET_PROTOCOL_VERSION = 8,
488 GET_TYPES_FOR_SOURCE_FILE = 11,
491 START_BUFFERING = 14,
504 /* FIXME: Merge into GET_INFO when the major protocol version is increased */
511 enum CmdEventRequest {
514 CLEAR_ALL_BREAKPOINTS = 3
519 GET_FRIENDLY_NAME = 2,
521 GET_ENTRY_ASSEMBLY = 4,
524 CREATE_BOXED_VALUE = 7
530 GET_MANIFEST_MODULE = 3,
542 GET_DECLARING_TYPE = 2,
550 MAKE_GENERIC_METHOD = 10
559 GET_SOURCE_FILES = 6,
561 IS_ASSIGNABLE_FROM = 8,
564 GET_FIELD_CATTRS = 11,
565 GET_PROPERTY_CATTRS = 12,
566 /* FIXME: Merge into GET_SOURCE_FILES when the major protocol version is increased */
567 GET_SOURCE_FILES_2 = 13,
568 /* FIXME: Merge into GET_VALUES when the major protocol version is increased */
570 CMD_TYPE_GET_METHODS_BY_NAME_FLAGS = 15,
572 GET_INTERFACE_MAP = 17,
582 enum BindingFlagsExtensions {
583 BINDING_FLAGS_IGNORE_CASE = 0x70000000,
617 public int command_set;
622 internal static int GetPacketLength (byte[] header) {
624 return decode_int (header, ref offset);
627 internal static bool IsReplyPacket (byte[] packet) {
629 return decode_byte (packet, ref offset) == 0x80;
632 internal static int GetPacketId (byte[] packet) {
634 return decode_int (packet, ref offset);
637 static int decode_byte (byte[] packet, ref int offset) {
638 return packet [offset++];
641 static int decode_short (byte[] packet, ref int offset) {
642 int res = ((int)packet [offset] << 8) | (int)packet [offset + 1];
647 static int decode_int (byte[] packet, ref int offset) {
648 int res = ((int)packet [offset] << 24) | ((int)packet [offset + 1] << 16) | ((int)packet [offset + 2] << 8) | (int)packet [offset + 3];
653 static long decode_id (byte[] packet, ref int offset) {
654 return decode_int (packet, ref offset);
657 static long decode_long (byte[] packet, ref int offset) {
658 uint high = (uint)decode_int (packet, ref offset);
659 uint low = (uint)decode_int (packet, ref offset);
661 return (long)(((ulong)high << 32) | (ulong)low);
664 internal static SuspendPolicy decode_suspend_policy (int suspend_policy) {
665 switch ((WPSuspendPolicy)suspend_policy) {
666 case WPSuspendPolicy.NONE:
667 return SuspendPolicy.None;
668 case WPSuspendPolicy.EVENT_THREAD:
669 return SuspendPolicy.EventThread;
670 case WPSuspendPolicy.ALL:
671 return SuspendPolicy.All;
673 throw new NotImplementedException ();
677 static Header decode_command_header (byte[] packet) {
679 Header res = new Header ();
681 decode_int (packet, ref offset);
682 res.id = decode_int (packet, ref offset);
683 res.flags = decode_byte (packet, ref offset);
684 res.command_set = decode_byte (packet, ref offset);
685 res.command = decode_byte (packet, ref offset);
690 static void encode_byte (byte[] buf, int b, ref int offset) {
691 buf [offset] = (byte)b;
695 static void encode_int (byte[] buf, int i, ref int offset) {
696 buf [offset] = (byte)((i >> 24) & 0xff);
697 buf [offset + 1] = (byte)((i >> 16) & 0xff);
698 buf [offset + 2] = (byte)((i >> 8) & 0xff);
699 buf [offset + 3] = (byte)((i >> 0) & 0xff);
703 static void encode_id (byte[] buf, long id, ref int offset) {
704 encode_int (buf, (int)id, ref offset);
707 static void encode_long (byte[] buf, long l, ref int offset) {
708 encode_int (buf, (int)((l >> 32) & 0xffffffff), ref offset);
709 encode_int (buf, (int)(l & 0xffffffff), ref offset);
712 internal static byte[] EncodePacket (int id, int commandSet, int command, byte[] data, int dataLen) {
713 byte[] buf = new byte [dataLen + 11];
716 encode_int (buf, buf.Length, ref offset);
717 encode_int (buf, id, ref offset);
718 encode_byte (buf, 0, ref offset);
719 encode_byte (buf, commandSet, ref offset);
720 encode_byte (buf, command, ref offset);
722 for (int i = 0; i < dataLen; ++i)
723 buf [offset + i] = data [i];
732 public PacketReader (byte[] packet) {
733 this.packet = packet;
736 Header header = decode_command_header (packet);
737 CommandSet = (CommandSet)header.command_set;
738 Command = header.command;
742 ReadInt (); // length
744 ReadByte (); // flags
745 ErrorCode = ReadShort ();
748 public CommandSet CommandSet {
756 public int ErrorCode {
766 public int ReadByte () {
767 return decode_byte (packet, ref offset);
770 public int ReadShort () {
771 return decode_short (packet, ref offset);
774 public int ReadInt () {
775 return decode_int (packet, ref offset);
778 public long ReadId () {
779 return decode_id (packet, ref offset);
782 public long ReadLong () {
783 return decode_long (packet, ref offset);
786 public float ReadFloat () {
787 float f = DataConverter.FloatFromBE (packet, offset);
792 public double ReadDouble () {
793 double d = DataConverter.DoubleFromBE (packet, offset);
798 public string ReadString () {
799 int len = decode_int (packet, ref offset);
800 string res = new String (Encoding.UTF8.GetChars (packet, offset, len));
805 public string ReadUTF16String () {
806 int len = decode_int (packet, ref offset);
807 string res = new String (Encoding.Unicode.GetChars (packet, offset, len));
812 public ValueImpl ReadValue () {
813 ElementType etype = (ElementType)ReadByte ();
816 case ElementType.Void:
817 return new ValueImpl { Type = etype };
819 return new ValueImpl { Type = etype, Value = (sbyte)ReadInt () };
821 return new ValueImpl { Type = etype, Value = (byte)ReadInt () };
822 case ElementType.Boolean:
823 return new ValueImpl { Type = etype, Value = ReadInt () != 0 };
825 return new ValueImpl { Type = etype, Value = (short)ReadInt () };
827 return new ValueImpl { Type = etype, Value = (ushort)ReadInt () };
828 case ElementType.Char:
829 return new ValueImpl { Type = etype, Value = (char)ReadInt () };
831 return new ValueImpl { Type = etype, Value = ReadInt () };
833 return new ValueImpl { Type = etype, Value = (uint)ReadInt () };
835 return new ValueImpl { Type = etype, Value = ReadLong () };
837 return new ValueImpl { Type = etype, Value = (ulong)ReadLong () };
839 return new ValueImpl { Type = etype, Value = ReadFloat () };
841 return new ValueImpl { Type = etype, Value = ReadDouble () };
844 case ElementType.Ptr:
845 // FIXME: The client and the debuggee might have different word sizes
846 return new ValueImpl { Type = etype, Value = ReadLong () };
847 case ElementType.String:
848 case ElementType.SzArray:
849 case ElementType.Class:
850 case ElementType.Array:
851 case ElementType.Object:
852 long objid = ReadId ();
853 return new ValueImpl () { Type = etype, Objid = objid };
854 case ElementType.ValueType:
855 bool is_enum = ReadByte () == 1;
856 long klass = ReadId ();
857 long nfields = ReadInt ();
858 ValueImpl[] fields = new ValueImpl [nfields];
859 for (int i = 0; i < nfields; ++i)
860 fields [i] = ReadValue ();
861 return new ValueImpl () { Type = etype, Klass = klass, Fields = fields, IsEnum = is_enum };
862 case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
863 return new ValueImpl { Type = etype };
864 case (ElementType)ValueTypeId.VALUE_TYPE_ID_TYPE:
865 return new ValueImpl () { Type = etype, Id = ReadId () };
866 case (ElementType)ValueTypeId.VALUE_TYPE_ID_PARENT_VTYPE:
867 return new ValueImpl () { Type = etype, Index = ReadInt () };
869 throw new NotImplementedException ("Unable to handle type " + etype);
873 public long[] ReadIds (int n) {
874 long[] res = new long [n];
875 for (int i = 0; i < n; ++i)
886 public PacketWriter () {
887 data = new byte [1024];
891 void MakeRoom (int size) {
892 if (offset + size >= data.Length) {
893 int new_len = data.Length * 2;
894 while (new_len < offset + size) {
897 byte[] new_data = new byte [new_len];
898 Array.Copy (data, new_data, data.Length);
903 public PacketWriter WriteByte (byte val) {
905 encode_byte (data, val, ref offset);
909 public PacketWriter WriteInt (int val) {
911 encode_int (data, val, ref offset);
915 public PacketWriter WriteId (long id) {
917 encode_id (data, id, ref offset);
921 public PacketWriter WriteLong (long val) {
923 encode_long (data, val, ref offset);
927 public PacketWriter WriteFloat (float f) {
929 byte[] b = DataConverter.GetBytesBE (f);
930 for (int i = 0; i < 4; ++i)
931 data [offset + i] = b [i];
936 public PacketWriter WriteDouble (double d) {
938 byte[] b = DataConverter.GetBytesBE (d);
939 for (int i = 0; i < 8; ++i)
940 data [offset + i] = b [i];
945 public PacketWriter WriteInts (int[] ids) {
946 for (int i = 0; i < ids.Length; ++i)
951 public PacketWriter WriteIds (long[] ids) {
952 for (int i = 0; i < ids.Length; ++i)
957 public PacketWriter WriteString (string s) {
959 return WriteInt (-1);
961 byte[] b = Encoding.UTF8.GetBytes (s);
963 encode_int (data, b.Length, ref offset);
965 Buffer.BlockCopy (b, 0, data, offset, b.Length);
970 public PacketWriter WriteBool (bool val) {
971 WriteByte (val ? (byte)1 : (byte)0);
975 public PacketWriter WriteValue (ValueImpl v) {
979 t = TypeCodeToElementType (Type.GetTypeCode (v.Value.GetType ()));
984 case ElementType.Boolean:
985 WriteInt ((bool)v.Value ? 1 : 0);
987 case ElementType.Char:
988 WriteInt ((int)(char)v.Value);
991 WriteInt ((int)(sbyte)v.Value);
994 WriteInt ((int)(byte)v.Value);
997 WriteInt ((int)(short)v.Value);
1000 WriteInt ((int)(ushort)v.Value);
1002 case ElementType.I4:
1003 WriteInt ((int)(int)v.Value);
1005 case ElementType.U4:
1006 WriteInt ((int)(uint)v.Value);
1008 case ElementType.I8:
1009 WriteLong ((long)(long)v.Value);
1011 case ElementType.U8:
1012 WriteLong ((long)(ulong)v.Value);
1014 case ElementType.R4:
1015 WriteFloat ((float)v.Value);
1017 case ElementType.R8:
1018 WriteDouble ((double)v.Value);
1020 case ElementType.String:
1021 case ElementType.SzArray:
1022 case ElementType.Class:
1023 case ElementType.Array:
1024 case ElementType.Object:
1027 case ElementType.ValueType:
1030 throw new NotImplementedException ();
1033 WriteInt (v.Fields.Length);
1034 for (int i = 0; i < v.Fields.Length; ++i)
1035 WriteValue (v.Fields [i]);
1037 case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
1040 throw new NotImplementedException ();
1046 public PacketWriter WriteValues (ValueImpl[] values) {
1047 for (int i = 0; i < values.Length; ++i)
1048 WriteValue (values [i]);
1052 public byte[] Data {
1065 delegate void ReplyCallback (int packet_id, byte[] packet);
1068 Thread receiver_thread;
1069 Dictionary<int, byte[]> reply_packets;
1070 Dictionary<int, ReplyCallback> reply_cbs;
1071 Dictionary<int, int> reply_cb_counts;
1072 object reply_packets_monitor;
1074 internal event EventHandler<ErrorHandlerEventArgs> ErrorHandler;
1076 protected Connection () {
1078 reply_packets = new Dictionary<int, byte[]> ();
1079 reply_cbs = new Dictionary<int, ReplyCallback> ();
1080 reply_cb_counts = new Dictionary<int, int> ();
1081 reply_packets_monitor = new Object ();
1082 if (EnableConnectionLogging) {
1083 var path = Environment.GetEnvironmentVariable ("MONO_SDB_LOG");
1084 if (path.Contains ("{0}")) {
1085 //C:\SomeDir\sdbLog{0}.txt -> C:\SomeDir\sdbLog1.txt
1086 LoggingStream = new StreamWriter (string.Format (path, ConnectionId++), false);
1087 } else if (Path.HasExtension (path)) {
1088 //C:\SomeDir\sdbLog.txt -> C:\SomeDir\sdbLog1.txt
1089 LoggingStream = new StreamWriter (Path.GetDirectoryName (path) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension (path) + ConnectionId++ + "." + Path.GetExtension (path), false);
1091 //C:\SomeDir\sdbLog -> C:\SomeDir\sdbLog1
1092 LoggingStream = new StreamWriter (path + ConnectionId++, false);
1097 protected abstract int TransportReceive (byte[] buf, int buf_offset, int len);
1098 protected abstract int TransportSend (byte[] buf, int buf_offset, int len);
1099 protected abstract void TransportSetTimeouts (int send_timeout, int receive_timeout);
1100 protected abstract void TransportClose ();
1102 internal VersionInfo Version;
1104 int Receive (byte[] buf, int buf_offset, int len) {
1107 while (offset < len) {
1108 int n = TransportReceive (buf, buf_offset + offset, len - offset);
1118 // Do the wire protocol handshake
1119 internal void Connect () {
1120 byte[] buf = new byte [HANDSHAKE_STRING.Length];
1121 char[] cbuf = new char [buf.Length];
1123 // FIXME: Add a timeout
1124 int n = Receive (buf, 0, buf.Length);
1126 throw new IOException ("DWP Handshake failed.");
1127 for (int i = 0; i < buf.Length; ++i)
1128 cbuf [i] = (char)buf [i];
1130 if (new String (cbuf) != HANDSHAKE_STRING)
1131 throw new IOException ("DWP Handshake failed.");
1133 TransportSend (buf, 0, buf.Length);
1135 receiver_thread = new Thread (new ThreadStart (receiver_thread_main));
1136 receiver_thread.Name = "SDB Receiver";
1137 receiver_thread.IsBackground = true;
1138 receiver_thread.Start ();
1140 Version = VM_GetVersion ();
1143 // Tell the debuggee our protocol version, so newer debuggees can work
1144 // with older clients
1148 // Older debuggees might not support this request
1149 EventHandler<ErrorHandlerEventArgs> OrigErrorHandler = ErrorHandler;
1150 ErrorHandler = null;
1151 ErrorHandler += delegate (object sender, ErrorHandlerEventArgs args) {
1152 throw new NotSupportedException ();
1155 VM_SetProtocolVersion (MAJOR_VERSION, MINOR_VERSION);
1156 } catch (NotSupportedException) {
1158 ErrorHandler = OrigErrorHandler;
1161 internal byte[] ReadPacket () {
1162 // FIXME: Throw ClosedConnectionException () if the connection is closed
1163 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1165 byte[] header = new byte [HEADER_LENGTH];
1167 int len = Receive (header, 0, header.Length);
1169 return new byte [0];
1170 if (len != HEADER_LENGTH) {
1172 throw new IOException ("Packet of length " + len + " is read.");
1175 int packetLength = GetPacketLength (header);
1176 if (packetLength < 11)
1177 throw new IOException ("Invalid packet length.");
1179 if (packetLength == 11) {
1182 byte[] buf = new byte [packetLength];
1183 for (int i = 0; i < header.Length; ++i)
1184 buf [i] = header [i];
1185 len = Receive (buf, header.Length, packetLength - header.Length);
1186 if (len != packetLength - header.Length)
1187 throw new IOException ();
1192 internal void WritePacket (byte[] packet) {
1193 // FIXME: Throw ClosedConnectionException () if the connection is closed
1194 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1196 TransportSend (packet, 0, packet.Length);
1199 internal void WritePackets (List<byte[]> packets) {
1200 // FIXME: Throw ClosedConnectionException () if the connection is closed
1201 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1204 for (int i = 0; i < packets.Count; ++i)
1205 len += packets [i].Length;
1206 byte[] data = new byte [len];
1208 for (int i = 0; i < packets.Count; ++i) {
1209 Buffer.BlockCopy (packets [i], 0, data, pos, packets [i].Length);
1210 pos += packets [i].Length;
1212 TransportSend (data, 0, data.Length);
1215 internal void Close () {
1219 internal bool IsClosed {
1227 internal ManualResetEvent DisconnectedEvent = new ManualResetEvent (false);
1229 void receiver_thread_main () {
1232 bool res = ReceivePacket ();
1235 } catch (Exception ex) {
1237 Console.WriteLine (ex);
1243 lock (reply_packets_monitor) {
1244 disconnected = true;
1245 DisconnectedEvent.Set ();
1246 Monitor.PulseAll (reply_packets_monitor);
1249 EventHandler.VMDisconnect (0, 0, null);
1252 bool ReceivePacket () {
1253 byte[] packet = ReadPacket ();
1255 if (packet.Length == 0) {
1259 if (IsReplyPacket (packet)) {
1260 int id = GetPacketId (packet);
1261 ReplyCallback cb = null;
1262 lock (reply_packets_monitor) {
1263 reply_cbs.TryGetValue (id, out cb);
1265 reply_packets [id] = packet;
1266 Monitor.PulseAll (reply_packets_monitor);
1268 int c = reply_cb_counts [id];
1271 reply_cbs.Remove (id);
1272 reply_cb_counts.Remove (id);
1278 cb.Invoke (id, packet);
1280 PacketReader r = new PacketReader (packet);
1282 if (r.CommandSet == CommandSet.EVENT && r.Command == (int)CmdEvent.COMPOSITE) {
1283 int spolicy = r.ReadByte ();
1284 int nevents = r.ReadInt ();
1286 SuspendPolicy suspend_policy = decode_suspend_policy (spolicy);
1288 EventInfo[] events = new EventInfo [nevents];
1290 for (int i = 0; i < nevents; ++i) {
1291 EventKind kind = (EventKind)r.ReadByte ();
1292 int req_id = r.ReadInt ();
1294 EventType etype = (EventType)kind;
1296 long thread_id = r.ReadId ();
1297 if (kind == EventKind.VM_START) {
1298 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id };
1299 //EventHandler.VMStart (req_id, thread_id, null);
1300 } else if (kind == EventKind.VM_DEATH) {
1302 if (Version.AtLeast (2, 27))
1303 exit_code = r.ReadInt ();
1304 //EventHandler.VMDeath (req_id, 0, null);
1305 events [i] = new EventInfo (etype, req_id) { ExitCode = exit_code };
1306 } else if (kind == EventKind.THREAD_START) {
1307 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = thread_id };
1308 //EventHandler.ThreadStart (req_id, thread_id, thread_id);
1309 } else if (kind == EventKind.THREAD_DEATH) {
1310 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = thread_id };
1311 //EventHandler.ThreadDeath (req_id, thread_id, thread_id);
1312 } else if (kind == EventKind.ASSEMBLY_LOAD) {
1313 long id = r.ReadId ();
1314 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1315 //EventHandler.AssemblyLoad (req_id, thread_id, id);
1316 } else if (kind == EventKind.ASSEMBLY_UNLOAD) {
1317 long id = r.ReadId ();
1318 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1319 //EventHandler.AssemblyUnload (req_id, thread_id, id);
1320 } else if (kind == EventKind.TYPE_LOAD) {
1321 long id = r.ReadId ();
1322 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1323 //EventHandler.TypeLoad (req_id, thread_id, id);
1324 } else if (kind == EventKind.METHOD_ENTRY) {
1325 long id = r.ReadId ();
1326 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1327 //EventHandler.MethodEntry (req_id, thread_id, id);
1328 } else if (kind == EventKind.METHOD_EXIT) {
1329 long id = r.ReadId ();
1330 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1331 //EventHandler.MethodExit (req_id, thread_id, id);
1332 } else if (kind == EventKind.BREAKPOINT) {
1333 long id = r.ReadId ();
1334 long loc = r.ReadLong ();
1335 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1336 //EventHandler.Breakpoint (req_id, thread_id, id, loc);
1337 } else if (kind == EventKind.STEP) {
1338 long id = r.ReadId ();
1339 long loc = r.ReadLong ();
1340 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1341 //EventHandler.Step (req_id, thread_id, id, loc);
1342 } else if (kind == EventKind.EXCEPTION) {
1343 long id = r.ReadId ();
1344 long loc = 0; // FIXME
1345 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1346 //EventHandler.Exception (req_id, thread_id, id, loc);
1347 } else if (kind == EventKind.APPDOMAIN_CREATE) {
1348 long id = r.ReadId ();
1349 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1350 //EventHandler.AppDomainCreate (req_id, thread_id, id);
1351 } else if (kind == EventKind.APPDOMAIN_UNLOAD) {
1352 long id = r.ReadId ();
1353 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1354 //EventHandler.AppDomainUnload (req_id, thread_id, id);
1355 } else if (kind == EventKind.USER_BREAK) {
1358 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1359 //EventHandler.Exception (req_id, thread_id, id, loc);
1360 } else if (kind == EventKind.USER_LOG) {
1361 int level = r.ReadInt ();
1362 string category = r.ReadString ();
1363 string message = r.ReadString ();
1364 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Level = level, Category = category, Message = message };
1365 //EventHandler.Exception (req_id, thread_id, id, loc);
1366 } else if (kind == EventKind.KEEPALIVE) {
1367 events [i] = new EventInfo (etype, req_id) { };
1369 throw new NotImplementedException ("Unknown event kind: " + kind);
1373 EventHandler.Events (suspend_policy, events);
1380 internal IEventHandler EventHandler {
1384 static String CommandString (CommandSet command_set, int command)
1387 switch (command_set) {
1389 cmd = ((CmdVM)command).ToString ();
1391 case CommandSet.OBJECT_REF:
1392 cmd = ((CmdObjectRef)command).ToString ();
1394 case CommandSet.STRING_REF:
1395 cmd = ((CmdStringRef)command).ToString ();
1397 case CommandSet.THREAD:
1398 cmd = ((CmdThread)command).ToString ();
1400 case CommandSet.ARRAY_REF:
1401 cmd = ((CmdArrayRef)command).ToString ();
1403 case CommandSet.EVENT_REQUEST:
1404 cmd = ((CmdEventRequest)command).ToString ();
1406 case CommandSet.STACK_FRAME:
1407 cmd = ((CmdStackFrame)command).ToString ();
1409 case CommandSet.APPDOMAIN:
1410 cmd = ((CmdAppDomain)command).ToString ();
1412 case CommandSet.ASSEMBLY:
1413 cmd = ((CmdAssembly)command).ToString ();
1415 case CommandSet.METHOD:
1416 cmd = ((CmdMethod)command).ToString ();
1418 case CommandSet.TYPE:
1419 cmd = ((CmdType)command).ToString ();
1421 case CommandSet.MODULE:
1422 cmd = ((CmdModule)command).ToString ();
1424 case CommandSet.FIELD:
1425 cmd = ((CmdField)command).ToString ();
1427 case CommandSet.EVENT:
1428 cmd = ((CmdEvent)command).ToString ();
1431 cmd = command.ToString ();
1434 return string.Format ("[{0} {1}]", command_set, cmd);
1437 long total_protocol_ticks;
1439 void LogPacket (int packet_id, byte[] encoded_packet, byte[] reply_packet, CommandSet command_set, int command, Stopwatch watch) {
1441 total_protocol_ticks += watch.ElapsedTicks;
1442 var ts = TimeSpan.FromTicks (total_protocol_ticks);
1443 string msg = string.Format ("Packet: {0} sent: {1} received: {2} ms: {3} total ms: {4} {5}",
1444 packet_id, encoded_packet.Length, reply_packet.Length, watch.ElapsedMilliseconds,
1445 (ts.Seconds * 1000) + ts.Milliseconds,
1446 CommandString (command_set, command));
1448 LoggingStream.WriteLine (msg);
1449 LoggingStream.Flush ();
1452 bool buffer_packets;
1453 List<byte[]> buffered_packets = new List<byte[]> ();
1456 // Start buffering request/response packets on both the client and the debuggee side.
1457 // Packets sent between StartBuffering ()/StopBuffering () must be async, i.e. sent
1458 // using Send () and not SendReceive ().
1460 public void StartBuffering () {
1461 buffer_packets = true;
1462 if (Version.AtLeast (2, 34))
1463 VM_StartBuffering ();
1466 public void StopBuffering () {
1467 if (Version.AtLeast (2, 34))
1468 VM_StopBuffering ();
1469 buffer_packets = false;
1471 WritePackets (buffered_packets);
1472 if (EnableConnectionLogging) {
1473 LoggingStream.WriteLine (String.Format ("Sent {0} packets.", buffered_packets.Count));
1474 LoggingStream.Flush ();
1476 buffered_packets.Clear ();
1479 /* Send a request and call cb when a result is received */
1480 int Send (CommandSet command_set, int command, PacketWriter packet, Action<PacketReader> cb, int count) {
1481 int id = IdGenerator;
1483 Stopwatch watch = null;
1484 if (EnableConnectionLogging)
1485 watch = Stopwatch.StartNew ();
1487 byte[] encoded_packet;
1489 encoded_packet = EncodePacket (id, (int)command_set, command, null, 0);
1491 encoded_packet = EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset);
1494 lock (reply_packets_monitor) {
1495 reply_cbs [id] = delegate (int packet_id, byte[] p) {
1496 if (EnableConnectionLogging)
1497 LogPacket (packet_id, encoded_packet, p, command_set, command, watch);
1498 /* Run the callback on a tp thread to avoid blocking the receive thread */
1499 PacketReader r = new PacketReader (p);
1500 cb.BeginInvoke (r, null, null);
1502 reply_cb_counts [id] = count;
1507 buffered_packets.Add (encoded_packet);
1509 WritePacket (encoded_packet);
1514 // Send a request without waiting for an answer
1515 void Send (CommandSet command_set, int command) {
1516 Send (command_set, command, null, null, 0);
1519 PacketReader SendReceive (CommandSet command_set, int command, PacketWriter packet) {
1520 int id = IdGenerator;
1521 Stopwatch watch = null;
1524 throw new VMDisconnectedException ();
1526 if (EnableConnectionLogging)
1527 watch = Stopwatch.StartNew ();
1529 byte[] encoded_packet;
1532 encoded_packet = EncodePacket (id, (int)command_set, command, null, 0);
1534 encoded_packet = EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset);
1536 WritePacket (encoded_packet);
1540 /* Wait for the reply packet */
1542 lock (reply_packets_monitor) {
1543 if (reply_packets.ContainsKey (packetId)) {
1544 byte[] reply = reply_packets [packetId];
1545 reply_packets.Remove (packetId);
1546 PacketReader r = new PacketReader (reply);
1548 if (EnableConnectionLogging)
1549 LogPacket (packetId, encoded_packet, reply, command_set, command, watch);
1550 if (r.ErrorCode != 0) {
1551 if (ErrorHandler != null)
1552 ErrorHandler (this, new ErrorHandlerEventArgs () { ErrorCode = (ErrorCode)r.ErrorCode });
1553 throw new NotImplementedException ("No error handler set.");
1559 throw new VMDisconnectedException ();
1560 Monitor.Wait (reply_packets_monitor);
1566 PacketReader SendReceive (CommandSet command_set, int command) {
1567 return SendReceive (command_set, command, null);
1570 int packet_id_generator;
1574 return Interlocked.Increment (ref packet_id_generator);
1578 CattrInfo[] ReadCattrs (PacketReader r) {
1579 CattrInfo[] res = new CattrInfo [r.ReadInt ()];
1580 for (int i = 0; i < res.Length; ++i) {
1581 CattrInfo info = new CattrInfo ();
1582 info.ctor_id = r.ReadId ();
1583 info.ctor_args = new ValueImpl [r.ReadInt ()];
1584 for (int j = 0; j < info.ctor_args.Length; ++j) {
1585 info.ctor_args [j] = r.ReadValue ();
1587 info.named_args = new CattrNamedArgInfo [r.ReadInt ()];
1588 for (int j = 0; j < info.named_args.Length; ++j) {
1589 CattrNamedArgInfo arg = new CattrNamedArgInfo ();
1590 int arg_type = r.ReadByte ();
1591 arg.is_property = arg_type == 0x54;
1592 arg.id = r.ReadId ();
1593 arg.value = r.ReadValue ();
1594 info.named_args [j] = arg;
1601 static ElementType TypeCodeToElementType (TypeCode c) {
1603 case TypeCode.Boolean:
1604 return ElementType.Boolean;
1606 return ElementType.Char;
1607 case TypeCode.SByte:
1608 return ElementType.I1;
1610 return ElementType.U1;
1611 case TypeCode.Int16:
1612 return ElementType.I2;
1613 case TypeCode.UInt16:
1614 return ElementType.U2;
1615 case TypeCode.Int32:
1616 return ElementType.I4;
1617 case TypeCode.UInt32:
1618 return ElementType.U4;
1619 case TypeCode.Int64:
1620 return ElementType.I8;
1621 case TypeCode.UInt64:
1622 return ElementType.U8;
1623 case TypeCode.Single:
1624 return ElementType.R4;
1625 case TypeCode.Double:
1626 return ElementType.R8;
1628 throw new NotImplementedException ();
1633 * Implementation of debugger commands
1636 internal VersionInfo VM_GetVersion () {
1637 var res = SendReceive (CommandSet.VM, (int)CmdVM.VERSION, null);
1638 VersionInfo info = new VersionInfo ();
1639 info.VMVersion = res.ReadString ();
1640 info.MajorVersion = res.ReadInt ();
1641 info.MinorVersion = res.ReadInt ();
1645 internal void VM_SetProtocolVersion (int major, int minor) {
1646 SendReceive (CommandSet.VM, (int)CmdVM.SET_PROTOCOL_VERSION, new PacketWriter ().WriteInt (major).WriteInt (minor));
1649 internal void VM_GetThreads (Action<long[]> resultCallaback) {
1650 Send (CommandSet.VM, (int)CmdVM.ALL_THREADS, null, (res) => {
1651 int len = res.ReadInt ();
1652 long[] arr = new long [len];
1653 for (int i = 0; i < len; ++i)
1654 arr [i] = res.ReadId ();
1655 resultCallaback(arr);
1659 internal void VM_Suspend () {
1660 SendReceive (CommandSet.VM, (int)CmdVM.SUSPEND);
1663 internal void VM_Resume () {
1664 SendReceive (CommandSet.VM, (int)CmdVM.RESUME);
1667 internal void VM_Exit (int exitCode) {
1668 SendReceive (CommandSet.VM, (int)CmdVM.EXIT, new PacketWriter ().WriteInt (exitCode));
1671 internal void VM_Dispose () {
1672 SendReceive (CommandSet.VM, (int)CmdVM.DISPOSE);
1675 internal ValueImpl VM_InvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, out ValueImpl exc) {
1677 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));
1678 if (r.ReadByte () == 0) {
1679 exc = r.ReadValue ();
1682 return r.ReadValue ();
1686 internal delegate void InvokeMethodCallback (ValueImpl v, ValueImpl exc, ValueImpl out_this, ValueImpl[] out_args, ErrorCode error, object state);
1688 void read_invoke_res (PacketReader r, out ValueImpl v, out ValueImpl exc, out ValueImpl out_this, out ValueImpl[] out_args) {
1689 int resflags = r.ReadByte ();
1694 if (resflags == 0) {
1695 exc = r.ReadValue ();
1698 if ((resflags & 2) != 0)
1699 out_this = r.ReadValue ();
1700 if ((resflags & 4) != 0) {
1701 int nargs = r.ReadInt ();
1702 out_args = new ValueImpl [nargs];
1703 for (int i = 0; i < nargs; ++i)
1704 out_args [i] = r.ReadValue ();
1709 internal int VM_BeginInvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, InvokeMethodCallback callback, object state) {
1710 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) {
1711 ValueImpl v, exc, out_this = null;
1712 ValueImpl[] out_args = null;
1714 if (r.ErrorCode != 0) {
1715 callback (null, null, null, null, (ErrorCode)r.ErrorCode, state);
1717 read_invoke_res (r, out v, out exc, out out_this, out out_args);
1718 callback (v, exc, out_this, out_args, 0, state);
1723 internal int VM_BeginInvokeMethods (long thread, long[] methods, ValueImpl this_arg, List<ValueImpl[]> arguments, InvokeFlags flags, InvokeMethodCallback callback, object state) {
1724 // FIXME: Merge this with INVOKE_METHOD
1725 var w = new PacketWriter ();
1727 w.WriteInt ((int)flags);
1728 w.WriteInt (methods.Length);
1729 for (int i = 0; i < methods.Length; ++i) {
1730 w.WriteId (methods [i]);
1731 w.WriteValue (this_arg);
1732 w.WriteInt (arguments [i].Length);
1733 w.WriteValues (arguments [i]);
1735 return Send (CommandSet.VM, (int)CmdVM.INVOKE_METHODS, w, delegate (PacketReader r) {
1736 ValueImpl v, exc, out_this = null;
1737 ValueImpl[] out_args = null;
1739 if (r.ErrorCode != 0) {
1740 callback (null, null, null, null, (ErrorCode)r.ErrorCode, state);
1742 read_invoke_res (r, out v, out exc, out out_this, out out_args);
1743 callback (v, exc, out_this, out_args, 0, state);
1748 internal void VM_AbortInvoke (long thread, int id)
1750 SendReceive (CommandSet.VM, (int)CmdVM.ABORT_INVOKE, new PacketWriter ().WriteId (thread).WriteInt (id));
1753 internal void SetSocketTimeouts (int send_timeout, int receive_timeout, int keepalive_interval)
1755 TransportSetTimeouts (send_timeout, receive_timeout);
1756 SendReceive (CommandSet.VM, (int)CmdVM.SET_KEEPALIVE, new PacketWriter ().WriteId (keepalive_interval));
1759 internal long[] VM_GetTypesForSourceFile (string fname, bool ignoreCase) {
1760 var res = SendReceive (CommandSet.VM, (int)CmdVM.GET_TYPES_FOR_SOURCE_FILE, new PacketWriter ().WriteString (fname).WriteBool (ignoreCase));
1761 int count = res.ReadInt ();
1762 long[] types = new long [count];
1763 for (int i = 0; i < count; ++i)
1764 types [i] = res.ReadId ();
1768 internal long[] VM_GetTypes (string name, bool ignoreCase) {
1769 var res = SendReceive (CommandSet.VM, (int)CmdVM.GET_TYPES, new PacketWriter ().WriteString (name).WriteBool (ignoreCase));
1770 int count = res.ReadInt ();
1771 long[] types = new long [count];
1772 for (int i = 0; i < count; ++i)
1773 types [i] = res.ReadId ();
1777 internal void VM_StartBuffering () {
1778 Send (CommandSet.VM, (int)CmdVM.START_BUFFERING);
1781 internal void VM_StopBuffering () {
1782 Send (CommandSet.VM, (int)CmdVM.STOP_BUFFERING);
1789 internal long RootDomain {
1791 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ROOT_DOMAIN, null).ReadId ();
1795 internal string Domain_GetName (long id) {
1796 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_FRIENDLY_NAME, new PacketWriter ().WriteId (id)).ReadString ();
1799 internal long[] Domain_GetAssemblies (long id) {
1800 var res = SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ASSEMBLIES, new PacketWriter ().WriteId (id));
1801 int count = res.ReadInt ();
1802 long[] assemblies = new long [count];
1803 for (int i = 0; i < count; ++i)
1804 assemblies [i] = res.ReadId ();
1808 internal long Domain_GetEntryAssembly (long id) {
1809 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ENTRY_ASSEMBLY, new PacketWriter ().WriteId (id)).ReadId ();
1812 internal long Domain_GetCorlib (long id) {
1813 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_CORLIB, new PacketWriter ().WriteId (id)).ReadId ();
1816 internal long Domain_CreateString (long id, string s) {
1817 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.CREATE_STRING, new PacketWriter ().WriteId (id).WriteString (s)).ReadId ();
1820 internal long Domain_CreateBoxedValue (long id, long type_id, ValueImpl v) {
1821 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.CREATE_BOXED_VALUE, new PacketWriter ().WriteId (id).WriteId (type_id).WriteValue (v)).ReadId ();
1828 internal string Method_GetName (long id) {
1829 return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
1832 internal long Method_GetDeclaringType (long id) {
1833 return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DECLARING_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
1836 internal DebugInfo Method_GetDebugInfo (long id) {
1837 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DEBUG_INFO, new PacketWriter ().WriteId (id));
1839 DebugInfo info = new DebugInfo ();
1840 info.max_il_offset = res.ReadInt ();
1842 SourceInfo[] sources = null;
1843 if (Version.AtLeast (2, 13)) {
1844 int n = res.ReadInt ();
1845 sources = new SourceInfo [n];
1846 for (int i = 0; i < n; ++i) {
1847 sources [i].source_file = res.ReadString ();
1848 if (Version.AtLeast (2, 14)) {
1849 sources [i].hash = new byte [16];
1850 for (int j = 0; j < 16; ++j)
1851 sources [i].hash [j] = (byte)res.ReadByte ();
1855 sources = new SourceInfo [1];
1856 sources [0].source_file = res.ReadString ();
1859 int n_il_offsets = res.ReadInt ();
1860 info.il_offsets = new int [n_il_offsets];
1861 info.line_numbers = new int [n_il_offsets];
1862 info.source_files = new SourceInfo [n_il_offsets];
1863 info.column_numbers = new int [n_il_offsets];
1864 info.end_line_numbers = new int [n_il_offsets];
1865 info.end_column_numbers = new int [n_il_offsets];
1866 for (int i = 0; i < n_il_offsets; ++i) {
1867 info.il_offsets [i] = res.ReadInt ();
1868 info.line_numbers [i] = res.ReadInt ();
1869 if (Version.AtLeast (2, 12)) {
1870 int idx = res.ReadInt ();
1871 info.source_files [i] = idx >= 0 ? sources [idx] : default (SourceInfo);
1873 info.source_files [i] = sources [0];
1875 if (Version.AtLeast (2, 19))
1876 info.column_numbers [i] = res.ReadInt ();
1878 info.column_numbers [i] = 0;
1879 if (Version.AtLeast (2, 32)) {
1880 info.end_line_numbers [i] = res.ReadInt ();
1881 info.end_column_numbers [i] = res.ReadInt ();
1883 info.end_column_numbers [i] = -1;
1884 info.end_column_numbers [i] = -1;
1891 internal ParamInfo Method_GetParamInfo (long id) {
1892 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_PARAM_INFO, new PacketWriter ().WriteId (id));
1894 ParamInfo info = new ParamInfo ();
1895 info.call_conv = res.ReadInt ();
1896 info.param_count = res.ReadInt ();
1897 info.generic_param_count = res.ReadInt ();
1898 info.ret_type = res.ReadId ();
1899 info.param_types = new long [info.param_count];
1900 for (int i = 0; i < info.param_count; ++i)
1901 info.param_types [i] = res.ReadId ();
1902 info.param_names = new string [info.param_count];
1903 for (int i = 0; i < info.param_count; ++i)
1904 info.param_names [i] = res.ReadString ();
1909 internal LocalsInfo Method_GetLocalsInfo (long id) {
1910 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_LOCALS_INFO, new PacketWriter ().WriteId (id));
1912 LocalsInfo info = new LocalsInfo ();
1913 int nlocals = res.ReadInt ();
1914 info.types = new long [nlocals];
1915 for (int i = 0; i < nlocals; ++i)
1916 info.types [i] = res.ReadId ();
1917 info.names = new string [nlocals];
1918 for (int i = 0; i < nlocals; ++i)
1919 info.names [i] = res.ReadString ();
1920 info.live_range_start = new int [nlocals];
1921 info.live_range_end = new int [nlocals];
1922 for (int i = 0; i < nlocals; ++i) {
1923 info.live_range_start [i] = res.ReadInt ();
1924 info.live_range_end [i] = res.ReadInt ();
1930 internal MethodInfo Method_GetInfo (long id) {
1931 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_INFO, new PacketWriter ().WriteId (id));
1933 MethodInfo info = new MethodInfo ();
1934 info.attributes = res.ReadInt ();
1935 info.iattributes = res.ReadInt ();
1936 info.token = res.ReadInt ();
1937 if (Version.AtLeast (2, 12)) {
1938 int attrs = res.ReadByte ();
1939 if ((attrs & (1 << 0)) != 0)
1941 if ((attrs & (1 << 1)) != 0)
1942 info.is_generic_method = true;
1943 info.gmd = res.ReadId ();
1944 if (Version.AtLeast (2, 15)) {
1945 if (info.is_generic_method) {
1946 int n = res.ReadInt ();
1947 info.type_args = res.ReadIds (n);
1954 internal MethodBodyInfo Method_GetBody (long id) {
1955 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_BODY, new PacketWriter ().WriteId (id));
1957 MethodBodyInfo info = new MethodBodyInfo ();
1958 info.il = new byte [res.ReadInt ()];
1959 for (int i = 0; i < info.il.Length; ++i)
1960 info.il [i] = (byte)res.ReadByte ();
1962 if (Version.AtLeast (2, 18)) {
1963 info.clauses = new ExceptionClauseInfo [res.ReadInt ()];
1965 for (int i = 0; i < info.clauses.Length; ++i) {
1966 var clause = new ExceptionClauseInfo {
1967 flags = (ExceptionClauseFlags) res.ReadInt (),
1968 try_offset = res.ReadInt (),
1969 try_length = res.ReadInt (),
1970 handler_offset = res.ReadInt (),
1971 handler_length = res.ReadInt (),
1974 if (clause.flags == ExceptionClauseFlags.None)
1975 clause.catch_type_id = res.ReadId ();
1976 else if (clause.flags == ExceptionClauseFlags.Filter)
1977 clause.filter_offset = res.ReadInt ();
1979 info.clauses [i] = clause;
1982 info.clauses = new ExceptionClauseInfo [0];
1987 internal ResolvedToken Method_ResolveToken (long id, int token) {
1988 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.RESOLVE_TOKEN, new PacketWriter ().WriteId (id).WriteInt (token));
1990 TokenType type = (TokenType)res.ReadByte ();
1992 case TokenType.STRING:
1993 return new ResolvedToken () { Type = type, Str = res.ReadString () };
1994 case TokenType.TYPE:
1995 case TokenType.METHOD:
1996 case TokenType.FIELD:
1997 return new ResolvedToken () { Type = type, Id = res.ReadId () };
1998 case TokenType.UNKNOWN:
1999 return new ResolvedToken () { Type = type };
2001 throw new NotImplementedException ();
2005 internal CattrInfo[] Method_GetCustomAttributes (long id, long attr_type_id, bool inherit) {
2006 PacketReader r = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_CATTRS, new PacketWriter ().WriteId (id).WriteId (attr_type_id));
2007 return ReadCattrs (r);
2010 internal long Method_MakeGenericMethod (long id, long[] args) {
2011 PacketReader r = SendReceive (CommandSet.METHOD, (int)CmdMethod.MAKE_GENERIC_METHOD, new PacketWriter ().WriteId (id).WriteInt (args.Length).WriteIds (args));
2019 internal string Thread_GetName (long id) {
2020 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
2023 internal void Thread_GetFrameInfo (long id, int start_frame, int length, Action<FrameInfo[]> resultCallaback) {
2024 Send (CommandSet.THREAD, (int)CmdThread.GET_FRAME_INFO, new PacketWriter ().WriteId (id).WriteInt (start_frame).WriteInt (length), (res) => {
2025 int count = res.ReadInt ();
2026 var frames = new FrameInfo[count];
2027 for (int i = 0; i < count; ++i) {
2028 var f = new FrameInfo ();
2029 f.id = res.ReadInt ();
2030 f.method = res.ReadId ();
2031 f.il_offset = res.ReadInt ();
2032 f.flags = (StackFrameFlags)res.ReadByte ();
2035 resultCallaback (frames);
2039 internal int Thread_GetState (long id) {
2040 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_STATE, new PacketWriter ().WriteId (id)).ReadInt ();
2043 internal ThreadInfo Thread_GetInfo (long id) {
2044 PacketReader r = SendReceive (CommandSet.THREAD, (int)CmdThread.GET_INFO, new PacketWriter ().WriteId (id));
2046 ThreadInfo res = new ThreadInfo () { is_thread_pool = r.ReadByte () > 0 ? true : false };
2051 internal long Thread_GetId (long id) {
2052 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_ID, new PacketWriter ().WriteId (id)).ReadLong ();
2055 internal long Thread_GetTID (long id) {
2056 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_TID, new PacketWriter ().WriteId (id)).ReadLong ();
2059 internal void Thread_SetIP (long id, long method_id, long il_offset) {
2060 SendReceive (CommandSet.THREAD, (int)CmdThread.SET_IP, new PacketWriter ().WriteId (id).WriteId (method_id).WriteLong (il_offset));
2067 internal ModuleInfo Module_GetInfo (long id) {
2068 PacketReader r = SendReceive (CommandSet.MODULE, (int)CmdModule.GET_INFO, new PacketWriter ().WriteId (id));
2069 ModuleInfo info = new ModuleInfo { Name = r.ReadString (), ScopeName = r.ReadString (), FQName = r.ReadString (), Guid = r.ReadString (), Assembly = r.ReadId () };
2077 internal string Assembly_GetLocation (long id) {
2078 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_LOCATION, new PacketWriter ().WriteId (id)).ReadString ();
2081 internal long Assembly_GetEntryPoint (long id) {
2082 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_ENTRY_POINT, new PacketWriter ().WriteId (id)).ReadId ();
2085 internal long Assembly_GetManifestModule (long id) {
2086 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_MANIFEST_MODULE, new PacketWriter ().WriteId (id)).ReadId ();
2089 internal long Assembly_GetObject (long id) {
2090 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
2093 internal long Assembly_GetType (long id, string name, bool ignoreCase) {
2094 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_TYPE, new PacketWriter ().WriteId (id).WriteString (name).WriteBool (ignoreCase)).ReadId ();
2097 internal string Assembly_GetName (long id) {
2098 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
2105 internal TypeInfo Type_GetInfo (long id) {
2106 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INFO, new PacketWriter ().WriteId (id));
2107 TypeInfo res = new TypeInfo ();
2109 res.ns = r.ReadString ();
2110 res.name = r.ReadString ();
2111 res.full_name = r.ReadString ();
2112 res.assembly = r.ReadId ();
2113 res.module = r.ReadId ();
2114 res.base_type = r.ReadId ();
2115 res.element_type = r.ReadId ();
2116 res.token = r.ReadInt ();
2117 res.rank = r.ReadByte ();
2118 res.attributes = r.ReadInt ();
2119 int b = r.ReadByte ();
2120 res.is_byref = (b & 1) != 0;
2121 res.is_pointer = (b & 2) != 0;
2122 res.is_primitive = (b & 4) != 0;
2123 res.is_valuetype = (b & 8) != 0;
2124 res.is_enum = (b & 16) != 0;
2125 res.is_gtd = (b & 32) != 0;
2126 res.is_generic_type = (b & 64) != 0;
2128 int nested_len = r.ReadInt ();
2129 res.nested = new long [nested_len];
2130 for (int i = 0; i < nested_len; ++i)
2131 res.nested [i] = r.ReadId ();
2133 if (Version.AtLeast (2, 12))
2134 res.gtd = r.ReadId ();
2135 if (Version.AtLeast (2, 15) && res.is_generic_type) {
2136 int n = r.ReadInt ();
2137 res.type_args = r.ReadIds (n);
2143 internal long[] Type_GetMethods (long id) {
2144 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_METHODS, new PacketWriter ().WriteId (id));
2146 int n = r.ReadInt ();
2147 long[] res = new long [n];
2148 for (int i = 0; i < n; ++i)
2149 res [i] = r.ReadId ();
2153 internal long[] Type_GetFields (long id, out string[] names, out long[] types, out int[] attrs) {
2154 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_FIELDS, new PacketWriter ().WriteId (id));
2156 int n = r.ReadInt ();
2157 long[] res = new long [n];
2158 names = new string [n];
2159 types = new long [n];
2160 attrs = new int [n];
2161 for (int i = 0; i < n; ++i) {
2162 res [i] = r.ReadId ();
2163 names [i] = r.ReadString ();
2164 types [i] = r.ReadId ();
2165 attrs [i] = r.ReadInt ();
2170 internal PropInfo[] Type_GetProperties (long id) {
2171 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_PROPERTIES, new PacketWriter ().WriteId (id));
2173 int n = r.ReadInt ();
2174 PropInfo[] res = new PropInfo [n];
2175 for (int i = 0; i < n; ++i) {
2176 res [i] = new PropInfo ();
2177 res [i].id = r.ReadId ();
2178 res [i].name = r.ReadString ();
2179 res [i].get_method = r.ReadId ();
2180 res [i].set_method = r.ReadId ();
2181 res [i].attrs = r.ReadInt ();
2187 internal long Type_GetObject (long id) {
2188 return SendReceive (CommandSet.TYPE, (int)CmdType.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
2191 internal ValueImpl[] Type_GetValues (long id, long[] fields, long thread_id) {
2192 int len = fields.Length;
2195 r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES_2, new PacketWriter ().WriteId (id).WriteId (thread_id).WriteInt (len).WriteIds (fields));
2197 r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));
2199 ValueImpl[] res = new ValueImpl [len];
2200 for (int i = 0; i < len; ++i)
2201 res [i] = r.ReadValue ();
2205 internal void Type_SetValues (long id, long[] fields, ValueImpl[] values) {
2206 SendReceive (CommandSet.TYPE, (int)CmdType.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
2209 internal string[] Type_GetSourceFiles (long id, bool return_full_paths) {
2210 var r = SendReceive (CommandSet.TYPE, return_full_paths ? (int)CmdType.GET_SOURCE_FILES_2 : (int)CmdType.GET_SOURCE_FILES, new PacketWriter ().WriteId (id));
2211 int len = r.ReadInt ();
2212 string[] res = new string [len];
2213 for (int i = 0; i < len; ++i)
2214 res [i] = r.ReadString ();
2218 internal bool Type_IsAssignableFrom (long id, long c_id) {
2219 return SendReceive (CommandSet.TYPE, (int)CmdType.IS_ASSIGNABLE_FROM, new PacketWriter ().WriteId (id).WriteId (c_id)).ReadByte () > 0;
2222 internal CattrInfo[] Type_GetCustomAttributes (long id, long attr_type_id, bool inherit) {
2223 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_CATTRS, new PacketWriter ().WriteId (id).WriteId (attr_type_id));
2224 return ReadCattrs (r);
2227 internal CattrInfo[] Type_GetFieldCustomAttributes (long id, long field_id, long attr_type_id, bool inherit) {
2228 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_FIELD_CATTRS, new PacketWriter ().WriteId (id).WriteId (field_id).WriteId (attr_type_id));
2229 return ReadCattrs (r);
2232 internal CattrInfo[] Type_GetPropertyCustomAttributes (long id, long field_id, long attr_type_id, bool inherit) {
2233 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_PROPERTY_CATTRS, new PacketWriter ().WriteId (id).WriteId (field_id).WriteId (attr_type_id));
2234 return ReadCattrs (r);
2237 public long[] Type_GetMethodsByNameFlags (long id, string name, int flags, bool ignoreCase) {
2238 flags |= ignoreCase ? (int)BindingFlagsExtensions.BINDING_FLAGS_IGNORE_CASE : 0;
2239 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.CMD_TYPE_GET_METHODS_BY_NAME_FLAGS, new PacketWriter ().WriteId (id).WriteString (name).WriteInt (flags));
2240 int len = r.ReadInt ();
2241 long[] res = new long [len];
2242 for (int i = 0; i < len; ++i)
2243 res [i] = r.ReadId ();
2247 internal long[] Type_GetInterfaces (long id) {
2248 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INTERFACES, new PacketWriter ().WriteId (id));
2249 int len = r.ReadInt ();
2250 return r.ReadIds (len);
2253 internal IfaceMapInfo[] Type_GetInterfaceMap (long id, long[] ids) {
2254 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INTERFACE_MAP, new PacketWriter ().WriteId (id).WriteInt (ids.Length).WriteIds (ids));
2255 var res = new IfaceMapInfo [ids.Length];
2256 for (int i = 0; i < ids.Length; ++i) {
2257 int n = r.ReadInt ();
2259 res [i].iface_id = ids [i];
2260 res [i].iface_methods = r.ReadIds (n);
2261 res [i].target_methods = r.ReadIds (n);
2267 internal bool Type_IsInitialized (long id) {
2268 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.IS_INITIALIZED, new PacketWriter ().WriteId (id));
2269 return r.ReadInt () == 1;
2272 internal long Type_CreateInstance (long id) {
2273 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.CREATE_INSTANCE, new PacketWriter ().WriteId (id));
2281 internal FieldMirrorInfo Field_GetInfo (long id) {
2282 PacketReader r = SendReceive (CommandSet.FIELD, (int)CmdField.GET_INFO, new PacketWriter ().WriteId (id));
2283 FieldMirrorInfo info = new FieldMirrorInfo { Name = r.ReadString (), Parent = r.ReadId (), TypeId = r.ReadId (), Attrs = r.ReadInt () };
2291 internal int EnableEvent (EventType etype, SuspendPolicy suspend_policy, List<Modifier> mods) {
2292 var w = new PacketWriter ().WriteByte ((byte)etype).WriteByte ((byte)suspend_policy);
2294 if (mods.Count > 255)
2295 throw new NotImplementedException ();
2296 w.WriteByte ((byte)mods.Count);
2297 foreach (Modifier mod in mods) {
2298 if (mod is CountModifier) {
2299 w.WriteByte ((byte)ModifierKind.COUNT);
2300 w.WriteInt ((mod as CountModifier).Count);
2301 } else if (mod is LocationModifier) {
2302 w.WriteByte ((byte)ModifierKind.LOCATION_ONLY);
2303 w.WriteId ((mod as LocationModifier).Method);
2304 w.WriteLong ((mod as LocationModifier).Location);
2305 } else if (mod is StepModifier) {
2306 w.WriteByte ((byte)ModifierKind.STEP);
2307 w.WriteId ((mod as StepModifier).Thread);
2308 w.WriteInt ((mod as StepModifier).Size);
2309 w.WriteInt ((mod as StepModifier).Depth);
2310 if (Version.AtLeast (2, 16))
2311 w.WriteInt ((mod as StepModifier).Filter);
2312 } else if (mod is ThreadModifier) {
2313 w.WriteByte ((byte)ModifierKind.THREAD_ONLY);
2314 w.WriteId ((mod as ThreadModifier).Thread);
2315 } else if (mod is ExceptionModifier) {
2316 var em = mod as ExceptionModifier;
2317 w.WriteByte ((byte)ModifierKind.EXCEPTION_ONLY);
2318 w.WriteId (em.Type);
2319 if (Version.MajorVersion > 2 || Version.MinorVersion > 0) {
2320 /* This is only supported in protocol version 2.1 */
2321 w.WriteBool (em.Caught);
2322 w.WriteBool (em.Uncaught);
2323 } else if (!em.Caught || !em.Uncaught) {
2324 throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
2326 if (Version.MajorVersion > 2 || Version.MinorVersion > 24) {
2327 w.WriteBool (em.Subclasses);
2328 } else if (!em.Subclasses) {
2329 throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
2331 } else if (mod is AssemblyModifier) {
2332 w.WriteByte ((byte)ModifierKind.ASSEMBLY_ONLY);
2333 var amod = (mod as AssemblyModifier);
2334 w.WriteInt (amod.Assemblies.Length);
2335 foreach (var id in amod.Assemblies)
2337 } else if (mod is SourceFileModifier) {
2338 w.WriteByte ((byte)ModifierKind.SOURCE_FILE_ONLY);
2339 var smod = (mod as SourceFileModifier);
2340 w.WriteInt (smod.SourceFiles.Length);
2341 foreach (var s in smod.SourceFiles)
2343 } else if (mod is TypeNameModifier) {
2344 w.WriteByte ((byte)ModifierKind.TYPE_NAME_ONLY);
2345 var tmod = (mod as TypeNameModifier);
2346 w.WriteInt (tmod.TypeNames.Length);
2347 foreach (var s in tmod.TypeNames)
2350 throw new NotImplementedException ();
2356 return SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.SET, w).ReadInt ();
2359 internal void ClearEventRequest (EventType etype, int req_id) {
2360 SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.CLEAR, new PacketWriter ().WriteByte ((byte)etype).WriteInt (req_id));
2363 internal void ClearAllBreakpoints () {
2364 SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.CLEAR_ALL_BREAKPOINTS, new PacketWriter ());
2370 internal ValueImpl StackFrame_GetThis (long thread_id, long id) {
2371 PacketReader r = SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_THIS, new PacketWriter ().WriteId (thread_id).WriteId (id));
2372 return r.ReadValue ();
2375 internal ValueImpl[] StackFrame_GetValues (long thread_id, long id, int[] pos) {
2376 /* pos < 0 -> argument at pos (-pos) - 1 */
2377 /* pos >= 0 -> local at pos */
2378 int len = pos.Length;
2379 PacketReader r = SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos));
2381 ValueImpl[] res = new ValueImpl [len];
2382 for (int i = 0; i < len; ++i)
2383 res [i] = r.ReadValue ();
2387 internal void StackFrame_SetValues (long thread_id, long id, int[] pos, ValueImpl[] values) {
2388 /* pos < 0 -> argument at pos (-pos) - 1 */
2389 /* pos >= 0 -> local at pos */
2390 int len = pos.Length;
2391 SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.SET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos).WriteValues (values));
2394 internal long StackFrame_GetDomain (long thread_id, long id) {
2395 return SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_DOMAIN, new PacketWriter ().WriteId (thread_id).WriteId (id)).ReadId ();
2401 internal int[] Array_GetLength (long id, out int rank, out int[] lower_bounds) {
2402 var r = SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.GET_LENGTH, new PacketWriter ().WriteId (id));
2403 rank = r.ReadInt ();
2404 int[] res = new int [rank];
2405 lower_bounds = new int [rank];
2406 for (int i = 0; i < rank; ++i) {
2407 res [i] = r.ReadInt ();
2408 lower_bounds [i] = r.ReadInt ();
2413 internal ValueImpl[] Array_GetValues (long id, int index, int len) {
2414 var r = SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (len));
2415 ValueImpl[] res = new ValueImpl [len];
2416 for (int i = 0; i < len; ++i)
2417 res [i] = r.ReadValue ();
2421 internal void Array_SetValues (long id, int index, ValueImpl[] values) {
2422 SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (values.Length).WriteValues (values));
2428 internal string String_GetValue (long id) {
2429 var r = SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_VALUE, new PacketWriter ().WriteId (id));
2431 bool is_utf16 = false;
2432 if (Version.AtLeast (2, 41))
2433 is_utf16 = r.ReadByte () == 1;
2436 return r.ReadUTF16String ();
2438 return r.ReadString ();
2441 internal int String_GetLength (long id) {
2442 return (int)SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_LENGTH, new PacketWriter ().WriteId (id)).ReadLong ();
2445 internal char[] String_GetChars (long id, int index, int length) {
2446 var r = SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_CHARS, new PacketWriter ().WriteId (id).WriteLong (index).WriteLong (length));
2447 var res = new char [length];
2448 for (int i = 0; i < length; ++i)
2449 res [i] = (char)r.ReadShort ();
2456 internal long Object_GetType (long id) {
2457 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
2460 internal long Object_GetDomain (long id) {
2461 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_DOMAIN, new PacketWriter ().WriteId (id)).ReadId ();
2464 internal ValueImpl[] Object_GetValues (long id, long[] fields) {
2465 int len = fields.Length;
2466 PacketReader r = SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));
2468 ValueImpl[] res = new ValueImpl [len];
2469 for (int i = 0; i < len; ++i)
2470 res [i] = r.ReadValue ();
2474 internal void Object_SetValues (long id, long[] fields, ValueImpl[] values) {
2475 SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
2478 internal bool Object_IsCollected (long id) {
2479 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.IS_COLLECTED, new PacketWriter ().WriteId (id)).ReadInt () == 1;
2482 internal long Object_GetAddress (long id) {
2483 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_ADDRESS, new PacketWriter ().WriteId (id)).ReadLong ();
2486 internal ObjectRefInfo Object_GetInfo (long id) {
2487 ObjectRefInfo res = new ObjectRefInfo ();
2488 PacketReader r = SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_INFO, new PacketWriter ().WriteId (id));
2490 res.type_id = r.ReadId ();
2491 res.domain_id = r.ReadId ();
2495 public void ForceDisconnect ()
2498 disconnected = true;
2499 DisconnectedEvent.Set ();
2504 class TcpConnection : Connection
2508 internal TcpConnection (Socket socket)
2510 this.socket = socket;
2511 //socket.SetSocketOption (SocketOptionLevel.IP, SocketOptionName.NoDelay, 1);
2514 internal EndPoint EndPoint {
2516 return socket.RemoteEndPoint;
2520 protected override int TransportSend (byte[] buf, int buf_offset, int len)
2522 return socket.Send (buf, buf_offset, len, SocketFlags.None);
2525 protected override int TransportReceive (byte[] buf, int buf_offset, int len)
2527 return socket.Receive (buf, buf_offset, len, SocketFlags.None);
2530 protected override void TransportSetTimeouts (int send_timeout, int receive_timeout)
2532 socket.SendTimeout = send_timeout;
2533 socket.ReceiveTimeout = receive_timeout;
2536 protected override void TransportClose ()
2542 /* This is the interface exposed by the debugger towards the debugger agent */
2543 interface IEventHandler
2545 void Events (SuspendPolicy suspend_policy, EventInfo[] events);
2547 void VMDisconnect (int req_id, long thread_id, string vm_uri);