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");
        }
        public MethodGroupExpression(ITargetStructType stype, string name,
					      ITargetStructObject instance,
					      ILanguage language, ArrayList methods)
        {
            this.stype = stype;
            this.instance = instance;
            this.language = language;
            this.name = name;
            this.methods = methods;
            resolved = true;
        }
        // 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");
        }
 protected ITargetObject GetMember(ITargetStructObject sobj, ITargetMemberInfo member)
 {
     if (member is ITargetPropertyInfo)
         return GetProperty (sobj, (ITargetPropertyInfo) member);
     else if (member is ITargetEventInfo)
         return GetEvent (sobj, (ITargetEventInfo) member);
     else
         return GetField (sobj, (ITargetFieldInfo) member);
 }
 protected ITargetObject GetProperty(ITargetStructObject sobj, ITargetPropertyInfo property)
 {
     try {
         return sobj.GetProperty (property.Index);
     } catch (Mono.Debugger.TargetInvocationException ex) {
         throw new EvaluationException ("Can't get property {0}: {1}", Name, ex.Message);
     }
 }
 protected ITargetObject GetEvent(ITargetStructObject sobj, ITargetEventInfo ev)
 {
     try {
         return sobj.GetEvent (ev.Index);
     } catch (Mono.Debugger.TargetInvocationException ex) {
         throw new EvaluationException ("Can't get event {0}: {1}", Name, ex.Message);
     }
 }
 protected ITargetObject GetField(ITargetStructObject sobj, ITargetFieldInfo field)
 {
     try {
         return sobj.GetField (field.Index);
     } catch (Mono.Debugger.TargetInvocationException ex) {
         throw new EvaluationException ("Can't get field {0}: {1}", Name, ex.Message);
     }
 }
        public static Expression FindMember(ITargetStructType stype, StackFrame frame,
						     ITargetStructObject instance, bool allow_instance,
						     string name)
        {
            ITargetMemberInfo member = FindMember (stype, (instance == null) && !allow_instance, name);
            if (member != null) {
                if (instance != null)
                    return new StructAccessExpression (frame, instance, name);
                else
                    return new StructAccessExpression (frame, stype, name);
            }

            ArrayList methods = new ArrayList ();

            again:
            if (name == ".ctor") {
                foreach (ITargetMethodInfo method in stype.Constructors) {
                    methods.Add (method);
                }
            }
            else if (name == ".cctor") {
                foreach (ITargetMethodInfo method in stype.StaticConstructors) {
                    methods.Add (method);
                }
            }
            else {
                if ((instance != null) || allow_instance) {
                    foreach (ITargetMethodInfo method in stype.Methods) {
                        if (method.Name != name)
                            continue;

                        methods.Add (method);
                    }
                }

                foreach (ITargetMethodInfo method in stype.StaticMethods) {
                    if (method.Name != name)
                        continue;

                    methods.Add (method);
                }
            }

            if (methods.Count > 0)
                return new MethodGroupExpression (
                    stype, name, instance, frame.Language, methods);

            ITargetClassType ctype = stype as ITargetClassType;
            if ((ctype != null) && ctype.HasParent) {
                stype = ctype.ParentType;
                goto again;
            }

            return null;
        }
        protected StructAccessExpression(StackFrame frame,
						  ITargetStructObject instance,
						  string identifier)
        {
            this.Frame = frame;
            this.Type = instance.Type;
            this.Instance = instance;
            this.Identifier = identifier;
            this.IsStatic = false;
            resolved = true;
        }
        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;
        }
        bool InsertStructMember(TreeIter parent, ITargetStructObject sobj, ITargetMemberInfo member, bool is_field)
        {
            bool inserted = false;

            string icon_name = GetIcon (member);

            #if NET_2_0
            DebuggerBrowsableAttribute battr = GetDebuggerBrowsableAttribute (member);
            if (battr != null) {
                TreeIter iter;

                switch (battr.State) {
                case DebuggerBrowsableState.Never:
                    // don't display it at all
                    continue;
                case DebuggerBrowsableState.Collapsed:
                    // the default behavior for the debugger (c&p from the battr == null branch at the bottom of this function)
                    iter = store.Append (parent);
                    AddObject (member.Name, icon_name, is_field ? sobj.GetField (member.Index) : sobj.GetProperty (member.Index),
                           iter);
                    inserted = true;
                    break;
                case DebuggerBrowsableState.Expanded:
                    // add it as in the Collapsed case...
                    iter = store.Append (parent);
                    AddObject (member.Name, icon_name, is_field ? sobj.GetField (member.Index) : sobj.GetProperty (member.Index),
                           iter);
                    inserted = true;
                    // then expand the row
                    tree.ExpandRow (store.GetPath (iter), false);
                    break;
                case DebuggerBrowsableState.RootHidden:
                    ITargetObject member_obj = is_field ? sobj.GetField (member.Index) : sobj.GetProperty (member.Index);

                    if (member_obj != null) {
                        switch (member_obj.TypeInfo.Type.Kind) {
                        case TargetObjectKind.Array:
                            iter = store.Append (parent);
                            // handle arrays normally, should check how vs2005 does this.
                            AddObject (member.Name, icon_name, member_obj, iter);
                            inserted = true;
                            break;
                        case TargetObjectKind.Class:
                            try {
                                inserted = InsertClassChildren (parent, (ITargetClassObject)member_obj, false);
                            }
                            catch {
                                // what about this case?  where the member is possibly
                                // uninitialized, do we try to add it later?
                            }
                            break;
                        case TargetObjectKind.Struct:
                            try {
                                inserted = InsertStructChildren (parent, (ITargetStructObject)member_obj, false);
                            }
                            catch {
                                // what about this case?  where the member is possibly
                                // uninitialized, do we try to add it later?
                            }
                            break;
                        default:
                            // nothing
                            break;
                        }
                    }
                    break;
                }
            }
            else {
            #endif
                TreeIter iter = store.Append (parent);
                AddObject (member.Name, icon_name, is_field ? sobj.GetField (member.Index) : sobj.GetProperty (member.Index),
                       iter);
                inserted = true;
            #if NET_2_0
            }
            #endif

            return inserted;
        }
        bool InsertStructChildren(TreeIter parent, ITargetStructObject sobj, bool raw_view)
        {
            bool inserted = false;

            #if NET_2_0
            if (!raw_view) {
                DebuggingService dbgr = (DebuggingService)Runtime.DebuggingService;
                DebuggerTypeProxyAttribute pattr = GetDebuggerTypeProxyAttribute (dbgr, sobj);

                if (pattr != null) {
                    if (InsertProxyChildren (dbgr, pattr, parent, sobj))
                        inserted = true;
                }

                return inserted;
            }
            #endif

            foreach (ITargetFieldInfo field in sobj.Type.Fields) {
                if (InsertStructMember (parent, sobj, field, true))
                    inserted = true;
            }

            foreach (ITargetPropertyInfo prop in sobj.Type.Properties) {
                if (InsertStructMember (parent, sobj, prop, false))
                    inserted = true;
            }

            return inserted;
        }