Inheritance: DebuggerMarshalByRefObject
示例#1
0
        protected TargetEnumInfo(TargetType type, string name, int index, bool is_static,
					  TargetMemberAccessibility accessibility, int position,
					  int offset, bool has_const_value)
            : base(type, name, index, is_static, accessibility)
        {
            this.HasConstValue = has_const_value;
        }
		public FieldReference (EvaluationContext ctx, TargetStructObject thisobj, TargetType type, TargetFieldInfo field): base (ctx)
		{
			this.type = type;
			this.field = field;
			if (!field.IsStatic)
				this.thisobj = thisobj;
		}
示例#3
0
        private void OnModuleLoadedEvent(Module module)
        {
            SourceFile[] sfiles = module.Sources;
            string[]     files  = new string [sfiles.Length];
            for (int n = 0; n < files.Length; n++)
            {
                files [n] = sfiles [n].FileName;
            }
            controller.NotifySourceFileLoaded(files);
            WriteDebuggerOutput(string.Format("Module loaded: {0}.\n", module.Name));

            if (process == null)
            {
                return;
            }

            lock (pendingCatchpoints) {
                foreach (Catchpoint cp in pendingCatchpoints.ToArray())
                {
                    ML.TargetType exc = module.Language.LookupType(cp.ExceptionName);
                    if (exc != null)
                    {
                        session.InsertExceptionCatchPoint(process.MainThread, ThreadGroup.Global, exc);
                        pendingCatchpoints.Remove(cp);
                    }
                }
            }
        }
示例#4
0
        protected TargetEventInfo(TargetType type, string name, int index,
					   bool is_static, TargetMemberAccessibility accessibility,
					   TargetFunctionType add, TargetFunctionType remove,
					   TargetFunctionType raise)
            : base(type, name, index, is_static, accessibility)
        {
            this.Add = add;
            this.Remove = remove;
            this.Raise = raise;
        }
示例#5
0
        internal bool CheckException(MonoLanguageBackend mono, TargetMemoryAccess target,
					      TargetAddress address)
        {
            TargetClassObject exc = mono.CreateObject (target, address) as TargetClassObject;
            if (exc == null)
                return false; // OOOPS

            if (exception == null)
                exception = mono.LookupType (Name);
            if (exception == null)
                return false;

            return IsSubclassOf (target, exc.Type, exception);
        }
示例#6
0
        static TargetFunctionType OverloadResolve(ScriptingContext context,
							   TargetType[] argtypes,
							   ArrayList candidates)
        {
            // Ok, no we need to find an exact match.
            TargetFunctionType match = null;
            foreach (TargetFunctionType method in candidates) {
                string error;
                if (!IsApplicable (context, method, argtypes, out error))
                    continue;

                // We need to find exactly one match
                if (match != null)
                    return null;

                match = method;
            }

            return match;
        }
示例#7
0
        public TargetFunctionType OverloadResolve(ScriptingContext context,
							   TargetType[] argtypes)
        {
            ArrayList candidates = new ArrayList ();

            foreach (TargetFunctionType method in methods) {
                if (method.ParameterTypes.Length != argtypes.Length)
                    continue;

                candidates.Add (method);
            }

            TargetFunctionType candidate;
            if (candidates.Count == 1) {
                candidate = (TargetFunctionType) candidates [0];
                string error;
                if (IsApplicable (context, candidate, argtypes, out error))
                    return candidate;

                throw new ScriptingException (
                    "The best overload of method `{0}' has some invalid " +
                    "arguments:\n{1}", Name, error);
            }

            if (candidates.Count == 0)
                throw new ScriptingException (
                    "No overload of method `{0}' has {1} arguments.",
                    Name, argtypes.Length);

            candidate = OverloadResolve (context, argtypes, candidates);

            if (candidate == null)
                throw new ScriptingException (
                    "Ambiguous method `{0}'; need to use " +
                    "full name", Name);

            return candidate;
        }
