Inheritance: DebuggerMarshalByRefObject
示例#1
0
        void NotifyTargetEvent(MD.Thread thread, MD.TargetEventArgs args)
        {
            if (args.Frame != null)
            {
                activeThread = args.Frame.Thread;
            }

            try {
                if (args.Type == MD.TargetEventType.TargetStopped && ((int)args.Data) != 0)
                {
                    DispatchEvent(delegate {
                        controller.OnDebuggerOutput(false, string.Format("Thread {0:x} received signal {1}.\n", args.Frame.Thread.ID, args.Data));
                    });
                }

                DL.TargetEventType type;

                switch (args.Type)
                {
                case MD.TargetEventType.Exception: type = DL.TargetEventType.ExceptionThrown; break;

                case MD.TargetEventType.TargetHitBreakpoint: type = DL.TargetEventType.TargetHitBreakpoint; break;

                case MD.TargetEventType.TargetInterrupted: type = DL.TargetEventType.TargetInterrupted; break;

                case MD.TargetEventType.TargetSignaled: type = DL.TargetEventType.TargetSignaled; break;

                case MD.TargetEventType.TargetStopped: type = DL.TargetEventType.TargetStopped; break;

                case MD.TargetEventType.UnhandledException: type = DL.TargetEventType.UnhandledException; break;

                default:
                    return;
                }

                OnCleanFrameData();

                DL.TargetEventArgs targetArgs = new DL.TargetEventArgs(type);

                if (args.Type != MD.TargetEventType.TargetExited)
                {
                    ML.TargetObject exception = null;
                    if (args.Type == MD.TargetEventType.UnhandledException || args.Type == MD.TargetEventType.Exception)
                    {
                        exception = args.Frame.ExceptionObject;
                    }
                    targetArgs.Backtrace = CreateBacktrace(thread, exception);
                    targetArgs.Thread    = CreateThreadInfo(activeThread);
                }


                running = false;

                DispatchEvent(delegate {
                    controller.OnTargetEvent(targetArgs);
                });
            } catch (Exception e) {
                Console.WriteLine("*** DS.OnTargetEvent2, exception : {0}", e.ToString());
            }
        }
		public static ValueReference CreateIndexerValueReference (MdbEvaluationContext ctx, TargetObject target, TargetObject[] index)
		{
			TargetFundamentalObject mstr = target as TargetFundamentalObject;
			if (mstr != null && mstr.TypeName == "string") {
				// Special case for strings
				string name = "[" + ctx.Evaluator.TargetObjectToExpression (ctx, index[0]) + "]";
				string val = (string) mstr.GetObject (ctx.Thread);
				object oo = ctx.Adapter.TargetObjectToObject (ctx, index[0]);
				int idx = (int) Convert.ChangeType (oo, typeof(int));
				return LiteralValueReference.CreateObjectLiteral (ctx, name, val [idx]);
			}
			
			TargetStructObject sob = target as TargetStructObject;
			if (sob == null)
				return null;
			
			TargetPropertyInfo indexerProp = null;
			foreach (MemberReference mem in ObjectUtil.GetTypeMembers (ctx, target.Type, false, true, true, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)) {
				if (mem.Member.IsStatic)
					continue;
				if (mem.Member is TargetPropertyInfo) {
					TargetPropertyInfo prop = (TargetPropertyInfo) mem.Member;
					if (prop.CanRead && prop.Getter.ParameterTypes.Length == 1) {
						indexerProp = prop;
						break;
					}
				}
			}
			if (indexerProp != null)
				return new IndexerValueReference (ctx, sob, index, indexerProp);
			else
				return null;
		}
示例#3
0
 public void SetElement(Thread thread, int[] indices, TargetObject obj)
 {
     thread.ThreadServant.DoTargetAccess(
         delegate(TargetMemoryAccess target) {
         SetElement(target, indices, obj);
         return(null);
     });
 }
		public MdbEvaluationContext (Thread thread, StackFrame frame, TargetObject exception, Mono.Debugging.Client.EvaluationOptions options): base (options)
		{
			Evaluator = Server.Instance.Evaluator;
			Adapter = Server.Instance.MdbObjectValueAdaptor;
			this.thread = thread;
			this.frame = frame;
			this.Exception = exception;
		}
