internal static ObjectValueFlags GetFlags (PropertyInfoMirror property, MethodMirror getter)
		{
			var flags = ObjectValueFlags.Property;

			if (property.GetSetMethod (true) == null)
				flags |= ObjectValueFlags.ReadOnly;

			if (getter.IsStatic)
				flags |= ObjectValueFlags.Global;

			if (getter.IsPublic)
				flags |= ObjectValueFlags.Public;
			else if (getter.IsPrivate)
				flags |= ObjectValueFlags.Private;
			else if (getter.IsFamily)
				flags |= ObjectValueFlags.Protected;
			else if (getter.IsFamilyAndAssembly)
				flags |= ObjectValueFlags.Internal;
			else if (getter.IsFamilyOrAssembly)
				flags |= ObjectValueFlags.InternalProtected;

			if (property.DeclaringType.IsValueType)
				flags |= ObjectValueFlags.ReadOnly; // Setting property values on structs is not supported by sdb

			return flags;
		}
		public PropertyInfoMirror (TypeMirror parent, long id, string name, MethodMirror get_method, MethodMirror set_method, PropertyAttributes attrs) : base (parent.VirtualMachine, id) {
			this.parent = parent;
			this.name = name;
			this.attrs = attrs;
			this.get_method = get_method;
			this.set_method = set_method;
		}
		public PropertyValueReference (EvaluationContext ctx, PropertyInfoMirror property, object obj, TypeMirror declaringType, MethodMirror getter, Value[] indexerArgs): base (ctx)
		{
			this.property = property;
			this.obj = obj;
			this.declaringType = declaringType;
			this.indexerArgs = indexerArgs;
			
			flags = ObjectValueFlags.Property;
			if (property.GetSetMethod (true) == null)
				flags |= ObjectValueFlags.ReadOnly;
			
			if (getter.IsStatic)
				flags |= ObjectValueFlags.Global;
			if (getter.IsPublic)
				flags |= ObjectValueFlags.Public;
			else if (getter.IsPrivate)
				flags |= ObjectValueFlags.Private;
			else if (getter.IsFamily)
				flags |= ObjectValueFlags.Protected;
			else if (getter.IsFamilyAndAssembly)
				flags |= ObjectValueFlags.Internal;
			else if (getter.IsFamilyOrAssembly)
				flags |= ObjectValueFlags.InternalProtected;
			
			if (property.DeclaringType.IsValueType)
				flags |= ObjectValueFlags.ReadOnly; // Setting property values on structs is not supported by sdb
		}
Пример #4
0
		internal ParameterInfoMirror (MethodMirror method, int pos, TypeMirror type, string name, ParameterAttributes attrs) : base (method.VirtualMachine, 0) {
			this.method = method;
			this.pos = pos;
			this.type = type;
			this.name = name;
			this.attrs = attrs;
		}
Пример #5
0
		//int column_number;
		
		internal Location (VirtualMachine vm, MethodMirror method, long native_addr, int il_offset, string source_file, int line_number, int column_number) : base (vm, 0) {
			this.method = method;
			//this.native_addr = native_addr;
			this.il_offset = il_offset;
			this.source_file = source_file;
			this.line_number = line_number;
			//this.column_number = column_number;
		}
Пример #6
0
 /*
  * FIXME: Decide on the way to request/handle debugging information:
  * - request the info in bulk for all frames/on demand for individual frames
  * - request the info from the runtime/request only the il offset, and compute
  *   everything else based on this info using the method debug info.
  */
 internal StackFrame(VirtualMachine vm, long id, ThreadMirror thread, MethodMirror method, int il_offset, StackFrameFlags flags)
     : base(vm, id)
 {
     this.thread = thread;
     this.method = method;
     this.il_offset = il_offset;
     this.flags = flags;
 }
		internal BreakpointEventRequest (VirtualMachine vm, MethodMirror method, long location) : base (vm, EventType.Breakpoint) {
			if (method == null)
				throw new ArgumentNullException ("method");
			CheckMirror (vm, method);
			if (method.Locations.Count > 0 && !method.Locations.Any (l => l.ILOffset == location))
				throw new ArgumentException ("A breakpoint can only be set at an IL offset which is equal to the ILOffset property of one of the locations in method.Locations", "location");
			this.method = method;
			this.location = location;
		}