示例#8
0
        protected override SourceLocation DoEvaluateSource(ScriptingContext context)
        {
            Expression[] types = new Expression [arguments.Length];
            TargetType[] argtypes = new TargetType [types.Length];

            for (int i = 0; i < arguments.Length; i++) {
                types [i] = arguments [i].ResolveType (context);
                argtypes [i] = types [i].EvaluateType (context);
            }

            TargetFunctionType func = method_expr.OverloadResolve (context, argtypes);
            if (func != null)
                return new SourceLocation (func);

            return null;
        }
示例#9
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);
        }
示例#10
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;
        }
		static MemberReference OverloadResolve (MdbEvaluationContext ctx, string methodName, TargetType[] argtypes, List<MemberReference> candidates, bool throwIfNotFound)
		{
			// Ok, no we need to find an exact match.
			MemberReference match = null;
			int bestCount = -1;
			bool repeatedBestCount = false;
			
			foreach (MemberReference method in candidates) {
				string error;
				int matchCount;
				TargetFunctionType func;
				if (method.Member is TargetMethodInfo)
					func = (TargetFunctionType) ((TargetMethodInfo) method.Member).Type;
				else
					func = (TargetFunctionType) ((TargetPropertyInfo) method.Member).Getter;
				
				if (!IsApplicable (ctx, func, argtypes, out error, out matchCount))
					continue;

				if (matchCount == bestCount) {
					repeatedBestCount = true;
				} else if (matchCount > bestCount) {
					match = method;
					bestCount = matchCount;
					repeatedBestCount = false;
				}
			}
			
			if (match == null) {
				if (!throwIfNotFound)
					return null;
				if (methodName != null)
					throw new EvaluatorException ("Invalid arguments for method `{0}'.", methodName);
				else
					throw new EvaluatorException ("Invalid arguments for indexer.");
			}
			
			if (repeatedBestCount) {
				// If there is an ambiguous match, just pick the first match. If the user was expecting
				// something else, he can provide more specific arguments
				
/*				if (!throwIfNotFound)
					return null;
				if (methodName != null)
					throw new EvaluatorException ("Ambiguous method `{0}'; need to use full name", methodName);
				else
					throw new EvaluatorException ("Ambiguous arguments for indexer.", methodName);
*/			}
			 
			return match;
		}		
示例#12
0
 public TargetNullObject(TargetType type)
     : base(type, new AbsoluteTargetLocation(TargetAddress.Null))
 {
 }
示例#13
0
 internal override void OnTargetExited()
 {
     exception = null;
 }
示例#14
0
 internal TargetObject(TargetType type, TargetLocation location)
 {
     this.type      = type;
     this.Location  = location;
     this.type_name = type.Name;
 }
示例#15
0
 public TypeExpression(TargetType type)
 {
     this.type = type;
     resolved = true;
 }
示例#16
0
        TargetObject DoCast(ScriptingContext context, Expression expr,
				     TargetType target_type)
        {
            TargetObject source = expr.EvaluateObject (context);
            if (source == null)
                return null;

            if (target_type is TargetObjectType) {
                if (((source is TargetClassObject) && !source.Type.IsByRef) ||
                    (source is TargetFundamentalObject))
                    return target_type.Language.CreateBoxedObject (context.CurrentThread, source);

                if (source is TargetObjectObject)
                    return source;

                throw new ScriptingException (
                    "Cannot box object `{0}': not a value-type", expr.Name);
            }

            if (target_type is TargetPointerType) {
                TargetAddress address;

                PointerExpression pexpr = expr as PointerExpression;
                if (pexpr != null)
                    address = pexpr.EvaluateAddress (context);
                else {
                    TargetPointerType ptype = expr.EvaluateType (context)
                        as TargetPointerType;
                    if ((ptype == null) || ptype.IsTypesafe)
                        return null;

                    pexpr = new AddressOfExpression (expr);
                    pexpr.Resolve (context);

                    address = pexpr.EvaluateAddress (context);
                }

                return ((TargetPointerType) target_type).GetObject (address);
            }

            if (target_type is TargetFundamentalType) {
                TargetFundamentalObject fobj = expr.EvaluateObject (context)
                    as TargetFundamentalObject;
                if (fobj == null)
                    return null;

                TargetFundamentalType ftype = target_type as TargetFundamentalType;
                return Convert.ExplicitFundamentalConversion (context, fobj, ftype);
            }

            TargetClassType ctype = Convert.ToClassType (target_type);
            TargetClassObject source_cobj = Convert.ToClassObject (context.CurrentThread, source);

            if (source_cobj == null)
                throw new ScriptingException (
                    "Variable {0} is not a class type.", expr.Name);

            return TryCast (context, source_cobj, ctype);
        }