示例#5
0
 public void SetElement(Thread thread, int[] indices, TargetObject obj)
 {
     thread.ThreadServant.DoTargetAccess (
         delegate (TargetMemoryAccess target) {
             SetElement (target, indices, obj);
             return null;
     });
 }
 public void SetObject(Thread thread, TargetObject obj)
 {
     thread.ThreadServant.DoTargetAccess (
         delegate (TargetMemoryAccess target) {
             Type.SetObject (target, Location, obj);
             return null;
     });
 }
示例#7
0
 public void SetObject(Thread thread, TargetObject obj)
 {
     thread.ThreadServant.DoTargetAccess(
         delegate(TargetMemoryAccess target) {
         Type.SetObject(target, Location, obj);
         return(null);
     });
 }
示例#8
0
        public static EvaluationResult GetProperty(Thread thread, TargetPropertyInfo property,
							    TargetStructObject instance, EvaluationFlags flags,
							    int timeout, out string error, out TargetObject result)
        {
            error = null;

            RuntimeInvokeResult rti;
            try {
                RuntimeInvokeFlags rti_flags = RuntimeInvokeFlags.VirtualMethod;

                if ((flags & EvaluationFlags.NestedBreakStates) != 0)
                    rti_flags |= RuntimeInvokeFlags.NestedBreakStates;

                rti = thread.RuntimeInvoke (
                    property.Getter, instance, new TargetObject [0], rti_flags);

                if (!rti.CompletedEvent.WaitOne (timeout, false)) {
                    rti.Abort ();
                    result = null;
                    return EvaluationResult.Timeout;
                }

                if ((rti.TargetException != null) &&
                    (rti.TargetException.Type == TargetError.ClassNotInitialized)) {
                    result = null;
                    error = rti.ExceptionMessage;
                    return EvaluationResult.NotInitialized;
                }

                if (rti.Result is Exception) {
                    result = null;
                    error = ((Exception) rti.Result).Message;
                    return EvaluationResult.UnknownError;
                }

                result = (TargetObject) rti.ReturnObject;

                if (rti.ExceptionMessage != null) {
                    error = rti.ExceptionMessage;
                    return EvaluationResult.Exception;
                } else if (rti.ReturnObject == null) {
                    rti.Abort ();
                    return EvaluationResult.UnknownError;
                }

                return EvaluationResult.Ok;
            } catch (TargetException ex) {
                result = null;
                error = ex.ToString ();
                return EvaluationResult.UnknownError;
            }
        }
		public static AbstractVariable Create(string name, TargetObject obj, StackFrame stackFrame)
		{
			if (obj == null) {
				return new ErrorVariable(name, "Object is null");
			}
			
			try {
				switch (obj.Kind) {
					case TargetObjectKind.Array:
						return new ArrayVariable(name, stackFrame, (TargetArrayObject)obj);
					case TargetObjectKind.Pointer:
						TargetPointerObject pobj = (TargetPointerObject)obj;
						if (!pobj.Type.IsTypesafe) {
							return new ErrorVariable(name, "Pointer is not typesafe");
						}
						try {
							TargetObject deref = pobj.GetDereferencedObject(stackFrame.Thread);
							return VariableFactory.Create(name, deref, stackFrame);
						} catch {
							return new ErrorVariable(name, "Can not dereference object");
						}
					case TargetObjectKind.Object:
						try {
							TargetObject deref = ((TargetObjectObject)obj).GetDereferencedObject(stackFrame.Thread);
							return VariableFactory.Create(name, deref, stackFrame);
						} catch {
							return new ErrorVariable(name, "Can not dereference object");
						}
					case TargetObjectKind.Struct:
					case TargetObjectKind.Class:
						return new ClassVariable(name, stackFrame, (TargetClassObject)obj);
					case TargetObjectKind.Fundamental:
						return new FundamentalVariable(name, stackFrame, (TargetFundamentalObject)obj);
					case TargetObjectKind.Enum:
						return new EnumVariable(name, stackFrame, (TargetEnumObject)obj);
					default:
						return new ErrorVariable(name, "Unknown kind of object");
				}
			} catch (Exception e) {
				return new ErrorVariable(name, e.Message);
			}
		}
