Example #1
0
        public override CallStack FindStack(Method method)
        {
            CallStack getStack = null;
            CallStack setStack = null;

            if (this.Get != null)
            {
                getStack = this.Get.FindStack(method);
            }

            if (this.Set != null)
            {
                setStack = this.Set.FindStack(method);
            }
            else
            {
                return getStack;
            }

            if ((getStack == null) || (setStack.Count < getStack.Count))
            {
                return setStack;
            }
            else
            {
                return getStack;
            }
        }
 public MethodItem(Method method, ThrownException exception)
 {
     this.Method = method;
     this.Exception = exception;
 }
 public MethodEventArgs(Method method, Method callingMethod, ThrownException exception)
 {
     this.Method = method;
     this.CallingMethod = callingMethod;
     this.Exception = exception;
 }
        /// <summary>Updates the list.</summary>
        protected void UpdateList()
        {
            Job worker = Job.ExceptionTree.NewJob(this, (cancelToken) =>
            {
                try
                {
                    this.InvokeIfRequired(() =>
                    {
                        try
                        {
                            this.SetWaiting(true);
                            this.BeginUpdate();
                            this.Items.Clear();
                        }
                        finally
                        {
                            this.EndUpdate();
                        }
                    });

                    List<ListViewItem> items = new List<ListViewItem>();

                    if (this.MethodContainer is Class)
                    {
                        HashSet<string> got = new HashSet<string>();

                        foreach (Method m in this.MethodContainer.CalledMethods)
                        {
                            foreach (ThrownException ex in m.UnhandledExceptions)
                            {
                                if (this.Exceptions.Contains(ex))
                                {
                                    string id = ex.Method.GetId() + ex.Exception.FullName;
                                    if (!got.Contains(id))
                                    {
                                        got.Add(id);
                                        //ListViewItem item = MakeItem(ex, ex.Method).Item;
                                        ListViewItem item = MakeItem(ex, m).Item;
                                        items.Add(item);
                                    }
                                }
                            }
                        }
                    }
                    else if (this.GroupByType)
                    {
                        // group the exceptions by type
                        ThrownExceptionDictionary dict = new ThrownExceptionDictionary(this.Exceptions);

                        foreach (IEnumerable<ThrownException> list in dict.GetLists())
                        {
                            Type type = list.First().Exception;
                            ListViewGroup lvg = this.Groups.Add(type.FullName, type.Name);
                            list.ToList().ForEach(item => items.Add(MakeItem(item, item.Method, lvg).Item));
                        }
                    }
                    else
                    {
                        IEnumerable<Method> methods;

                        if (this.MethodContainer is Method)
                        {

                        }
                        else
                        {
                            methods = new Method[] { this.MethodContainer as Method }.Concat(this.MethodContainer.CalledMethods);
                        }

                        foreach (ThrownException ex in this.Exceptions)
                        {
                            Method m = null;
                            if (ex.Method == this.MethodContainer)
                            {
                                m = this.MethodContainer as Method;
                            }
                            else
                            {
                                m = this.MethodContainer.CalledMethods.FirstOrDefault(md => md.UnhandledExceptions.Contains(ex));
                                if (m == null)
                                {
                                    m = this.MethodContainer as Method;
                                }
                            }
                            ListViewItem item = MakeItem(ex, m).Item;
                            items.Add(item);
                        }
                    }

                    if (cancelToken.IsCancellationRequested)
                    {
                        return;
                    }

                    this.InvokeIfRequired(() =>
                    {
                        try
                        {
                            this.BeginUpdate();
                            this.Items.AddRange(items.ToArray());
                        }
                        finally
                        {
                            this.EndUpdate();
                        }
                    });
                }
                finally
                {
                    this.SetWaiting(false);
                }
            });

            worker.Execute();
        }
        /// <summary>
        /// Makes a new item.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <param name="method">The method.</param>
        /// <param name="group">The group.</param>
        /// <returns></returns>
        protected ItemInfo MakeItem(ThrownException exception, Method method = null, ListViewGroup group = null)
        {
            bool isMethod = (method != null);
            bool isProperty = isMethod && method.MethodBase.IsProperty();
            bool isThrow = !isMethod && (exception != null);

            if (!isMethod)
            {
                method = exception.Method;
            }

            ListViewItem item;
            PropertyInfo pi = null;
            if (isProperty)
            {
                bool getter = method.MethodBase.Name.StartsWith("get_");
                pi = method.MethodBase.GetMethodProperty();
                item = new ListViewItem(string.Format(CultureInfo.InvariantCulture, "{0} ({1})", pi.Name, getter ? "get" : "set"));
            }
            else
            {
                item = new ListViewItem(method.ToString());
            }

            if (isProperty)
            {
                item.ImageKey = NodeInfo.ImageKeyFromObject(pi);
            }
            else if (isMethod)
            {
                // use the method for the icon
                item.ImageKey = NodeInfo.ImageKeyFromObject(method.MethodBase);
            }
            else
            {
                // use the exception for the icon
                item.ImageKey = NodeInfo.ImageKeyFromObject(exception.Exception);
            }

            ItemInfo info;
            MethodItem me = new MethodItem(method, exception);

            if (exception == null)
            {
                info = new ItemInfo(item, me, NodeType.Method);
                item.SubItems.Add("");
            }
            else
            {
                info = new ItemInfo(item, me, NodeType.Method);
                info.Expandable = !isThrow;
                item.SubItems.Add(exception.Exception.Name);

            }

            item.Tag = info;

            item.SubItems.Add(method.MethodBase.DeclaringType.Name);
            item.SubItems.Add(method.MethodBase.DeclaringType.Module.Name);

            item.IndentCount = 1;

            if (group != null)
            {
                item.Group = group;
            }

            return info;
        }
