public Stream GetData()
        {
            TargetMemoryStream tms = new TargetMemoryStream (thread);

            ITargetMethodInfo method = null;
            foreach (ITargetMethodInfo m in objectSourceType.Methods) {
                if (m.FullName == "GetData(System.Object,System.IO.Stream)") {
                    method = m;
                    break;
                }
            }

            if (method == null)
                throw new Exception ("couldn't find VisualizerObjectSource.GetData implementation in object source");

            ITargetFunctionObject GetData = objectSource.GetMethod (method.Index);

            ITargetObject[] args = new ITargetObject[2];
            args[0] = target;
            args[1] = tms.TargetStream;

            GetData.Invoke (args, false);

            return new MemoryStream (tms.ToArray());
        }
        public byte[] ToArray()
        {
            ITargetMethodInfo method = null;
            foreach (ITargetMethodInfo m in streamType.Methods) {
                if (m.FullName == "ToArray()") {
                    method = m;
                    break;
                }
            }

            if (method == null)
                throw new Exception ("couldn't find MemoryStream.ToArray()");

            ITargetFunctionObject ToArray = debugeeStream.GetMethod (method.Index);
            ITargetObject[] args = new ITargetObject[0];

            ITargetArrayObject target_array = ToArray.Invoke (args, false) as ITargetArrayObject;
            if (target_array == null)
                throw new Exception ("MemoryStream.ToArray returned null");
            ITargetArrayType array_type = (ITargetArrayType)target_array.TypeInfo.Type;

            ITargetFundamentalType fund = array_type.ElementType as ITargetFundamentalType;
            if (fund == null || fund.Type != typeof (System.Byte))
                throw new Exception (String.Format ("Array is not of type byte[] (element type is {0})",
                                    array_type.ElementType));

            byte[] rv = new byte[target_array.UpperBound - target_array.LowerBound];
            for (int i = 0; i < rv.Length; i ++) {
                ITargetObject el = target_array[target_array.LowerBound + i];
                rv[i] = (byte)((ITargetFundamentalObject)el).Object;
            }

            return rv;
        }
Ejemplo n.º 3
0
        public void SetUp()
        {
            CategoryFactory.AddCategoryType(TestCategoryFactory.CategoryName, TestCategoryFactory.CategoryTypes,
                                            TestCategoryFactory.CategoryAttributes);

            _category = CategoryFactory.GetCategory(TestCategoryFactory.CategoryName);
            _targetObject = new TargetObject(_category, _category.CategoryTypes[TestCategoryFactory.BeginnerCategory]);
        }
        private static void GetProbabilities(ITargetObject titanicPassenger, ICategory category, out double survivedProbability, out double notSurvivedProbability)
        {
            IClassifer classifer = new Classifer();
            classifer.Init(category);

            Dictionary<string, double> classification = classifer.GetClassification(titanicPassenger);

            survivedProbability = classification["Edible"];
            notSurvivedProbability = classification["Poisonous"];
        }
Ejemplo n.º 5
0
        public Dictionary<string, double> GetClassification(ITargetObject targetObject)
        {
            if (!String.IsNullOrEmpty(targetObject.CategoryType))
            {
                throw new TargetObjectIsClassifiedBeforeException(
                    "Object not need classification because it was classified before.");
            }

            return this.EvalClassifitaction(targetObject);
        }
Ejemplo n.º 6
0
        private static void GetProbabilities(ITargetObject snowboardExpensiveFreestyleToClassify, ICategory category, out double beginnerProbability, out double mediumProbability, out double advancedProbability)
        {
            IClassifer classifer = new Classifer();
            classifer.Init(category);

            Dictionary<string, double> classification = classifer.GetClassification(snowboardExpensiveFreestyleToClassify);

            beginnerProbability = classification[category.CategoryTypes[TestCategoryFactory.BeginnerCategory]];
            mediumProbability = classification[category.CategoryTypes[TestCategoryFactory.MediumCategory]];
            advancedProbability = classification[category.CategoryTypes[TestCategoryFactory.AdvancedCategory]];
        }
