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
388 public class ErrorHandlerEventArgs : EventArgs {
390 public ErrorCode ErrorCode {
396 * Represents the connection to the debuggee
398 public abstract class Connection
401 * The protocol and the packet format is based on JDWP, the differences
402 * are in the set of supported events, and the commands.
404 internal const string HANDSHAKE_STRING = "DWP-Handshake";
406 internal const int HEADER_LENGTH = 11;
408 static readonly bool EnableConnectionLogging = !String.IsNullOrEmpty (Environment.GetEnvironmentVariable ("MONO_SDB_LOG"));
409 static int ConnectionId;
410 readonly StreamWriter LoggingStream;
413 * Th version of the wire-protocol implemented by the library. The library
414 * and the debuggee can communicate if they implement the same major version.
415 * If they implement a different minor version, they can communicate, but some
416 * features might not be available. This allows older clients to communicate
417 * with newer runtimes, and vice versa.
419 internal const int MAJOR_VERSION = 2;
420 internal const int MINOR_VERSION = 41;
422 enum WPSuspendPolicy {
450 APPDOMAIN_CREATE = 4, // Not in JDI
451 APPDOMAIN_UNLOAD = 5, // Not in JDI
472 SOURCE_FILE_ONLY = 12,
484 SET_PROTOCOL_VERSION = 8,
487 GET_TYPES_FOR_SOURCE_FILE = 11,
490 START_BUFFERING = 14,
503 /* FIXME: Merge into GET_INFO when the major protocol version is increased */
510 enum CmdEventRequest {
513 CLEAR_ALL_BREAKPOINTS = 3
518 GET_FRIENDLY_NAME = 2,
520 GET_ENTRY_ASSEMBLY = 4,
523 CREATE_BOXED_VALUE = 7
529 GET_MANIFEST_MODULE = 3,
541 GET_DECLARING_TYPE = 2,
549 MAKE_GENERIC_METHOD = 10
558 GET_SOURCE_FILES = 6,
560 IS_ASSIGNABLE_FROM = 8,
563 GET_FIELD_CATTRS = 11,
564 GET_PROPERTY_CATTRS = 12,
565 /* FIXME: Merge into GET_SOURCE_FILES when the major protocol version is increased */
566 GET_SOURCE_FILES_2 = 13,
567 /* FIXME: Merge into GET_VALUES when the major protocol version is increased */
569 CMD_TYPE_GET_METHODS_BY_NAME_FLAGS = 15,
571 GET_INTERFACE_MAP = 17,
581 enum BindingFlagsExtensions {
582 BINDING_FLAGS_IGNORE_CASE = 0x70000000,
616 public int command_set;
621 internal static int GetPacketLength (byte[] header) {
623 return decode_int (header, ref offset);
626 internal static bool IsReplyPacket (byte[] packet) {
628 return decode_byte (packet, ref offset) == 0x80;
631 internal static int GetPacketId (byte[] packet) {
633 return decode_int (packet, ref offset);
636 static int decode_byte (byte[] packet, ref int offset) {
637 return packet [offset++];
640 static int decode_short (byte[] packet, ref int offset) {
641 int res = ((int)packet [offset] << 8) | (int)packet [offset + 1];
646 static int decode_int (byte[] packet, ref int offset) {
647 int res = ((int)packet [offset] << 24) | ((int)packet [offset + 1] << 16) | ((int)packet [offset + 2] << 8) | (int)packet [offset + 3];
652 static long decode_id (byte[] packet, ref int offset) {
653 return decode_int (packet, ref offset);
656 static long decode_long (byte[] packet, ref int offset) {
657 uint high = (uint)decode_int (packet, ref offset);
658 uint low = (uint)decode_int (packet, ref offset);
660 return (long)(((ulong)high << 32) | (ulong)low);
663 internal static SuspendPolicy decode_suspend_policy (int suspend_policy) {
664 switch ((WPSuspendPolicy)suspend_policy) {
665 case WPSuspendPolicy.NONE:
666 return SuspendPolicy.None;
667 case WPSuspendPolicy.EVENT_THREAD:
668 return SuspendPolicy.EventThread;
669 case WPSuspendPolicy.ALL:
670 return SuspendPolicy.All;
672 throw new NotImplementedException ();
676 static Header decode_command_header (byte[] packet) {
678 Header res = new Header ();
680 decode_int (packet, ref offset);
681 res.id = decode_int (packet, ref offset);
682 res.flags = decode_byte (packet, ref offset);
683 res.command_set = decode_byte (packet, ref offset);
684 res.command = decode_byte (packet, ref offset);
689 static void encode_byte (byte[] buf, int b, ref int offset) {
690 buf [offset] = (byte)b;
694 static void encode_int (byte[] buf, int i, ref int offset) {
695 buf [offset] = (byte)((i >> 24) & 0xff);
696 buf [offset + 1] = (byte)((i >> 16) & 0xff);
697 buf [offset + 2] = (byte)((i >> 8) & 0xff);
698 buf [offset + 3] = (byte)((i >> 0) & 0xff);
702 static void encode_id (byte[] buf, long id, ref int offset) {
703 encode_int (buf, (int)id, ref offset);
706 static void encode_long (byte[] buf, long l, ref int offset) {
707 encode_int (buf, (int)((l >> 32) & 0xffffffff), ref offset);
708 encode_int (buf, (int)(l & 0xffffffff), ref offset);
711 internal static byte[] EncodePacket (int id, int commandSet, int command, byte[] data, int dataLen) {
712 byte[] buf = new byte [dataLen + 11];
715 encode_int (buf, buf.Length, ref offset);
716 encode_int (buf, id, ref offset);
717 encode_byte (buf, 0, ref offset);
718 encode_byte (buf, commandSet, ref offset);
719 encode_byte (buf, command, ref offset);
721 for (int i = 0; i < dataLen; ++i)
722 buf [offset + i] = data [i];
731 public PacketReader (byte[] packet) {
732 this.packet = packet;
735 Header header = decode_command_header (packet);
736 CommandSet = (CommandSet)header.command_set;
737 Command = header.command;
741 ReadInt (); // length
743 ReadByte (); // flags
744 ErrorCode = ReadShort ();
747 public CommandSet CommandSet {
755 public int ErrorCode {
765 public int ReadByte () {
766 return decode_byte (packet, ref offset);
769 public int ReadShort () {
770 return decode_short (packet, ref offset);
773 public int ReadInt () {
774 return decode_int (packet, ref offset);
777 public long ReadId () {
778 return decode_id (packet, ref offset);
781 public long ReadLong () {
782 return decode_long (packet, ref offset);
785 public float ReadFloat () {
786 float f = DataConverter.FloatFromBE (packet, offset);
791 public double ReadDouble () {
792 double d = DataConverter.DoubleFromBE (packet, offset);
797 public string ReadString () {
798 int len = decode_int (packet, ref offset);
799 string res = new String (Encoding.UTF8.GetChars (packet, offset, len));
804 public string ReadUTF16String () {
805 int len = decode_int (packet, ref offset);
806 string res = new String (Encoding.Unicode.GetChars (packet, offset, len));
811 public ValueImpl ReadValue () {
812 ElementType etype = (ElementType)ReadByte ();
815 case ElementType.Void:
816 return new ValueImpl { Type = etype };
818 return new ValueImpl { Type = etype, Value = (sbyte)ReadInt () };
820 return new ValueImpl { Type = etype, Value = (byte)ReadInt () };
821 case ElementType.Boolean:
822 return new ValueImpl { Type = etype, Value = ReadInt () != 0 };
824 return new ValueImpl { Type = etype, Value = (short)ReadInt () };
826 return new ValueImpl { Type = etype, Value = (ushort)ReadInt () };
827 case ElementType.Char:
828 return new ValueImpl { Type = etype, Value = (char)ReadInt () };
830 return new ValueImpl { Type = etype, Value = ReadInt () };
832 return new ValueImpl { Type = etype, Value = (uint)ReadInt () };
834 return new ValueImpl { Type = etype, Value = ReadLong () };
836 return new ValueImpl { Type = etype, Value = (ulong)ReadLong () };
838 return new ValueImpl { Type = etype, Value = ReadFloat () };
840 return new ValueImpl { Type = etype, Value = ReadDouble () };
843 case ElementType.Ptr:
844 // FIXME: The client and the debuggee might have different word sizes
845 return new ValueImpl { Type = etype, Value = ReadLong () };
846 case ElementType.String:
847 case ElementType.SzArray:
848 case ElementType.Class:
849 case ElementType.Array:
850 case ElementType.Object:
851 long objid = ReadId ();
852 return new ValueImpl () { Type = etype, Objid = objid };
853 case ElementType.ValueType:
854 bool is_enum = ReadByte () == 1;
855 long klass = ReadId ();
856 long nfields = ReadInt ();
857 ValueImpl[] fields = new ValueImpl [nfields];
858 for (int i = 0; i < nfields; ++i)
859 fields [i] = ReadValue ();
860 return new ValueImpl () { Type = etype, Klass = klass, Fields = fields, IsEnum = is_enum };
861 case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
862 return new ValueImpl { Type = etype };
863 case (ElementType)ValueTypeId.VALUE_TYPE_ID_TYPE:
864 return new ValueImpl () { Type = etype, Id = ReadId () };
865 case (ElementType)ValueTypeId.VALUE_TYPE_ID_PARENT_VTYPE:
866 return new ValueImpl () { Type = etype, Index = ReadInt () };
868 throw new NotImplementedException ("Unable to handle type " + etype);
872 public long[] ReadIds (int n) {
873 long[] res = new long [n];
874 for (int i = 0; i < n; ++i)
885 public PacketWriter () {
886 data = new byte [1024];
890 void MakeRoom (int size) {
891 if (offset + size >= data.Length) {
892 int new_len = data.Length * 2;
893 while (new_len < offset + size) {
896 byte[] new_data = new byte [new_len];
897 Array.Copy (data, new_data, data.Length);
902 public PacketWriter WriteByte (byte val) {
904 encode_byte (data, val, ref offset);
908 public PacketWriter WriteInt (int val) {
910 encode_int (data, val, ref offset);
914 public PacketWriter WriteId (long id) {
916 encode_id (data, id, ref offset);
920 public PacketWriter WriteLong (long val) {
922 encode_long (data, val, ref offset);
926 public PacketWriter WriteFloat (float f) {
928 byte[] b = DataConverter.GetBytesBE (f);
929 for (int i = 0; i < 4; ++i)
930 data [offset + i] = b [i];
935 public PacketWriter WriteDouble (double d) {
937 byte[] b = DataConverter.GetBytesBE (d);
938 for (int i = 0; i < 8; ++i)
939 data [offset + i] = b [i];
944 public PacketWriter WriteInts (int[] ids) {
945 for (int i = 0; i < ids.Length; ++i)
950 public PacketWriter WriteIds (long[] ids) {
951 for (int i = 0; i < ids.Length; ++i)
956 public PacketWriter WriteString (string s) {
958 return WriteInt (-1);
960 byte[] b = Encoding.UTF8.GetBytes (s);
962 encode_int (data, b.Length, ref offset);
964 Buffer.BlockCopy (b, 0, data, offset, b.Length);
969 public PacketWriter WriteBool (bool val) {
970 WriteByte (val ? (byte)1 : (byte)0);
974 public PacketWriter WriteValue (ValueImpl v) {
978 t = TypeCodeToElementType (Type.GetTypeCode (v.Value.GetType ()));
983 case ElementType.Boolean:
984 WriteInt ((bool)v.Value ? 1 : 0);
986 case ElementType.Char:
987 WriteInt ((int)(char)v.Value);
990 WriteInt ((int)(sbyte)v.Value);
993 WriteInt ((int)(byte)v.Value);
996 WriteInt ((int)(short)v.Value);
999 WriteInt ((int)(ushort)v.Value);
1001 case ElementType.I4:
1002 WriteInt ((int)(int)v.Value);
1004 case ElementType.U4:
1005 WriteInt ((int)(uint)v.Value);
1007 case ElementType.I8:
1008 WriteLong ((long)(long)v.Value);
1010 case ElementType.U8:
1011 WriteLong ((long)(ulong)v.Value);
1013 case ElementType.R4:
1014 WriteFloat ((float)v.Value);
1016 case ElementType.R8:
1017 WriteDouble ((double)v.Value);
1019 case ElementType.String:
1020 case ElementType.SzArray:
1021 case ElementType.Class:
1022 case ElementType.Array:
1023 case ElementType.Object:
1026 case ElementType.ValueType:
1029 throw new NotImplementedException ();
1032 WriteInt (v.Fields.Length);
1033 for (int i = 0; i < v.Fields.Length; ++i)
1034 WriteValue (v.Fields [i]);
1036 case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
1039 throw new NotImplementedException ();
1045 public PacketWriter WriteValues (ValueImpl[] values) {
1046 for (int i = 0; i < values.Length; ++i)
1047 WriteValue (values [i]);
1051 public byte[] Data {
1064 delegate void ReplyCallback (int packet_id, byte[] packet);
1067 Thread receiver_thread;
1068 Dictionary<int, byte[]> reply_packets;
1069 Dictionary<int, ReplyCallback> reply_cbs;
1070 Dictionary<int, int> reply_cb_counts;
1071 object reply_packets_monitor;
1073 internal event EventHandler<ErrorHandlerEventArgs> ErrorHandler;
1075 protected Connection () {
1077 reply_packets = new Dictionary<int, byte[]> ();
1078 reply_cbs = new Dictionary<int, ReplyCallback> ();
1079 reply_cb_counts = new Dictionary<int, int> ();
1080 reply_packets_monitor = new Object ();
1081 if (EnableConnectionLogging) {
1082 var path = Environment.GetEnvironmentVariable ("MONO_SDB_LOG");
1083 if (path.Contains ("{0}")) {
1084 //C:\SomeDir\sdbLog{0}.txt -> C:\SomeDir\sdbLog1.txt
1085 LoggingStream = new StreamWriter (string.Format (path, ConnectionId++), false);
1086 } else if (Path.HasExtension (path)) {
1087 //C:\SomeDir\sdbLog.txt -> C:\SomeDir\sdbLog1.txt
1088 LoggingStream = new StreamWriter (Path.GetDirectoryName (path) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension (path) + ConnectionId++ + "." + Path.GetExtension (path), false);
1090 //C:\SomeDir\sdbLog -> C:\SomeDir\sdbLog1
1091 LoggingStream = new StreamWriter (path + ConnectionId++, false);
1096 protected abstract int TransportReceive (byte[] buf, int buf_offset, int len);
1097 protected abstract int TransportSend (byte[] buf, int buf_offset, int len);
1098 protected abstract void TransportSetTimeouts (int send_timeout, int receive_timeout);
1099 protected abstract void TransportClose ();
1101 internal VersionInfo Version;
1103 int Receive (byte[] buf, int buf_offset, int len) {
1106 while (offset < len) {
1107 int n = TransportReceive (buf, buf_offset + offset, len - offset);
1117 // Do the wire protocol handshake
1118 internal void Connect () {
1119 byte[] buf = new byte [HANDSHAKE_STRING.Length];
1120 char[] cbuf = new char [buf.Length];
1122 // FIXME: Add a timeout
1123 int n = Receive (buf, 0, buf.Length);
1125 throw new IOException ("DWP Handshake failed.");
1126 for (int i = 0; i < buf.Length; ++i)
1127 cbuf [i] = (char)buf [i];
1129 if (new String (cbuf) != HANDSHAKE_STRING)
1130 throw new IOException ("DWP Handshake failed.");
1132 TransportSend (buf, 0, buf.Length);
1134 receiver_thread = new Thread (new ThreadStart (receiver_thread_main));
1135 receiver_thread.Name = "SDB Receiver";
1136 receiver_thread.IsBackground = true;
1137 receiver_thread.Start ();
1139 Version = VM_GetVersion ();
1142 // Tell the debuggee our protocol version, so newer debuggees can work
1143 // with older clients
1147 // Older debuggees might not support this request
1148 EventHandler<ErrorHandlerEventArgs> OrigErrorHandler = ErrorHandler;
1149 ErrorHandler = null;
1150 ErrorHandler += delegate (object sender, ErrorHandlerEventArgs args) {
1151 throw new NotSupportedException ();
1154 VM_SetProtocolVersion (MAJOR_VERSION, MINOR_VERSION);
1155 } catch (NotSupportedException) {
1157 ErrorHandler = OrigErrorHandler;
1160 internal byte[] ReadPacket () {
1161 // FIXME: Throw ClosedConnectionException () if the connection is closed
1162 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1164 byte[] header = new byte [HEADER_LENGTH];
1166 int len = Receive (header, 0, header.Length);
1168 return new byte [0];
1169 if (len != HEADER_LENGTH) {
1171 throw new IOException ("Packet of length " + len + " is read.");
1174 int packetLength = GetPacketLength (header);
1175 if (packetLength < 11)
1176 throw new IOException ("Invalid packet length.");
1178 if (packetLength == 11) {
1181 byte[] buf = new byte [packetLength];
1182 for (int i = 0; i < header.Length; ++i)
1183 buf [i] = header [i];
1184 len = Receive (buf, header.Length, packetLength - header.Length);
1185 if (len != packetLength - header.Length)
1186 throw new IOException ();
1191 internal void WritePacket (byte[] packet) {
1192 // FIXME: Throw ClosedConnectionException () if the connection is closed
1193 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1195 TransportSend (packet, 0, packet.Length);
1198 internal void WritePackets (List<byte[]> packets) {
1199 // FIXME: Throw ClosedConnectionException () if the connection is closed
1200 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1203 for (int i = 0; i < packets.Count; ++i)
1204 len += packets [i].Length;
1205 byte[] data = new byte [len];
1207 for (int i = 0; i < packets.Count; ++i) {
1208 Buffer.BlockCopy (packets [i], 0, data, pos, packets [i].Length);
1209 pos += packets [i].Length;
1211 TransportSend (data, 0, data.Length);
1214 internal void Close () {
1218 internal bool IsClosed {
1226 internal ManualResetEvent DisconnectedEvent = new ManualResetEvent (false);
1228 void receiver_thread_main () {
1231 bool res = ReceivePacket ();
1234 } catch (Exception ex) {
1236 Console.WriteLine (ex);
1242 lock (reply_packets_monitor) {
1243 disconnected = true;
1244 DisconnectedEvent.Set ();
1245 Monitor.PulseAll (reply_packets_monitor);
1248 EventHandler.VMDisconnect (0, 0, null);
1251 bool ReceivePacket () {
1252 byte[] packet = ReadPacket ();
1254 if (packet.Length == 0) {
1258 if (IsReplyPacket (packet)) {
1259 int id = GetPacketId (packet);
1260 ReplyCallback cb = null;
1261 lock (reply_packets_monitor) {
1262 reply_cbs.TryGetValue (id, out cb);
1264 reply_packets [id] = packet;
1265 Monitor.PulseAll (reply_packets_monitor);
1267 int c = reply_cb_counts [id];
1270 reply_cbs.Remove (id);
1271 reply_cb_counts.Remove (id);
1277 cb.Invoke (id, packet);
1279 PacketReader r = new PacketReader (packet);
1281 if (r.CommandSet == CommandSet.EVENT && r.Command == (int)CmdEvent.COMPOSITE) {
1282 int spolicy = r.ReadByte ();
1283 int nevents = r.ReadInt ();
1285 SuspendPolicy suspend_policy = decode_suspend_policy (spolicy);
1287 EventInfo[] events = new EventInfo [nevents];
1289 for (int i = 0; i < nevents; ++i) {
1290 EventKind kind = (EventKind)r.ReadByte ();
1291 int req_id = r.ReadInt ();
1293 EventType etype = (EventType)kind;
1295 long thread_id = r.ReadId ();
1296 if (kind == EventKind.VM_START) {
1297 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id };
1298 //EventHandler.VMStart (req_id, thread_id, null);
1299 } else if (kind == EventKind.VM_DEATH) {
1301 if (Version.AtLeast (2, 27))
1302 exit_code = r.ReadInt ();
1303 //EventHandler.VMDeath (req_id, 0, null);
1304 events [i] = new EventInfo (etype, req_id) { ExitCode = exit_code };
1305 } else if (kind == EventKind.THREAD_START) {
1306 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = thread_id };
1307 //EventHandler.ThreadStart (req_id, thread_id, thread_id);
1308 } else if (kind == EventKind.THREAD_DEATH) {
1309 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = thread_id };
1310 //EventHandler.ThreadDeath (req_id, thread_id, thread_id);
1311 } else if (kind == EventKind.ASSEMBLY_LOAD) {
1312 long id = r.ReadId ();
1313 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1314 //EventHandler.AssemblyLoad (req_id, thread_id, id);
1315 } else if (kind == EventKind.ASSEMBLY_UNLOAD) {
1316 long id = r.ReadId ();
1317 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1318 //EventHandler.AssemblyUnload (req_id, thread_id, id);
1319 } else if (kind == EventKind.TYPE_LOAD) {
1320 long id = r.ReadId ();
1321 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1322 //EventHandler.TypeLoad (req_id, thread_id, id);
1323 } else if (kind == EventKind.METHOD_ENTRY) {
1324 long id = r.ReadId ();
1325 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1326 //EventHandler.MethodEntry (req_id, thread_id, id);
1327 } else if (kind == EventKind.METHOD_EXIT) {
1328 long id = r.ReadId ();
1329 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1330 //EventHandler.MethodExit (req_id, thread_id, id);
1331 } else if (kind == EventKind.BREAKPOINT) {
1332 long id = r.ReadId ();
1333 long loc = r.ReadLong ();
1334 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1335 //EventHandler.Breakpoint (req_id, thread_id, id, loc);
1336 } else if (kind == EventKind.STEP) {
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.Step (req_id, thread_id, id, loc);
1341 } else if (kind == EventKind.EXCEPTION) {
1342 long id = r.ReadId ();
1343 long loc = 0; // FIXME
1344 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1345 //EventHandler.Exception (req_id, thread_id, id, loc);
1346 } else if (kind == EventKind.APPDOMAIN_CREATE) {
1347 long id = r.ReadId ();
1348 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1349 //EventHandler.AppDomainCreate (req_id, thread_id, id);
1350 } else if (kind == EventKind.APPDOMAIN_UNLOAD) {
1351 long id = r.ReadId ();
1352 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1353 //EventHandler.AppDomainUnload (req_id, thread_id, id);
1354 } else if (kind == EventKind.USER_BREAK) {
1357 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1358 //EventHandler.Exception (req_id, thread_id, id, loc);
1359 } else if (kind == EventKind.USER_LOG) {
1360 int level = r.ReadInt ();
1361 string category = r.ReadString ();
1362 string message = r.ReadString ();
1363 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Level = level, Category = category, Message = message };
1364 //EventHandler.Exception (req_id, thread_id, id, loc);
1365 } else if (kind == EventKind.KEEPALIVE) {
1366 events [i] = new EventInfo (etype, req_id) { };
1368 throw new NotImplementedException ("Unknown event kind: " + kind);
1372 EventHandler.Events (suspend_policy, events);
1379 internal IEventHandler EventHandler {
1383 static String CommandString (CommandSet command_set, int command)
1386 switch (command_set) {
1388 cmd = ((CmdVM)command).ToString ();
1390 case CommandSet.OBJECT_REF:
1391 cmd = ((CmdObjectRef)command).ToString ();
1393 case CommandSet.STRING_REF:
1394 cmd = ((CmdStringRef)command).ToString ();
1396 case CommandSet.THREAD:
1397 cmd = ((CmdThread)command).ToString ();
1399 case CommandSet.ARRAY_REF:
1400 cmd = ((CmdArrayRef)command).ToString ();
1402 case CommandSet.EVENT_REQUEST:
1403 cmd = ((CmdEventRequest)command).ToString ();
1405 case CommandSet.STACK_FRAME:
1406 cmd = ((CmdStackFrame)command).ToString ();
1408 case CommandSet.APPDOMAIN:
1409 cmd = ((CmdAppDomain)command).ToString ();
1411 case CommandSet.ASSEMBLY:
1412 cmd = ((CmdAssembly)command).ToString ();
1414 case CommandSet.METHOD:
1415 cmd = ((CmdMethod)command).ToString ();
1417 case CommandSet.TYPE:
1418 cmd = ((CmdType)command).ToString ();
1420 case CommandSet.MODULE:
1421 cmd = ((CmdModule)command).ToString ();
1423 case CommandSet.FIELD:
1424 cmd = ((CmdField)command).ToString ();
1426 case CommandSet.EVENT:
1427 cmd = ((CmdEvent)command).ToString ();
1430 cmd = command.ToString ();
1433 return string.Format ("[{0} {1}]", command_set, cmd);
1436 long total_protocol_ticks;
1438 void LogPacket (int packet_id, byte[] encoded_packet, byte[] reply_packet, CommandSet command_set, int command, Stopwatch watch) {
1440 total_protocol_ticks += watch.ElapsedTicks;
1441 var ts = TimeSpan.FromTicks (total_protocol_ticks);
1442 string msg = string.Format ("Packet: {0} sent: {1} received: {2} ms: {3} total ms: {4} {5}",
1443 packet_id, encoded_packet.Length, reply_packet.Length, watch.ElapsedMilliseconds,
1444 (ts.Seconds * 1000) + ts.Milliseconds,
1445 CommandString (command_set, command));
1447 LoggingStream.WriteLine (msg);
1448 LoggingStream.Flush ();
1451 bool buffer_packets;
1452 List<byte[]> buffered_packets = new List<byte[]> ();
1455 // Start buffering request/response packets on both the client and the debuggee side.
1456 // Packets sent between StartBuffering ()/StopBuffering () must be async, i.e. sent
1457 // using Send () and not SendReceive ().
1459 public void StartBuffering () {
1460 buffer_packets = true;
1461 if (Version.AtLeast (2, 34))
1462 VM_StartBuffering ();
1465 public void StopBuffering () {
1466 if (Version.AtLeast (2, 34))
1467 VM_StopBuffering ();
1468 buffer_packets = false;
1470 WritePackets (buffered_packets);
1471 if (EnableConnectionLogging) {
1472 LoggingStream.WriteLine (String.Format ("Sent {0} packets.", buffered_packets.Count));
1473 LoggingStream.Flush ();
1475 buffered_packets.Clear ();
1478 /* Send a request and call cb when a result is received */
1479 int Send (CommandSet command_set, int command, PacketWriter packet, Action<PacketReader> cb, int count) {
1480 int id = IdGenerator;
1482 Stopwatch watch = null;
1483 if (EnableConnectionLogging)
1484 watch = Stopwatch.StartNew ();
1486 byte[] encoded_packet;
1488 encoded_packet = EncodePacket (id, (int)command_set, command, null, 0);
1490 encoded_packet = EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset);
1493 lock (reply_packets_monitor) {
1494 reply_cbs [id] = delegate (int packet_id, byte[] p) {
1495 if (EnableConnectionLogging)
1496 LogPacket (packet_id, encoded_packet, p, command_set, command, watch);
1497 /* Run the callback on a tp thread to avoid blocking the receive thread */
1498 PacketReader r = new PacketReader (p);
1499 cb.BeginInvoke (r, null, null);
1501 reply_cb_counts [id] = count;
1506 buffered_packets.Add (encoded_packet);
1508 WritePacket (encoded_packet);
1513 // Send a request without waiting for an answer
1514 void Send (CommandSet command_set, int command) {
1515 Send (command_set, command, null, null, 0);
1518 PacketReader SendReceive (CommandSet command_set, int command, PacketWriter packet) {
1519 int id = IdGenerator;
1520 Stopwatch watch = null;
1523 throw new VMDisconnectedException ();
1525 if (EnableConnectionLogging)
1526 watch = Stopwatch.StartNew ();
1528 byte[] encoded_packet;
1531 encoded_packet = EncodePacket (id, (int)command_set, command, null, 0);
1533 encoded_packet = EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset);
1535 WritePacket (encoded_packet);
1539 /* Wait for the reply packet */
1541 lock (reply_packets_monitor) {
1542 if (reply_packets.ContainsKey (packetId)) {
1543 byte[] reply = reply_packets [packetId];
1544 reply_packets.Remove (packetId);
1545 PacketReader r = new PacketReader (reply);
1547 if (EnableConnectionLogging)
1548 LogPacket (packetId, encoded_packet, reply, command_set, command, watch);
1549 if (r.ErrorCode != 0) {
1550 if (ErrorHandler != null)
1551 ErrorHandler (this, new ErrorHandlerEventArgs () { ErrorCode = (ErrorCode)r.ErrorCode });
1552 throw new NotImplementedException ("No error handler set.");
1558 throw new VMDisconnectedException ();
1559 Monitor.Wait (reply_packets_monitor);
1565 PacketReader SendReceive (CommandSet command_set, int command) {
1566 return SendReceive (command_set, command, null);
1569 int packet_id_generator;
1573 return Interlocked.Increment (ref packet_id_generator);
1577 CattrInfo[] ReadCattrs (PacketReader r) {
1578 CattrInfo[] res = new CattrInfo [r.ReadInt ()];
1579 for (int i = 0; i < res.Length; ++i) {
1580 CattrInfo info = new CattrInfo ();
1581 info.ctor_id = r.ReadId ();
1582 info.ctor_args = new ValueImpl [r.ReadInt ()];
1583 for (int j = 0; j < info.ctor_args.Length; ++j) {
1584 info.ctor_args [j] = r.ReadValue ();
1586 info.named_args = new CattrNamedArgInfo [r.ReadInt ()];
1587 for (int j = 0; j < info.named_args.Length; ++j) {
1588 CattrNamedArgInfo arg = new CattrNamedArgInfo ();
1589 int arg_type = r.ReadByte ();
1590 arg.is_property = arg_type == 0x54;
1591 arg.id = r.ReadId ();
1592 arg.value = r.ReadValue ();
1593 info.named_args [j] = arg;
1600 static ElementType TypeCodeToElementType (TypeCode c) {
1602 case TypeCode.Boolean:
1603 return ElementType.Boolean;
1605 return ElementType.Char;
1606 case TypeCode.SByte:
1607 return ElementType.I1;
1609 return ElementType.U1;
1610 case TypeCode.Int16:
1611 return ElementType.I2;
1612 case TypeCode.UInt16:
1613 return ElementType.U2;
1614 case TypeCode.Int32:
1615 return ElementType.I4;
1616 case TypeCode.UInt32:
1617 return ElementType.U4;
1618 case TypeCode.Int64:
1619 return ElementType.I8;
1620 case TypeCode.UInt64:
1621 return ElementType.U8;
1622 case TypeCode.Single:
1623 return ElementType.R4;
1624 case TypeCode.Double:
1625 return ElementType.R8;
1627 throw new NotImplementedException ();
1632 * Implementation of debugger commands
1635 internal VersionInfo VM_GetVersion () {
1636 var res = SendReceive (CommandSet.VM, (int)CmdVM.VERSION, null);
1637 VersionInfo info = new VersionInfo ();
1638 info.VMVersion = res.ReadString ();
1639 info.MajorVersion = res.ReadInt ();
1640 info.MinorVersion = res.ReadInt ();
1644 internal void VM_SetProtocolVersion (int major, int minor) {
1645 SendReceive (CommandSet.VM, (int)CmdVM.SET_PROTOCOL_VERSION, new PacketWriter ().WriteInt (major).WriteInt (minor));
1648 internal void VM_GetThreads (Action<long[]> resultCallaback) {
1649 Send (CommandSet.VM, (int)CmdVM.ALL_THREADS, null, (res) => {
1650 int len = res.ReadInt ();
1651 long[] arr = new long [len];
1652 for (int i = 0; i < len; ++i)
1653 arr [i] = res.ReadId ();
1654 resultCallaback(arr);
1658 internal void VM_Suspend () {
1659 SendReceive (CommandSet.VM, (int)CmdVM.SUSPEND);
1662 internal void VM_Resume () {
1663 SendReceive (CommandSet.VM, (int)CmdVM.RESUME);
1666 internal void VM_Exit (int exitCode) {
1667 SendReceive (CommandSet.VM, (int)CmdVM.EXIT, new PacketWriter ().WriteInt (exitCode));
1670 internal void VM_Dispose () {
1671 SendReceive (CommandSet.VM, (int)CmdVM.DISPOSE);
1674 internal ValueImpl VM_InvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, out ValueImpl exc) {
1676 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));
1677 if (r.ReadByte () == 0) {
1678 exc = r.ReadValue ();
1681 return r.ReadValue ();
1685 internal delegate void InvokeMethodCallback (ValueImpl v, ValueImpl exc, ValueImpl out_this, ValueImpl[] out_args, ErrorCode error, object state);
1687 void read_invoke_res (PacketReader r, out ValueImpl v, out ValueImpl exc, out ValueImpl out_this, out ValueImpl[] out_args) {
1688 int resflags = r.ReadByte ();
1693 if (resflags == 0) {
1694 exc = r.ReadValue ();
1697 if ((resflags & 2) != 0)
1698 out_this = r.ReadValue ();
1699 if ((resflags & 4) != 0) {
1700 int nargs = r.ReadInt ();
1701 out_args = new ValueImpl [nargs];
1702 for (int i = 0; i < nargs; ++i)
1703 out_args [i] = r.ReadValue ();
1708 internal int VM_BeginInvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, InvokeMethodCallback callback, object state) {
1709 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) {
1710 ValueImpl v, exc, out_this = null;
1711 ValueImpl[] out_args = null;
1713 if (r.ErrorCode != 0) {
1714 callback (null, null, null, null, (ErrorCode)r.ErrorCode, state);
1716 read_invoke_res (r, out v, out exc, out out_this, out out_args);
1717 callback (v, exc, out_this, out_args, 0, state);
1722 internal int VM_BeginInvokeMethods (long thread, long[] methods, ValueImpl this_arg, List<ValueImpl[]> arguments, InvokeFlags flags, InvokeMethodCallback callback, object state) {
1723 // FIXME: Merge this with INVOKE_METHOD
1724 var w = new PacketWriter ();
1726 w.WriteInt ((int)flags);
1727 w.WriteInt (methods.Length);
1728 for (int i = 0; i < methods.Length; ++i) {
1729 w.WriteId (methods [i]);
1730 w.WriteValue (this_arg);
1731 w.WriteInt (arguments [i].Length);
1732 w.WriteValues (arguments [i]);
1734 return Send (CommandSet.VM, (int)CmdVM.INVOKE_METHODS, w, delegate (PacketReader r) {
1735 ValueImpl v, exc, out_this = null;
1736 ValueImpl[] out_args = null;
1738 if (r.ErrorCode != 0) {
1739 callback (null, null, null, null, (ErrorCode)r.ErrorCode, state);
1741 read_invoke_res (r, out v, out exc, out out_this, out out_args);
1742 callback (v, exc, out_this, out_args, 0, state);
1747 internal void VM_AbortInvoke (long thread, int id)
1749 SendReceive (CommandSet.VM, (int)CmdVM.ABORT_INVOKE, new PacketWriter ().WriteId (thread).WriteInt (id));
1752 internal void SetSocketTimeouts (int send_timeout, int receive_timeout, int keepalive_interval)
1754 TransportSetTimeouts (send_timeout, receive_timeout);
1755 SendReceive (CommandSet.VM, (int)CmdVM.SET_KEEPALIVE, new PacketWriter ().WriteId (keepalive_interval));
1758 internal long[] VM_GetTypesForSourceFile (string fname, bool ignoreCase) {
1759 var res = SendReceive (CommandSet.VM, (int)CmdVM.GET_TYPES_FOR_SOURCE_FILE, new PacketWriter ().WriteString (fname).WriteBool (ignoreCase));
1760 int count = res.ReadInt ();
1761 long[] types = new long [count];
1762 for (int i = 0; i < count; ++i)
1763 types [i] = res.ReadId ();
1767 internal long[] VM_GetTypes (string name, bool ignoreCase) {
1768 var res = SendReceive (CommandSet.VM, (int)CmdVM.GET_TYPES, new PacketWriter ().WriteString (name).WriteBool (ignoreCase));
1769 int count = res.ReadInt ();
1770 long[] types = new long [count];
1771 for (int i = 0; i < count; ++i)
1772 types [i] = res.ReadId ();
1776 internal void VM_StartBuffering () {
1777 Send (CommandSet.VM, (int)CmdVM.START_BUFFERING);
1780 internal void VM_StopBuffering () {
1781 Send (CommandSet.VM, (int)CmdVM.STOP_BUFFERING);
1788 internal long RootDomain {
1790 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ROOT_DOMAIN, null).ReadId ();
1794 internal string Domain_GetName (long id) {
1795 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_FRIENDLY_NAME, new PacketWriter ().WriteId (id)).ReadString ();
1798 internal long[] Domain_GetAssemblies (long id) {
1799 var res = SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ASSEMBLIES, new PacketWriter ().WriteId (id));
1800 int count = res.ReadInt ();
1801 long[] assemblies = new long [count];
1802 for (int i = 0; i < count; ++i)
1803 assemblies [i] = res.ReadId ();
1807 internal long Domain_GetEntryAssembly (long id) {
1808 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ENTRY_ASSEMBLY, new PacketWriter ().WriteId (id)).ReadId ();
1811 internal long Domain_GetCorlib (long id) {
1812 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_CORLIB, new PacketWriter ().WriteId (id)).ReadId ();
1815 internal long Domain_CreateString (long id, string s) {
1816 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.CREATE_STRING, new PacketWriter ().WriteId (id).WriteString (s)).ReadId ();
1819 internal long Domain_CreateBoxedValue (long id, long type_id, ValueImpl v) {
1820 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.CREATE_BOXED_VALUE, new PacketWriter ().WriteId (id).WriteId (type_id).WriteValue (v)).ReadId ();
1827 internal string Method_GetName (long id) {
1828 return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
1831 internal long Method_GetDeclaringType (long id) {
1832 return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DECLARING_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
1835 internal DebugInfo Method_GetDebugInfo (long id) {
1836 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DEBUG_INFO, new PacketWriter ().WriteId (id));
1838 DebugInfo info = new DebugInfo ();
1839 info.max_il_offset = res.ReadInt ();
1841 SourceInfo[] sources = null;
1842 if (Version.AtLeast (2, 13)) {
1843 int n = res.ReadInt ();
1844 sources = new SourceInfo [n];
1845 for (int i = 0; i < n; ++i) {
1846 sources [i].source_file = res.ReadString ();
1847 if (Version.AtLeast (2, 14)) {
1848 sources [i].hash = new byte [16];
1849 for (int j = 0; j < 16; ++j)
1850 sources [i].hash [j] = (byte)res.ReadByte ();
1854 sources = new SourceInfo [1];
1855 sources [0].source_file = res.ReadString ();
1858 int n_il_offsets = res.ReadInt ();
1859 info.il_offsets = new int [n_il_offsets];
1860 info.line_numbers = new int [n_il_offsets];
1861 info.source_files = new SourceInfo [n_il_offsets];
1862 info.column_numbers = new int [n_il_offsets];
1863 info.end_line_numbers = new int [n_il_offsets];
1864 info.end_column_numbers = new int [n_il_offsets];
1865 for (int i = 0; i < n_il_offsets; ++i) {
1866 info.il_offsets [i] = res.ReadInt ();
1867 info.line_numbers [i] = res.ReadInt ();
1868 if (Version.AtLeast (2, 12)) {
1869 int idx = res.ReadInt ();
1870 info.source_files [i] = idx >= 0 ? sources [idx] : default (SourceInfo);
1872 info.source_files [i] = sources [0];
1874 if (Version.AtLeast (2, 19))
1875 info.column_numbers [i] = res.ReadInt ();
1877 info.column_numbers [i] = 0;
1878 if (Version.AtLeast (2, 32)) {
1879 info.end_line_numbers [i] = res.ReadInt ();
1880 info.end_column_numbers [i] = res.ReadInt ();
1882 info.end_column_numbers [i] = -1;
1883 info.end_column_numbers [i] = -1;
1890 internal ParamInfo Method_GetParamInfo (long id) {
1891 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_PARAM_INFO, new PacketWriter ().WriteId (id));
1893 ParamInfo info = new ParamInfo ();
1894 info.call_conv = res.ReadInt ();
1895 info.param_count = res.ReadInt ();
1896 info.generic_param_count = res.ReadInt ();
1897 info.ret_type = res.ReadId ();
1898 info.param_types = new long [info.param_count];
1899 for (int i = 0; i < info.param_count; ++i)
1900 info.param_types [i] = res.ReadId ();
1901 info.param_names = new string [info.param_count];
1902 for (int i = 0; i < info.param_count; ++i)
1903 info.param_names [i] = res.ReadString ();
1908 internal LocalsInfo Method_GetLocalsInfo (long id) {
1909 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_LOCALS_INFO, new PacketWriter ().WriteId (id));
1911 LocalsInfo info = new LocalsInfo ();
1912 int nlocals = res.ReadInt ();
1913 info.types = new long [nlocals];
1914 for (int i = 0; i < nlocals; ++i)
1915 info.types [i] = res.ReadId ();
1916 info.names = new string [nlocals];
1917 for (int i = 0; i < nlocals; ++i)
1918 info.names [i] = res.ReadString ();
1919 info.live_range_start = new int [nlocals];
1920 info.live_range_end = new int [nlocals];
1921 for (int i = 0; i < nlocals; ++i) {
1922 info.live_range_start [i] = res.ReadInt ();
1923 info.live_range_end [i] = res.ReadInt ();
1929 internal MethodInfo Method_GetInfo (long id) {
1930 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_INFO, new PacketWriter ().WriteId (id));
1932 MethodInfo info = new MethodInfo ();
1933 info.attributes = res.ReadInt ();
1934 info.iattributes = res.ReadInt ();
1935 info.token = res.ReadInt ();
1936 if (Version.AtLeast (2, 12)) {
1937 int attrs = res.ReadByte ();
1938 if ((attrs & (1 << 0)) != 0)
1940 if ((attrs & (1 << 1)) != 0)
1941 info.is_generic_method = true;
1942 info.gmd = res.ReadId ();
1943 if (Version.AtLeast (2, 15)) {
1944 if (info.is_generic_method) {
1945 int n = res.ReadInt ();
1946 info.type_args = res.ReadIds (n);
1953 internal MethodBodyInfo Method_GetBody (long id) {
1954 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_BODY, new PacketWriter ().WriteId (id));
1956 MethodBodyInfo info = new MethodBodyInfo ();
1957 info.il = new byte [res.ReadInt ()];
1958 for (int i = 0; i < info.il.Length; ++i)
1959 info.il [i] = (byte)res.ReadByte ();
1961 if (Version.AtLeast (2, 18)) {
1962 info.clauses = new ExceptionClauseInfo [res.ReadInt ()];
1964 for (int i = 0; i < info.clauses.Length; ++i) {
1965 var clause = new ExceptionClauseInfo {
1966 flags = (ExceptionClauseFlags) res.ReadInt (),
1967 try_offset = res.ReadInt (),
1968 try_length = res.ReadInt (),
1969 handler_offset = res.ReadInt (),
1970 handler_length = res.ReadInt (),
1973 if (clause.flags == ExceptionClauseFlags.None)
1974 clause.catch_type_id = res.ReadId ();
1975 else if (clause.flags == ExceptionClauseFlags.Filter)
1976 clause.filter_offset = res.ReadInt ();
1978 info.clauses [i] = clause;
1981 info.clauses = new ExceptionClauseInfo [0];
1986 internal ResolvedToken Method_ResolveToken (long id, int token) {
1987 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.RESOLVE_TOKEN, new PacketWriter ().WriteId (id).WriteInt (token));
1989 TokenType type = (TokenType)res.ReadByte ();
1991 case TokenType.STRING:
1992 return new ResolvedToken () { Type = type, Str = res.ReadString () };
1993 case TokenType.TYPE:
1994 case TokenType.METHOD:
1995 case TokenType.FIELD:
1996 return new ResolvedToken () { Type = type, Id = res.ReadId () };
1997 case TokenType.UNKNOWN:
1998 return new ResolvedToken () { Type = type };
2000 throw new NotImplementedException ();
2004 internal CattrInfo[] Method_GetCustomAttributes (long id, long attr_type_id, bool inherit) {
2005 PacketReader r = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_CATTRS, new PacketWriter ().WriteId (id).WriteId (attr_type_id));
2006 return ReadCattrs (r);
2009 internal long Method_MakeGenericMethod (long id, long[] args) {
2010 PacketReader r = SendReceive (CommandSet.METHOD, (int)CmdMethod.MAKE_GENERIC_METHOD, new PacketWriter ().WriteId (id).WriteInt (args.Length).WriteIds (args));
2018 internal string Thread_GetName (long id) {
2019 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
2022 internal void Thread_GetFrameInfo (long id, int start_frame, int length, Action<FrameInfo[]> resultCallaback) {
2023 Send (CommandSet.THREAD, (int)CmdThread.GET_FRAME_INFO, new PacketWriter ().WriteId (id).WriteInt (start_frame).WriteInt (length), (res) => {
2024 int count = res.ReadInt ();
2025 var frames = new FrameInfo[count];
2026 for (int i = 0; i < count; ++i) {
2027 var f = new FrameInfo ();
2028 f.id = res.ReadInt ();
2029 f.method = res.ReadId ();
2030 f.il_offset = res.ReadInt ();
2031 f.flags = (StackFrameFlags)res.ReadByte ();
2034 resultCallaback (frames);
2038 internal int Thread_GetState (long id) {
2039 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_STATE, new PacketWriter ().WriteId (id)).ReadInt ();
2042 internal ThreadInfo Thread_GetInfo (long id) {
2043 PacketReader r = SendReceive (CommandSet.THREAD, (int)CmdThread.GET_INFO, new PacketWriter ().WriteId (id));
2045 ThreadInfo res = new ThreadInfo () { is_thread_pool = r.ReadByte () > 0 ? true : false };
2050 internal long Thread_GetId (long id) {
2051 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_ID, new PacketWriter ().WriteId (id)).ReadLong ();
2054 internal long Thread_GetTID (long id) {
2055 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_TID, new PacketWriter ().WriteId (id)).ReadLong ();
2058 internal void Thread_SetIP (long id, long method_id, long il_offset) {
2059 SendReceive (CommandSet.THREAD, (int)CmdThread.SET_IP, new PacketWriter ().WriteId (id).WriteId (method_id).WriteLong (il_offset));
2066 internal ModuleInfo Module_GetInfo (long id) {
2067 PacketReader r = SendReceive (CommandSet.MODULE, (int)CmdModule.GET_INFO, new PacketWriter ().WriteId (id));
2068 ModuleInfo info = new ModuleInfo { Name = r.ReadString (), ScopeName = r.ReadString (), FQName = r.ReadString (), Guid = r.ReadString (), Assembly = r.ReadId () };
2076 internal string Assembly_GetLocation (long id) {
2077 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_LOCATION, new PacketWriter ().WriteId (id)).ReadString ();
2080 internal long Assembly_GetEntryPoint (long id) {
2081 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_ENTRY_POINT, new PacketWriter ().WriteId (id)).ReadId ();
2084 internal long Assembly_GetManifestModule (long id) {
2085 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_MANIFEST_MODULE, new PacketWriter ().WriteId (id)).ReadId ();
2088 internal long Assembly_GetObject (long id) {
2089 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
2092 internal long Assembly_GetType (long id, string name, bool ignoreCase) {
2093 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_TYPE, new PacketWriter ().WriteId (id).WriteString (name).WriteBool (ignoreCase)).ReadId ();
2096 internal string Assembly_GetName (long id) {
2097 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
2104 internal TypeInfo Type_GetInfo (long id) {
2105 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INFO, new PacketWriter ().WriteId (id));
2106 TypeInfo res = new TypeInfo ();
2108 res.ns = r.ReadString ();
2109 res.name = r.ReadString ();
2110 res.full_name = r.ReadString ();
2111 res.assembly = r.ReadId ();
2112 res.module = r.ReadId ();
2113 res.base_type = r.ReadId ();
2114 res.element_type = r.ReadId ();
2115 res.token = r.ReadInt ();
2116 res.rank = r.ReadByte ();
2117 res.attributes = r.ReadInt ();
2118 int b = r.ReadByte ();
2119 res.is_byref = (b & 1) != 0;
2120 res.is_pointer = (b & 2) != 0;
2121 res.is_primitive = (b & 4) != 0;
2122 res.is_valuetype = (b & 8) != 0;
2123 res.is_enum = (b & 16) != 0;
2124 res.is_gtd = (b & 32) != 0;
2125 res.is_generic_type = (b & 64) != 0;
2127 int nested_len = r.ReadInt ();
2128 res.nested = new long [nested_len];
2129 for (int i = 0; i < nested_len; ++i)
2130 res.nested [i] = r.ReadId ();
2132 if (Version.AtLeast (2, 12))
2133 res.gtd = r.ReadId ();
2134 if (Version.AtLeast (2, 15) && res.is_generic_type) {
2135 int n = r.ReadInt ();
2136 res.type_args = r.ReadIds (n);
2142 internal long[] Type_GetMethods (long id) {
2143 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_METHODS, new PacketWriter ().WriteId (id));
2145 int n = r.ReadInt ();
2146 long[] res = new long [n];
2147 for (int i = 0; i < n; ++i)
2148 res [i] = r.ReadId ();
2152 internal long[] Type_GetFields (long id, out string[] names, out long[] types, out int[] attrs) {
2153 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_FIELDS, new PacketWriter ().WriteId (id));
2155 int n = r.ReadInt ();
2156 long[] res = new long [n];
2157 names = new string [n];
2158 types = new long [n];
2159 attrs = new int [n];
2160 for (int i = 0; i < n; ++i) {
2161 res [i] = r.ReadId ();
2162 names [i] = r.ReadString ();
2163 types [i] = r.ReadId ();
2164 attrs [i] = r.ReadInt ();
2169 internal PropInfo[] Type_GetProperties (long id) {
2170 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_PROPERTIES, new PacketWriter ().WriteId (id));
2172 int n = r.ReadInt ();
2173 PropInfo[] res = new PropInfo [n];
2174 for (int i = 0; i < n; ++i) {
2175 res [i] = new PropInfo ();
2176 res [i].id = r.ReadId ();
2177 res [i].name = r.ReadString ();
2178 res [i].get_method = r.ReadId ();
2179 res [i].set_method = r.ReadId ();
2180 res [i].attrs = r.ReadInt ();
2186 internal long Type_GetObject (long id) {
2187 return SendReceive (CommandSet.TYPE, (int)CmdType.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
2190 internal ValueImpl[] Type_GetValues (long id, long[] fields, long thread_id) {
2191 int len = fields.Length;
2194 r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES_2, new PacketWriter ().WriteId (id).WriteId (thread_id).WriteInt (len).WriteIds (fields));
2196 r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));
2198 ValueImpl[] res = new ValueImpl [len];
2199 for (int i = 0; i < len; ++i)
2200 res [i] = r.ReadValue ();
2204 internal void Type_SetValues (long id, long[] fields, ValueImpl[] values) {
2205 SendReceive (CommandSet.TYPE, (int)CmdType.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
2208 internal string[] Type_GetSourceFiles (long id, bool return_full_paths) {
2209 var r = SendReceive (CommandSet.TYPE, return_full_paths ? (int)CmdType.GET_SOURCE_FILES_2 : (int)CmdType.GET_SOURCE_FILES, new PacketWriter ().WriteId (id));
2210 int len = r.ReadInt ();
2211 string[] res = new string [len];
2212 for (int i = 0; i < len; ++i)
2213 res [i] = r.ReadString ();
2217 internal bool Type_IsAssignableFrom (long id, long c_id) {
2218 return SendReceive (CommandSet.TYPE, (int)CmdType.IS_ASSIGNABLE_FROM, new PacketWriter ().WriteId (id).WriteId (c_id)).ReadByte () > 0;
2221 internal CattrInfo[] Type_GetCustomAttributes (long id, long attr_type_id, bool inherit) {
2222 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_CATTRS, new PacketWriter ().WriteId (id).WriteId (attr_type_id));
2223 return ReadCattrs (r);
2226 internal CattrInfo[] Type_GetFieldCustomAttributes (long id, long field_id, long attr_type_id, bool inherit) {
2227 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_FIELD_CATTRS, new PacketWriter ().WriteId (id).WriteId (field_id).WriteId (attr_type_id));
2228 return ReadCattrs (r);
2231 internal CattrInfo[] Type_GetPropertyCustomAttributes (long id, long field_id, long attr_type_id, bool inherit) {
2232 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_PROPERTY_CATTRS, new PacketWriter ().WriteId (id).WriteId (field_id).WriteId (attr_type_id));
2233 return ReadCattrs (r);
2236 public long[] Type_GetMethodsByNameFlags (long id, string name, int flags, bool ignoreCase) {
2237 flags |= ignoreCase ? (int)BindingFlagsExtensions.BINDING_FLAGS_IGNORE_CASE : 0;
2238 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.CMD_TYPE_GET_METHODS_BY_NAME_FLAGS, new PacketWriter ().WriteId (id).WriteString (name).WriteInt (flags));
2239 int len = r.ReadInt ();
2240 long[] res = new long [len];
2241 for (int i = 0; i < len; ++i)
2242 res [i] = r.ReadId ();
2246 internal long[] Type_GetInterfaces (long id) {
2247 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INTERFACES, new PacketWriter ().WriteId (id));
2248 int len = r.ReadInt ();
2249 return r.ReadIds (len);
2252 internal IfaceMapInfo[] Type_GetInterfaceMap (long id, long[] ids) {
2253 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INTERFACE_MAP, new PacketWriter ().WriteId (id).WriteInt (ids.Length).WriteIds (ids));
2254 var res = new IfaceMapInfo [ids.Length];
2255 for (int i = 0; i < ids.Length; ++i) {
2256 int n = r.ReadInt ();
2258 res [i].iface_id = ids [i];
2259 res [i].iface_methods = r.ReadIds (n);
2260 res [i].target_methods = r.ReadIds (n);
2266 internal bool Type_IsInitialized (long id) {
2267 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.IS_INITIALIZED, new PacketWriter ().WriteId (id));
2268 return r.ReadInt () == 1;
2271 internal long Type_CreateInstance (long id) {
2272 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.CREATE_INSTANCE, new PacketWriter ().WriteId (id));
2280 internal FieldMirrorInfo Field_GetInfo (long id) {
2281 PacketReader r = SendReceive (CommandSet.FIELD, (int)CmdField.GET_INFO, new PacketWriter ().WriteId (id));
2282 FieldMirrorInfo info = new FieldMirrorInfo { Name = r.ReadString (), Parent = r.ReadId (), TypeId = r.ReadId (), Attrs = r.ReadInt () };
2290 internal int EnableEvent (EventType etype, SuspendPolicy suspend_policy, List<Modifier> mods) {
2291 var w = new PacketWriter ().WriteByte ((byte)etype).WriteByte ((byte)suspend_policy);
2293 if (mods.Count > 255)
2294 throw new NotImplementedException ();
2295 w.WriteByte ((byte)mods.Count);
2296 foreach (Modifier mod in mods) {
2297 if (mod is CountModifier) {
2298 w.WriteByte ((byte)ModifierKind.COUNT);
2299 w.WriteInt ((mod as CountModifier).Count);
2300 } else if (mod is LocationModifier) {
2301 w.WriteByte ((byte)ModifierKind.LOCATION_ONLY);
2302 w.WriteId ((mod as LocationModifier).Method);
2303 w.WriteLong ((mod as LocationModifier).Location);
2304 } else if (mod is StepModifier) {
2305 w.WriteByte ((byte)ModifierKind.STEP);
2306 w.WriteId ((mod as StepModifier).Thread);
2307 w.WriteInt ((mod as StepModifier).Size);
2308 w.WriteInt ((mod as StepModifier).Depth);
2309 if (Version.AtLeast (2, 16))
2310 w.WriteInt ((mod as StepModifier).Filter);
2311 } else if (mod is ThreadModifier) {
2312 w.WriteByte ((byte)ModifierKind.THREAD_ONLY);
2313 w.WriteId ((mod as ThreadModifier).Thread);
2314 } else if (mod is ExceptionModifier) {
2315 var em = mod as ExceptionModifier;
2316 w.WriteByte ((byte)ModifierKind.EXCEPTION_ONLY);
2317 w.WriteId (em.Type);
2318 if (Version.MajorVersion > 2 || Version.MinorVersion > 0) {
2319 /* This is only supported in protocol version 2.1 */
2320 w.WriteBool (em.Caught);
2321 w.WriteBool (em.Uncaught);
2322 } else if (!em.Caught || !em.Uncaught) {
2323 throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
2325 if (Version.MajorVersion > 2 || Version.MinorVersion > 24) {
2326 w.WriteBool (em.Subclasses);
2327 } else if (!em.Subclasses) {
2328 throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
2330 } else if (mod is AssemblyModifier) {
2331 w.WriteByte ((byte)ModifierKind.ASSEMBLY_ONLY);
2332 var amod = (mod as AssemblyModifier);
2333 w.WriteInt (amod.Assemblies.Length);
2334 foreach (var id in amod.Assemblies)
2336 } else if (mod is SourceFileModifier) {
2337 w.WriteByte ((byte)ModifierKind.SOURCE_FILE_ONLY);
2338 var smod = (mod as SourceFileModifier);
2339 w.WriteInt (smod.SourceFiles.Length);
2340 foreach (var s in smod.SourceFiles)
2342 } else if (mod is TypeNameModifier) {
2343 w.WriteByte ((byte)ModifierKind.TYPE_NAME_ONLY);
2344 var tmod = (mod as TypeNameModifier);
2345 w.WriteInt (tmod.TypeNames.Length);
2346 foreach (var s in tmod.TypeNames)
2349 throw new NotImplementedException ();
2355 return SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.SET, w).ReadInt ();
2358 internal void ClearEventRequest (EventType etype, int req_id) {
2359 SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.CLEAR, new PacketWriter ().WriteByte ((byte)etype).WriteInt (req_id));
2362 internal void ClearAllBreakpoints () {
2363 SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.CLEAR_ALL_BREAKPOINTS, new PacketWriter ());
2369 internal ValueImpl StackFrame_GetThis (long thread_id, long id) {
2370 PacketReader r = SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_THIS, new PacketWriter ().WriteId (thread_id).WriteId (id));
2371 return r.ReadValue ();
2374 internal ValueImpl[] StackFrame_GetValues (long thread_id, long id, int[] pos) {
2375 /* pos < 0 -> argument at pos (-pos) - 1 */
2376 /* pos >= 0 -> local at pos */
2377 int len = pos.Length;
2378 PacketReader r = SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos));
2380 ValueImpl[] res = new ValueImpl [len];
2381 for (int i = 0; i < len; ++i)
2382 res [i] = r.ReadValue ();
2386 internal void StackFrame_SetValues (long thread_id, long id, int[] pos, ValueImpl[] values) {
2387 /* pos < 0 -> argument at pos (-pos) - 1 */
2388 /* pos >= 0 -> local at pos */
2389 int len = pos.Length;
2390 SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.SET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos).WriteValues (values));
2393 internal long StackFrame_GetDomain (long thread_id, long id) {
2394 return SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_DOMAIN, new PacketWriter ().WriteId (thread_id).WriteId (id)).ReadId ();
2400 internal int[] Array_GetLength (long id, out int rank, out int[] lower_bounds) {
2401 var r = SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.GET_LENGTH, new PacketWriter ().WriteId (id));
2402 rank = r.ReadInt ();
2403 int[] res = new int [rank];
2404 lower_bounds = new int [rank];
2405 for (int i = 0; i < rank; ++i) {
2406 res [i] = r.ReadInt ();
2407 lower_bounds [i] = r.ReadInt ();
2412 internal ValueImpl[] Array_GetValues (long id, int index, int len) {
2413 var r = SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (len));
2414 ValueImpl[] res = new ValueImpl [len];
2415 for (int i = 0; i < len; ++i)
2416 res [i] = r.ReadValue ();
2420 internal void Array_SetValues (long id, int index, ValueImpl[] values) {
2421 SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (values.Length).WriteValues (values));
2427 internal string String_GetValue (long id) {
2428 var r = SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_VALUE, new PacketWriter ().WriteId (id));
2430 bool is_utf16 = false;
2431 if (Version.AtLeast (2, 41))
2432 is_utf16 = r.ReadByte () == 1;
2435 return r.ReadUTF16String ();
2437 return r.ReadString ();
2440 internal int String_GetLength (long id) {
2441 return (int)SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_LENGTH, new PacketWriter ().WriteId (id)).ReadLong ();
2444 internal char[] String_GetChars (long id, int index, int length) {
2445 var r = SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_CHARS, new PacketWriter ().WriteId (id).WriteLong (index).WriteLong (length));
2446 var res = new char [length];
2447 for (int i = 0; i < length; ++i)
2448 res [i] = (char)r.ReadShort ();
2455 internal long Object_GetType (long id) {
2456 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
2459 internal long Object_GetDomain (long id) {
2460 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_DOMAIN, new PacketWriter ().WriteId (id)).ReadId ();
2463 internal ValueImpl[] Object_GetValues (long id, long[] fields) {
2464 int len = fields.Length;
2465 PacketReader r = SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));
2467 ValueImpl[] res = new ValueImpl [len];
2468 for (int i = 0; i < len; ++i)
2469 res [i] = r.ReadValue ();
2473 internal void Object_SetValues (long id, long[] fields, ValueImpl[] values) {
2474 SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
2477 internal bool Object_IsCollected (long id) {
2478 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.IS_COLLECTED, new PacketWriter ().WriteId (id)).ReadInt () == 1;
2481 internal long Object_GetAddress (long id) {
2482 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_ADDRESS, new PacketWriter ().WriteId (id)).ReadLong ();
2485 internal ObjectRefInfo Object_GetInfo (long id) {
2486 ObjectRefInfo res = new ObjectRefInfo ();
2487 PacketReader r = SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_INFO, new PacketWriter ().WriteId (id));
2489 res.type_id = r.ReadId ();
2490 res.domain_id = r.ReadId ();
2494 public void ForceDisconnect ()
2497 disconnected = true;
2498 DisconnectedEvent.Set ();
2503 class TcpConnection : Connection
2507 internal TcpConnection (Socket socket)
2509 this.socket = socket;
2510 //socket.SetSocketOption (SocketOptionLevel.IP, SocketOptionName.NoDelay, 1);
2513 internal EndPoint EndPoint {
2515 return socket.RemoteEndPoint;
2519 protected override int TransportSend (byte[] buf, int buf_offset, int len)
2521 return socket.Send (buf, buf_offset, len, SocketFlags.None);
2524 protected override int TransportReceive (byte[] buf, int buf_offset, int len)
2526 return socket.Receive (buf, buf_offset, len, SocketFlags.None);
2529 protected override void TransportSetTimeouts (int send_timeout, int receive_timeout)
2531 socket.SendTimeout = send_timeout;
2532 socket.ReceiveTimeout = receive_timeout;
2535 protected override void TransportClose ()
2541 /* This is the interface exposed by the debugger towards the debugger agent */
2542 interface IEventHandler
2544 void Events (SuspendPolicy suspend_policy, EventInfo[] events);
2546 void VMDisconnect (int req_id, long thread_id, string vm_uri);