示例#10
0
        internal virtual void SetObject(TargetMemoryAccess target, TargetLocation location,
                                        TargetObject obj)
        {
            if (obj == null)
            {
                if (IsByRef)
                {
                    location.WriteAddress(target, TargetAddress.Null);
                    return;
                }

                throw new InvalidOperationException();
            }

            if (IsByRef)
            {
                if (obj.Type.IsByRef)
                {
                    location.WriteAddress(target, obj.Location.GetAddress(target));
                    return;
                }

                throw new InvalidOperationException();
            }

            if (!HasFixedSize || !obj.Type.HasFixedSize)
            {
                throw new InvalidOperationException();
            }
            if (Size != obj.Type.Size)
            {
                throw new InvalidOperationException();
            }

            byte[] contents = obj.Location.ReadBuffer(target, obj.Type.Size);
            location.WriteBuffer(target, contents);
        }
示例#11
0
        DL.Backtrace CreateBacktrace(MD.Thread thread, ML.TargetObject exception)
        {
            List <MD.StackFrame> frames = new List <MD.StackFrame> ();
            DateTime             t      = DateTime.Now;

            if (!thread.CurrentFrame.Language.IsManaged)
            {
                MD.Backtrace bt = thread.GetBacktrace(MD.Backtrace.Mode.Native, max_frames);
                if (bt != null)
                {
                    Console.WriteLine("GetBacktrace native time: {0} ms n:{1}", (DateTime.Now - t).TotalMilliseconds, bt.Count);
                    frames.AddRange(bt.Frames);
                }
            }
            else
            {
                t = DateTime.Now;
                MD.Backtrace backtrace = thread.GetBacktrace(MD.Backtrace.Mode.Managed, max_frames);
                if (backtrace != null)
                {
                    Console.WriteLine("GetBacktrace managed time: {0} ms n:{1}", (DateTime.Now - t).TotalMilliseconds, backtrace.Count);
                    frames.AddRange(backtrace.Frames);
                }
            }
            if (frames.Count > 0)
            {
                BacktraceWrapper wrapper = new BacktraceWrapper(frames.ToArray(), exception);
                return(new DL.Backtrace(wrapper));
            }
            else if (thread.CurrentBacktrace != null)
            {
                BacktraceWrapper wrapper = new BacktraceWrapper(thread.CurrentBacktrace.Frames, exception);
                return(new DL.Backtrace(wrapper));
            }
            return(null);
        }
示例#12
0
        protected override Expression DoResolve(ScriptingContext context)
        {
            exc = context.CurrentFrame.ExceptionObject;
            if (exc == null)
                throw new ScriptingException ("No current exception.");

            resolved = true;
            return this;
        }
示例#13
0
        protected override bool DoAssign(ScriptingContext context, TargetObject obj)
        {
            if (!var.CanWrite)
                return false;

            TargetObject new_obj = Convert.ImplicitConversionRequired (
                context, obj, var.Type);

            var.SetObject (context.CurrentFrame, new_obj);
            return true;
        }
示例#14
0
 protected void SetField(Thread target, TargetFieldInfo field, TargetObject obj)
 {
     ResolveClass (target);
     class_info.SetField (target, InstanceObject, field, obj);
 }
示例#15
0
        protected override bool DoAssign(ScriptingContext context, TargetObject tobj)
        {
            long value;

            TargetPointerObject pobj = tobj as TargetPointerObject;
            if (pobj != null) {
                TargetAddress addr = pobj.GetAddress (context.CurrentThread);
                value = addr.Address;
            } else {
                TargetFundamentalObject fobj = tobj as TargetFundamentalObject;
                if (fobj == null)
                    throw new ScriptingException (
                        "Cannot store non-fundamental object `{0}' in " +
                        "a register", tobj.Type.Name);

                object obj = fobj.GetObject (context.CurrentThread);
                value = System.Convert.ToInt64 (obj);
            }

            Register register = context.CurrentFrame.Registers [name];
            if (register == null)
                throw new ScriptingException ("No such register `{0}'.", name);

            register.WriteRegister (context.CurrentThread, value);
            return true;
        }