Ejemplo n.º 7
0
        private Dictionary<string, double> EvalClassifitaction(ITargetObject targetObject)
        {
            var classifitaction = new Dictionary<string, double>(this._category.CategoryTypes.Count);

            foreach (string categoryType in this._category.CategoryTypes)
            {
                double probability = this.EvalProbabilityForCategoryType(categoryType, targetObject.ExistsAttributes);
                probability *= this._category.Engine.GetApriori(categoryType);
                classifitaction.Add(categoryType, probability);
            }

            return this.GetSortedDictionaryByValue(classifitaction);
        }
        void CreateDebugeeStream()
        {
            Console.WriteLine ("Creating Debuggee-side memory stream");

            Mono.Debugger.StackFrame frame = thread.CurrentFrame;

            streamType = frame.Language.LookupType (frame, "System.IO.MemoryStream") as ITargetStructType;
            if (streamType == null)
                throw new Exception ("couldn't find type `System.IO.MemoryStream'");

            ITargetMethodInfo method = null;
            foreach (ITargetMethodInfo m in streamType.Constructors) {
                if (m.FullName == ".ctor()") {
                    method = m;
                    break;
                }
            }

            if (method == null)
                throw new Exception ("couldn't find applicable constructor for memory stream");

            ITargetFunctionObject ctor = streamType.GetConstructor (frame, method.Index);
            ITargetObject[] args = new ITargetObject[0];

            debugeeStream = ctor.Type.InvokeStatic (frame, args, false) as ITargetStructObject;
            if (debugeeStream == null)
                throw new Exception ("unable to create instance of memory stream");

            Console.WriteLine ("succeeded in creating debuggee-side memory stream");
        }
Ejemplo n.º 9
0
        static ITargetObject TryCast(EvaluationContext context, ITargetObject source,
					      ITargetClassType target_type)
        {
            if (source.TypeInfo.Type == target_type)
                return source;

            ITargetClassObject sobj = source as ITargetClassObject;
            if (sobj == null)
                return null;

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

            return TryCurrentCast (context, sobj, sobj.Type, target_type);
        }
Ejemplo n.º 10
0
        void AddPlaceholder(ITargetObject obj, TreeIter parent)
        {
            if (obj.TypeInfo.Type.Kind == TargetObjectKind.Array) {
                ITargetArrayObject array = (ITargetArrayObject) obj;
                if (array.LowerBound == array.UpperBound)
                    return;
            }

            store.Append (parent);
            iters.Add (parent, obj);
        }
Ejemplo n.º 11
0
 void AddObject(string name, string icon_name, ITargetObject obj, TreeIter iter)
 {
     store.SetValue (iter, NAME_COL, name);
     store.SetValue (iter, VALUE_COL, GetObjectValueString (obj));
     store.SetValue (iter, TYPE_COL,
             obj == null ? "" : Runtime.Ambience.CurrentAmbience.GetIntrinsicTypeName (obj.TypeInfo.Type.Name));
     Gdk.Pixbuf icon = Runtime.Gui.Resources.GetIcon (icon_name, Gtk.IconSize.Menu);
     if (icon != null)
         store.SetValue (iter, PIXBUF_COL, icon);
     if (obj != null)
         AddPlaceholder (obj, iter);
 }
 public TargetObjectProvider(ITargetObject target, Process thread, string sourceType)
 {
     this.target = target;
     this.thread = thread;
     CreateVisualizerObjectSource (sourceType);
 }
Ejemplo n.º 13
0
        string GetIcon(ITargetObject obj)
        {
            string icon = "";

            if (obj.TypeInfo.Type.TypeHandle is Type)
                icon = Runtime.Gui.Icons.GetIcon ((Type)obj.TypeInfo.Type.TypeHandle);

            return icon;
        }