Example #6
0
        void ShowMethodCall(Method caller, Method called)
        {
            Job.SourceView.NewJob(this.SourceViewer, (cancelToken) =>
            {
                if ((caller == null) || (caller == called))
                {
                    this.SourceViewer.SetSource(called.MethodBase, cancelToken);
                }
                else
                {
                    //this.SourceViewer.SetSource(caller.MethodBase, called.MethodBase, caller.Calls[called]);
                    List<SourceViewer.HighlightItem> items = new List<SourceViewer.HighlightItem>();

                    foreach (int offset in caller.Calls[called])
                    {
                        items.Add(new SourceViewer.HighlightItem(called.MethodBase)
                        {
                            Display = Decompiler.SourceViewer.HighlightDisplay.Highlight,
                            Offset = offset,
                            Tooltip = called.ToString()
                        });
                    }

                    this.SourceViewer.SetSource(caller.MethodBase, items, cancelToken);
                }
            }).Execute();
        }
Example #7
0
        void ShowExceptionThrow(Method caller, ThrownException te)
        {
            if (caller == null)
            {
                caller = te.Method;
            }

            Job.SourceView.NewJob(this.SourceViewer, (cancelToken) =>
            {
                if (Environment.TickCount == 123)
                {
                    throw new TimeZoneNotFoundException();
                }
                List<SourceViewer.HighlightItem> items = new List<SourceViewer.HighlightItem>();

                foreach (ThrownException ex in caller.UnhandledExceptions)
                {
                    if (ex.Exception == te.Exception)
                    {
                        SourceViewer.HighlightItem item = new SourceViewer.HighlightItem(te.Exception)
                        {
                            Display = Decompiler.SourceViewer.HighlightDisplay.Highlight,
                            Offset = ex.Offset
                        };

                        if (ex.IsXmlDoc)
                        {
                            item.HighlightType |= Decompiler.SourceViewer.HighlightType.DocumentedException;
                        }

                        items.Add(item);
                    }
                }

                this.SourceViewer.SetSource(caller.MethodBase, items, cancelToken);
            }).Execute();
        }
Example #8
0
        /// <summary>
        /// Finds the shortest callstack to the provided method.
        /// </summary>
        /// <param name="method">The method to search for.</param>
        /// <returns>
        /// The shortest call-stack from this method to the specified method.
        /// </returns>
        public override CallStack FindStack(Method method)
        {
            CallStack shortest = null;
            foreach (Method m in this.CalledMethods)
            {
                CallStack cs = m.FindStack(method);
                if ((cs != null) && (cs.Count > 0) && ((shortest == null) || (cs.Count < shortest.Count)))
                {
                    shortest = cs;
                }
            }

            return shortest;
        }
Example #9
0
 /// <summary>Initializes a new instance of the <see cref="MethodCall"/> class.</summary>
 /// <param name="offset">The offset.</param>
 /// <param name="method">The method.</param>
 public MethodCall(int offset, Method method)
 {
     this.Method = method;
     this.Offset = offset;
 }