示例#16
0
        protected TargetObject DoInvoke(ScriptingContext context, bool debug)
        {
            TargetObject[] args = new TargetObject [arguments.Length];

            for (int i = 0; i < arguments.Length; i++)
                args [i] = arguments [i].EvaluateObject (context);

            TargetMethodSignature sig = method.GetSignature (context.CurrentThread);

            TargetObject[] objs = new TargetObject [args.Length];
            for (int i = 0; i < args.Length; i++) {
                objs [i] = Convert.ImplicitConversionRequired (
                    context, args [i], sig.ParameterTypes [i]);
            }

            TargetStructObject instance = method_expr.InstanceObject;

            if (!method.IsStatic && !method.IsConstructor && (instance == null))
                throw new ScriptingException (
                    "Cannot invoke instance method `{0}' with a type reference.",
                    method.FullName);

            try {
                Thread thread = context.CurrentThread;
                RuntimeInvokeResult result;

                RuntimeInvokeFlags flags = context.GetRuntimeInvokeFlags ();
                if (debug)
                    flags |= RuntimeInvokeFlags.BreakOnEntry | RuntimeInvokeFlags.SendEventOnCompletion |
                        RuntimeInvokeFlags.NestedBreakStates;

                result = context.RuntimeInvoke (thread, method, instance, objs, flags);

                if (result == null)
                    throw new ScriptingException (
                        "Invocation of `{0}' aborted abnormally.", Name);

                if (result.ExceptionMessage != null)
                    throw new InvocationException (Name, result.ExceptionMessage, result.ReturnObject);

                return result.ReturnObject;
            } catch (TargetException ex) {
                throw new ScriptingException (
                    "Invocation of `{0}' raised an exception: {1}", Name, ex.Message);
            } catch (EvaluationTimeoutException ex) {
                throw new ScriptingException ("Invocation of `{0}' timed out.", Name);
            }
        }
示例#17
0
        public void Assign(ScriptingContext context, TargetObject obj)
        {
            if (!resolved)
                throw new InvalidOperationException (
                    String.Format (
                        "Some clown tried to evaluate the " +
                        "unresolved expression `{0}'", Name));

            bool ok = DoAssign (context, obj);
            if (!ok)
                throw new ScriptingException (
                    "Expression `{0}' is not an lvalue", Name);
        }
示例#18
0
        public static TargetObject ImplicitConversionRequired(ScriptingContext context,
								       TargetObject obj, TargetType type)
        {
            TargetObject new_obj = ImplicitConversion (context, obj, type);
            if (new_obj != null)
                return new_obj;

            throw new ScriptingException (
                "Cannot implicitly convert `{0}' to `{1}'", obj.Type.Name, type.Name);
        }
示例#19
0
 internal abstract void SetElement(TargetMemoryAccess target, int[] indices,
                                   TargetObject obj);
示例#20
0
 public abstract void SetObject(StackFrame frame, TargetObject obj);
		public IndexerValueReference (EvaluationContext ctx, TargetStructObject target, TargetObject[] index, TargetPropertyInfo indexerProp): base (ctx)
		{
			this.indexer = indexerProp;
			this.target = target;
			this.index = index;
		}
示例#22
0
 public abstract void SetObject(StackFrame frame, TargetObject obj);
示例#23
0
 public abstract TargetObjectObject CreateBoxedObject(Thread target, TargetObject value);