Пример #8
0
	    internal LocalVariable (VirtualMachine vm, MethodMirror method, int index, long type_id, string name, int live_range_start, int live_range_end, bool is_arg) : base (vm, 0) {
			this.method = method;
			this.index = index;
			this.name = name;
			this.type_id = type_id;
			this.is_arg = is_arg;
			this.live_range_start = live_range_start;
			this.live_range_end = live_range_end;
		}
		public PropertyValueReference (EvaluationContext ctx, PropertyInfoMirror property, object obj, TypeMirror declaringType, MethodMirror getter, Value[] indexerArgs): base (ctx)
		{
			this.property = property;
			this.obj = obj;
			this.declaringType = declaringType;
			this.indexerArgs = indexerArgs;
			
			flags = GetFlags (property, getter);
		}
		public PropertyValueReference (EvaluationContext ctx, PropertyInfoMirror property, object obj, TypeMirror declaringType, MethodMirror getter, Value[] indexerArgs): base (ctx)
		{
			this.declaringType = declaringType;
			this.indexerArgs = indexerArgs;
			this.property = property;
			this.getter = getter;
			this.obj = obj;

			var objectMirror = obj as ObjectMirror;
			if (objectMirror != null)
				EnsureContextHasDomain (objectMirror.Domain);

			flags = GetFlags (property, getter);
		}
        DC.StackFrame CreateStackFrame(MDB.StackFrame frame)
        {
            MDB.MethodMirror method     = frame.Method;
            MDB.TypeMirror   type       = method.DeclaringType;
            string           methodName = method.Name;

            if (type != null)
            {
                methodName = type.FullName + "." + methodName;
            }
            var location = new DC.SourceLocation(methodName, SoftDebuggerSession.NormalizePath(frame.FileName), frame.LineNumber);
            var lang     = frame.Method != null ? "Managed" : "Native";

            return(new DC.StackFrame(frame.ILOffset, method.FullName, location, lang, session.IsExternalCode(frame), true, type.Module.FullyQualifiedName, type.FullName));
        }
Пример #12
0
        internal static StatementRange GetILOffset(MonoPendingBreakpoint bp, MethodMirror methodMirror, out int ilOffset)
        {
            List<Mono.Debugger.Soft.Location> locations = methodMirror.Locations.ToList();

            foreach (Mono.Debugger.Soft.Location location in locations)
            {
                int line = location.LineNumber;
                int column = location.ColumnNumber;

                if (line != bp.StartLine + 1)
                    continue;
                //if (column != bp.StartColumn)
                //    continue;

                ilOffset = location.ILOffset;

                Console.WriteLine(location.ColumnNumber);
                return null;
            }

            throw new Exception("Cant bind breakpoint");
        }
Пример #13
0
		public MethodMirror GetGenericMethodDefinition () {
			vm.CheckProtocolVersion (2, 12);
			if (gmd == null) {
				if (info.gmd == 0)
					throw new InvalidOperationException ();
				gmd = vm.GetMethod (info.gmd);
			}
			return gmd;
		}
Пример #14
0
 internal static Value InvokeMethod(VirtualMachine vm, ThreadMirror thread, MethodMirror method, Value this_obj, IList <Value> arguments, InvokeOptions options)
 {
     return(EndInvokeMethodInternal(BeginInvokeMethod(vm, thread, method, this_obj, arguments, options, null, null)));
 }
Пример #15
0
		// Since protocol version 2.11
		public InterfaceMappingMirror GetInterfaceMap (TypeMirror interfaceType) {
			if (interfaceType == null)
				throw new ArgumentNullException ("interfaceType");
			if (!interfaceType.IsInterface)
				throw new ArgumentException ("Argument must be an interface.", "interfaceType");
			if (IsInterface)
				throw new ArgumentException ("'this' type cannot be an interface itself");

			if (iface_map == null) {
				// Query the info in bulk
				GetInterfaces ();
				var ids = new long [ifaces.Length];
				for (int i = 0; i < ifaces.Length; ++i)
					ids [i] = ifaces [i].Id;

				var ifacemap = vm.conn.Type_GetInterfaceMap (id, ids);

				var imap = new Dictionary<TypeMirror, InterfaceMappingMirror> ();
				for (int i = 0; i < ifacemap.Length; ++i) {
					IfaceMapInfo info = ifacemap [i];

					MethodMirror[] imethods = new MethodMirror [info.iface_methods.Length];
					for (int j = 0; j < info.iface_methods.Length; ++j)
						imethods [j] = vm.GetMethod (info.iface_methods [j]);

					MethodMirror[] tmethods = new MethodMirror [info.iface_methods.Length];
					for (int j = 0; j < info.target_methods.Length; ++j)
						tmethods [j] = vm.GetMethod (info.target_methods [j]);

					InterfaceMappingMirror map = new InterfaceMappingMirror (vm, this, vm.GetType (info.iface_id), imethods, tmethods);

					imap [map.InterfaceType] = map;
				}

				iface_map = imap;
			}

			InterfaceMappingMirror res;
			if (!iface_map.TryGetValue (interfaceType, out res))
				throw new ArgumentException ("Interface not found", "interfaceType");
			return res;
		}
