예제 #1
0
        /// <summary>
        /// Creates a SARIF StackFrame instance from a .NET StackFrame instance
        /// </summary>
        /// <param name="stackTrace"></param>
        /// <returns></returns>
        public static StackFrame Create(System.Diagnostics.StackFrame dotNetStackFrame)
        {
            // This value is -1 if not present
            int        ilOffset           = dotNetStackFrame.GetILOffset();
            string     fileName           = dotNetStackFrame.GetFileName();
            int        nativeOffset       = dotNetStackFrame.GetNativeOffset();
            MethodBase methodBase         = dotNetStackFrame.GetMethod();
            Assembly   assembly           = methodBase?.DeclaringType.Assembly;
            string     fullyQualifiedName = CreateFullyQualifiedName(methodBase);

            StackFrame stackFrame = new StackFrame
            {
                Module = assembly?.GetName().Name,
                FullyQualifiedLogicalName = fullyQualifiedName
            };

            if (fileName != null)
            {
                stackFrame.Uri    = new Uri(fileName);
                stackFrame.Line   = dotNetStackFrame.GetFileLineNumber();
                stackFrame.Column = dotNetStackFrame.GetFileColumnNumber();
            }

            if (ilOffset != -1)
            {
                stackFrame.Offset = ilOffset;
            }

            if (nativeOffset != -1)
            {
                stackFrame.SetProperty("NativeOffset", nativeOffset.ToString(CultureInfo.InvariantCulture));
            }

            return(stackFrame);
        }
예제 #2
0
        /// <summary>
        /// Creates a SARIF StackFrame instance from a .NET StackFrame instance
        /// </summary>
        /// <param name="stackTrace"></param>
        /// <returns></returns>
        public static StackFrame Create(System.Diagnostics.StackFrame dotNetStackFrame)
        {
            // This value is -1 if not present
            int ilOffset = dotNetStackFrame.GetILOffset();
            string fileName = dotNetStackFrame.GetFileName();
            int nativeOffset = dotNetStackFrame.GetNativeOffset();
            MethodBase methodBase = dotNetStackFrame.GetMethod();
            Assembly assembly = methodBase?.DeclaringType.Assembly;
            string fullyQualifiedName = CreateFullyQualifiedName(methodBase);

            StackFrame stackFrame = new StackFrame
            {
                Module = assembly?.GetName().Name,
                FullyQualifiedLogicalName = fullyQualifiedName
            };

            if (fileName != null)
            {
                stackFrame.Uri = new Uri(fileName);
                stackFrame.Line = dotNetStackFrame.GetFileLineNumber();
                stackFrame.Column = dotNetStackFrame.GetFileColumnNumber();
            }

            if (ilOffset != -1)
            {
                stackFrame.Offset = ilOffset;
            }

            if (nativeOffset != -1)
            {
                stackFrame.SetProperty("NativeOffset", nativeOffset.ToString(CultureInfo.InvariantCulture));
            }

            return stackFrame;
        }
예제 #3
0
        /// <summary>
        /// Creates a SARIF StackFrame instance from a .NET StackFrame instance
        /// </summary>
        /// <param name="dotNetStackFrame"></param>
        /// <returns></returns>
        public static StackFrame Create(System.Diagnostics.StackFrame dotNetStackFrame)
        {
            // This value is -1 if not present
            int        ilOffset           = dotNetStackFrame.GetILOffset();
            string     fileName           = dotNetStackFrame.GetFileName();
            int        nativeOffset       = dotNetStackFrame.GetNativeOffset();
            MethodBase methodBase         = dotNetStackFrame.GetMethod();
            Assembly   assembly           = methodBase?.DeclaringType.Assembly;
            string     fullyQualifiedName = CreateFullyQualifiedName(methodBase);

            StackFrame stackFrame = new StackFrame
            {
                Module   = assembly?.GetName().Name,
                Location = new Location()
            };

            if (!string.IsNullOrWhiteSpace(fullyQualifiedName))
            {
                stackFrame.Location = new Location
                {
                    LogicalLocation = new LogicalLocation
                    {
                        FullyQualifiedName = fullyQualifiedName
                    }
                };
            }

            if (fileName != null)
            {
                if (stackFrame.Location == null)
                {
                    stackFrame.Location = new Location();
                }

                stackFrame.Location.PhysicalLocation = new PhysicalLocation
                {
                    ArtifactLocation = new ArtifactLocation
                    {
                        Uri = new Uri(fileName)
                    },
                    Region = new Region
                    {
                        StartLine   = dotNetStackFrame.GetFileLineNumber(),
                        StartColumn = dotNetStackFrame.GetFileColumnNumber()
                    }
                };
            }

            if (ilOffset != -1)
            {
                if (stackFrame.Location == null)
                {
                    stackFrame.Location = new Location();
                }

                if (stackFrame.Location.PhysicalLocation == null)
                {
                    stackFrame.Location.PhysicalLocation = new PhysicalLocation();
                }

                stackFrame.Location.PhysicalLocation.Address = new Address
                {
                    OffsetFromParent = ilOffset
                };
            }

            if (nativeOffset != -1)
            {
                stackFrame.SetProperty("NativeOffset", nativeOffset.ToString(CultureInfo.InvariantCulture));
            }

            return(stackFrame);
        }