Example #1
0
        /// <summary>
        /// Gets the list of DynamicStackFrames for the current exception.
        /// </summary>
        internal static DynamicStackFrame[] GetDynamicStackFrames(Exception e)
        {
            List<DynamicStackFrame> frames = e.GetFrameList();

            if (frames == null)
                return new DynamicStackFrame[0];

            frames = new List<DynamicStackFrame>(frames);
            List<DynamicStackFrame> res = new List<DynamicStackFrame>();

            // merge .NET frames w/ any dynamic frames that we have
            try
            {
                StackTrace outermostTrace = new StackTrace(e);
                IList<StackTrace> otherTraces = ExceptionHelpers.GetExceptionStackTraces(e) ?? new List<StackTrace>();
                List<StackFrame> clrFrames = new List<StackFrame>();

                foreach (StackTrace trace in otherTraces)
                {
                    clrFrames.AddRange(trace.GetFrames() ?? new StackFrame[0]); // rare, sometimes GetFrames returns null
                }
                clrFrames.AddRange(outermostTrace.GetFrames() ?? new StackFrame[0]);    // rare, sometimes GetFrames returns null

                int lastFound = 0;
                foreach (StackFrame clrFrame in InterpretedFrame.GroupStackFrames(clrFrames))
                {
                    MethodBase method = clrFrame.GetMethod();

                    for (int j = lastFound; j < frames.Count; j++)
                    {
                        MethodBase other = frames[j].GetMethod();
                        // method info's don't always compare equal, check based
                        // upon name/module/declaring type which will always be a correct
                        // check for dynamic methodSetups.
                        if (MethodsMatch(method, other))
                        {
                            res.Add(frames[j]);
                            frames.RemoveAt(j);
                            lastFound = j;
                            break;
                        }
                    }
                }
            }
            catch (MemberAccessException)
            {
                // can't access new StackTrace(e) due to security
            }

            // add any remaining frames we couldn't find
            res.AddRange(frames);
            return res.ToArray();
        }
Example #2
0
        public static void UpdateStackTrace(Exception e, CodeContext context, FunctionCode funcCode, int line)
        {
            if (line != -1)
            {
                Debug.Assert(line != SourceLocation.None.Line);

                List<DynamicStackFrame> totemFrames = e.GetFrameList();

                if (totemFrames == null)
                {
                    e.SetFrameList(totemFrames = new List<DynamicStackFrame>());
                }

                var frame = new TotemDynamicStackFrame(context, funcCode, line);
                funcCode.LightThrowCompile(context);
                totemFrames.Add(frame);
            }
        }