Esempio n. 1
0
        public static StackFrame Create(System.Diagnostics.StackFrame frame)
        {
            if (frame == null)
            {
                return(null);
            }

            string      fileName      = null;
            bool        isTaskAwaiter = false;
            ITypeMember member        = null;

            try {
                fileName = frame.GetFileName();
            } catch (SecurityException) {
                // CAS check failure
            }

            var method = frame.GetMethod();

            if (method != null)
            {
                isTaskAwaiter = method.DeclaringType.IsTaskAwaiter() ||
                                method.DeclaringType.DeclaringType.IsTaskAwaiter();

                var property = GetPropertyForMethodAccessor(method);
                if (property != null)
                {
                    member = Property.Create(property);
                }
                else
                {
                    member = Method.Create(method);
                }
            }

            return(new StackFrame(
                       fileName,
                       frame.GetFileLineNumber(),
                       frame.GetFileColumnNumber(),
                       frame.GetILOffset(),
                       frame.GetNativeOffset(),
                       frame.GetMethodAddress(),
                       frame.GetMethodIndex(),
                       isTaskAwaiter,
                       ParseInternalMethodName(frame.GetInternalMethodName()),
                       member));
        }
        bool AddFrames(StringBuilder sb)
        {
            bool any_frame = false;

            for (int i = 0; i < FrameCount; i++)
            {
                StackFrame frame = GetFrame(i);

                if (frame.GetMethod() == null)
                {
                    if (any_frame)
                    {
                        sb.Append(Environment.NewLine);
                    }
                    sb.Append(prefix);

                    string internal_name = frame.GetInternalMethodName();
                    if (internal_name != null)
                    {
                        sb.Append(internal_name);
                    }
                    else
                    {
                        sb.AppendFormat("<0x{0:x5} + 0x{1:x5}> <unknown method>", frame.GetMethodAddress(), frame.GetNativeOffset());
                    }
                }
                else
                {
                    GetFullNameForStackTrace(sb, frame.GetMethod(), any_frame, out var skipped);
                    if (skipped)
                    {
                        continue;
                    }

                    if (frame.GetILOffset() == -1)
                    {
                        sb.AppendFormat(" <0x{0:x5} + 0x{1:x5}>", frame.GetMethodAddress(), frame.GetNativeOffset());
                        if (frame.GetMethodIndex() != 0xffffff)
                        {
                            sb.AppendFormat(" {0}", frame.GetMethodIndex());
                        }
                    }
                    else
                    {
                        sb.AppendFormat(" [0x{0:x5}]", frame.GetILOffset());
                    }

                    var filename = frame.GetSecureFileName();
                    if (filename[0] == '<')
                    {
                        var mvid  = frame.GetMethod().Module.ModuleVersionId.ToString("N");
                        var aotid = GetAotId();
                        if (frame.GetILOffset() != -1 || aotid == null)
                        {
                            filename = string.Format("<{0}>", mvid);
                        }
                        else
                        {
                            filename = string.Format("<{0}#{1}>", mvid, aotid);
                        }
                    }

                    sb.AppendFormat(" in {0}:{1} ", filename, frame.GetFileLineNumber());
                }

                any_frame = true;
            }

            return(any_frame);
        }
Esempio n. 3
0
        bool AddFrames(StringBuilder sb)
        {
            bool   printOffset;
            string debugInfo, indentation;
            string unknown = Locale.GetText("<unknown method>");

            indentation = "  ";
            debugInfo   = Locale.GetText(" in {0}:{1} ");

            var newline = String.Format("{0}{1}{2} ", Environment.NewLine, indentation,
                                        Locale.GetText("at"));

            int i;

            for (i = 0; i < FrameCount; i++)
            {
                StackFrame frame = GetFrame(i);
                if (i == 0)
                {
                    sb.AppendFormat("{0}{1} ", indentation, Locale.GetText("at"));
                }
                else
                {
                    sb.Append(newline);
                }

                if (frame.GetMethod() == null)
                {
                    string internal_name = frame.GetInternalMethodName();
                    if (internal_name != null)
                    {
                        sb.Append(internal_name);
                    }
                    else
                    {
                        sb.AppendFormat("<0x{0:x5} + 0x{1:x5}> {2}", frame.GetMethodAddress(), frame.GetNativeOffset(), unknown);
                    }
                }
                else
                {
                    GetFullNameForStackTrace(sb, frame.GetMethod());

                    if (frame.GetILOffset() == -1)
                    {
                        sb.AppendFormat(" <0x{0:x5} + 0x{1:x5}>", frame.GetMethodAddress(), frame.GetNativeOffset());
                        if (frame.GetMethodIndex() != 0xffffff)
                        {
                            sb.AppendFormat(" {0}", frame.GetMethodIndex());
                        }
                    }
                    else
                    {
                        sb.AppendFormat(" [0x{0:x5}]", frame.GetILOffset());
                    }

                    sb.AppendFormat(debugInfo, frame.GetSecureFileName(),
                                    frame.GetFileLineNumber());
                }
            }

            return(i != 0);
        }