示例#24
0
        bool BreakEventCheck(MD.TargetEventArgs args)
        {
            MD.StackFrame frame = args.Frame;
            if (!(args.Data is int))
            {
                return(true);
            }

            int eventHandle = (int)args.Data;

            DL.BreakEvent be;
            if (!events.TryGetValue(eventHandle, out be))
            {
                return(true);
            }

            // Check hit count
            if (be.HitCount > 0)
            {
                be.HitCount--;
                DispatchEvent(delegate {
                    NotifyBreakEventUpdate(eventHandle, be.HitCount, null);
                });
                return(false);
            }

            MdbEvaluationContext ctx = new MdbEvaluationContext(frame.Thread, frame, null, SessionOptions.EvaluationOptions);

            DL.Breakpoint bp = be as DL.Breakpoint;
            if (bp != null && !string.IsNullOrEmpty(bp.ConditionExpression))
            {
                ML.TargetObject val = EvaluateExp(ctx, bp.ConditionExpression);
                if (val == null)
                {
                    return(false);
                }
                if (bp.BreakIfConditionChanges)
                {
                    string current = evaluator.TargetObjectToExpression(ctx, val).Value;
                    string last;
                    bool   found = lastConditionValue.TryGetValue(eventHandle, out last);
                    lastConditionValue [eventHandle] = current;
                    if (!found || last == current)
                    {
                        return(false);
                    }
                }
                else
                {
                    ML.TargetFundamentalObject fob = val as ML.TargetFundamentalObject;
                    if (fob == null)
                    {
                        return(false);
                    }
                    object ob = fob.GetObject(frame.Thread);
                    if (!(ob is bool) || !(bool)ob)
                    {
                        return(false);
                    }
                }
            }

            switch (be.HitAction)
            {
            case HitAction.Break:
                return(true);

            case HitAction.CustomAction:
                return(controller.OnCustomBreakpointAction(be.CustomActionId, eventHandle));

            case HitAction.PrintExpression:
                if (string.IsNullOrEmpty(be.TraceExpression) || frame == null)
                {
                    return(false);
                }
                ML.TargetObject val = EvaluateExp(ctx, be.TraceExpression);
                if (val != null)
                {
                    string str = evaluator.TargetObjectToString(ctx, val);
                    DispatchEvent(delegate {
                        NotifyBreakEventUpdate(eventHandle, -1, str);
                    });
                }
                return(false);
            }
            return(false);
        }
示例#25
0
        public int InsertBreakEvent(DL.BreakEvent be, bool enable)
        {
            CancelRuntimeInvokes();
            DL.Breakpoint bp = be as DL.Breakpoint;
            MD.Event      ev = null;

            if (bp != null)
            {
                MD.SourceLocation   location = new MD.SourceLocation(bp.FileName, bp.Line);
                MD.SourceBreakpoint sbp      = new MD.SourceBreakpoint(session, ThreadGroup.Global, location);
                mdbAdaptor.InitializeBreakpoint(sbp);
                session.AddEvent(sbp);
                ev = sbp;
            }
            else if (be is Catchpoint)
            {
                lock (pendingCatchpoints) {
                    Catchpoint    cp  = (Catchpoint)be;
                    ML.TargetType exc = null;
                    if (process != null)
                    {
                        foreach (Module mod in process.Modules)
                        {
                            exc = mod.Language.LookupType(cp.ExceptionName);
                            if (exc != null)
                            {
                                break;
                            }
                        }
                    }
                    if (exc != null)
                    {
                        ev = session.InsertExceptionCatchPoint(process.MainThread, ThreadGroup.Global, exc);
                    }
                    else
                    {
                        pendingCatchpoints.Add(cp);
                        return(-1);
                    }
                }
            }

            ev.IsEnabled = enable;

            if (!initializing)
            {
                lock (debugger) {
                    mdbAdaptor.ActivateEvent(ev);
                }
            }

            if (bp != null && !running && !initializing && activeThread.CurrentFrame != null && !string.IsNullOrEmpty(bp.ConditionExpression) && bp.BreakIfConditionChanges)
            {
                // Initial expression evaluation
                MdbEvaluationContext ctx = new MdbEvaluationContext(activeThread, activeThread.CurrentFrame, null, SessionOptions.EvaluationOptions);
                ML.TargetObject      ob  = EvaluateExp(ctx, bp.ConditionExpression);
                if (ob != null)
                {
                    lastConditionValue [ev.Index] = evaluator.TargetObjectToExpression(ctx, ob).Value;
                }
            }

            events [ev.Index] = be;
            return(ev.Index);
        }
