msos.UnifiedStackTraces.GetNativeStackTrace C# (CSharp) Method

GetNativeStackTrace() private method

private GetNativeStackTrace ( uint engineThreadId, CONTEXT context ) : List
engineThreadId uint
context CONTEXT
return List
        private List<UnifiedStackFrame> GetNativeStackTrace(uint? engineThreadId, CONTEXT? context)
        {
            if (engineThreadId.HasValue)
                Util.VerifyHr(((IDebugSystemObjects)_debugClient).SetCurrentThreadId(engineThreadId.Value));

            DEBUG_STACK_FRAME[] stackFrames = new DEBUG_STACK_FRAME[200];
            uint framesFilled;

            if (context.HasValue)
            {
                int ctxSize = Marshal.SizeOf(context);
                IntPtr ctxPtr = Marshal.AllocHGlobal(ctxSize);
                IntPtr frameCtxsPtr = Marshal.AllocHGlobal(ctxSize * stackFrames.Length);
                try
                {
                    Marshal.StructureToPtr(context, ctxPtr, false);
                    Util.VerifyHr(((IDebugControl4)_debugClient).GetContextStackTrace(
                        ctxPtr, (uint)ctxSize, stackFrames, stackFrames.Length, frameCtxsPtr, (uint)(stackFrames.Length * ctxSize), (uint)ctxSize, out framesFilled));
                }
                finally
                {
                    Marshal.FreeHGlobal(ctxPtr);
                    Marshal.FreeHGlobal(frameCtxsPtr);
                }
            }
            else
            {
                Util.VerifyHr(((IDebugControl)_debugClient).GetStackTrace(
                    0, 0, 0, stackFrames, stackFrames.Length, out framesFilled));
            }

            List<UnifiedStackFrame> stackTrace = new List<UnifiedStackFrame>();
            for (uint i = 0; i < framesFilled; ++i)
            {
                stackTrace.Add(new UnifiedStackFrame(stackFrames[i], (IDebugSymbols2)_debugClient));
            }
            return stackTrace;
        }