Пример #16
0
		internal MethodBodyMirror (VirtualMachine vm, MethodMirror method, MethodBodyInfo info) : base (vm, 0) {
			this.method = method;
			this.info = info;
		}
Пример #17
0
		public MethodMirror[] GetMethodsByNameFlags (string name, BindingFlags flags, bool ignoreCase) {
			if (vm.conn.Version.AtLeast (2, 6)) {
				long[] ids = vm.conn.Type_GetMethodsByNameFlags (id, name, (int)flags, ignoreCase);
				MethodMirror[] m = new MethodMirror [ids.Length];
				for (int i = 0; i < ids.Length; ++i)
					m [i] = vm.GetMethod (ids [i]);
				return m;
			} else {
				if ((flags & BindingFlags.IgnoreCase) != 0) {
					flags &= ~BindingFlags.IgnoreCase;
					ignoreCase = true;
				}
				
				if (flags == BindingFlags.Default)
					flags = BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.Static;
				
				MethodAttributes access = (MethodAttributes) 0;
				bool matchInstance = false;
				bool matchStatic = false;
				
				if ((flags & BindingFlags.NonPublic) != 0) {
					access |= MethodAttributes.Private;
					flags &= ~BindingFlags.NonPublic;
				}
				if ((flags & BindingFlags.Public) != 0) {
					access |= MethodAttributes.Public;
					flags &= ~BindingFlags.Public;
				}
				if ((flags & BindingFlags.Instance) != 0) {
					flags &= ~BindingFlags.Instance;
					matchInstance = true;
				}
				if ((flags & BindingFlags.Static) != 0) {
					flags &= ~BindingFlags.Static;
					matchStatic = true;
				}
				
				if ((int) flags != 0)
					throw new NotImplementedException ();
				
				var res = new List<MethodMirror> ();
				foreach (MethodMirror m in GetMethods ()) {
					if ((m.Attributes & access) == (MethodAttributes) 0)
						continue;
					
					if (!((matchStatic && m.IsStatic) || (matchInstance && !m.IsStatic)))
						continue;
					
					if ((!ignoreCase && m.Name == name) || (ignoreCase && m.Name.Equals (name, StringComparison.CurrentCultureIgnoreCase)))
						res.Add (m);
				}
				return res.ToArray ();
			}
		}
Пример #18
0
		public Value NewInstance (ThreadMirror thread, MethodMirror method, IList<Value> arguments) {
			return NewInstance (thread, method, arguments, InvokeOptions.None);
		}			
Пример #19
0
 public IAsyncResult BeginInvokeMethod(ThreadMirror thread, MethodMirror method, IList <Value> arguments, InvokeOptions options, AsyncCallback callback, object state)
 {
     return(ObjectMirror.BeginInvokeMethod(vm, thread, method, this, arguments, options, callback, state));
 }
Пример #20
0
        internal static Task <TResult> InvokeMethodAsync <TResult> (VirtualMachine vm, ThreadMirror thread, MethodMirror method, Value this_obj, IList <Value> arguments, InvokeOptions options, Func <IAsyncResult, TResult> callback)
        {
            var tcs = new TaskCompletionSource <TResult> ();

            BeginInvokeMethod(vm, thread, method, this_obj, arguments, options, iar =>
            {
                try {
                    tcs.SetResult(callback(iar));
                } catch (OperationCanceledException) {
                    tcs.TrySetCanceled();
                } catch (Exception ex) {
                    tcs.TrySetException(ex);
                }
            }, null);
            return(tcs.Task);
        }
Пример #21
0
 //
 // Methods to create event request objects
 //
 public BreakpointEventRequest CreateBreakpointRequest(MethodMirror method, long il_offset)
 {
     return(new BreakpointEventRequest(this, method, il_offset));
 }
Пример #22
0
 public Value InvokeMethod(ThreadMirror thread, MethodMirror method, IList <Value> arguments, InvokeOptions options)
 {
     return(ObjectMirror.InvokeMethod(vm, thread, method, this, arguments, options));
 }
Пример #23
0
 public PropertyInfoMirror(TypeMirror parent, long id, string name, MethodMirror get_method, MethodMirror set_method, PropertyAttributes attrs) : base(parent.VirtualMachine, id)
 {
     this.parent     = parent;
     this.name       = name;
     this.attrs      = attrs;
     this.get_method = get_method;
     this.set_method = set_method;
 }
Пример #24
0
 public Value NewInstance(ThreadMirror thread, MethodMirror method, IList <Value> arguments)
 {
     return(NewInstance(thread, method, arguments, InvokeOptions.None));
 }