示例#26
0
        public static TargetObject ImplicitConversion(ScriptingContext context,
							       TargetObject obj, TargetType type)
        {
            if (obj.Type.Equals (type))
                return obj;

            if ((obj is TargetFundamentalObject) && (type is TargetFundamentalType))
                return ImplicitFundamentalConversion (
                    context, (TargetFundamentalObject) obj,
                    (TargetFundamentalType) type);

            if ((obj is TargetFundamentalObject) && (type is TargetObjectType) &&
                (((TargetFundamentalType) obj.Type).FundamentalKind == FundamentalKind.String))
                return obj.Type.Language.CreateBoxedObject (context.CurrentThread, obj);

            if ((obj is TargetClassObject) && (type is TargetClassType))
                return ImplicitReferenceConversion (
                    context, (TargetClassObject) obj,
                    (TargetClassType) type);

            TargetNullableType ntype = type as TargetNullableType;
            if (ntype != null) {
                if (obj.Kind == TargetObjectKind.Null)
                    return obj;
                else if (obj.Kind != TargetObjectKind.Nullable)
                    return ImplicitConversion (context, obj, ntype.ElementType);

                TargetNullableType ntype2 = (TargetNullableType) obj.Type;
                if (ImplicitConversionExists (context, ntype2.ElementType, ntype.ElementType))
                    return obj;
            }

            return null;
        }
		public MethodCall (MdbEvaluationContext ctx, TargetFunctionType function, TargetStructObject object_argument, TargetObject[] param_objects)
		{
			this.ctx = ctx;
			this.function = function;
			this.object_argument = object_argument;
			this.param_objects = param_objects;
		}
示例#28
0
        public static TargetClassObject ToStructObject(Thread target, TargetObject obj)
        {
            TargetClassObject sobj = obj as TargetClassObject;
            if (sobj != null)
                return sobj;

            TargetObjectObject oobj = obj as TargetObjectObject;
            if (oobj != null)
                return oobj.GetClassObject (target);

            TargetArrayObject aobj = obj as TargetArrayObject;
            if ((aobj != null) && aobj.HasClassObject)
                return aobj.GetClassObject (target);

            return null;
        }
		public override object RuntimeInvoke (EvaluationContext gctx, object targetType, object target, string methodName, object[] argTypes, object[] argValues)
		{
			gctx.AssertTargetInvokeAllowed ();
			MdbEvaluationContext ctx = (MdbEvaluationContext) gctx;
			TargetObject[] lst = new TargetObject [argValues.Length];
			Array.Copy (argValues, lst, argValues.Length);
			if (target != null)
				return CallMethod (ctx, methodName, (TargetObject) target, lst);
			else
				return CallStaticMethod (ctx, methodName, (TargetType) targetType, lst);
		}
示例#30
0
 protected virtual bool DoAssign(ScriptingContext context, TargetObject obj)
 {
     return false;
 }
		public override object CreateValue (EvaluationContext gctx, object type, params object[] args)
		{
			MdbEvaluationContext ctx = (MdbEvaluationContext) gctx;
			TargetType tt = (TargetType) type;
			TargetObject[] lst = new TargetObject [args.Length];
			Array.Copy (args, lst, args.Length);
			return CallStaticMethod (ctx, ".ctor", tt, lst);
		}
