Ejemplo n.º 1
0
 internal ValueImpl[] Array_GetValues(long id, int index, int len)
 {
     var r = SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (len));
     ValueImpl[] res = new ValueImpl [len];
     for (int i = 0; i < len; ++i)
         res [i] = r.ReadValue ();
     return res;
 }
Ejemplo n.º 2
0
            public PacketWriter WriteValue(ValueImpl v)
            {
                ElementType t;

                if (v.Value != null)
                    t = TypeCodeToElementType (Type.GetTypeCode (v.Value.GetType ()));
                else
                    t = v.Type;
                WriteByte ((byte)t);
                switch (t) {
                case ElementType.Boolean:
                    WriteInt ((bool)v.Value ? 1 : 0);
                    break;
                case ElementType.Char:
                    WriteInt ((int)(char)v.Value);
                    break;
                case ElementType.I1:
                    WriteInt ((int)(sbyte)v.Value);
                    break;
                case ElementType.U1:
                    WriteInt ((int)(byte)v.Value);
                    break;
                case ElementType.I2:
                    WriteInt ((int)(short)v.Value);
                    break;
                case ElementType.U2:
                    WriteInt ((int)(ushort)v.Value);
                    break;
                case ElementType.I4:
                    WriteInt ((int)(int)v.Value);
                    break;
                case ElementType.U4:
                    WriteInt ((int)(uint)v.Value);
                    break;
                case ElementType.I8:
                    WriteLong ((long)(long)v.Value);
                    break;
                case ElementType.U8:
                    WriteLong ((long)(ulong)v.Value);
                    break;
                case ElementType.R4:
                    WriteFloat ((float)v.Value);
                    break;
                case ElementType.R8:
                    WriteDouble ((double)v.Value);
                    break;
                case ElementType.String:
                case ElementType.SzArray:
                case ElementType.Class:
                case ElementType.Array:
                case ElementType.Object:
                    WriteId (v.Objid);
                    break;
                case ElementType.ValueType:
                    // FIXME:
                    if (v.IsEnum)
                        throw new NotImplementedException ();
                    WriteByte (0);
                    WriteId (v.Klass);
                    WriteInt (v.Fields.Length);
                    for (int i = 0; i < v.Fields.Length; ++i)
                        WriteValue (v.Fields [i]);
                    break;
                case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
                    break;
                default:
                    throw new NotImplementedException ();
                }

                return this;
            }
Ejemplo n.º 3
0
 public PacketWriter WriteValues(ValueImpl[] values)
 {
     for (int i = 0; i < values.Length; ++i)
         WriteValue (values [i]);
     return this;
 }
Ejemplo n.º 4
0
 void read_invoke_res(PacketReader r, out ValueImpl v, out ValueImpl exc, out ValueImpl out_this, out ValueImpl[] out_args)
 {
     int resflags = r.ReadByte ();
     v = null;
     exc = null;
     out_this = null;
     out_args = null;
     if (resflags == 0) {
         exc = r.ReadValue ();
     } else {
         v = r.ReadValue ();
         if ((resflags & 2) != 0)
             out_this = r.ReadValue ();
         if ((resflags & 4) != 0) {
             int nargs = r.ReadInt ();
             out_args = new ValueImpl [nargs];
             for (int i = 0; i < nargs; ++i)
                 out_args [i] = r.ReadValue ();
         }
     }
 }