示例#17
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);
        }
		static bool IsApplicable (MdbEvaluationContext ctx, TargetFunctionType method, TargetType[] types, out string error, out int matchCount)
		{
			TargetMethodSignature sig = method.GetSignature (ctx.Thread);
			matchCount = 0;

			for (int i = 0; i < types.Length; i++) {
				TargetType param_type = sig.ParameterTypes [i];

				if (param_type == types [i]) {
					matchCount++;
					continue;
				}

				if (TargetObjectConvert.ImplicitConversionExists (ctx, types [i], param_type))
					continue;

				error = String.Format (
					"Argument {0}: Cannot implicitly convert `{1}' to `{2}'",
					i, types [i].Name, param_type.Name);
				return false;
			}

			error = null;
			return true;
		}
示例#19
0
文件: Style.cs 项目: baulig/debugger
 public override string FormatType(Thread target, TargetType type)
 {
     return FormatType (target, "", type, null);
 }
		public static IEnumerable<MemberReference> GetTypeMembers (MdbEvaluationContext ctx, TargetType t, bool includeFields, bool includeProps, bool includeMethods, BindingFlags flags)
		{
			// Don't use yield in this method because the whole list of members
			// must be retrieved before we can do anything with them.
			List<MemberReference> members = new List<MemberReference> ();
			
			Dictionary<string,string> foundMethods = new Dictionary<string,string> ();

			while (t != null) {
				
				TargetFieldInfo[] fields = null;
				TargetPropertyInfo[] properties = null;
				TargetMethodInfo[] methods = null;

				TargetClass cls = t.HasClassType ? t.ClassType.GetClass (ctx.Thread) : null;
				if (cls != null) {
					if (includeFields)
						fields = cls.GetFields (ctx.Thread);
					if (includeProps)
						properties = cls.GetProperties (ctx.Thread);
					if (includeMethods)
						methods = cls.GetMethods (ctx.Thread);
				}
				else {
					TargetClassType ct = t as TargetClassType;
					if (ct == null && t.HasClassType)
						ct = t.ClassType;
					if (ct != null) {
						if (includeFields)
							fields = ct.Fields;
						if (includeProps)
							properties = ct.Properties;
						if (includeMethods)
							methods = ct.Methods;
					}
				}
				
				if (fields != null) {
					foreach (TargetFieldInfo field in fields) {
						if (field.IsCompilerGenerated)
							continue;
						if (field.Accessibility == TargetMemberAccessibility.Public && (flags & BindingFlags.Public) == 0)
							continue;
						if (field.Accessibility != TargetMemberAccessibility.Public && (flags & BindingFlags.NonPublic) == 0)
							continue;
						if (field.IsStatic && (flags & BindingFlags.Static) == 0)
							continue;
						if (!field.IsStatic && (flags & BindingFlags.Instance) == 0)
							continue;
						members.Add (new MemberReference (field, t));
					}
				}
				
				if (properties != null) {
					foreach (TargetPropertyInfo prop in properties) {
						if (prop.Accessibility == TargetMemberAccessibility.Public && (flags & BindingFlags.Public) == 0)
							continue;
						if (prop.Accessibility != TargetMemberAccessibility.Public && (flags & BindingFlags.NonPublic) == 0)
							continue;
						if (prop.IsStatic && (flags & BindingFlags.Static) == 0)
							continue;
						if (!prop.IsStatic && (flags & BindingFlags.Instance) == 0)
							continue;
						members.Add (new MemberReference (prop, t));
					}
				}
				
				if (methods != null) {
					foreach (TargetMethodInfo met in methods) {
						if (met.Accessibility == TargetMemberAccessibility.Public && (flags & BindingFlags.Public) == 0)
							continue;
						if (met.Accessibility != TargetMemberAccessibility.Public && (flags & BindingFlags.NonPublic) == 0)
							continue;
						if (met.IsStatic && (flags & BindingFlags.Static) == 0)
							continue;
						if (!met.IsStatic && (flags & BindingFlags.Instance) == 0)
							continue;
						string sig = met.FullName;
						if (!foundMethods.ContainsKey (sig)) {
							foundMethods [sig] = sig;
							members.Add (new MemberReference (met, t));
						}
					}
				}
				
				TargetStructType type = t as TargetStructType;
				if (type != null && type.HasParent && (flags & BindingFlags.DeclaredOnly) == 0)
					t = type.GetParentType (ctx.Thread);
				else
					break;
			}
			return members;
		}