示例#32
0
        protected override bool DoAssign(ScriptingContext context, TargetObject right)
        {
            Thread target = context.CurrentThread;
            TargetObject obj = expr.EvaluateObject (context);

            // array[int]
            TargetArrayObject aobj = obj as TargetArrayObject;
            if (aobj != null) {
                int[] int_indices = GetIntIndices (target, context);
                try {
                    aobj.SetElement (target, int_indices, right);
                } catch (ArgumentException) {
                    throw new ScriptingException (
                        "Index of array expression `{0}' out of bounds.",
                        expr.Name);
                }

                return true;
            }

            // indexers
            TargetClassObject sobj = Convert.ToClassObject (target, obj);
            if (sobj != null) {
                ArrayList props = new ArrayList ();
                foreach (TargetPropertyInfo prop in sobj.Type.Properties) {
                    if (!prop.CanWrite)
                        continue;

                    props.Add (prop.Setter);
                }

                if (props.Count == 0)
                    throw new ScriptingException (
                        "Indexer `{0}' doesn't have a setter.", expr.Name);

                TargetFunctionType[] funcs = new TargetFunctionType [props.Count];
                props.CopyTo (funcs, 0);

                MethodGroupExpression mg = new MethodGroupExpression (
                    sobj.Type, sobj, expr.Name + "[]", funcs, true, false);

                Expression[] indexargs = new Expression [indices.Length + 1];
                indices.CopyTo (indexargs, 0);
                indexargs [indices.Length] = new ArgumentExpression (right);

                InvocationExpression invocation = new InvocationExpression (
                    mg, indexargs);
                invocation.Resolve (context);

                invocation.Invoke (context, false);
                return true;
            }

            throw new ScriptingException (
                "{0} is neither an array/pointer type, nor is it " +
                "an object with a valid indexer.", expr);
        }
		public static TargetObject CallMethod (MdbEvaluationContext ctx, string name,
							  TargetObject target,
							  params TargetObject[] args)
		{
#if REFLECTION_INVOKE
			if (target is TargetGenericInstanceObject || !(target is TargetStructObject)) {
				// Calling methods on generic objects is suprisingly not supported
				// by the debugger. As a workaround we do the call using reflection.
				
				if (name != "ToString" || args.Length != 0) {
					GetTypeOf (ctx, "System.Convert");
					TargetType cc = ctx.Frame.Language.LookupType ("System.Convert");
					SR.BindingFlags sf = SR.BindingFlags.InvokeMethod | SR.BindingFlags.Static | SR.BindingFlags.FlattenHierarchy | SR.BindingFlags.Public | SR.BindingFlags.NonPublic;
					CallMethodWithReflection (ctx, sf, "ToString", cc, null, target);
				}

				SR.BindingFlags f = SR.BindingFlags.InvokeMethod | SR.BindingFlags.Instance | SR.BindingFlags.Public | SR.BindingFlags.NonPublic;
				return CallMethodWithReflection (ctx, f, name, target.Type, target, args);
			}
#endif
			ctx.AssertTargetInvokeAllowed ();
			
			TargetType[] types = new TargetType [args.Length];
			for (int n=0; n<types.Length; n++)
				types [n] = args [n].Type;
			
			TargetStructObject starget = (TargetStructObject) target;
			MemberReference mem = OverloadResolve (ctx, name, starget.Type, types, true, false, true);
			TargetFunctionType function = (TargetFunctionType) ((TargetMethodInfo) mem.Member).Type;
			
			while (starget.Type != mem.DeclaringType) {
				TargetStructObject par = starget.GetParentObject (ctx.Thread);
				if (par != null)
					starget = par;
				else
					break;
			}
			
			TargetMethodSignature sig = function.GetSignature (ctx.Thread);

			TargetObject[] objs = new TargetObject [args.Length];
			for (int i = 0; i < args.Length; i++) {
				objs [i] = TargetObjectConvert.ImplicitConversionRequired (
					ctx, args [i], sig.ParameterTypes [i]);
			}

			return Server.Instance.RuntimeInvoke (ctx, function, starget, objs);
		}