Ejemplo n.º 14
0
        string GetObjectValueString(ITargetObject obj)
        {
            if (obj == null) {
                return "null";
            }

            switch (obj.TypeInfo.Type.Kind) {
            case TargetObjectKind.Fundamental:
                object contents = ((ITargetFundamentalObject) obj).Object;
                return contents.ToString ();

            case TargetObjectKind.Array:
                ITargetArrayObject array = (ITargetArrayObject) obj;
                if (array.LowerBound == array.UpperBound && array.LowerBound == 0)
                    return "[]";
                else
                    return "";

            case TargetObjectKind.Struct:
            case TargetObjectKind.Class:
                try {
            #if NET_2_0
                    DebuggingService dbgr = (DebuggingService)Runtime.DebuggingService;
                    DebuggerDisplayAttribute dattr = GetDebuggerDisplayAttribute (dbgr, obj);
                    if (dattr != null) {
                        return dbgr.AttributeHandler.EvaluateDebuggerDisplay (obj, dattr.Value);
                    }
                    else {
            #endif
                        // call the object's ToString() method.
                        return ((ITargetStructObject)obj).PrintObject();
            #if NET_2_0
                    }
            #endif
                }
                catch (Exception e) {
                  //Console.WriteLine ("getting object value failed: {0}", e);
                    return "";
                }
            default:
                return "";
            }
        }
        // Create the debuggee-side object that we'll communicate with
        void CreateVisualizerObjectSource(string sourceType)
        {
            Console.WriteLine ("Creating Debuggee-side object (of type {0})", sourceType);

            Mono.Debugger.StackFrame frame = thread.CurrentFrame;

            // shouldn't be hardcoded - it comes from the attribute
            objectSourceType = frame.Language.LookupType (frame, sourceType) as ITargetStructType;
            if (objectSourceType == null)
                throw new Exception ("couldn't find type for object source");

            ITargetMethodInfo method = null;
            foreach (ITargetMethodInfo m in objectSourceType.Constructors) {
                if (m.FullName == ".ctor()") {
                    method = m;
                    break;
                }
            }

            if (method == null)
                throw new Exception ("couldn't find applicable constructor for object source");

            ITargetFunctionObject ctor = objectSourceType.GetConstructor (frame, method.Index);
            ITargetObject[] args = new ITargetObject[0];

            objectSource = ctor.Type.InvokeStatic (frame, args, false) as ITargetStructObject;
            if (objectSource == null)
                throw new Exception ("unable to create instance of object source");

            Console.WriteLine ("succeeded in creating debuggee-side object source");
        }
Ejemplo n.º 16
0
        private void GetProbabilities(ITargetObject snowboardExpensiveFreestyleToClassify, out double beginnerProbability, out double mediumProbability, out double advancedProbability)
        {
            Dictionary<string, double> classification = this._classifer.GetClassification(snowboardExpensiveFreestyleToClassify);

            beginnerProbability = classification[this._category.CategoryTypes[TestCategoryFactory.BeginnerCategory]];
            mediumProbability = classification[this._category.CategoryTypes[TestCategoryFactory.MediumCategory]];
            advancedProbability = classification[this._category.CategoryTypes[TestCategoryFactory.AdvancedCategory]];
        }