Ejemplo n.º 5
0
            public ValueImpl ReadValue()
            {
                ElementType etype = (ElementType)ReadByte ();

                switch (etype) {
                case ElementType.Void:
                    return new ValueImpl { Type = etype };
                case ElementType.I1:
                    return new ValueImpl { Type = etype, Value = (sbyte)ReadInt () };
                case ElementType.U1:
                    return new ValueImpl { Type = etype, Value = (byte)ReadInt () };
                case ElementType.Boolean:
                    return new ValueImpl { Type = etype, Value = ReadInt () != 0 };
                case ElementType.I2:
                    return new ValueImpl { Type = etype, Value = (short)ReadInt () };
                case ElementType.U2:
                    return new ValueImpl { Type = etype, Value = (ushort)ReadInt () };
                case ElementType.Char:
                    return new ValueImpl { Type = etype, Value = (char)ReadInt () };
                case ElementType.I4:
                    return new ValueImpl { Type = etype, Value = ReadInt () };
                case ElementType.U4:
                    return new ValueImpl { Type = etype, Value = (uint)ReadInt () };
                case ElementType.I8:
                    return new ValueImpl { Type = etype, Value = ReadLong () };
                case ElementType.U8:
                    return new ValueImpl { Type = etype, Value = (ulong)ReadLong () };
                case ElementType.R4:
                    return new ValueImpl { Type = etype, Value = ReadFloat () };
                case ElementType.R8:
                    return new ValueImpl { Type = etype, Value = ReadDouble () };
                case ElementType.I:
                case ElementType.U:
                case ElementType.Ptr:
                    // FIXME: The client and the debuggee might have different word sizes
                    return new ValueImpl { Type = etype, Value = ReadLong () };
                case ElementType.String:
                case ElementType.SzArray:
                case ElementType.Class:
                case ElementType.Array:
                case ElementType.Object:
                    long objid = ReadId ();
                    return new ValueImpl () { Type = etype, Objid = objid };
                case ElementType.ValueType:
                    bool is_enum = ReadByte () == 1;
                    long klass = ReadId ();
                    long nfields = ReadInt ();
                    ValueImpl[] fields = new ValueImpl [nfields];
                    for (int i = 0; i < nfields; ++i)
                        fields [i] = ReadValue ();
                    return new ValueImpl () { Type = etype, Klass = klass, Fields = fields, IsEnum = is_enum };
                case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
                    return new ValueImpl { Type = etype };
                case (ElementType)ValueTypeId.VALUE_TYPE_ID_TYPE:
                    return new ValueImpl () { Type = etype, Id = ReadId () };
                case (ElementType)ValueTypeId.VALUE_TYPE_ID_PARENT_VTYPE:
                    return new ValueImpl () { Type = etype, Index = ReadInt () };
                default:
                    throw new NotImplementedException ("Unable to handle type " + etype);
                }
            }
Ejemplo n.º 6
0
		// This is called when the result of an invoke is received
		static void InvokeCB (ValueImpl v, ValueImpl exc, ValueImpl out_this, ValueImpl[] out_args, ErrorCode error, object state) {
			InvokeAsyncResult r = (InvokeAsyncResult)state;

			if (error != 0) {
				r.ErrorCode = error;
			} else {
				r.Value = v;
				r.Exception = exc;
			}

			r.OutThis = out_this;
			r.OutArgs = out_args;

			r.IsCompleted = true;
			((ManualResetEvent)r.AsyncWaitHandle).Set ();

			if (r.Callback != null)
				r.Callback.BeginInvoke (r, null, null);
		}
Ejemplo n.º 7
0
		internal int VM_BeginInvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, InvokeMethodCallback callback, object state) {
			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) {
					ValueImpl v, exc;

					if (r.ErrorCode != 0) {
						callback (null, null, (ErrorCode)r.ErrorCode, state);
					} else {
						if (r.ReadByte () == 0) {
							exc = r.ReadValue ();
							v = null;
						} else {
							v = r.ReadValue ();
							exc = null;
						}

						callback (v, exc, 0, state);
					}
				}, 1);
		}
Ejemplo n.º 8
0
 internal void Type_SetValues(long id, long[] fields, ValueImpl[] values)
 {
     SendReceive (CommandSet.TYPE, (int)CmdType.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
 }
Ejemplo n.º 9
0
        internal int VM_BeginInvokeMethod(long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, InvokeMethodCallback callback, object state)
        {
            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) {
                    ValueImpl v, exc, out_this = null;
                    ValueImpl[] out_args = null;

                    if (r.ErrorCode != 0) {
                        callback (null, null, null, null, (ErrorCode)r.ErrorCode, state);
                    } else {
                        read_invoke_res (r, out v, out exc, out out_this, out out_args);
                        callback (v, exc, out_this, out_args, 0, state);
                    }
                }, 1);
        }
Ejemplo n.º 10
0
 internal void StackFrame_SetValues(long thread_id, long id, int[] pos, ValueImpl[] values)
 {
     /* pos < 0 -> argument at pos (-pos) - 1 */
     /* pos >= 0 -> local at pos */
     int len = pos.Length;
     SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.SET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos).WriteValues (values));
 }