示例#21
0
文件: Style.cs 项目: baulig/debugger
 public override string ShowVariableType(TargetType type, string name)
 {
     return type.Name;
 }
示例#22
0
        public static bool ImplicitConversionExists(ScriptingContext context,
							     TargetType source, TargetType target)
        {
            if (source.Equals (target))
                return true;

            if ((source is TargetFundamentalType) && (target is TargetFundamentalType))
                return ImplicitFundamentalConversionExists (
                    context, (TargetFundamentalType) source,
                    (TargetFundamentalType) target);

            if ((source is TargetFundamentalType) && (target is TargetObjectType) &&
                (((TargetFundamentalType) source).FundamentalKind == FundamentalKind.String))
                return true;

            if ((source is TargetClassType) && (target is TargetClassType))
                return ImplicitReferenceConversionExists (
                    context, (TargetClassType) source,
                    (TargetClassType) target);

            return false;
        }
示例#23
0
文件: Style.cs 项目: baulig/debugger
        protected string FormatType(Thread target, string prefix,
					     TargetType type, Hashtable hash)
        {
            string retval;

            if (hash == null)
                hash = new Hashtable ();

            if (hash.Contains (type))
                return type.Name;
            else
                hash.Add (type, true);

            switch (type.Kind) {
            case TargetObjectKind.Array: {
                TargetArrayType atype = (TargetArrayType) type;
                retval = atype.Name;
                break;
            }

            case TargetObjectKind.Enum: {
                StringBuilder sb = new StringBuilder ();
                TargetEnumType etype = type as TargetEnumType;
                sb.Append ("enum ");

                if (etype.Name != null)
                    sb.Append (etype.Name);

                sb.Append ("\n" + prefix + "{\n");

                foreach (TargetEnumInfo field in etype.Members) {
                    sb.Append (FormatEnumMember (target, prefix, field, false, hash));
                    if (field != etype.Members[etype.Members.Length - 1])
                        sb.Append (",");
                    sb.Append ("\n");
                }

                sb.Append (prefix + "}");

                retval = sb.ToString ();
                break;
            }

            case TargetObjectKind.Class:
            case TargetObjectKind.Struct: {
                StringBuilder sb = new StringBuilder ();
                TargetClassType ctype = (TargetClassType) type;
                if (type.Kind == TargetObjectKind.Struct)
                    sb.Append ("struct ");
                else
                    sb.Append ("class ");
                if (ctype.Name != null) {
                    sb.Append (ctype.Name);
                    sb.Append (" ");
                }
                if (ctype.HasParent) {
                    TargetClassType parent = ctype.GetParentType (target);
                    sb.Append (": ");
                    sb.Append (parent.Name);
                }

                sb.Append ("\n" + prefix + "{\n");
                sb.Append (FormatStruct (prefix, ctype, hash));
                sb.Append (prefix + "}");

                retval = sb.ToString ();
                break;
            }

            case TargetObjectKind.Alias: {
                TargetTypeAlias alias = (TargetTypeAlias) type;
                string name;
                if (alias.TargetType != null)
                    name = FormatType (target, prefix, alias.TargetType, hash);
                else
                    name = "<unknown type>";
                retval = String.Format ("typedef {0} = {1}", alias.Name, name);
                break;
            }

            case TargetObjectKind.GenericInstance: {
                TargetGenericInstanceType gtype = (TargetGenericInstanceType) type;

                StringBuilder sb = new StringBuilder ();
                if (gtype.ContainerType.Kind == TargetObjectKind.Struct)
                    sb.Append ("struct ");
                else
                    sb.Append ("class ");

                sb.Append (String.Format ("{0} = ", gtype.Name));

                TargetClassType parent = gtype.ContainerType.GetParentType (target);
                sb.Append (String.Format ("{0}", gtype.ContainerType.Name));
                if (parent != null)
                    sb.Append (String.Format (" : {0}", parent.Name));

                sb.Append ("\n" + prefix + "{\n");
                sb.Append (FormatStruct (prefix, gtype.ContainerType, hash));
                sb.Append (prefix + "}");

                retval = sb.ToString ();
                break;
            }

            default:
                retval = type.Name;
                break;
            }

            hash.Remove (type);
            return retval;
        }