示例#34
0
        protected override bool DoAssign(ScriptingContext context, TargetObject obj)
        {
            if (Member is TargetFieldInfo) {
                obj = Convert.ImplicitConversionRequired (context, obj, Member.Type);
                SetField (context.CurrentThread, (TargetFieldInfo) Member, obj);
            } else if (Member is TargetPropertyInfo) {
                obj = Convert.ImplicitConversionRequired (context, obj, Member.Type);
                SetProperty (context, (TargetPropertyInfo) Member, obj);
            } else if (Member is TargetEventInfo)
                throw new ScriptingException ("Can't set events directly.");
            else if (Member is TargetMethodInfo)
                throw new ScriptingException ("Can't set methods directly.");

            return true;
        }
		public static TargetObject CallStaticMethod (MdbEvaluationContext ctx, string name,
							  TargetType type,
							  params TargetObject[] args)
		{
#if REFLECTION_INVOKE
			if (type is TargetGenericInstanceType || !(type is TargetStructType)) {
				// Calling methods on generic objects is suprisingly not supported
				// by the debugger. As a workaround we do the call using reflection.
				
				SR.BindingFlags f = SR.BindingFlags.InvokeMethod | SR.BindingFlags.Static | SR.BindingFlags.Public | SR.BindingFlags.NonPublic;
				return CallMethodWithReflection (ctx, f, name, type, null, args);
			}
#endif			
			ctx.AssertTargetInvokeAllowed ();
			
			TargetType[] types = new TargetType [args.Length];
			for (int n=0; n<types.Length; n++)
				types [n] = args [n].Type;
			
			MemberReference mem = OverloadResolve (ctx, name, type, types, false, true, true);
			TargetFunctionType function = (TargetFunctionType) ((TargetMethodInfo) mem.Member).Type;
			
			TargetMethodSignature sig = function.GetSignature (ctx.Thread);

			TargetObject[] objs = new TargetObject [args.Length];
			for (int i = 0; i < args.Length; i++) {
				objs [i] = TargetObjectConvert.ImplicitConversionRequired (ctx, args [i], sig.ParameterTypes [i]);
			}

			return Server.Instance.RuntimeInvoke (ctx, function, null, objs);
		}
示例#36
0
        protected void SetProperty(ScriptingContext context, TargetPropertyInfo prop,
					    TargetObject obj)
        {
            ResolveClass (context.CurrentThread);
            if (prop.Setter == null)
                throw new ScriptingException ("Property `{0}' has no setter.", Name);

            RuntimeInvokeFlags flags = context.GetRuntimeInvokeFlags ();

            RuntimeInvokeResult result = context.RuntimeInvoke (
                context.CurrentThread, prop.Setter, InstanceObject,
                new TargetObject [] { obj }, flags);

            if (result.ExceptionMessage != null)
                throw new ScriptingException (
                    "Invocation of `{0}' raised an exception: {1}",
                    Name, result.ExceptionMessage);
        }
		public static TargetObject GetRealObject (MdbEvaluationContext ctx, TargetObject obj)
		{
			if (obj == null)
				return null;

			try {
				switch (obj.Kind) {
					case TargetObjectKind.Array:
					case TargetObjectKind.Fundamental:
						return obj;
						
					case TargetObjectKind.Struct:
					case TargetObjectKind.GenericInstance:
					case TargetObjectKind.Class:
						TargetStructObject co = obj as TargetStructObject;
						if (co == null)
							return null;
						TargetObject res = co.GetCurrentObject (ctx.Thread);
						return res ?? obj;
						
					case TargetObjectKind.Object:
						TargetObjectObject oob = obj as TargetObjectObject;
						if (oob == null)
							return null;
						if (oob.Type.CanDereference)
							return oob.GetDereferencedObject (ctx.Thread);
						else
							return oob;
				}
			}
			catch {
				// Ignore
			}
			return obj;
		}
示例#38
0
        public static TargetObject TryCast(ScriptingContext context, TargetObject source,
						    TargetClassType target_type)
        {
            if (source.Type == target_type)
                return source;

            TargetClassObject sobj = Convert.ToClassObject (context.CurrentThread, source);
            if (sobj == null)
                return null;

            TargetClassObject result = TryParentCast (context, sobj, sobj.Type, target_type);
            if (result != null)
                return result;

            return TryCurrentCast (context, sobj, target_type);
        }
示例#39
0
 public ArgumentExpression(TargetObject obj)
 {
     this.obj = obj;
     resolved = true;
 }
		public override ValueReference GetIndexerReference (EvaluationContext gctx, object target, object[] indices)
		{
			MdbEvaluationContext ctx = (MdbEvaluationContext) gctx;
			TargetObject[] indexArray = new TargetObject [indices.Length];
			Array.Copy (indices, indexArray, indices.Length);
			return IndexerValueReference.CreateIndexerValueReference (ctx, (TargetObject) target, indexArray);
		}
示例#41
0
 public abstract void SetField(Thread thread, TargetStructObject instance,
                               TargetFieldInfo field, TargetObject value);