Ejemplo n.º 11
0
        internal ValueImpl[] Type_GetValues(long id, long[] fields, long thread_id)
        {
            int len = fields.Length;
            PacketReader r;
            if (thread_id != 0)
                r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES_2, new PacketWriter ().WriteId (id).WriteId (thread_id).WriteInt (len).WriteIds (fields));
            else
                r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));

            ValueImpl[] res = new ValueImpl [len];
            for (int i = 0; i < len; ++i)
                res [i] = r.ReadValue ();
            return res;
        }
Ejemplo n.º 12
0
        internal ValueImpl[] StackFrame_GetValues(long thread_id, long id, int[] pos)
        {
            /* pos < 0 -> argument at pos (-pos) - 1 */
            /* pos >= 0 -> local at pos */
            int len = pos.Length;
            PacketReader r = SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos));

            ValueImpl[] res = new ValueImpl [len];
            for (int i = 0; i < len; ++i)
                res [i] = r.ReadValue ();
            return res;
        }
Ejemplo n.º 13
0
 internal void Object_SetValues(long id, long[] fields, ValueImpl[] values)
 {
     SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
 }
Ejemplo n.º 14
0
        internal ValueImpl[] Object_GetValues(long id, long[] fields)
        {
            int len = fields.Length;
            PacketReader r = SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));

            ValueImpl[] res = new ValueImpl [len];
            for (int i = 0; i < len; ++i)
                res [i] = r.ReadValue ();
            return res;
        }
Ejemplo n.º 15
0
 internal void Array_SetValues(long id, int index, ValueImpl[] values)
 {
     SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (values.Length).WriteValues (values));
 }
Ejemplo n.º 16
0
        internal int VM_BeginInvokeMethods(long thread, long[] methods, ValueImpl this_arg, List<ValueImpl[]> arguments, InvokeFlags flags, InvokeMethodCallback callback, object state)
        {
            // FIXME: Merge this with INVOKE_METHOD
            var w = new PacketWriter ();
            w.WriteId (thread);
            w.WriteInt ((int)flags);
            w.WriteInt (methods.Length);
            for (int i = 0; i < methods.Length; ++i) {
                w.WriteId (methods [i]);
                w.WriteValue (this_arg);
                w.WriteInt (arguments [i].Length);
                w.WriteValues (arguments [i]);
            }
            return Send (CommandSet.VM, (int)CmdVM.INVOKE_METHODS, w, delegate (PacketReader r) {
                    ValueImpl v, exc, out_this = null;
                    ValueImpl[] out_args = null;

                    if (r.ErrorCode != 0) {
                        callback (null, null, null, null, (ErrorCode)r.ErrorCode, state);
                    } else {
                        read_invoke_res (r, out v, out exc, out out_this, out out_args);
                        callback (v, exc, out_this, out_args, 0, state);
                    }
                }, methods.Length);
        }
Ejemplo n.º 17
0
 internal long Domain_CreateBoxedValue(long id, long type_id, ValueImpl v)
 {
     return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.CREATE_BOXED_VALUE, new PacketWriter ().WriteId (id).WriteId (type_id).WriteValue (v)).ReadId ();
 }
Ejemplo n.º 18
0
 internal ValueImpl VM_InvokeMethod(long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, out ValueImpl exc)
 {
     exc = null;
     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));
     if (r.ReadByte () == 0) {
         exc = r.ReadValue ();
         return null;
     } else {
         return r.ReadValue ();
     }
 }
Ejemplo n.º 19
0
		// This is called when the result of an invoke is received
		static void InvokeMultipleCB (ValueImpl v, ValueImpl exc, ValueImpl out_this, ValueImpl[] out_args, ErrorCode error, object state) {
			var r = (InvokeAsyncResult)state;

			Interlocked.Decrement (ref r.NumPending);

			if (r.NumPending == 0) {
				r.IsCompleted = true;
				((ManualResetEvent)r.AsyncWaitHandle).Set ();
			}

			// Have to pass another asyncresult to the callback since multiple threads can execute it concurrently with results of multiple invocations
			var r2 = new InvokeAsyncResult { AsyncState = r.AsyncState, AsyncWaitHandle = null, VM = r.VM, Thread = r.Thread, Callback = r.Callback, IsCompleted = true };

			if (error != 0) {
				r2.ErrorCode = error;
			} else {
				r2.Value = v;
				r2.Exception = exc;
			}

			r.Callback.BeginInvoke (r2, null, null);
		}
Ejemplo n.º 20
0
		internal void StackFrame_SetThis (long thread_id, long id, ValueImpl value) {
			SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.SET_THIS, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteValue (value));
		}