Exemple #1
0
        /// <summary>
        /// Initialize the stack trace based on current thread and given initial frame index.
        /// </summary>
        private void InitializeForThreadFrameIndex(int skipFrames, bool needFileInfo)
        {
            int frameCount = -RuntimeImports.RhGetCurrentThreadStackTrace(Array.Empty <IntPtr>());

            Debug.Assert(frameCount >= 0);
            IntPtr[] stackTrace     = new IntPtr[frameCount];
            int      trueFrameCount = RuntimeImports.RhGetCurrentThreadStackTrace(stackTrace);

            Debug.Assert(trueFrameCount == frameCount);
            InitializeForIpAddressArray(stackTrace, skipFrames, frameCount, needFileInfo);
        }
Exemple #2
0
        private void BuildStackFrame(int frameIndex, bool needFileInfo)
        {
            const int SystemDiagnosticsStackDepth = 2;

            frameIndex += SystemDiagnosticsStackDepth;
            IntPtr[] frameArray         = new IntPtr[frameIndex + 1];
            int      returnedFrameCount = RuntimeImports.RhGetCurrentThreadStackTrace(frameArray);
            int      realFrameCount     = (returnedFrameCount >= 0 ? returnedFrameCount : frameArray.Length);

            IntPtr ipAddress = (frameIndex < realFrameCount) ? frameArray[frameIndex] : IntPtr.Zero;

            InitializeForIpAddress(ipAddress, needFileInfo);
        }
        private void InitializeForCurrentThread(int skipFrames, bool needFileInfo)
        {
            const int SystemDiagnosticsStackDepth = 2;

            int frameCount = -RuntimeImports.RhGetCurrentThreadStackTrace(Array.Empty <IntPtr>());

            Debug.Assert(frameCount >= 0);
            IntPtr[] stackTrace     = new IntPtr[frameCount];
            int      trueFrameCount = RuntimeImports.RhGetCurrentThreadStackTrace(stackTrace);

            Debug.Assert(trueFrameCount == frameCount);
            InitializeForIpAddressArray(stackTrace, skipFrames + SystemDiagnosticsStackDepth, frameCount, needFileInfo);
        }
Exemple #4
0
        /// <summary>
        /// Locate IP address corresponding to a given frame. Ignore .NET Native-specific rethrow markers.
        /// </summary>
        private IntPtr LocateIpAddressForStackFrame(int frameIndex)
        {
            IntPtr[] frameArray         = new IntPtr[frameIndex + 1];
            int      returnedFrameCount = RuntimeImports.RhGetCurrentThreadStackTrace(frameArray);
            int      realFrameCount     = (returnedFrameCount >= 0 ? returnedFrameCount : frameArray.Length);

            if (frameIndex < realFrameCount)
            {
                return(frameArray[frameIndex]);
            }

            // No more frames are available
            return(IntPtr.Zero);
        }