Пример #25
0
        public MethodMirror[] GetMethodsByNameFlags(string name, BindingFlags flags, bool ignoreCase)
        {
            if (vm.conn.Version.AtLeast(2, 6))
            {
                long[]         ids = vm.conn.Type_GetMethodsByNameFlags(id, name, (int)flags, ignoreCase);
                MethodMirror[] m   = new MethodMirror [ids.Length];
                for (int i = 0; i < ids.Length; ++i)
                {
                    m [i] = vm.GetMethod(ids [i]);
                }
                return(m);
            }
            else
            {
                if ((flags & BindingFlags.IgnoreCase) != 0)
                {
                    flags     &= ~BindingFlags.IgnoreCase;
                    ignoreCase = true;
                }

                if (flags == BindingFlags.Default)
                {
                    flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
                }

                MethodAttributes access        = (MethodAttributes)0;
                bool             matchInstance = false;
                bool             matchStatic   = false;

                if ((flags & BindingFlags.NonPublic) != 0)
                {
                    access |= MethodAttributes.Private;
                    flags  &= ~BindingFlags.NonPublic;
                }
                if ((flags & BindingFlags.Public) != 0)
                {
                    access |= MethodAttributes.Public;
                    flags  &= ~BindingFlags.Public;
                }
                if ((flags & BindingFlags.Instance) != 0)
                {
                    flags        &= ~BindingFlags.Instance;
                    matchInstance = true;
                }
                if ((flags & BindingFlags.Static) != 0)
                {
                    flags      &= ~BindingFlags.Static;
                    matchStatic = true;
                }

                if ((int)flags != 0)
                {
                    throw new NotImplementedException();
                }

                var res = new List <MethodMirror> ();
                foreach (MethodMirror m in GetMethods())
                {
                    if ((m.Attributes & access) == (MethodAttributes)0)
                    {
                        continue;
                    }

                    if (!((matchStatic && m.IsStatic) || (matchInstance && !m.IsStatic)))
                    {
                        continue;
                    }

                    if ((!ignoreCase && m.Name == name) || (ignoreCase && m.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        res.Add(m);
                    }
                }
                return(res.ToArray());
            }
        }
Пример #26
0
		internal static IInvokeAsyncResult BeginInvokeMethod (VirtualMachine vm, ThreadMirror thread, MethodMirror method, Value this_obj, IList<Value> arguments, InvokeOptions options, AsyncCallback callback, object state) {
			if (thread == null)
				throw new ArgumentNullException ("thread");
			if (method == null)
				throw new ArgumentNullException ("method");
			if (arguments == null)
				arguments = new Value [0];

			InvokeFlags f = InvokeFlags.NONE;

			if ((options & InvokeOptions.DisableBreakpoints) != 0)
				f |= InvokeFlags.DISABLE_BREAKPOINTS;
			if ((options & InvokeOptions.SingleThreaded) != 0)
				f |= InvokeFlags.SINGLE_THREADED;
			if ((options & InvokeOptions.ReturnOutThis) != 0)
				f |= InvokeFlags.OUT_THIS;
			if ((options & InvokeOptions.ReturnOutArgs) != 0)
				f |= InvokeFlags.OUT_ARGS;

			InvokeAsyncResult r = new InvokeAsyncResult { AsyncState = state, AsyncWaitHandle = new ManualResetEvent (false), VM = vm, Thread = thread, Callback = callback };
			thread.InvalidateFrames ();
			r.ID = vm.conn.VM_BeginInvokeMethod (thread.Id, method.Id, this_obj != null ? vm.EncodeValue (this_obj) : vm.EncodeValue (vm.CreateValue (null)), vm.EncodeValues (arguments), f, InvokeCB, r);

			return r;
		}
Пример #27
0
 public Task <InvokeResult> InvokeMethodAsyncWithResult(ThreadMirror thread, MethodMirror method, IList <Value> arguments, InvokeOptions options = InvokeOptions.None)
 {
     return(ObjectMirror.InvokeMethodAsyncWithResult(vm, thread, method, this, arguments, options));
 }
Пример #28
0
		//
		// Implementation of InvokeMultiple
		//

		internal static IInvokeAsyncResult BeginInvokeMultiple (VirtualMachine vm, ThreadMirror thread, MethodMirror[] methods, Value this_obj, IList<IList<Value>> arguments, InvokeOptions options, AsyncCallback callback, object state) {
			if (thread == null)
				throw new ArgumentNullException ("thread");
			if (methods == null)
				throw new ArgumentNullException ("methods");
			foreach (var m in methods)
				if (m == null)
					throw new ArgumentNullException ("method");
			if (arguments == null) {
				arguments = new List<IList<Value>> ();
				for (int i = 0; i < methods.Length; ++i)
					arguments.Add (new Value [0]);
			} else {
				// FIXME: Not needed for property evaluation
				throw new NotImplementedException ();
			}
			if (callback == null)
				throw new ArgumentException ("A callback argument is required for this method.", "callback");

			InvokeFlags f = InvokeFlags.NONE;

			if ((options & InvokeOptions.DisableBreakpoints) != 0)
				f |= InvokeFlags.DISABLE_BREAKPOINTS;
			if ((options & InvokeOptions.SingleThreaded) != 0)
				f |= InvokeFlags.SINGLE_THREADED;

			InvokeAsyncResult r = new InvokeAsyncResult { AsyncState = state, AsyncWaitHandle = new ManualResetEvent (false), VM = vm, Thread = thread, Callback = callback, NumPending = methods.Length, IsMultiple = true };

			var mids = new long [methods.Length];
			for (int i = 0; i < methods.Length; ++i)
				mids [i] = methods [i].Id;
			var args = new List<ValueImpl[]> ();
			for (int i = 0; i < methods.Length; ++i)
				args.Add (vm.EncodeValues (arguments [i]));
			thread.InvalidateFrames ();
			r.ID = vm.conn.VM_BeginInvokeMethods (thread.Id, mids, this_obj != null ? vm.EncodeValue (this_obj) : vm.EncodeValue (vm.CreateValue (null)), args, f, InvokeMultipleCB, r);

			return r;
		}
Пример #29
0
 public Task <Value> InvokeMethodAsync(ThreadMirror thread, MethodMirror method, IList <Value> arguments, InvokeOptions options = InvokeOptions.None)
 {
     return(InvokeMethodAsync(vm, thread, method, this, arguments, options));
 }
Пример #30
0
		public MethodMirror[] GetMethods () {
			if (methods == null) {
				long[] ids = vm.conn.Type_GetMethods (id);
				MethodMirror[] m = new MethodMirror [ids.Length];
				for (int i = 0; i < ids.Length; ++i) {
					m [i] = vm.GetMethod (ids [i]);
				}
				methods = m;
			}
			return methods;
		}
Пример #31
0
 public Value InvokeMethod(ThreadMirror thread, MethodMirror method, IList <Value> arguments)
 {
     return(InvokeMethod(vm, thread, method, this, arguments, InvokeOptions.None));
 }
Пример #32
0
		public IAsyncResult BeginInvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options, AsyncCallback callback, object state) {
			return ObjectMirror.BeginInvokeMethod (vm, thread, method, null, arguments, options, callback, state);
		}
