4 using System.Net.Sockets;
5 using System.Threading;
6 using System.Collections.Generic;
8 using System.Diagnostics;
9 using Mono.Cecil.Metadata;
11 namespace Mono.Debugger.Soft
13 public class VersionInfo {
14 public string VMVersion {
18 public int MajorVersion {
22 public int MinorVersion {
27 * Check that this version is at least major:minor
29 public bool AtLeast (int major, int minor) {
30 if ((MajorVersion > major) || ((MajorVersion == major && MinorVersion >= minor)))
38 public string source_file;
43 public int max_il_offset;
44 public int[] il_offsets;
45 public int[] line_numbers;
46 public int[] column_numbers;
47 public int[] end_line_numbers;
48 public int[] end_column_numbers;
49 public SourceInfo[] source_files;
56 public StackFrameFlags flags;
60 public string ns, name, full_name;
61 public long assembly, module, base_type, element_type;
62 public int token, rank, attributes;
63 public bool is_byref, is_pointer, is_primitive, is_valuetype, is_enum;
64 public bool is_gtd, is_generic_type;
67 public long[] type_args;
72 public long[] iface_methods;
73 public long[] target_methods;
77 public int attributes, iattributes, token;
78 public bool is_gmd, is_generic_method;
80 public long[] type_args;
83 class MethodBodyInfo {
85 public ExceptionClauseInfo[] clauses;
88 struct ExceptionClauseInfo {
89 public ExceptionClauseFlags flags;
90 public int try_offset;
91 public int try_length;
92 public int handler_offset;
93 public int handler_length;
94 public int filter_offset;
95 public long catch_type_id;
99 enum ExceptionClauseFlags {
107 public int call_conv;
108 public int param_count;
109 public int generic_param_count;
110 public long ret_type;
111 public long[] param_types;
112 public string[] param_names;
117 public string[] names;
118 public int[] live_range_start;
119 public int[] live_range_end;
120 public int[] scopes_start;
121 public int[] scopes_end;
123 public int[] hoisted_scopes_start;
124 public int[] hoisted_scopes_end;
130 public long get_method, set_method;
134 class CattrNamedArgInfo {
135 public bool is_property;
137 public ValueImpl value;
142 public ValueImpl[] ctor_args;
143 public CattrNamedArgInfo[] named_args;
147 public bool is_thread_pool;
150 struct ObjectRefInfo {
152 public long domain_id;
156 VALUE_TYPE_ID_NULL = 0xf0,
157 VALUE_TYPE_ID_TYPE = 0xf1,
158 VALUE_TYPE_ID_PARENT_VTYPE = 0xf2
164 DISABLE_BREAKPOINTS = 1,
214 public ElementType Type; /* or one of the VALUE_TYPE_ID constants */
217 public long Klass; // For ElementType.ValueType
218 public ValueImpl[] Fields; // for ElementType.ValueType
219 public bool IsEnum; // For ElementType.ValueType
220 public long Id; /* For VALUE_TYPE_ID_TYPE */
221 public int Index; /* For VALUE_TYPE_PARENT_VTYPE */
225 public string Name, ScopeName, FQName, Guid;
226 public long Assembly;
229 class FieldMirrorInfo {
231 public long Parent, TypeId;
244 enum StackFrameFlags {
247 NATIVE_TRANSITION = 2
250 class ResolvedToken {
251 public TokenType Type;
259 class CountModifier : Modifier {
265 class LocationModifier : Modifier {
270 public long Location {
275 class StepModifier : Modifier {
293 class ThreadModifier : Modifier {
299 class ExceptionModifier : Modifier {
306 public bool Uncaught {
309 public bool Subclasses {
314 class AssemblyModifier : Modifier {
315 public long[] Assemblies {
320 class SourceFileModifier : Modifier {
321 public string[] SourceFiles {
326 class TypeNameModifier : Modifier {
327 public string[] TypeNames {
333 public EventType EventType {
341 public SuspendPolicy SuspendPolicy {
345 public long ThreadId {
353 public long Location {
361 public string Category {
365 public string Message {
369 public int ExitCode {
373 public EventInfo (EventType type, int req_id) {
379 public enum ErrorCode {
382 INVALID_FIELDID = 25,
383 INVALID_FRAMEID = 30,
384 NOT_IMPLEMENTED = 100,
386 INVALID_ARGUMENT = 102,
388 ERR_NO_INVOCATION = 104,
389 ABSENT_INFORMATION = 105,
390 NO_SEQ_POINT_AT_IL_OFFSET = 106,
394 public class ErrorHandlerEventArgs : EventArgs {
396 public ErrorCode ErrorCode {
402 * Represents the connection to the debuggee
404 public abstract class Connection
407 * The protocol and the packet format is based on JDWP, the differences
408 * are in the set of supported events, and the commands.
410 internal const string HANDSHAKE_STRING = "DWP-Handshake";
412 internal const int HEADER_LENGTH = 11;
414 static readonly bool EnableConnectionLogging = !String.IsNullOrEmpty (Environment.GetEnvironmentVariable ("MONO_SDB_LOG"));
415 static int ConnectionId;
416 readonly StreamWriter LoggingStream;
419 * Th version of the wire-protocol implemented by the library. The library
420 * and the debuggee can communicate if they implement the same major version.
421 * If they implement a different minor version, they can communicate, but some
422 * features might not be available. This allows older clients to communicate
423 * with newer runtimes, and vice versa.
425 internal const int MAJOR_VERSION = 2;
426 internal const int MINOR_VERSION = 46;
428 enum WPSuspendPolicy {
456 APPDOMAIN_CREATE = 4, // Not in JDI
457 APPDOMAIN_UNLOAD = 5, // Not in JDI
478 SOURCE_FILE_ONLY = 12,
490 SET_PROTOCOL_VERSION = 8,
493 GET_TYPES_FOR_SOURCE_FILE = 11,
496 START_BUFFERING = 14,
509 /* FIXME: Merge into GET_INFO when the major protocol version is increased */
516 enum CmdEventRequest {
519 CLEAR_ALL_BREAKPOINTS = 3
524 GET_FRIENDLY_NAME = 2,
526 GET_ENTRY_ASSEMBLY = 4,
529 CREATE_BOXED_VALUE = 7
535 GET_MANIFEST_MODULE = 3,
548 GET_DECLARING_TYPE = 2,
556 MAKE_GENERIC_METHOD = 10
565 GET_SOURCE_FILES = 6,
567 IS_ASSIGNABLE_FROM = 8,
570 GET_FIELD_CATTRS = 11,
571 GET_PROPERTY_CATTRS = 12,
572 /* FIXME: Merge into GET_SOURCE_FILES when the major protocol version is increased */
573 GET_SOURCE_FILES_2 = 13,
574 /* FIXME: Merge into GET_VALUES when the major protocol version is increased */
576 CMD_TYPE_GET_METHODS_BY_NAME_FLAGS = 15,
578 GET_INTERFACE_MAP = 17,
588 enum BindingFlagsExtensions {
589 BINDING_FLAGS_IGNORE_CASE = 0x70000000,
624 public int command_set;
629 internal static int GetPacketLength (byte[] header) {
631 return decode_int (header, ref offset);
634 internal static bool IsReplyPacket (byte[] packet) {
636 return decode_byte (packet, ref offset) == 0x80;
639 internal static int GetPacketId (byte[] packet) {
641 return decode_int (packet, ref offset);
644 static int decode_byte (byte[] packet, ref int offset) {
645 return packet [offset++];
648 static int decode_short (byte[] packet, ref int offset) {
649 int res = ((int)packet [offset] << 8) | (int)packet [offset + 1];
654 static int decode_int (byte[] packet, ref int offset) {
655 int res = ((int)packet [offset] << 24) | ((int)packet [offset + 1] << 16) | ((int)packet [offset + 2] << 8) | (int)packet [offset + 3];
660 static long decode_id (byte[] packet, ref int offset) {
661 return decode_int (packet, ref offset);
664 static long decode_long (byte[] packet, ref int offset) {
665 uint high = (uint)decode_int (packet, ref offset);
666 uint low = (uint)decode_int (packet, ref offset);
668 return (long)(((ulong)high << 32) | (ulong)low);
671 internal static SuspendPolicy decode_suspend_policy (int suspend_policy) {
672 switch ((WPSuspendPolicy)suspend_policy) {
673 case WPSuspendPolicy.NONE:
674 return SuspendPolicy.None;
675 case WPSuspendPolicy.EVENT_THREAD:
676 return SuspendPolicy.EventThread;
677 case WPSuspendPolicy.ALL:
678 return SuspendPolicy.All;
680 throw new NotImplementedException ();
684 static Header decode_command_header (byte[] packet) {
686 Header res = new Header ();
688 decode_int (packet, ref offset);
689 res.id = decode_int (packet, ref offset);
690 res.flags = decode_byte (packet, ref offset);
691 res.command_set = decode_byte (packet, ref offset);
692 res.command = decode_byte (packet, ref offset);
697 static void encode_byte (byte[] buf, int b, ref int offset) {
698 buf [offset] = (byte)b;
702 static void encode_int (byte[] buf, int i, ref int offset) {
703 buf [offset] = (byte)((i >> 24) & 0xff);
704 buf [offset + 1] = (byte)((i >> 16) & 0xff);
705 buf [offset + 2] = (byte)((i >> 8) & 0xff);
706 buf [offset + 3] = (byte)((i >> 0) & 0xff);
710 static void encode_id (byte[] buf, long id, ref int offset) {
711 encode_int (buf, (int)id, ref offset);
714 static void encode_long (byte[] buf, long l, ref int offset) {
715 encode_int (buf, (int)((l >> 32) & 0xffffffff), ref offset);
716 encode_int (buf, (int)(l & 0xffffffff), ref offset);
719 internal static byte[] EncodePacket (int id, int commandSet, int command, byte[] data, int dataLen) {
720 byte[] buf = new byte [dataLen + 11];
723 encode_int (buf, buf.Length, ref offset);
724 encode_int (buf, id, ref offset);
725 encode_byte (buf, 0, ref offset);
726 encode_byte (buf, commandSet, ref offset);
727 encode_byte (buf, command, ref offset);
729 for (int i = 0; i < dataLen; ++i)
730 buf [offset + i] = data [i];
739 public PacketReader (byte[] packet) {
740 this.packet = packet;
743 Header header = decode_command_header (packet);
744 CommandSet = (CommandSet)header.command_set;
745 Command = header.command;
749 ReadInt (); // length
751 ReadByte (); // flags
752 ErrorCode = ReadShort ();
755 public CommandSet CommandSet {
763 public int ErrorCode {
773 public int ReadByte () {
774 return decode_byte (packet, ref offset);
777 public int ReadShort () {
778 return decode_short (packet, ref offset);
781 public int ReadInt () {
782 return decode_int (packet, ref offset);
785 public long ReadId () {
786 return decode_id (packet, ref offset);
789 public long ReadLong () {
790 return decode_long (packet, ref offset);
793 public float ReadFloat () {
794 float f = DataConverter.FloatFromBE (packet, offset);
799 public double ReadDouble () {
800 double d = DataConverter.DoubleFromBE (packet, offset);
805 public string ReadString () {
806 int len = decode_int (packet, ref offset);
807 string res = new String (Encoding.UTF8.GetChars (packet, offset, len));
812 public string ReadUTF16String () {
813 int len = decode_int (packet, ref offset);
814 string res = new String (Encoding.Unicode.GetChars (packet, offset, len));
819 public ValueImpl ReadValue () {
820 ElementType etype = (ElementType)ReadByte ();
823 case ElementType.Void:
824 return new ValueImpl { Type = etype };
826 return new ValueImpl { Type = etype, Value = (sbyte)ReadInt () };
828 return new ValueImpl { Type = etype, Value = (byte)ReadInt () };
829 case ElementType.Boolean:
830 return new ValueImpl { Type = etype, Value = ReadInt () != 0 };
832 return new ValueImpl { Type = etype, Value = (short)ReadInt () };
834 return new ValueImpl { Type = etype, Value = (ushort)ReadInt () };
835 case ElementType.Char:
836 return new ValueImpl { Type = etype, Value = (char)ReadInt () };
838 return new ValueImpl { Type = etype, Value = ReadInt () };
840 return new ValueImpl { Type = etype, Value = (uint)ReadInt () };
842 return new ValueImpl { Type = etype, Value = ReadLong () };
844 return new ValueImpl { Type = etype, Value = (ulong)ReadLong () };
846 return new ValueImpl { Type = etype, Value = ReadFloat () };
848 return new ValueImpl { Type = etype, Value = ReadDouble () };
851 case ElementType.Ptr:
852 // FIXME: The client and the debuggee might have different word sizes
853 return new ValueImpl { Type = etype, Value = ReadLong () };
854 case ElementType.String:
855 case ElementType.SzArray:
856 case ElementType.Class:
857 case ElementType.Array:
858 case ElementType.Object:
859 long objid = ReadId ();
860 return new ValueImpl () { Type = etype, Objid = objid };
861 case ElementType.ValueType:
862 bool is_enum = ReadByte () == 1;
863 long klass = ReadId ();
864 long nfields = ReadInt ();
865 ValueImpl[] fields = new ValueImpl [nfields];
866 for (int i = 0; i < nfields; ++i)
867 fields [i] = ReadValue ();
868 return new ValueImpl () { Type = etype, Klass = klass, Fields = fields, IsEnum = is_enum };
869 case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
870 return new ValueImpl { Type = etype };
871 case (ElementType)ValueTypeId.VALUE_TYPE_ID_TYPE:
872 return new ValueImpl () { Type = etype, Id = ReadId () };
873 case (ElementType)ValueTypeId.VALUE_TYPE_ID_PARENT_VTYPE:
874 return new ValueImpl () { Type = etype, Index = ReadInt () };
876 throw new NotImplementedException ("Unable to handle type " + etype);
880 public long[] ReadIds (int n) {
881 long[] res = new long [n];
882 for (int i = 0; i < n; ++i)
893 public PacketWriter () {
894 data = new byte [1024];
898 void MakeRoom (int size) {
899 if (offset + size >= data.Length) {
900 int new_len = data.Length * 2;
901 while (new_len < offset + size) {
904 byte[] new_data = new byte [new_len];
905 Array.Copy (data, new_data, data.Length);
910 public PacketWriter WriteByte (byte val) {
912 encode_byte (data, val, ref offset);
916 public PacketWriter WriteInt (int val) {
918 encode_int (data, val, ref offset);
922 public PacketWriter WriteId (long id) {
924 encode_id (data, id, ref offset);
928 public PacketWriter WriteLong (long val) {
930 encode_long (data, val, ref offset);
934 public PacketWriter WriteFloat (float f) {
936 byte[] b = DataConverter.GetBytesBE (f);
937 for (int i = 0; i < 4; ++i)
938 data [offset + i] = b [i];
943 public PacketWriter WriteDouble (double d) {
945 byte[] b = DataConverter.GetBytesBE (d);
946 for (int i = 0; i < 8; ++i)
947 data [offset + i] = b [i];
952 public PacketWriter WriteInts (int[] ids) {
953 for (int i = 0; i < ids.Length; ++i)
958 public PacketWriter WriteIds (long[] ids) {
959 for (int i = 0; i < ids.Length; ++i)
964 public PacketWriter WriteString (string s) {
966 return WriteInt (-1);
968 byte[] b = Encoding.UTF8.GetBytes (s);
970 encode_int (data, b.Length, ref offset);
972 Buffer.BlockCopy (b, 0, data, offset, b.Length);
977 public PacketWriter WriteBool (bool val) {
978 WriteByte (val ? (byte)1 : (byte)0);
982 public PacketWriter WriteValue (ValueImpl v) {
986 t = TypeCodeToElementType (Type.GetTypeCode (v.Value.GetType ()));
991 case ElementType.Boolean:
992 WriteInt ((bool)v.Value ? 1 : 0);
994 case ElementType.Char:
995 WriteInt ((int)(char)v.Value);
998 WriteInt ((int)(sbyte)v.Value);
1000 case ElementType.U1:
1001 WriteInt ((int)(byte)v.Value);
1003 case ElementType.I2:
1004 WriteInt ((int)(short)v.Value);
1006 case ElementType.U2:
1007 WriteInt ((int)(ushort)v.Value);
1009 case ElementType.I4:
1010 WriteInt ((int)(int)v.Value);
1012 case ElementType.U4:
1013 WriteInt ((int)(uint)v.Value);
1015 case ElementType.I8:
1016 WriteLong ((long)(long)v.Value);
1018 case ElementType.U8:
1019 WriteLong ((long)(ulong)v.Value);
1021 case ElementType.R4:
1022 WriteFloat ((float)v.Value);
1024 case ElementType.R8:
1025 WriteDouble ((double)v.Value);
1027 case ElementType.String:
1028 case ElementType.SzArray:
1029 case ElementType.Class:
1030 case ElementType.Array:
1031 case ElementType.Object:
1034 case ElementType.ValueType:
1037 throw new NotImplementedException ();
1040 WriteInt (v.Fields.Length);
1041 for (int i = 0; i < v.Fields.Length; ++i)
1042 WriteValue (v.Fields [i]);
1044 case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
1047 throw new NotImplementedException ();
1053 public PacketWriter WriteValues (ValueImpl[] values) {
1054 for (int i = 0; i < values.Length; ++i)
1055 WriteValue (values [i]);
1059 public byte[] Data {
1072 delegate void ReplyCallback (int packet_id, byte[] packet);
1075 Thread receiver_thread;
1076 Dictionary<int, byte[]> reply_packets;
1077 Dictionary<int, ReplyCallback> reply_cbs;
1078 Dictionary<int, int> reply_cb_counts;
1079 object reply_packets_monitor;
1081 internal event EventHandler<ErrorHandlerEventArgs> ErrorHandler;
1083 protected Connection () {
1085 reply_packets = new Dictionary<int, byte[]> ();
1086 reply_cbs = new Dictionary<int, ReplyCallback> ();
1087 reply_cb_counts = new Dictionary<int, int> ();
1088 reply_packets_monitor = new Object ();
1089 if (EnableConnectionLogging) {
1090 var path = Environment.GetEnvironmentVariable ("MONO_SDB_LOG");
1091 if (path.Contains ("{0}")) {
1092 //C:\SomeDir\sdbLog{0}.txt -> C:\SomeDir\sdbLog1.txt
1093 LoggingStream = new StreamWriter (string.Format (path, ConnectionId++), false);
1094 } else if (Path.HasExtension (path)) {
1095 //C:\SomeDir\sdbLog.txt -> C:\SomeDir\sdbLog1.txt
1096 LoggingStream = new StreamWriter (Path.GetDirectoryName (path) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension (path) + ConnectionId++ + "." + Path.GetExtension (path), false);
1098 //C:\SomeDir\sdbLog -> C:\SomeDir\sdbLog1
1099 LoggingStream = new StreamWriter (path + ConnectionId++, false);
1104 protected abstract int TransportReceive (byte[] buf, int buf_offset, int len);
1105 protected abstract int TransportSend (byte[] buf, int buf_offset, int len);
1106 protected abstract void TransportSetTimeouts (int send_timeout, int receive_timeout);
1107 protected abstract void TransportClose ();
1109 internal VersionInfo Version;
1111 int Receive (byte[] buf, int buf_offset, int len) {
1114 while (offset < len) {
1115 int n = TransportReceive (buf, buf_offset + offset, len - offset);
1125 // Do the wire protocol handshake
1126 internal void Connect () {
1127 byte[] buf = new byte [HANDSHAKE_STRING.Length];
1128 char[] cbuf = new char [buf.Length];
1130 // FIXME: Add a timeout
1131 int n = Receive (buf, 0, buf.Length);
1133 throw new IOException ("DWP Handshake failed.");
1134 for (int i = 0; i < buf.Length; ++i)
1135 cbuf [i] = (char)buf [i];
1137 if (new String (cbuf) != HANDSHAKE_STRING)
1138 throw new IOException ("DWP Handshake failed.");
1140 TransportSend (buf, 0, buf.Length);
1142 receiver_thread = new Thread (new ThreadStart (receiver_thread_main));
1143 receiver_thread.Name = "SDB Receiver";
1144 receiver_thread.IsBackground = true;
1145 receiver_thread.Start ();
1147 Version = VM_GetVersion ();
1150 // Tell the debuggee our protocol version, so newer debuggees can work
1151 // with older clients
1155 // Older debuggees might not support this request
1156 EventHandler<ErrorHandlerEventArgs> OrigErrorHandler = ErrorHandler;
1157 ErrorHandler = null;
1158 ErrorHandler += delegate (object sender, ErrorHandlerEventArgs args) {
1159 throw new NotSupportedException ();
1162 VM_SetProtocolVersion (MAJOR_VERSION, MINOR_VERSION);
1163 } catch (NotSupportedException) {
1165 ErrorHandler = OrigErrorHandler;
1168 internal byte[] ReadPacket () {
1169 // FIXME: Throw ClosedConnectionException () if the connection is closed
1170 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1172 byte[] header = new byte [HEADER_LENGTH];
1174 int len = Receive (header, 0, header.Length);
1176 return new byte [0];
1177 if (len != HEADER_LENGTH) {
1179 throw new IOException ("Packet of length " + len + " is read.");
1182 int packetLength = GetPacketLength (header);
1183 if (packetLength < 11)
1184 throw new IOException ("Invalid packet length.");
1186 if (packetLength == 11) {
1189 byte[] buf = new byte [packetLength];
1190 for (int i = 0; i < header.Length; ++i)
1191 buf [i] = header [i];
1192 len = Receive (buf, header.Length, packetLength - header.Length);
1193 if (len != packetLength - header.Length)
1194 throw new IOException ();
1199 internal void WritePacket (byte[] packet) {
1200 // FIXME: Throw ClosedConnectionException () if the connection is closed
1201 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1203 TransportSend (packet, 0, packet.Length);
1206 internal void WritePackets (List<byte[]> packets) {
1207 // FIXME: Throw ClosedConnectionException () if the connection is closed
1208 // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1211 for (int i = 0; i < packets.Count; ++i)
1212 len += packets [i].Length;
1213 byte[] data = new byte [len];
1215 for (int i = 0; i < packets.Count; ++i) {
1216 Buffer.BlockCopy (packets [i], 0, data, pos, packets [i].Length);
1217 pos += packets [i].Length;
1219 TransportSend (data, 0, data.Length);
1222 internal void Close () {
1226 internal bool IsClosed {
1234 internal ManualResetEvent DisconnectedEvent = new ManualResetEvent (false);
1236 void receiver_thread_main () {
1239 bool res = ReceivePacket ();
1242 } catch (ThreadAbortException) {
1244 } catch (Exception ex) {
1246 Console.WriteLine (ex);
1252 lock (reply_packets_monitor) {
1253 disconnected = true;
1254 DisconnectedEvent.Set ();
1255 Monitor.PulseAll (reply_packets_monitor);
1258 EventHandler.VMDisconnect (0, 0, null);
1261 bool ReceivePacket () {
1262 byte[] packet = ReadPacket ();
1264 if (packet.Length == 0) {
1268 if (IsReplyPacket (packet)) {
1269 int id = GetPacketId (packet);
1270 ReplyCallback cb = null;
1271 lock (reply_packets_monitor) {
1272 reply_cbs.TryGetValue (id, out cb);
1274 reply_packets [id] = packet;
1275 Monitor.PulseAll (reply_packets_monitor);
1277 int c = reply_cb_counts [id];
1280 reply_cbs.Remove (id);
1281 reply_cb_counts.Remove (id);
1287 cb.Invoke (id, packet);
1289 PacketReader r = new PacketReader (packet);
1291 if (r.CommandSet == CommandSet.EVENT && r.Command == (int)CmdEvent.COMPOSITE) {
1292 int spolicy = r.ReadByte ();
1293 int nevents = r.ReadInt ();
1295 SuspendPolicy suspend_policy = decode_suspend_policy (spolicy);
1297 EventInfo[] events = new EventInfo [nevents];
1299 for (int i = 0; i < nevents; ++i) {
1300 EventKind kind = (EventKind)r.ReadByte ();
1301 int req_id = r.ReadInt ();
1303 EventType etype = (EventType)kind;
1305 long thread_id = r.ReadId ();
1306 if (kind == EventKind.VM_START) {
1307 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id };
1308 //EventHandler.VMStart (req_id, thread_id, null);
1309 } else if (kind == EventKind.VM_DEATH) {
1311 if (Version.AtLeast (2, 27))
1312 exit_code = r.ReadInt ();
1313 //EventHandler.VMDeath (req_id, 0, null);
1314 events [i] = new EventInfo (etype, req_id) { ExitCode = exit_code };
1315 } else if (kind == EventKind.THREAD_START) {
1316 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = thread_id };
1317 //EventHandler.ThreadStart (req_id, thread_id, thread_id);
1318 } else if (kind == EventKind.THREAD_DEATH) {
1319 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = thread_id };
1320 //EventHandler.ThreadDeath (req_id, thread_id, thread_id);
1321 } else if (kind == EventKind.ASSEMBLY_LOAD) {
1322 long id = r.ReadId ();
1323 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1324 //EventHandler.AssemblyLoad (req_id, thread_id, id);
1325 } else if (kind == EventKind.ASSEMBLY_UNLOAD) {
1326 long id = r.ReadId ();
1327 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1328 //EventHandler.AssemblyUnload (req_id, thread_id, id);
1329 } else if (kind == EventKind.TYPE_LOAD) {
1330 long id = r.ReadId ();
1331 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1332 //EventHandler.TypeLoad (req_id, thread_id, id);
1333 } else if (kind == EventKind.METHOD_ENTRY) {
1334 long id = r.ReadId ();
1335 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1336 //EventHandler.MethodEntry (req_id, thread_id, id);
1337 } else if (kind == EventKind.METHOD_EXIT) {
1338 long id = r.ReadId ();
1339 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1340 //EventHandler.MethodExit (req_id, thread_id, id);
1341 } else if (kind == EventKind.BREAKPOINT) {
1342 long id = r.ReadId ();
1343 long loc = r.ReadLong ();
1344 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1345 //EventHandler.Breakpoint (req_id, thread_id, id, loc);
1346 } else if (kind == EventKind.STEP) {
1347 long id = r.ReadId ();
1348 long loc = r.ReadLong ();
1349 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1350 //EventHandler.Step (req_id, thread_id, id, loc);
1351 } else if (kind == EventKind.EXCEPTION) {
1352 long id = r.ReadId ();
1353 long loc = 0; // FIXME
1354 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1355 //EventHandler.Exception (req_id, thread_id, id, loc);
1356 } else if (kind == EventKind.APPDOMAIN_CREATE) {
1357 long id = r.ReadId ();
1358 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1359 //EventHandler.AppDomainCreate (req_id, thread_id, id);
1360 } else if (kind == EventKind.APPDOMAIN_UNLOAD) {
1361 long id = r.ReadId ();
1362 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
1363 //EventHandler.AppDomainUnload (req_id, thread_id, id);
1364 } else if (kind == EventKind.USER_BREAK) {
1367 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id, Location = loc };
1368 //EventHandler.Exception (req_id, thread_id, id, loc);
1369 } else if (kind == EventKind.USER_LOG) {
1370 int level = r.ReadInt ();
1371 string category = r.ReadString ();
1372 string message = r.ReadString ();
1373 events [i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Level = level, Category = category, Message = message };
1374 //EventHandler.Exception (req_id, thread_id, id, loc);
1375 } else if (kind == EventKind.KEEPALIVE) {
1376 events [i] = new EventInfo (etype, req_id) { };
1378 throw new NotImplementedException ("Unknown event kind: " + kind);
1382 EventHandler.Events (suspend_policy, events);
1389 internal IEventHandler EventHandler {
1393 static String CommandString (CommandSet command_set, int command)
1396 switch (command_set) {
1398 cmd = ((CmdVM)command).ToString ();
1400 case CommandSet.OBJECT_REF:
1401 cmd = ((CmdObjectRef)command).ToString ();
1403 case CommandSet.STRING_REF:
1404 cmd = ((CmdStringRef)command).ToString ();
1406 case CommandSet.THREAD:
1407 cmd = ((CmdThread)command).ToString ();
1409 case CommandSet.ARRAY_REF:
1410 cmd = ((CmdArrayRef)command).ToString ();
1412 case CommandSet.EVENT_REQUEST:
1413 cmd = ((CmdEventRequest)command).ToString ();
1415 case CommandSet.STACK_FRAME:
1416 cmd = ((CmdStackFrame)command).ToString ();
1418 case CommandSet.APPDOMAIN:
1419 cmd = ((CmdAppDomain)command).ToString ();
1421 case CommandSet.ASSEMBLY:
1422 cmd = ((CmdAssembly)command).ToString ();
1424 case CommandSet.METHOD:
1425 cmd = ((CmdMethod)command).ToString ();
1427 case CommandSet.TYPE:
1428 cmd = ((CmdType)command).ToString ();
1430 case CommandSet.MODULE:
1431 cmd = ((CmdModule)command).ToString ();
1433 case CommandSet.FIELD:
1434 cmd = ((CmdField)command).ToString ();
1436 case CommandSet.EVENT:
1437 cmd = ((CmdEvent)command).ToString ();
1440 cmd = command.ToString ();
1443 return string.Format ("[{0} {1}]", command_set, cmd);
1446 long total_protocol_ticks;
1448 void LogPacket (int packet_id, byte[] encoded_packet, byte[] reply_packet, CommandSet command_set, int command, Stopwatch watch) {
1450 total_protocol_ticks += watch.ElapsedTicks;
1451 var ts = TimeSpan.FromTicks (total_protocol_ticks);
1452 string msg = string.Format ("Packet: {0} sent: {1} received: {2} ms: {3} total ms: {4} {5}",
1453 packet_id, encoded_packet.Length, reply_packet.Length, watch.ElapsedMilliseconds,
1454 (ts.Seconds * 1000) + ts.Milliseconds,
1455 CommandString (command_set, command));
1457 LoggingStream.WriteLine (msg);
1458 LoggingStream.Flush ();
1461 bool buffer_packets;
1462 List<byte[]> buffered_packets = new List<byte[]> ();
1465 // Start buffering request/response packets on both the client and the debuggee side.
1466 // Packets sent between StartBuffering ()/StopBuffering () must be async, i.e. sent
1467 // using Send () and not SendReceive ().
1469 public void StartBuffering () {
1470 buffer_packets = true;
1471 if (Version.AtLeast (2, 34))
1472 VM_StartBuffering ();
1475 public void StopBuffering () {
1476 if (Version.AtLeast (2, 34))
1477 VM_StopBuffering ();
1478 buffer_packets = false;
1480 WritePackets (buffered_packets);
1481 if (EnableConnectionLogging) {
1482 LoggingStream.WriteLine (String.Format ("Sent {0} packets.", buffered_packets.Count));
1483 LoggingStream.Flush ();
1485 buffered_packets.Clear ();
1488 /* Send a request and call cb when a result is received */
1489 int Send (CommandSet command_set, int command, PacketWriter packet, Action<PacketReader> cb, int count) {
1490 int id = IdGenerator;
1492 Stopwatch watch = null;
1493 if (EnableConnectionLogging)
1494 watch = Stopwatch.StartNew ();
1496 byte[] encoded_packet;
1498 encoded_packet = EncodePacket (id, (int)command_set, command, null, 0);
1500 encoded_packet = EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset);
1503 lock (reply_packets_monitor) {
1504 reply_cbs [id] = delegate (int packet_id, byte[] p) {
1505 if (EnableConnectionLogging)
1506 LogPacket (packet_id, encoded_packet, p, command_set, command, watch);
1507 /* Run the callback on a tp thread to avoid blocking the receive thread */
1508 PacketReader r = new PacketReader (p);
1509 cb.BeginInvoke (r, null, null);
1511 reply_cb_counts [id] = count;
1516 buffered_packets.Add (encoded_packet);
1518 WritePacket (encoded_packet);
1523 // Send a request without waiting for an answer
1524 void Send (CommandSet command_set, int command) {
1525 Send (command_set, command, null, null, 0);
1528 PacketReader SendReceive (CommandSet command_set, int command, PacketWriter packet) {
1529 int id = IdGenerator;
1530 Stopwatch watch = null;
1533 throw new VMDisconnectedException ();
1535 if (EnableConnectionLogging)
1536 watch = Stopwatch.StartNew ();
1538 byte[] encoded_packet;
1541 encoded_packet = EncodePacket (id, (int)command_set, command, null, 0);
1543 encoded_packet = EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset);
1545 WritePacket (encoded_packet);
1549 /* Wait for the reply packet */
1551 lock (reply_packets_monitor) {
1552 if (reply_packets.ContainsKey (packetId)) {
1553 byte[] reply = reply_packets [packetId];
1554 reply_packets.Remove (packetId);
1555 PacketReader r = new PacketReader (reply);
1557 if (EnableConnectionLogging)
1558 LogPacket (packetId, encoded_packet, reply, command_set, command, watch);
1559 if (r.ErrorCode != 0) {
1560 if (ErrorHandler != null)
1561 ErrorHandler (this, new ErrorHandlerEventArgs () { ErrorCode = (ErrorCode)r.ErrorCode });
1562 throw new NotImplementedException ("No error handler set.");
1568 throw new VMDisconnectedException ();
1569 Monitor.Wait (reply_packets_monitor);
1575 PacketReader SendReceive (CommandSet command_set, int command) {
1576 return SendReceive (command_set, command, null);
1579 int packet_id_generator;
1583 return Interlocked.Increment (ref packet_id_generator);
1587 CattrInfo[] ReadCattrs (PacketReader r) {
1588 CattrInfo[] res = new CattrInfo [r.ReadInt ()];
1589 for (int i = 0; i < res.Length; ++i) {
1590 CattrInfo info = new CattrInfo ();
1591 info.ctor_id = r.ReadId ();
1592 info.ctor_args = new ValueImpl [r.ReadInt ()];
1593 for (int j = 0; j < info.ctor_args.Length; ++j) {
1594 info.ctor_args [j] = r.ReadValue ();
1596 info.named_args = new CattrNamedArgInfo [r.ReadInt ()];
1597 for (int j = 0; j < info.named_args.Length; ++j) {
1598 CattrNamedArgInfo arg = new CattrNamedArgInfo ();
1599 int arg_type = r.ReadByte ();
1600 arg.is_property = arg_type == 0x54;
1601 arg.id = r.ReadId ();
1602 arg.value = r.ReadValue ();
1603 info.named_args [j] = arg;
1610 static ElementType TypeCodeToElementType (TypeCode c) {
1612 case TypeCode.Boolean:
1613 return ElementType.Boolean;
1615 return ElementType.Char;
1616 case TypeCode.SByte:
1617 return ElementType.I1;
1619 return ElementType.U1;
1620 case TypeCode.Int16:
1621 return ElementType.I2;
1622 case TypeCode.UInt16:
1623 return ElementType.U2;
1624 case TypeCode.Int32:
1625 return ElementType.I4;
1626 case TypeCode.UInt32:
1627 return ElementType.U4;
1628 case TypeCode.Int64:
1629 return ElementType.I8;
1630 case TypeCode.UInt64:
1631 return ElementType.U8;
1632 case TypeCode.Single:
1633 return ElementType.R4;
1634 case TypeCode.Double:
1635 return ElementType.R8;
1637 throw new NotImplementedException ();
1642 * Implementation of debugger commands
1645 internal VersionInfo VM_GetVersion () {
1646 var res = SendReceive (CommandSet.VM, (int)CmdVM.VERSION, null);
1647 VersionInfo info = new VersionInfo ();
1648 info.VMVersion = res.ReadString ();
1649 info.MajorVersion = res.ReadInt ();
1650 info.MinorVersion = res.ReadInt ();
1654 internal void VM_SetProtocolVersion (int major, int minor) {
1655 SendReceive (CommandSet.VM, (int)CmdVM.SET_PROTOCOL_VERSION, new PacketWriter ().WriteInt (major).WriteInt (minor));
1658 internal void VM_GetThreads (Action<long[]> resultCallaback) {
1659 Send (CommandSet.VM, (int)CmdVM.ALL_THREADS, null, (res) => {
1660 int len = res.ReadInt ();
1661 long[] arr = new long [len];
1662 for (int i = 0; i < len; ++i)
1663 arr [i] = res.ReadId ();
1664 resultCallaback(arr);
1668 internal void VM_Suspend () {
1669 SendReceive (CommandSet.VM, (int)CmdVM.SUSPEND);
1672 internal void VM_Resume () {
1673 SendReceive (CommandSet.VM, (int)CmdVM.RESUME);
1676 internal void VM_Exit (int exitCode) {
1677 SendReceive (CommandSet.VM, (int)CmdVM.EXIT, new PacketWriter ().WriteInt (exitCode));
1680 internal void VM_Dispose () {
1681 SendReceive (CommandSet.VM, (int)CmdVM.DISPOSE);
1684 internal ValueImpl VM_InvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, out ValueImpl exc) {
1686 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));
1687 if (r.ReadByte () == 0) {
1688 exc = r.ReadValue ();
1691 return r.ReadValue ();
1695 internal delegate void InvokeMethodCallback (ValueImpl v, ValueImpl exc, ValueImpl out_this, ValueImpl[] out_args, ErrorCode error, object state);
1697 void read_invoke_res (PacketReader r, out ValueImpl v, out ValueImpl exc, out ValueImpl out_this, out ValueImpl[] out_args) {
1698 int resflags = r.ReadByte ();
1703 if (resflags == 0) {
1704 exc = r.ReadValue ();
1707 if ((resflags & 2) != 0)
1708 out_this = r.ReadValue ();
1709 if ((resflags & 4) != 0) {
1710 int nargs = r.ReadInt ();
1711 out_args = new ValueImpl [nargs];
1712 for (int i = 0; i < nargs; ++i)
1713 out_args [i] = r.ReadValue ();
1718 internal int VM_BeginInvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, InvokeMethodCallback callback, object state) {
1719 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) {
1720 ValueImpl v, exc, out_this = null;
1721 ValueImpl[] out_args = null;
1723 if (r.ErrorCode != 0) {
1724 callback (null, null, null, null, (ErrorCode)r.ErrorCode, state);
1726 read_invoke_res (r, out v, out exc, out out_this, out out_args);
1727 callback (v, exc, out_this, out_args, 0, state);
1732 internal int VM_BeginInvokeMethods (long thread, long[] methods, ValueImpl this_arg, List<ValueImpl[]> arguments, InvokeFlags flags, InvokeMethodCallback callback, object state) {
1733 // FIXME: Merge this with INVOKE_METHOD
1734 var w = new PacketWriter ();
1736 w.WriteInt ((int)flags);
1737 w.WriteInt (methods.Length);
1738 for (int i = 0; i < methods.Length; ++i) {
1739 w.WriteId (methods [i]);
1740 w.WriteValue (this_arg);
1741 w.WriteInt (arguments [i].Length);
1742 w.WriteValues (arguments [i]);
1744 return Send (CommandSet.VM, (int)CmdVM.INVOKE_METHODS, w, delegate (PacketReader r) {
1745 ValueImpl v, exc, out_this = null;
1746 ValueImpl[] out_args = null;
1748 if (r.ErrorCode != 0) {
1749 callback (null, null, null, null, (ErrorCode)r.ErrorCode, state);
1751 read_invoke_res (r, out v, out exc, out out_this, out out_args);
1752 callback (v, exc, out_this, out_args, 0, state);
1757 internal void VM_AbortInvoke (long thread, int id)
1759 SendReceive (CommandSet.VM, (int)CmdVM.ABORT_INVOKE, new PacketWriter ().WriteId (thread).WriteInt (id));
1762 internal void SetSocketTimeouts (int send_timeout, int receive_timeout, int keepalive_interval)
1764 TransportSetTimeouts (send_timeout, receive_timeout);
1765 SendReceive (CommandSet.VM, (int)CmdVM.SET_KEEPALIVE, new PacketWriter ().WriteId (keepalive_interval));
1768 internal long[] VM_GetTypesForSourceFile (string fname, bool ignoreCase) {
1769 var res = SendReceive (CommandSet.VM, (int)CmdVM.GET_TYPES_FOR_SOURCE_FILE, new PacketWriter ().WriteString (fname).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 long[] VM_GetTypes (string name, bool ignoreCase) {
1778 var res = SendReceive (CommandSet.VM, (int)CmdVM.GET_TYPES, new PacketWriter ().WriteString (name).WriteBool (ignoreCase));
1779 int count = res.ReadInt ();
1780 long[] types = new long [count];
1781 for (int i = 0; i < count; ++i)
1782 types [i] = res.ReadId ();
1786 internal void VM_StartBuffering () {
1787 Send (CommandSet.VM, (int)CmdVM.START_BUFFERING);
1790 internal void VM_StopBuffering () {
1791 Send (CommandSet.VM, (int)CmdVM.STOP_BUFFERING);
1798 internal long RootDomain {
1800 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ROOT_DOMAIN, null).ReadId ();
1804 internal string Domain_GetName (long id) {
1805 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_FRIENDLY_NAME, new PacketWriter ().WriteId (id)).ReadString ();
1808 internal long[] Domain_GetAssemblies (long id) {
1809 var res = SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ASSEMBLIES, new PacketWriter ().WriteId (id));
1810 int count = res.ReadInt ();
1811 long[] assemblies = new long [count];
1812 for (int i = 0; i < count; ++i)
1813 assemblies [i] = res.ReadId ();
1817 internal long Domain_GetEntryAssembly (long id) {
1818 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ENTRY_ASSEMBLY, new PacketWriter ().WriteId (id)).ReadId ();
1821 internal long Domain_GetCorlib (long id) {
1822 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_CORLIB, new PacketWriter ().WriteId (id)).ReadId ();
1825 internal long Domain_CreateString (long id, string s) {
1826 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.CREATE_STRING, new PacketWriter ().WriteId (id).WriteString (s)).ReadId ();
1829 internal long Domain_CreateBoxedValue (long id, long type_id, ValueImpl v) {
1830 return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.CREATE_BOXED_VALUE, new PacketWriter ().WriteId (id).WriteId (type_id).WriteValue (v)).ReadId ();
1837 internal string Method_GetName (long id) {
1838 return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
1841 internal long Method_GetDeclaringType (long id) {
1842 return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DECLARING_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
1845 internal DebugInfo Method_GetDebugInfo (long id) {
1846 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DEBUG_INFO, new PacketWriter ().WriteId (id));
1848 DebugInfo info = new DebugInfo ();
1849 info.max_il_offset = res.ReadInt ();
1851 SourceInfo[] sources = null;
1852 if (Version.AtLeast (2, 13)) {
1853 int n = res.ReadInt ();
1854 sources = new SourceInfo [n];
1855 for (int i = 0; i < n; ++i) {
1856 sources [i].source_file = res.ReadString ();
1857 if (Version.AtLeast (2, 14)) {
1858 sources [i].hash = new byte [16];
1859 for (int j = 0; j < 16; ++j)
1860 sources [i].hash [j] = (byte)res.ReadByte ();
1864 sources = new SourceInfo [1];
1865 sources [0].source_file = res.ReadString ();
1868 int n_il_offsets = res.ReadInt ();
1869 info.il_offsets = new int [n_il_offsets];
1870 info.line_numbers = new int [n_il_offsets];
1871 info.source_files = new SourceInfo [n_il_offsets];
1872 info.column_numbers = new int [n_il_offsets];
1873 info.end_line_numbers = new int [n_il_offsets];
1874 info.end_column_numbers = new int [n_il_offsets];
1875 for (int i = 0; i < n_il_offsets; ++i) {
1876 info.il_offsets [i] = res.ReadInt ();
1877 info.line_numbers [i] = res.ReadInt ();
1878 if (Version.AtLeast (2, 12)) {
1879 int idx = res.ReadInt ();
1880 info.source_files [i] = idx >= 0 ? sources [idx] : default (SourceInfo);
1882 info.source_files [i] = sources [0];
1884 if (Version.AtLeast (2, 19))
1885 info.column_numbers [i] = res.ReadInt ();
1887 info.column_numbers [i] = 0;
1888 if (Version.AtLeast (2, 32)) {
1889 info.end_line_numbers [i] = res.ReadInt ();
1890 info.end_column_numbers [i] = res.ReadInt ();
1892 info.end_column_numbers [i] = -1;
1893 info.end_column_numbers [i] = -1;
1900 internal ParamInfo Method_GetParamInfo (long id) {
1901 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_PARAM_INFO, new PacketWriter ().WriteId (id));
1903 ParamInfo info = new ParamInfo ();
1904 info.call_conv = res.ReadInt ();
1905 info.param_count = res.ReadInt ();
1906 info.generic_param_count = res.ReadInt ();
1907 info.ret_type = res.ReadId ();
1908 info.param_types = new long [info.param_count];
1909 for (int i = 0; i < info.param_count; ++i)
1910 info.param_types [i] = res.ReadId ();
1911 info.param_names = new string [info.param_count];
1912 for (int i = 0; i < info.param_count; ++i)
1913 info.param_names [i] = res.ReadString ();
1918 internal LocalsInfo Method_GetLocalsInfo (long id) {
1919 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_LOCALS_INFO, new PacketWriter ().WriteId (id));
1921 LocalsInfo info = new LocalsInfo ();
1923 if (Version.AtLeast (2, 43)) {
1924 int nscopes = res.ReadInt ();
1925 info.scopes_start = new int [nscopes];
1926 info.scopes_end = new int [nscopes];
1928 for (int i = 0; i < nscopes; ++i) {
1929 info.scopes_start [i] = last_start + res.ReadInt ();
1930 info.scopes_end [i] = info.scopes_start [i] + res.ReadInt ();
1931 last_start = info.scopes_start [i];
1933 if (Version.AtLeast (2, 46)) {
1934 info.nhoisted = res.ReadInt ();
1935 info.hoisted_scopes_start = new int [info.nhoisted];
1936 info.hoisted_scopes_end = new int [info.nhoisted];
1937 for (int i = 0; i < info.nhoisted; ++i) {
1938 info.hoisted_scopes_start [i] = res.ReadInt ();
1939 info.hoisted_scopes_end [i] = res.ReadInt ();
1944 int nlocals = res.ReadInt ();
1945 info.types = new long [nlocals];
1946 for (int i = 0; i < nlocals; ++i)
1947 info.types [i] = res.ReadId ();
1948 info.names = new string [nlocals];
1949 for (int i = 0; i < nlocals; ++i)
1950 info.names [i] = res.ReadString ();
1951 info.live_range_start = new int [nlocals];
1952 info.live_range_end = new int [nlocals];
1953 for (int i = 0; i < nlocals; ++i) {
1954 info.live_range_start [i] = res.ReadInt ();
1955 info.live_range_end [i] = res.ReadInt ();
1961 internal MethodInfo Method_GetInfo (long id) {
1962 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_INFO, new PacketWriter ().WriteId (id));
1964 MethodInfo info = new MethodInfo ();
1965 info.attributes = res.ReadInt ();
1966 info.iattributes = res.ReadInt ();
1967 info.token = res.ReadInt ();
1968 if (Version.AtLeast (2, 12)) {
1969 int attrs = res.ReadByte ();
1970 if ((attrs & (1 << 0)) != 0)
1972 if ((attrs & (1 << 1)) != 0)
1973 info.is_generic_method = true;
1974 info.gmd = res.ReadId ();
1975 if (Version.AtLeast (2, 15)) {
1976 if (info.is_generic_method) {
1977 int n = res.ReadInt ();
1978 info.type_args = res.ReadIds (n);
1985 internal MethodBodyInfo Method_GetBody (long id) {
1986 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_BODY, new PacketWriter ().WriteId (id));
1988 MethodBodyInfo info = new MethodBodyInfo ();
1989 info.il = new byte [res.ReadInt ()];
1990 for (int i = 0; i < info.il.Length; ++i)
1991 info.il [i] = (byte)res.ReadByte ();
1993 if (Version.AtLeast (2, 18)) {
1994 info.clauses = new ExceptionClauseInfo [res.ReadInt ()];
1996 for (int i = 0; i < info.clauses.Length; ++i) {
1997 var clause = new ExceptionClauseInfo {
1998 flags = (ExceptionClauseFlags) res.ReadInt (),
1999 try_offset = res.ReadInt (),
2000 try_length = res.ReadInt (),
2001 handler_offset = res.ReadInt (),
2002 handler_length = res.ReadInt (),
2005 if (clause.flags == ExceptionClauseFlags.None)
2006 clause.catch_type_id = res.ReadId ();
2007 else if (clause.flags == ExceptionClauseFlags.Filter)
2008 clause.filter_offset = res.ReadInt ();
2010 info.clauses [i] = clause;
2013 info.clauses = new ExceptionClauseInfo [0];
2018 internal ResolvedToken Method_ResolveToken (long id, int token) {
2019 var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.RESOLVE_TOKEN, new PacketWriter ().WriteId (id).WriteInt (token));
2021 TokenType type = (TokenType)res.ReadByte ();
2023 case TokenType.STRING:
2024 return new ResolvedToken () { Type = type, Str = res.ReadString () };
2025 case TokenType.TYPE:
2026 case TokenType.METHOD:
2027 case TokenType.FIELD:
2028 return new ResolvedToken () { Type = type, Id = res.ReadId () };
2029 case TokenType.UNKNOWN:
2030 return new ResolvedToken () { Type = type };
2032 throw new NotImplementedException ();
2036 internal CattrInfo[] Method_GetCustomAttributes (long id, long attr_type_id, bool inherit) {
2037 PacketReader r = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_CATTRS, new PacketWriter ().WriteId (id).WriteId (attr_type_id));
2038 return ReadCattrs (r);
2041 internal long Method_MakeGenericMethod (long id, long[] args) {
2042 PacketReader r = SendReceive (CommandSet.METHOD, (int)CmdMethod.MAKE_GENERIC_METHOD, new PacketWriter ().WriteId (id).WriteInt (args.Length).WriteIds (args));
2050 internal string Thread_GetName (long id) {
2051 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
2054 internal void Thread_GetFrameInfo (long id, int start_frame, int length, Action<FrameInfo[]> resultCallaback) {
2055 Send (CommandSet.THREAD, (int)CmdThread.GET_FRAME_INFO, new PacketWriter ().WriteId (id).WriteInt (start_frame).WriteInt (length), (res) => {
2056 int count = res.ReadInt ();
2057 var frames = new FrameInfo[count];
2058 for (int i = 0; i < count; ++i) {
2059 var f = new FrameInfo ();
2060 f.id = res.ReadInt ();
2061 f.method = res.ReadId ();
2062 f.il_offset = res.ReadInt ();
2063 f.flags = (StackFrameFlags)res.ReadByte ();
2066 resultCallaback (frames);
2070 internal int Thread_GetState (long id) {
2071 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_STATE, new PacketWriter ().WriteId (id)).ReadInt ();
2074 internal ThreadInfo Thread_GetInfo (long id) {
2075 PacketReader r = SendReceive (CommandSet.THREAD, (int)CmdThread.GET_INFO, new PacketWriter ().WriteId (id));
2077 ThreadInfo res = new ThreadInfo () { is_thread_pool = r.ReadByte () > 0 ? true : false };
2082 internal long Thread_GetId (long id) {
2083 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_ID, new PacketWriter ().WriteId (id)).ReadLong ();
2086 internal long Thread_GetTID (long id) {
2087 return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_TID, new PacketWriter ().WriteId (id)).ReadLong ();
2090 internal void Thread_SetIP (long id, long method_id, long il_offset) {
2091 SendReceive (CommandSet.THREAD, (int)CmdThread.SET_IP, new PacketWriter ().WriteId (id).WriteId (method_id).WriteLong (il_offset));
2098 internal ModuleInfo Module_GetInfo (long id) {
2099 PacketReader r = SendReceive (CommandSet.MODULE, (int)CmdModule.GET_INFO, new PacketWriter ().WriteId (id));
2100 ModuleInfo info = new ModuleInfo { Name = r.ReadString (), ScopeName = r.ReadString (), FQName = r.ReadString (), Guid = r.ReadString (), Assembly = r.ReadId () };
2108 internal string Assembly_GetLocation (long id) {
2109 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_LOCATION, new PacketWriter ().WriteId (id)).ReadString ();
2112 internal long Assembly_GetEntryPoint (long id) {
2113 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_ENTRY_POINT, new PacketWriter ().WriteId (id)).ReadId ();
2116 internal long Assembly_GetManifestModule (long id) {
2117 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_MANIFEST_MODULE, new PacketWriter ().WriteId (id)).ReadId ();
2120 internal long Assembly_GetObject (long id) {
2121 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
2124 internal long Assembly_GetType (long id, string name, bool ignoreCase) {
2125 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_TYPE, new PacketWriter ().WriteId (id).WriteString (name).WriteBool (ignoreCase)).ReadId ();
2128 internal string Assembly_GetName (long id) {
2129 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
2132 internal long Assembly_GetIdDomain (long id) {
2133 return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_DOMAIN, new PacketWriter ().WriteId (id)).ReadId ();
2140 internal TypeInfo Type_GetInfo (long id) {
2141 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INFO, new PacketWriter ().WriteId (id));
2142 TypeInfo res = new TypeInfo ();
2144 res.ns = r.ReadString ();
2145 res.name = r.ReadString ();
2146 res.full_name = r.ReadString ();
2147 res.assembly = r.ReadId ();
2148 res.module = r.ReadId ();
2149 res.base_type = r.ReadId ();
2150 res.element_type = r.ReadId ();
2151 res.token = r.ReadInt ();
2152 res.rank = r.ReadByte ();
2153 res.attributes = r.ReadInt ();
2154 int b = r.ReadByte ();
2155 res.is_byref = (b & 1) != 0;
2156 res.is_pointer = (b & 2) != 0;
2157 res.is_primitive = (b & 4) != 0;
2158 res.is_valuetype = (b & 8) != 0;
2159 res.is_enum = (b & 16) != 0;
2160 res.is_gtd = (b & 32) != 0;
2161 res.is_generic_type = (b & 64) != 0;
2163 int nested_len = r.ReadInt ();
2164 res.nested = new long [nested_len];
2165 for (int i = 0; i < nested_len; ++i)
2166 res.nested [i] = r.ReadId ();
2168 if (Version.AtLeast (2, 12))
2169 res.gtd = r.ReadId ();
2170 if (Version.AtLeast (2, 15) && res.is_generic_type) {
2171 int n = r.ReadInt ();
2172 res.type_args = r.ReadIds (n);
2178 internal long[] Type_GetMethods (long id) {
2179 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_METHODS, new PacketWriter ().WriteId (id));
2181 int n = r.ReadInt ();
2182 long[] res = new long [n];
2183 for (int i = 0; i < n; ++i)
2184 res [i] = r.ReadId ();
2188 internal long[] Type_GetFields (long id, out string[] names, out long[] types, out int[] attrs) {
2189 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_FIELDS, new PacketWriter ().WriteId (id));
2191 int n = r.ReadInt ();
2192 long[] res = new long [n];
2193 names = new string [n];
2194 types = new long [n];
2195 attrs = new int [n];
2196 for (int i = 0; i < n; ++i) {
2197 res [i] = r.ReadId ();
2198 names [i] = r.ReadString ();
2199 types [i] = r.ReadId ();
2200 attrs [i] = r.ReadInt ();
2205 internal PropInfo[] Type_GetProperties (long id) {
2206 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_PROPERTIES, new PacketWriter ().WriteId (id));
2208 int n = r.ReadInt ();
2209 PropInfo[] res = new PropInfo [n];
2210 for (int i = 0; i < n; ++i) {
2211 res [i] = new PropInfo ();
2212 res [i].id = r.ReadId ();
2213 res [i].name = r.ReadString ();
2214 res [i].get_method = r.ReadId ();
2215 res [i].set_method = r.ReadId ();
2216 res [i].attrs = r.ReadInt ();
2222 internal long Type_GetObject (long id) {
2223 return SendReceive (CommandSet.TYPE, (int)CmdType.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
2226 internal ValueImpl[] Type_GetValues (long id, long[] fields, long thread_id) {
2227 int len = fields.Length;
2230 r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES_2, new PacketWriter ().WriteId (id).WriteId (thread_id).WriteInt (len).WriteIds (fields));
2232 r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));
2234 ValueImpl[] res = new ValueImpl [len];
2235 for (int i = 0; i < len; ++i)
2236 res [i] = r.ReadValue ();
2240 internal void Type_SetValues (long id, long[] fields, ValueImpl[] values) {
2241 SendReceive (CommandSet.TYPE, (int)CmdType.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
2244 internal string[] Type_GetSourceFiles (long id, bool return_full_paths) {
2245 var r = SendReceive (CommandSet.TYPE, return_full_paths ? (int)CmdType.GET_SOURCE_FILES_2 : (int)CmdType.GET_SOURCE_FILES, new PacketWriter ().WriteId (id));
2246 int len = r.ReadInt ();
2247 string[] res = new string [len];
2248 for (int i = 0; i < len; ++i)
2249 res [i] = r.ReadString ();
2253 internal bool Type_IsAssignableFrom (long id, long c_id) {
2254 return SendReceive (CommandSet.TYPE, (int)CmdType.IS_ASSIGNABLE_FROM, new PacketWriter ().WriteId (id).WriteId (c_id)).ReadByte () > 0;
2257 internal CattrInfo[] Type_GetCustomAttributes (long id, long attr_type_id, bool inherit) {
2258 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_CATTRS, new PacketWriter ().WriteId (id).WriteId (attr_type_id));
2259 return ReadCattrs (r);
2262 internal CattrInfo[] Type_GetFieldCustomAttributes (long id, long field_id, long attr_type_id, bool inherit) {
2263 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_FIELD_CATTRS, new PacketWriter ().WriteId (id).WriteId (field_id).WriteId (attr_type_id));
2264 return ReadCattrs (r);
2267 internal CattrInfo[] Type_GetPropertyCustomAttributes (long id, long field_id, long attr_type_id, bool inherit) {
2268 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_PROPERTY_CATTRS, new PacketWriter ().WriteId (id).WriteId (field_id).WriteId (attr_type_id));
2269 return ReadCattrs (r);
2272 public long[] Type_GetMethodsByNameFlags (long id, string name, int flags, bool ignoreCase) {
2273 flags |= ignoreCase ? (int)BindingFlagsExtensions.BINDING_FLAGS_IGNORE_CASE : 0;
2274 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.CMD_TYPE_GET_METHODS_BY_NAME_FLAGS, new PacketWriter ().WriteId (id).WriteString (name).WriteInt (flags));
2275 int len = r.ReadInt ();
2276 long[] res = new long [len];
2277 for (int i = 0; i < len; ++i)
2278 res [i] = r.ReadId ();
2282 internal long[] Type_GetInterfaces (long id) {
2283 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INTERFACES, new PacketWriter ().WriteId (id));
2284 int len = r.ReadInt ();
2285 return r.ReadIds (len);
2288 internal IfaceMapInfo[] Type_GetInterfaceMap (long id, long[] ids) {
2289 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INTERFACE_MAP, new PacketWriter ().WriteId (id).WriteInt (ids.Length).WriteIds (ids));
2290 var res = new IfaceMapInfo [ids.Length];
2291 for (int i = 0; i < ids.Length; ++i) {
2292 int n = r.ReadInt ();
2294 res [i].iface_id = ids [i];
2295 res [i].iface_methods = r.ReadIds (n);
2296 res [i].target_methods = r.ReadIds (n);
2302 internal bool Type_IsInitialized (long id) {
2303 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.IS_INITIALIZED, new PacketWriter ().WriteId (id));
2304 return r.ReadInt () == 1;
2307 internal long Type_CreateInstance (long id) {
2308 PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.CREATE_INSTANCE, new PacketWriter ().WriteId (id));
2316 internal FieldMirrorInfo Field_GetInfo (long id) {
2317 PacketReader r = SendReceive (CommandSet.FIELD, (int)CmdField.GET_INFO, new PacketWriter ().WriteId (id));
2318 FieldMirrorInfo info = new FieldMirrorInfo { Name = r.ReadString (), Parent = r.ReadId (), TypeId = r.ReadId (), Attrs = r.ReadInt () };
2326 internal int EnableEvent (EventType etype, SuspendPolicy suspend_policy, List<Modifier> mods) {
2327 var w = new PacketWriter ().WriteByte ((byte)etype).WriteByte ((byte)suspend_policy);
2329 if (mods.Count > 255)
2330 throw new NotImplementedException ();
2331 w.WriteByte ((byte)mods.Count);
2332 foreach (Modifier mod in mods) {
2333 if (mod is CountModifier) {
2334 w.WriteByte ((byte)ModifierKind.COUNT);
2335 w.WriteInt ((mod as CountModifier).Count);
2336 } else if (mod is LocationModifier) {
2337 w.WriteByte ((byte)ModifierKind.LOCATION_ONLY);
2338 w.WriteId ((mod as LocationModifier).Method);
2339 w.WriteLong ((mod as LocationModifier).Location);
2340 } else if (mod is StepModifier) {
2341 w.WriteByte ((byte)ModifierKind.STEP);
2342 w.WriteId ((mod as StepModifier).Thread);
2343 w.WriteInt ((mod as StepModifier).Size);
2344 w.WriteInt ((mod as StepModifier).Depth);
2345 if (Version.AtLeast (2, 16))
2346 w.WriteInt ((mod as StepModifier).Filter);
2347 } else if (mod is ThreadModifier) {
2348 w.WriteByte ((byte)ModifierKind.THREAD_ONLY);
2349 w.WriteId ((mod as ThreadModifier).Thread);
2350 } else if (mod is ExceptionModifier) {
2351 var em = mod as ExceptionModifier;
2352 w.WriteByte ((byte)ModifierKind.EXCEPTION_ONLY);
2353 w.WriteId (em.Type);
2354 if (Version.MajorVersion > 2 || Version.MinorVersion > 0) {
2355 /* This is only supported in protocol version 2.1 */
2356 w.WriteBool (em.Caught);
2357 w.WriteBool (em.Uncaught);
2358 } else if (!em.Caught || !em.Uncaught) {
2359 throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
2361 if (Version.MajorVersion > 2 || Version.MinorVersion > 24) {
2362 w.WriteBool (em.Subclasses);
2363 } else if (!em.Subclasses) {
2364 throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
2366 } else if (mod is AssemblyModifier) {
2367 w.WriteByte ((byte)ModifierKind.ASSEMBLY_ONLY);
2368 var amod = (mod as AssemblyModifier);
2369 w.WriteInt (amod.Assemblies.Length);
2370 foreach (var id in amod.Assemblies)
2372 } else if (mod is SourceFileModifier) {
2373 w.WriteByte ((byte)ModifierKind.SOURCE_FILE_ONLY);
2374 var smod = (mod as SourceFileModifier);
2375 w.WriteInt (smod.SourceFiles.Length);
2376 foreach (var s in smod.SourceFiles)
2378 } else if (mod is TypeNameModifier) {
2379 w.WriteByte ((byte)ModifierKind.TYPE_NAME_ONLY);
2380 var tmod = (mod as TypeNameModifier);
2381 w.WriteInt (tmod.TypeNames.Length);
2382 foreach (var s in tmod.TypeNames)
2385 throw new NotImplementedException ();
2391 return SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.SET, w).ReadInt ();
2394 internal void ClearEventRequest (EventType etype, int req_id) {
2395 SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.CLEAR, new PacketWriter ().WriteByte ((byte)etype).WriteInt (req_id));
2398 internal void ClearAllBreakpoints () {
2399 SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.CLEAR_ALL_BREAKPOINTS, new PacketWriter ());
2405 internal ValueImpl StackFrame_GetThis (long thread_id, long id) {
2406 PacketReader r = SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_THIS, new PacketWriter ().WriteId (thread_id).WriteId (id));
2407 return r.ReadValue ();
2410 internal ValueImpl[] StackFrame_GetValues (long thread_id, long id, int[] pos) {
2411 /* pos < 0 -> argument at pos (-pos) - 1 */
2412 /* pos >= 0 -> local at pos */
2413 int len = pos.Length;
2414 PacketReader r = SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos));
2416 ValueImpl[] res = new ValueImpl [len];
2417 for (int i = 0; i < len; ++i)
2418 res [i] = r.ReadValue ();
2422 internal void StackFrame_SetValues (long thread_id, long id, int[] pos, ValueImpl[] values) {
2423 /* pos < 0 -> argument at pos (-pos) - 1 */
2424 /* pos >= 0 -> local at pos */
2425 int len = pos.Length;
2426 SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.SET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos).WriteValues (values));
2429 internal long StackFrame_GetDomain (long thread_id, long id) {
2430 return SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_DOMAIN, new PacketWriter ().WriteId (thread_id).WriteId (id)).ReadId ();
2433 internal void StackFrame_SetThis (long thread_id, long id, ValueImpl value) {
2434 SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.SET_THIS, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteValue (value));
2440 internal int[] Array_GetLength (long id, out int rank, out int[] lower_bounds) {
2441 var r = SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.GET_LENGTH, new PacketWriter ().WriteId (id));
2442 rank = r.ReadInt ();
2443 int[] res = new int [rank];
2444 lower_bounds = new int [rank];
2445 for (int i = 0; i < rank; ++i) {
2446 res [i] = r.ReadInt ();
2447 lower_bounds [i] = r.ReadInt ();
2452 internal ValueImpl[] Array_GetValues (long id, int index, int len) {
2453 var r = SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (len));
2454 ValueImpl[] res = new ValueImpl [len];
2455 for (int i = 0; i < len; ++i)
2456 res [i] = r.ReadValue ();
2460 internal void Array_SetValues (long id, int index, ValueImpl[] values) {
2461 SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (values.Length).WriteValues (values));
2467 internal string String_GetValue (long id) {
2468 var r = SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_VALUE, new PacketWriter ().WriteId (id));
2470 bool is_utf16 = false;
2471 if (Version.AtLeast (2, 41))
2472 is_utf16 = r.ReadByte () == 1;
2475 return r.ReadUTF16String ();
2477 return r.ReadString ();
2480 internal int String_GetLength (long id) {
2481 return (int)SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_LENGTH, new PacketWriter ().WriteId (id)).ReadLong ();
2484 internal char[] String_GetChars (long id, int index, int length) {
2485 var r = SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_CHARS, new PacketWriter ().WriteId (id).WriteLong (index).WriteLong (length));
2486 var res = new char [length];
2487 for (int i = 0; i < length; ++i)
2488 res [i] = (char)r.ReadShort ();
2495 internal long Object_GetType (long id) {
2496 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
2499 internal long Object_GetDomain (long id) {
2500 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_DOMAIN, new PacketWriter ().WriteId (id)).ReadId ();
2503 internal ValueImpl[] Object_GetValues (long id, long[] fields) {
2504 int len = fields.Length;
2505 PacketReader r = SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));
2507 ValueImpl[] res = new ValueImpl [len];
2508 for (int i = 0; i < len; ++i)
2509 res [i] = r.ReadValue ();
2513 internal void Object_SetValues (long id, long[] fields, ValueImpl[] values) {
2514 SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
2517 internal bool Object_IsCollected (long id) {
2518 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.IS_COLLECTED, new PacketWriter ().WriteId (id)).ReadInt () == 1;
2521 internal long Object_GetAddress (long id) {
2522 return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_ADDRESS, new PacketWriter ().WriteId (id)).ReadLong ();
2525 internal ObjectRefInfo Object_GetInfo (long id) {
2526 ObjectRefInfo res = new ObjectRefInfo ();
2527 PacketReader r = SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_INFO, new PacketWriter ().WriteId (id));
2529 res.type_id = r.ReadId ();
2530 res.domain_id = r.ReadId ();
2534 public void ForceDisconnect ()
2537 disconnected = true;
2538 DisconnectedEvent.Set ();
2543 class TcpConnection : Connection
2547 internal TcpConnection (Socket socket)
2549 this.socket = socket;
2550 //socket.SetSocketOption (SocketOptionLevel.IP, SocketOptionName.NoDelay, 1);
2553 internal EndPoint EndPoint {
2555 return socket.RemoteEndPoint;
2559 protected override int TransportSend (byte[] buf, int buf_offset, int len)
2561 return socket.Send (buf, buf_offset, len, SocketFlags.None);
2564 protected override int TransportReceive (byte[] buf, int buf_offset, int len)
2566 return socket.Receive (buf, buf_offset, len, SocketFlags.None);
2569 protected override void TransportSetTimeouts (int send_timeout, int receive_timeout)
2571 socket.SendTimeout = send_timeout;
2572 socket.ReceiveTimeout = receive_timeout;
2575 protected override void TransportClose ()
2581 /* This is the interface exposed by the debugger towards the debugger agent */
2582 interface IEventHandler
2584 void Events (SuspendPolicy suspend_policy, EventInfo[] events);
2586 void VMDisconnect (int req_id, long thread_id, string vm_uri);