GetParentObject() abstract private method

abstract private GetParentObject ( TargetMemoryAccess target ) : TargetClassObject
target TargetMemoryAccess
return TargetClassObject
Example #1
0
        public static EvaluationResult MonoObjectToString(Thread thread, TargetStructObject obj,
								   EvaluationFlags flags, int timeout,
								   out string result)
        {
            result = null;

            if (!obj.Type.Language.IsManaged)
                return EvaluationResult.MethodNotFound;

            again:
            TargetStructType ctype = obj.Type;
            if ((ctype.Name == "System.Object") || (ctype.Name == "System.ValueType"))
                return EvaluationResult.MethodNotFound;

            TargetClass klass = ctype.GetClass (thread);
            if (klass == null)
                return EvaluationResult.NotInitialized;

            TargetMethodInfo[] methods = klass.GetMethods (thread);
            if (methods == null)
                return EvaluationResult.MethodNotFound;

            foreach (TargetMethodInfo minfo in methods) {
                if (minfo.Name != "ToString")
                    continue;

                TargetFunctionType ftype = minfo.Type;
                if (ftype.ParameterTypes.Length != 0)
                    continue;
                if (ftype.ReturnType != ftype.Language.StringType)
                    continue;

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

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

                    rti = thread.RuntimeInvoke (
                        ftype, obj, new TargetObject [0], rti_flags);

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

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

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

                    if (rti.ExceptionMessage != null) {
                        result = rti.ExceptionMessage;
                        return EvaluationResult.Exception;
                    } else if (rti.ReturnObject == null) {
                        rti.Abort ();
                        return EvaluationResult.UnknownError;
                    }
                } catch (TargetException ex) {
                    result = ex.ToString ();
                    return EvaluationResult.UnknownError;
                }

                TargetObject retval = (TargetObject) rti.ReturnObject;
                result = (string) ((TargetFundamentalObject) retval).GetObject (thread);
                return EvaluationResult.Ok;
            }

            if (obj.Type.HasParent) {
                obj = obj.GetParentObject (thread) as TargetClassObject;
                if (obj != null)
                    goto again;
            }

            return EvaluationResult.MethodNotFound;
        }
Example #2
0
        public static MemberExpression FindMember(Thread target, TargetStructType stype,
							   TargetStructObject instance, string name,
							   bool search_static, bool search_instance)
        {
            again:
            TargetClass klass = stype.GetClass (target);
            if (klass != null) {
                TargetMemberInfo member = klass.FindMember (
                    target, name, search_static, search_instance);
                if (member != null)
                    return new StructAccessExpression (stype, instance, member);

                ArrayList methods = new ArrayList ();
                bool is_instance = false;
                bool is_static = false;

                TargetMethodInfo[] klass_methods = klass.GetMethods (target);
                if (klass_methods != null) {
                    foreach (TargetMethodInfo method in klass_methods) {
                        if (method.IsStatic && !search_static)
                            continue;
                        if (!method.IsStatic && !search_instance)
                            continue;
                        if (method.Name != name)
                            continue;

                        methods.Add (method.Type);
                        if (method.IsStatic)
                            is_static = true;
                        else
                            is_instance = true;
                    }
                }

                if (methods.Count > 0) {
                    TargetFunctionType[] funcs = new TargetFunctionType [methods.Count];
                    methods.CopyTo (funcs, 0);
                    return new MethodGroupExpression (
                        stype, instance, name, funcs, is_instance, is_static);
                }
            }

            TargetClassType ctype = stype as TargetClassType;
            if (ctype != null) {
                TargetMemberInfo member = ctype.FindMember (
                    name, search_static, search_instance);

                if (member != null)
                    return new StructAccessExpression (ctype, instance, member);

                ArrayList methods = new ArrayList ();
                bool is_instance = false;
                bool is_static = false;

                if (name == ".ctor") {
                    foreach (TargetMethodInfo method in ctype.Constructors) {
                        if (method.IsStatic)
                            continue;
                        methods.Add (method.Type);
                        is_instance = true;
                    }
                } else if (name == ".cctor") {
                    foreach (TargetMethodInfo method in ctype.Constructors) {
                        if (!method.IsStatic)
                            continue;
                        methods.Add (method.Type);
                        is_static = true;
                    }
                } else {
                    foreach (TargetMethodInfo method in ctype.Methods) {
                        if (method.IsStatic && !search_static)
                            continue;
                        if (!method.IsStatic && !search_instance)
                            continue;
                        if (method.Name != name)
                            continue;

                        methods.Add (method.Type);
                        if (method.IsStatic)
                            is_static = true;
                        else
                            is_instance = true;
                    }
                }

                if (methods.Count > 0) {
                    TargetFunctionType[] funcs = new TargetFunctionType [methods.Count];
                    methods.CopyTo (funcs, 0);
                    return new MethodGroupExpression (
                        ctype, instance, name, funcs, is_instance, is_static);
                }
            }

            if (stype.HasParent) {
                stype = stype.GetParentType (target);
                if (instance != null) {
                    instance = instance.GetParentObject (target);
                    if (instance == null)
                        return null;
                }
                goto again;
            }

            return null;
        }
		static TargetStructObject TryParentCast (MdbEvaluationContext ctx, TargetStructObject source, TargetStructType source_type, TargetStructType target_type)
		{
			if (source_type == target_type)
				return source;

			if (!source_type.HasParent)
				return null;

			TargetStructType parent_type = source_type.GetParentType (ctx.Thread);
			source = TryParentCast (ctx, source, parent_type, target_type);
			if (source == null)
				return null;

			return source.GetParentObject (ctx.Thread) as TargetClassObject;
		}