Пример #33
0
 internal MethodBodyMirror(VirtualMachine vm, MethodMirror method, MethodBodyInfo info) : base(vm, 0)
 {
     this.method = method;
     this.info   = info;
 }
Пример #34
0
		public Value NewInstance (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options) {
			if (method == null)
				throw new ArgumentNullException ("method");

			if (!method.IsConstructor)
				throw new ArgumentException ("The method must be a constructor.", "method");

			return ObjectMirror.InvokeMethod (vm, thread, method, null, arguments, options);
		}
Пример #35
0
 public Value NewInstance(ThreadMirror thread, MethodMirror method, IList <Value> arguments, InvokeOptions options)
 {
     return(ObjectMirror.InvokeMethod(vm, thread, method, null, arguments, options));
 }
Пример #36
0
		public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments) {
			return ObjectMirror.InvokeMethod (vm, thread, method, this, arguments, InvokeOptions.None);
		}
Пример #37
0
		public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options) {
			return InvokeMethod (vm, thread, method, this, arguments, options);
		}
		public Value RuntimeInvoke (MethodMirror method, object target, Value[] values)
		{
			if (values != null) {
				// Some arguments may need to be boxed
				var mparams = method.GetParameters ();
				if (mparams.Length != values.Length)
					throw new EvaluatorException ("Invalid number of arguments when calling: " + method.Name);
				
				for (int n = 0; n < mparams.Length; n++) {
					var tm = mparams[n].ParameterType;
					if (tm.IsValueType || tm.IsPrimitive)
						continue;

					var type = Adapter.GetValueType (this, values[n]);
					var argTypeMirror = type as TypeMirror;
					var argType = type as Type;

					if (IsValueTypeOrPrimitive (argTypeMirror) || IsValueTypeOrPrimitive (argType)) {
						// A value type being assigned to a parameter which is not a value type. The value has to be boxed.
						try {
							values[n] = Thread.Domain.CreateBoxedValue (values [n]);
						} catch (NotSupportedException) {
							// This runtime doesn't support creating boxed values
							throw new EvaluatorException ("This runtime does not support creating boxed values.");
						}
					}
				}
			}

			if (!method.IsStatic && method.DeclaringType.IsClass && !IsValueTypeOrPrimitive (method.DeclaringType)) {
				object type = Adapter.GetValueType (this, target);
				var targetTypeMirror = type as TypeMirror;
				var targetType = type as Type;

				if ((target is StructMirror && ((StructMirror) target).Type != method.DeclaringType) ||
				    (IsValueTypeOrPrimitive (targetTypeMirror) || IsValueTypeOrPrimitive (targetType))) {
					// A value type being assigned to a parameter which is not a value type. The value has to be boxed.
					try {
						target = Thread.Domain.CreateBoxedValue ((Value) target);
					} catch (NotSupportedException) {
						// This runtime doesn't support creating boxed values
						throw new EvaluatorException ("This runtime does not support creating boxed values.");
					}
				}
			}

			try {
				return method.Evaluate (target is TypeMirror ? null : (Value) target, values);
			} catch (NotSupportedException) {
				AssertTargetInvokeAllowed ();

				var mc = new MethodCall (this, method, target, values);
				Adapter.AsyncExecute (mc, Options.EvaluationTimeout);

				return mc.ReturnValue;
			}
		}