示例#24
0
        public static TargetClassType ToClassType(TargetType type)
        {
            TargetClassType ctype = type as TargetClassType;
            if (ctype != null)
                return ctype;

            TargetObjectType otype = type as TargetObjectType;
            if (otype != null) {
                ctype = otype.ClassType;
                if (ctype != null)
                    return ctype;
            }

            TargetArrayType atype = type as TargetArrayType;
            if (atype != null) {
                if (atype.Language.ArrayType != null)
                    return atype.Language.ArrayType;
            }

            throw new ScriptingException (
                "Type `{0}' is not a struct or class.", type.Name);
        }
		public MemberReference (TargetMemberInfo member, TargetType type)
		{
			Member = member;
			DeclaringType = type;
		}
示例#26
0
        public static bool IsApplicable(ScriptingContext context, TargetFunctionType method,
						 TargetType[] types, out string error)
        {
            TargetMethodSignature sig = method.GetSignature (context.CurrentThread);

            for (int i = 0; i < types.Length; i++) {
                TargetType param_type = sig.ParameterTypes [i];

                if (param_type == types [i])
                    continue;

                if (Convert.ImplicitConversionExists (context, types [i], param_type))
                    continue;

                error = String.Format (
                    "Argument {0}: Cannot implicitly convert `{1}' to `{2}'",
                    i, types [i].Name, param_type.Name);
                return false;
            }

            error = null;
            return true;
        }
		public override bool HasMethod (EvaluationContext gctx, object targetType, string methodName, object[] argTypes, BindingFlags flags)
		{
			MdbEvaluationContext ctx = (MdbEvaluationContext) gctx;
			
			if (argTypes == null) {
				foreach (MemberReference mm in ObjectUtil.GetTypeMembers (ctx, (TargetType) targetType, false, false, true, flags | BindingFlags.Public | BindingFlags.NonPublic)) {
					TargetMethodInfo met = (TargetMethodInfo) mm.Member;
					if (met.Name == methodName)
						return true;
				}
				return false;
			}
			
			TargetStructType stype = targetType as TargetStructType;
			if (stype == null)
				return false;
		
			TargetType[] types = new TargetType [argTypes.Length];
			Array.Copy (argTypes, types, argTypes.Length);
			
			MemberReference mem;
			mem = OverloadResolve (ctx, methodName, stype, types, (flags & BindingFlags.Instance) != 0, (flags & BindingFlags.Static) != 0, false);
			return mem != null;
		}