Ejemplo n.º 17
0
        void UpdateVariableChildren(IVariable variable, ITargetObject obj, TreePath path, TreeIter iter)
        {
            bool expanded = tree.GetRowExpanded (path);
            TreeIter citer;

            if (!expanded) {

                /* we aren't expanded, just remove all
                 * children and add the object back
                 * (since it might be a different
                 * object now) */

                if (store.IterChildren (out citer, iter))
                    while (store.Remove (ref citer)) ;
                iters.Remove (iter);

                AddPlaceholder (obj, iter);
            }
            else {
                /* in a perfect world, we'd just iterate
                 * over the stuff we're showing and update
                 * it.  for now, just remove all rows and
                 * re-add them. */

                if (store.IterChildren (out citer, iter))
                    while (store.Remove (ref citer)) ;

                iters.Remove (iter);

                AddObject (variable.Name, GetIcon (obj), obj, iter);

                tree.ExpandRow (path, false);
            }
        }
        public string EvaluateDebuggerDisplay(ITargetObject obj, string display)
        {
            StringBuilder sb = new StringBuilder ("");
            DebuggingService dbgr = (DebuggingService)Runtime.DebuggingService;
            EvaluationContext ctx = new EvaluationContext (obj);

            ctx.CurrentProcess = new ProcessHandle (dbgr.MainThread);

            /* break up the string into runs of {...} and
             * normal text.  treat the {...} as C#
             * expressions, and evaluate them */
            int start_idx = 0;

            while (true) {
                int left_idx;
                int right_idx;
                left_idx = display.IndexOf ('{', start_idx);

                if (left_idx == -1) {
                    /* we're done. */
                    sb.Append (display.Substring (start_idx));
                    break;
                }
                if (left_idx != start_idx) {
                    sb.Append (display.Substring (start_idx, left_idx - start_idx));
                }
                right_idx = display.IndexOf ('}', left_idx + 1);
                if (right_idx == -1) {
                    // '{...\0'.  ignore the '{', append the rest, and break out */
                    sb.Append (display.Substring (left_idx + 1));
                    break;
                }

                if (right_idx - left_idx > 1) {
                    /* there's enough space for an
                     * expression.  parse it and see
                     * what we get. */
                    RefParse.Parser parser;
                    AST.Expression ast_expr;
                    Expression dbgr_expr;
                    DebuggerASTVisitor visitor;
                    string snippet;
                    object retval;

                    /* parse the snippet to build up MD's AST */
                    parser = new RefParse.Parser();

                    snippet = display.Substring (left_idx + 1, right_idx - left_idx - 1);
                    ast_expr = parser.ParseExpression (new RefParse.Lexer (new RefParse.StringReader (snippet)));

                    /* use our visitor to convert from MD's AST to types that
                     * facilitate evaluation by the debugger */
                    visitor = new DebuggerASTVisitor ();
                    dbgr_expr = (Expression)ast_expr.AcceptVisitor (visitor, null);

                    /* finally, resolve and evaluate the expression */
                    dbgr_expr = dbgr_expr.Resolve (ctx);
                    retval = dbgr_expr.Evaluate (ctx);

            #region "c&p'ed from debugger/frontend/Style.cs"
                    if (retval is long) {
                        sb.Append (String.Format ("0x{0:x}", (long) retval));
                    }
                    else if (retval is string) {
                        sb.Append ('"' + (string) retval + '"');
                    }
                    else if (retval is ITargetObject) {
                        ITargetObject tobj = (ITargetObject) retval;
                        sb.Append (tobj.Print ());
                    }
                    else {
                        sb.Append (retval.ToString ());
                    }
            #endregion
                }

                start_idx = right_idx + 1;
            }

            return sb.ToString ();
        }
Ejemplo n.º 19
0
        public ITargetObject Invoke(EvaluationContext context, bool debug)
        {
            FrameHandle frame = context.CurrentFrame;

            ITargetStructType stype = type_expr.EvaluateType (context)
                as ITargetStructType;
            if (stype == null)
                throw new EvaluationException (
                    "Type `{0}' is not a struct or class.",
                    type_expr.Name);

            ArrayList candidates = new ArrayList ();
            candidates.AddRange (stype.Constructors);

            ITargetMethodInfo method;
            if (candidates.Count == 0)
                throw new EvaluationException (
                    "Type `{0}' has no public constructor.",
                    type_expr.Name);
            else if (candidates.Count == 1)
                method = (ITargetMethodInfo) candidates [0];
            else
                method = MethodGroupExpression.OverloadResolve (
                    context, frame.Frame.Language, stype, arguments,
                    candidates);

            if (method == null)
                throw new EvaluationException (
                    "Type `{0}' has no constructor which is applicable " +
                    "for your list of arguments.", type_expr.Name);

            ITargetFunctionObject ctor = stype.GetConstructor (
                frame.Frame, method.Index);

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

            try {
                return ctor.Type.InvokeStatic (frame.Frame, args, debug);
            } catch (Mono.Debugger.TargetInvocationException ex) {
                throw new EvaluationException (
                    "Invocation of type `{0}'s constructor raised an " +
                    "exception: {1}", type_expr.Name, ex.Message);
            }
        }
Ejemplo n.º 20
0
        DebuggerVisualizerAttribute[] GetDebuggerVisualizerAttributes(DebuggingService dbgr, ITargetObject obj)
        {
            if (obj.TypeInfo.Type.TypeHandle != null && obj.TypeInfo.Type.TypeHandle is Type)
              return dbgr.AttributeHandler.GetDebuggerVisualizerAttributes ((Type)obj.TypeInfo.Type.TypeHandle);

            return null;
        }
Ejemplo n.º 21
0
        DebuggerTypeProxyAttribute GetDebuggerTypeProxyAttribute(DebuggingService dbgr, ITargetObject obj)
        {
            if (obj.TypeInfo.Type.TypeHandle != null && obj.TypeInfo.Type.TypeHandle is Type)
                return dbgr.AttributeHandler.GetDebuggerTypeProxyAttribute ((Type)obj.TypeInfo.Type.TypeHandle);

            return null;
        }