Пример #39
0
		public Task<InvokeResult> InvokeMethodAsyncWithResult (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options = InvokeOptions.None) {
			var tcs = new TaskCompletionSource<InvokeResult> ();
			BeginInvokeMethod (thread, method, arguments, options, iar =>
					{
						try {
							tcs.SetResult (EndInvokeMethodInternalWithResult (iar));
						} catch (OperationCanceledException) {
							tcs.TrySetCanceled ();
						} catch (Exception ex) {
							tcs.TrySetException (ex);
						}
					}, null);
			return tcs.Task;
		}
 internal MethodBodyMirror(VirtualMachine vm, MethodMirror method, byte[] il) : base(vm, 0)
 {
     this.method = method;
     this.il     = il;
 }
Пример #41
0
        internal static IInvokeAsyncResult BeginInvokeMethod(VirtualMachine vm, ThreadMirror thread, MethodMirror method, Value this_obj, IList <Value> arguments, InvokeOptions options, AsyncCallback callback, object state)
        {
            if (thread == null)
            {
                throw new ArgumentNullException("thread");
            }
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            if (arguments == null)
            {
                arguments = new Value [0];
            }

            InvokeFlags f = InvokeFlags.NONE;

            if ((options & InvokeOptions.DisableBreakpoints) != 0)
            {
                f |= InvokeFlags.DISABLE_BREAKPOINTS;
            }
            if ((options & InvokeOptions.SingleThreaded) != 0)
            {
                f |= InvokeFlags.SINGLE_THREADED;
            }
            if ((options & InvokeOptions.ReturnOutThis) != 0)
            {
                f |= InvokeFlags.OUT_THIS;
            }
            if ((options & InvokeOptions.ReturnOutArgs) != 0)
            {
                f |= InvokeFlags.OUT_ARGS;
            }
            if ((options & InvokeOptions.Virtual) != 0)
            {
                f |= InvokeFlags.VIRTUAL;
            }

            InvokeAsyncResult r = new InvokeAsyncResult {
                AsyncState = state, AsyncWaitHandle = new ManualResetEvent(false), VM = vm, Thread = thread, Callback = callback
            };

            thread.InvalidateFrames();
            r.ID = vm.conn.VM_BeginInvokeMethod(thread.Id, method.Id, this_obj != null ? vm.EncodeValue(this_obj) : vm.EncodeValue(vm.CreateValue(null)), vm.EncodeValues(arguments), f, InvokeCB, r);

            return(r);
        }
Пример #42
0
		public IAsyncResult BeginInvokeMethod (VirtualMachine vm, ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options, AsyncCallback callback, object state) {
			return BeginInvokeMethod (vm, thread, method, this, arguments, options, callback, state);
		}
Пример #43
0
		public Value NewInstance (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options) {
			return ObjectMirror.InvokeMethod (vm, thread, method, null, arguments, options);
		}
Пример #44
0
		//
		// Invoke the members of METHODS one-by-one, calling CALLBACK after each invoke was finished. The IAsyncResult will be marked as completed after all invokes have
		// finished. The callback will be called with a different IAsyncResult that represents one method invocation.
		// From protocol version 2.22.
		//
		public IAsyncResult BeginInvokeMultiple (ThreadMirror thread, MethodMirror[] methods, IList<IList<Value>> arguments, InvokeOptions options, AsyncCallback callback, object state) {
			return BeginInvokeMultiple (vm, thread, methods, this, arguments, options, callback, state);
		}
Пример #45
0
 public SdbMethodMirror(MDS.MethodMirror methodMirror)
     : base(methodMirror)
 {
     locations = new List <ILocation> (this.methodMirror.Locations.Select(SdbLocationFor));
 }