示例#28
0
        protected override TargetFunctionType DoEvaluateMethod(ScriptingContext context,
									LocationType type,
									Expression[] types)
        {
            if (type != LocationType.Method)
                return null;

            if (types == null) {
                if (methods.Length == 1)
                    return (TargetFunctionType) methods [0];

                                throw new ScriptingException (
                                        "Ambiguous method `{0}'; need to use full name", Name);
            }

            TargetType[] argtypes = new TargetType [types.Length];
            for (int i = 0; i < types.Length; i++)
                argtypes [i] = types [i].EvaluateType (context);

            TargetFunctionType func = OverloadResolve (context, argtypes);
            if (func != null)
                return func;

            return context.Interpreter.QueryMethod (methods);
        }
		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);
		}
示例#30
0
        protected bool DoResolveBase(ScriptingContext context)
        {
            if (expr is SimpleNameExpression) {
                Process process = context.CurrentThread.Process;
                Language native = process.NativeLanguage;

                underlying_type = native.LookupType (expr.Name);
            } else {
                TypeExpr te = expr.ResolveType (context) as TypeExpr;
                if (te == null)
                    return false;

                underlying_type = te.Type;
            }

            if (underlying_type == null)
                return false;

            pointer_type = underlying_type.Language.CreatePointerType (underlying_type);
            if (pointer_type == null)
                throw new ScriptingException ("Can't create of pointer of type `{0}'",
                                  underlying_type.Name);

            resolved = true;
            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);
		}
示例#32
0
        public static bool TryCast(ScriptingContext context, TargetType source,
					    TargetClassType target_type)
        {
            if (source == target_type)
                return true;

            TargetClassType stype = Convert.ToClassType (source);
            if (stype == null)
                return false;

            return TryParentCast (context, stype, target_type);
        }
		public static MemberReference OverloadResolve (MdbEvaluationContext ctx, string methodName, TargetType type, TargetType[] argtypes, bool allowInstance, bool allowStatic, bool throwIfNotFound)
		{
			List<MemberReference> candidates = new List<MemberReference> ();

			if (methodName == ".ctor") {
				TargetClassType ct = type as TargetClassType;
				if (ct == null && type.HasClassType)
					ct = type.ClassType;
				
				foreach (TargetMethodInfo met in ct.Constructors) {
					if (met.Type.ParameterTypes.Length == argtypes.Length)
						candidates.Add (new MemberReference (met, type));
				}
			}
			else {
				foreach (MemberReference mem in ObjectUtil.GetTypeMembers (ctx, type, false, false, true, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)) {
					TargetMethodInfo met = (TargetMethodInfo) mem.Member;
					if (met.Name == methodName && met.Type.ParameterTypes.Length == argtypes.Length && (met.IsStatic && allowStatic || !met.IsStatic && allowInstance))
						candidates.Add (mem);
				}
			}
			
			if (candidates.Count == 1) {
				TargetFunctionType func = (TargetFunctionType) ((TargetMethodInfo) candidates [0].Member).Type;
				string error;
				int matchCount;
				if (IsApplicable (ctx, func, argtypes, out error, out matchCount))
					return candidates [0];

				if (throwIfNotFound)
					throw new EvaluatorException ("Invalid arguments for method `{0}': {1}", methodName, error);
				else
					return null;
			}

			if (candidates.Count == 0) {
				if (throwIfNotFound)
					throw new EvaluatorException ("Method `{0}' not found in type `{1}'.", methodName, type.Name);
				else
					return null;
			}

			return OverloadResolve (ctx, methodName, argtypes, candidates, throwIfNotFound);
		}
示例#34
0
        public int InsertExceptionCatchPoint(Thread target, ThreadGroup group,
						      TargetType exception, bool unhandled)
        {
            Event handle = target.Process.Session.InsertExceptionCatchPoint (
                target, group, exception, unhandled);
            return handle.Index;
        }
 public TargetNullableType(TargetType element_type)
     : base(element_type.Language, TargetObjectKind.Nullable)
 {
     this.element_type = element_type;
 }