Example #10
0
        private Dictionary<string, NodeInfo> GetProperties(TreeNode node, Method method)
        {
            Dictionary<string, NodeInfo> properties = new Dictionary<string, NodeInfo>();
            foreach (Method m in method.CalledMethods)
            {
                MethodBase mb = m.MethodBase;
                if (mb.Name.Contains("get_UserInt"))
                {
                }

                // see if it's a getter/setter
                if (mb.IsSpecialName && mb.IsHideBySig)
                {
                    bool getter = mb.Name.StartsWith("get_");
                    if (getter || mb.Name.StartsWith("set_"))
                    {
                        NodeInfo ni = null;
                        string name = mb.Name.Substring(4);
                        PropertyInfo pi = null;
                        bool alreadyFound = properties.ContainsKey(name);
                        if (!alreadyFound)
                        {
                            try
                            {
                                pi = mb.DeclaringType.GetProperty(name, Binding);
                            }
                            catch (AmbiguousMatchException)
                            {
                                // be a bit more specific with the search
                                Type returnType = typeof(void);
                                if (mb is MethodInfo)
                                {
                                    returnType = ((MethodInfo)mb).ReturnType;
                                }

                                IEnumerable<Type> paras = from p in mb.GetParameters() select p.ParameterType;
                                if (!getter)
                                {
                                    returnType = paras.Last();
                                    paras = paras.Take(paras.Count() - 1);
                                }

                                pi = mb.DeclaringType.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, null, returnType, paras.ToArray(), null);
                            }

                            if (pi == null)
                            {
                                continue;
                            }

                            ni = this.NewNode(new Property(pi), NodeType.Property).GetInfo();
                            ni.Node.Nodes.Clear();
                            properties.Add(name, ni);
                        }
                        else
                        {
                            ni = properties[name];
                        }

                        if (m.UnhandledExceptions.Count > 0)
                        {
                            ni.Node.Nodes.Add(this.NewNode(getter ? "get" : "set", m, NodeType.Method));
                            if (!alreadyFound)
                            {
                                node.Nodes.Add(ni.Node);
                            }
                        }
                    }
                }
            }
            return properties;
        }
Example #11
0
 private Dictionary<string, NodeInfo> GetEvents(TreeNode node, Method method)
 {
     Dictionary<string, NodeInfo> events = new Dictionary<string, NodeInfo>();
     foreach (Method m in method.CalledMethods)
     {
     }
     return events;
 }
Example #12
0
        /// <summary>Finds the stack.</summary>
        /// <param name="method">The method.</param>
        /// <param name="stack">The stack.</param>
        /// <param name="shortest">The shortest.</param>
        /// <param name="visited">The visited.</param>
        /// <returns></returns>
        private int FindStack(Method method, CallStack stack, CallStack shortest, HashSet<Method> visited)
        {
            stack.Push(this);

            try
            {
                visited.Add(this);

                if ((shortest.Count > 0) && (stack.Count >= shortest.Count))
                {
                    // the shortest stack found is less than the current one - don't search any further
                    return -1;
                }

                if (this == method)
                {
                    // copy the current stack
                    shortest.Clear();
                    foreach (Method m in stack)
                    {
                        shortest.Push(m);
                    }
                    return 0;
                }

                // go through the unhandled exceptions for each called method, and see if the method that the exception
                // matches the one being found.
                int best = -1;
                foreach (Method m in this.CalledMethods)
                {
                    if (visited.Contains(m))
                    {
                        continue;
                    }

                    // see if this method has an uncaught exception that was thrown in the target method
                    var xx = m.UnhandledExceptions.FirstOrDefault(ex => ex.Method == method);
                    var yy = m.UnhandledExceptions.Where(ex => ex.Method == method);

                    bool found = (m == method) ||
                        m.UnhandledExceptions.FirstOrDefault(ex => ex.Method == method) != null;

                    if (found)
                    {
                        int depth = m.FindStack(method, stack, shortest, visited);

                        if (depth == 0)
                        {
                            // it's this one, no need to search the rest
                            return depth + 1;
                        }
                        else if ((depth < best) || (best == -1))
                        {
                            best = depth;
                        }
                    }
                }
                return best;
            }
            finally
            {
                stack.Pop();
            }
        }
Example #13
0
        /// <summary>Finds the shortest callstack to the provided method.</summary>
        /// <param name="method">The method to search for.</param>
        /// <returns>The shortest call-stack from this method to the specified method.</returns>
        public override CallStack FindStack(Method method)
        {
            if (method == null)
            {
                return null;
            }

            HashSet<Method> visited = new HashSet<Method>();
            CallStack shortest = new CallStack();
            this.FindStack(method, new CallStack(), shortest, visited);
            visited.Clear();

            return shortest;
        }
 public CallStack GetCallstack(Method method)
 {
     return this.Method.FindStack(method);
 }
Example #15
0
        public void ReadProperty(ExceptionFinder finder, CancellationToken cancelToken)
        {
            Method[] methods = new Method[] {
                this.Get,
                this.Set
            };

            foreach (Method m in methods)
            {
                if (m != null)
                {
                    if (!m.Complete && (cancelToken != null))
                    {
                        ExceptionFinder.Instance.ReadMethod(m, cancelToken);
                    }

                    this.CalledMethods.UnionWith(m.CalledMethods);
                    this.UnhandledExceptions.UnionWith(m.UnhandledExceptions);
                    this.DocumentedThrownExceptions.AddRange(m.DocumentedThrownExceptions);
                }
            }

            this._complete = ((this.Get == null) || this.Get.Complete)
                          && ((this.Set == null) || this.Set.Complete);
        }
 /// <summary>Finds the shortest callstack to the provided method.</summary>
 /// <param name="method">The method to search for.</param>
 /// <returns>The shortest call-stack from this method to the specified method.</returns>
 public abstract CallStack FindStack(Method method);