Пример #46
0
		internal static Value InvokeMethod (VirtualMachine vm, ThreadMirror thread, MethodMirror method, Value this_obj, IList<Value> arguments, InvokeOptions options) {
			return EndInvokeMethodInternal (BeginInvokeMethod (vm, thread, method, this_obj, arguments, options, null, null));
		}
Пример #47
0
 public ILInterpreter(MethodMirror method)
 {
     this.method = method;
 }
Пример #48
0
        DC.StackFrame CreateStackFrame(MDB.StackFrame frame)
        {
            MDB.MethodMirror method       = frame.Method;
            MDB.TypeMirror   type         = method.DeclaringType;
            string           fileName     = frame.FileName;
            string           typeFullName = null;
            string           typeFQN      = null;
            string           methodName;

            if (fileName != null)
            {
                fileName = SoftDebuggerSession.NormalizePath(fileName);
            }

            if (method.VirtualMachine.Version.AtLeast(2, 12) && method.IsGenericMethod)
            {
                StringBuilder name = new StringBuilder(method.Name);

                name.Append('<');

                if (method.VirtualMachine.Version.AtLeast(2, 15))
                {
                    bool first = true;

                    foreach (var argumentType in method.GetGenericArguments())
                    {
                        if (!first)
                        {
                            name.Append(", ");
                        }

                        name.Append(session.Adaptor.GetDisplayTypeName(argumentType.FullName));
                        first = false;
                    }
                }

                name.Append('>');

                methodName = name.ToString();
            }
            else
            {
                methodName = method.Name;
            }

            // Compiler generated anonymous/lambda methods
            bool special_method = false;

            if (methodName [0] == '<' && methodName.Contains(">m__"))
            {
                int nidx = methodName.IndexOf(">m__") + 2;
                methodName     = "AnonymousMethod" + methodName.Substring(nidx, method.Name.Length - nidx);
                special_method = true;
            }

            if (type != null)
            {
                string typeDisplayName = session.Adaptor.GetDisplayTypeName(type.FullName);

                if (SoftDebuggerAdaptor.IsGeneratedType(type))
                {
                    // The user-friendly method name is embedded in the generated type name
                    var mn = SoftDebuggerAdaptor.GetNameFromGeneratedType(type);

                    // Strip off the generated type name
                    int dot   = typeDisplayName.LastIndexOf('.');
                    var tname = typeDisplayName.Substring(0, dot);

                    // Keep any type arguments
                    int targs = typeDisplayName.LastIndexOf('<');
                    if (targs > dot + 1)
                    {
                        mn += typeDisplayName.Substring(targs, typeDisplayName.Length - targs);
                    }

                    typeDisplayName = tname;

                    if (special_method)
                    {
                        typeDisplayName += "." + mn;
                    }
                    else
                    {
                        methodName = mn;
                    }
                }

                methodName = typeDisplayName + "." + methodName;

                typeFQN      = type.Module.FullyQualifiedName;
                typeFullName = type.FullName;
            }

            var location = new DC.SourceLocation(methodName, fileName, frame.LineNumber);
            var external = session.IsExternalCode(frame);

            return(new SoftDebuggerStackFrame(frame, method.FullName, location, "Managed", external, true, typeFQN, typeFullName));
        }
Пример #49
0
 internal static Task <InvokeResult> InvokeMethodAsyncWithResult(VirtualMachine vm, ThreadMirror thread, MethodMirror method, Value this_obj, IList <Value> arguments, InvokeOptions options)
 {
     return(InvokeMethodAsync(vm, thread, method, this_obj, arguments, options, EndInvokeMethodInternalWithResult));
 }
		public Value RuntimeInvoke (MethodMirror method, object target, Value[] values)
		{
			if (values != null) {
				// Some arguments may need to be boxed
				ParameterInfoMirror[] mparams = method.GetParameters ();
				if (mparams.Length != values.Length)
					throw new EvaluatorException ("Invalid number of arguments when calling: " + method.Name);
				
				for (int n=0; n<mparams.Length; n++) {
					TypeMirror tm = mparams [n].ParameterType;
					if (tm.IsValueType || tm.IsPrimitive)
						continue;
					object type = Adapter.GetValueType (this, values [n]);
					TypeMirror argTypeMirror = type as TypeMirror;
					Type argType = type as Type;
					if ((argTypeMirror != null && (argTypeMirror.IsValueType || argTypeMirror.IsPrimitive)) || (argType != null && (argType.IsValueType || argType.IsPrimitive))) {
						// A value type being assigned to a parameter which is not a value type. The value has to be boxed.
						try {
							values [n] = Thread.Domain.CreateBoxedValue (values [n]);
						} catch (NotSupportedException) {
							// This runtime doesn't support creating boxed values
							break;
						}
					}
				}
			}			
			MethodCall mc = new MethodCall (this, method, target, values);
			Adapter.AsyncExecute (mc, Options.EvaluationTimeout);
			return mc.ReturnValue;
		}