Ejemplo n.º 22
0
        bool InsertProxyChildren(DebuggingService dbgr, DebuggerTypeProxyAttribute pattr, TreeIter parent, ITargetStructObject sobj)
        {
            Mono.Debugger.StackFrame frame = dbgr.MainThread.CurrentFrame;
             		ITargetStructType proxy_type = frame.Language.LookupType (frame, pattr.ProxyTypeName) as ITargetStructType;
            if (proxy_type == null)
                proxy_type = frame.Language.LookupType (frame,
                                    sobj.Type.Name + "+" + pattr.ProxyTypeName) as ITargetStructType;
            if (proxy_type != null) {
                string name = String.Format (".ctor({0})", sobj.Type.Name);
                ITargetMethodInfo method = null;

                foreach (ITargetMethodInfo m in proxy_type.Constructors) {
                    if (m.FullName == name)
                        method = m;
                }

                if (method != null) {
                    ITargetFunctionObject ctor = proxy_type.GetConstructor (frame, method.Index);
                    ITargetObject[] args = new ITargetObject[1];
                    args[0] = sobj;

                    ITargetStructObject proxy_obj = ctor.Type.InvokeStatic (frame, args, false) as ITargetStructObject;

                    if (proxy_obj != null) {
                        foreach (ITargetPropertyInfo prop in proxy_obj.Type.Properties) {
                            InsertStructMember (parent, proxy_obj, prop, false);
                        }

                        TreeIter iter = store.Append (parent);
                        store.SetValue (iter, NAME_COL, "Raw View");
                        store.SetValue (iter, RAW_VIEW_COL, true);

                        Gdk.Pixbuf icon = Runtime.Gui.Resources.GetIcon (Stock.Class, Gtk.IconSize.Menu);
                        if (icon != null)
                            store.SetValue (iter, PIXBUF_COL, icon);

                        iters.Remove (iter);
                        AddPlaceholder (sobj, iter);

                        return true;
                    }
                }
            }

            return false;
        }
 public EvaluationContext(ITargetObject this_obj)
 {
     this.this_obj = this_obj;
 }
Ejemplo n.º 24
0
        public void Assign(EvaluationContext context, ITargetObject 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 EvaluationException (
                    "Expression `{0}' is not an lvalue", Name);
        }
Ejemplo n.º 25
0
        public void TeachCategory(ITargetObject targetObject)
        {
            if (String.IsNullOrEmpty(targetObject.CategoryType))
            {
                throw new CannotTeachByTargetObjectToClassifyException("Object to classify cannot be used by teaching method.");
            }

            ICategoryType categoryType = this._categoryTypeAttributes[targetObject.CategoryType];
            this._categoryTypeEvidence[targetObject.CategoryType] += 1;

            foreach (string attribute in targetObject.ExistsAttributes.Keys)
            {
                categoryType.AddAttribute(attribute);
            }

            this.SetCanBeClassifyToFalse();
        }
Ejemplo n.º 26
0
 protected virtual bool DoAssign(EvaluationContext context, ITargetObject obj)
 {
     return false;
 }
Ejemplo n.º 27
0
        public ITargetObject Invoke(EvaluationContext context, bool debug)
        {
            Expression[] args = new Expression [arguments.Length];
            for (int i = 0; i < arguments.Length; i++) {
                args [i] = arguments [i].Resolve (context);
                if (args [i] == null)
                    return null;
            }

            ITargetFunctionObject func = mg.EvaluateMethod (
                context, context.CurrentFrame.Frame, args);

            ITargetObject[] objs = new ITargetObject [args.Length];
            for (int i = 0; i < args.Length; i++)
                objs [i] = args [i].EvaluateVariable (context);

            try {
                ITargetObject retval = func.Invoke (objs, debug);
                if (!debug && !func.Type.HasReturnValue)
                    throw new EvaluationException ("Method `{0}' doesn't return a value.", Name);

                return retval;
            } catch (Mono.Debugger.TargetInvocationException ex) {
                throw new EvaluationException ("Invocation of `{0}' raised an exception: {1}", Name, ex.Message);
            }
        }
Ejemplo n.º 28
0
    public bool PlaceItem(ITargetObject item)
    {
        TargetGameObject.SetActive(item.Id.Equals(ItemId));

        return(item.Id.Equals(ItemId));
    }