Пример #51
0
        DC.StackFrame CreateStackFrame(MDB.StackFrame frame, int frameIndex)
        {
            MDB.MethodMirror method       = frame.Method;
            MDB.TypeMirror   type         = method.DeclaringType;
            string           fileName     = frame.FileName;
            string           typeFullName = null;
            string           typeFQN      = null;
            string           methodName;

            if (fileName != null)
            {
                fileName = SoftDebuggerSession.NormalizePath(fileName);
            }

            if (method.VirtualMachine.Version.AtLeast(2, 12) && method.IsGenericMethod)
            {
                StringBuilder name = new StringBuilder(method.Name);

                name.Append('<');

                if (method.VirtualMachine.Version.AtLeast(2, 15))
                {
                    bool first = true;

                    foreach (var argumentType in method.GetGenericArguments())
                    {
                        if (!first)
                        {
                            name.Append(", ");
                        }

                        name.Append(session.Adaptor.GetDisplayTypeName(argumentType.FullName));
                        first = false;
                    }
                }

                name.Append('>');

                methodName = name.ToString();
            }
            else
            {
                methodName = method.Name;
            }

            if (string.IsNullOrEmpty(methodName))
            {
                methodName = "[Function Without Name]";
            }

            // Compiler generated anonymous/lambda methods
            bool special_method = false;

            if (methodName [0] == '<' && methodName.Contains(">m__"))
            {
                int nidx = methodName.IndexOf(">m__", StringComparison.Ordinal) + 2;
                methodName     = "AnonymousMethod" + methodName.Substring(nidx, method.Name.Length - nidx);
                special_method = true;
            }

            if (type != null)
            {
                string typeDisplayName = session.Adaptor.GetDisplayTypeName(type.FullName);

                if (SoftDebuggerAdaptor.IsGeneratedType(type))
                {
                    // The user-friendly method name is embedded in the generated type name
                    var mn = SoftDebuggerAdaptor.GetNameFromGeneratedType(type);

                    // Strip off the generated type name
                    int dot   = typeDisplayName.LastIndexOf('.');
                    var tname = typeDisplayName.Substring(0, dot);

                    // Keep any type arguments
                    int targs = typeDisplayName.LastIndexOf('<');
                    if (targs > dot + 1)
                    {
                        mn += typeDisplayName.Substring(targs, typeDisplayName.Length - targs);
                    }

                    typeDisplayName = tname;

                    if (special_method)
                    {
                        typeDisplayName += "." + mn;
                    }
                    else
                    {
                        methodName = mn;
                    }
                }

                methodName = typeDisplayName + "." + methodName;

                typeFQN      = type.Module.FullyQualifiedName;
                typeFullName = type.FullName;
            }
            bool external = false;
            bool hidden   = false;

            if (session.VirtualMachine.Version.AtLeast(2, 21))
            {
                var ctx        = GetEvaluationContext(frameIndex, session.EvaluationOptions);
                var hiddenAttr = session.Adaptor.GetType(ctx, "System.Diagnostics.DebuggerHiddenAttribute") as MDB.TypeMirror;
                hidden = method.GetCustomAttributes(hiddenAttr, true).Any();
            }
            if (hidden)
            {
                external = true;
            }
            else
            {
                external = session.IsExternalCode(frame);
                if (!external && session.Options.ProjectAssembliesOnly && session.VirtualMachine.Version.AtLeast(2, 21))
                {
                    var ctx             = GetEvaluationContext(frameIndex, session.EvaluationOptions);
                    var nonUserCodeAttr = session.Adaptor.GetType(ctx, "System.Diagnostics.DebuggerNonUserCodeAttribute") as MDB.TypeMirror;
                    external = method.GetCustomAttributes(nonUserCodeAttr, true).Any();
                }
            }

            var location = new DC.SourceLocation(methodName, fileName, frame.LineNumber, frame.ColumnNumber, frame.Location.EndLineNumber, frame.Location.EndColumnNumber, frame.Location.SourceFileHash);

            string addressSpace = string.Empty;
            bool   hasDebugInfo = false;
            string language;

            if (frame.Method != null)
            {
                if (frame.IsNativeTransition)
                {
                    language = "Transition";
                }
                else
                {
                    addressSpace = method.FullName;
                    language     = "Managed";
                    hasDebugInfo = true;
                }
            }
            else
            {
                language = "Native";
            }

            return(new SoftDebuggerStackFrame(frame, addressSpace, location, language, external, hasDebugInfo, hidden, typeFQN, typeFullName));
        }