Exemplo n.º 1
0
        protected override DesktopStackFrame GetStackFrame(DesktopThread thread, byte[] context, ulong ip, ulong framePtr, ulong frameVtbl)
        {
            DesktopStackFrame frame;

            if (frameVtbl != 0)
            {
                ClrMethod innerMethod = null;
                string    frameName   = _sos.GetFrameName(frameVtbl);

                ulong md = _sos.GetMethodDescPtrFromFrame(framePtr);
                if (md != 0)
                {
                    V45MethodDescDataWrapper mdData = new V45MethodDescDataWrapper();
                    if (mdData.Init(_sos, md))
                    {
                        innerMethod = DesktopMethod.Create(this, mdData);
                    }
                }

                frame = new DesktopStackFrame(this, thread, context, framePtr, frameName, innerMethod);
            }
            else
            {
                frame = new DesktopStackFrame(this, thread, context, ip, framePtr, _sos.GetMethodDescPtrFromIP(ip));
            }

            return(frame);
        }
Exemplo n.º 2
0
        protected override DesktopStackFrame GetStackFrame(DesktopThread thread, byte[] context, ulong ip, ulong sp, ulong frameVtbl)
        {
            DesktopStackFrame frame;

            ClearBuffer();

            if (frameVtbl != 0)
            {
                ClrMethod method    = null;
                string    frameName = "Unknown Frame";
                if (Request(DacRequests.FRAME_NAME, frameVtbl, _buffer))
                {
                    frameName = BytesToString(_buffer);
                }

                IMethodDescData mdData = GetMethodDescData(DacRequests.METHODDESC_FRAME_DATA, sp);
                if (mdData != null)
                {
                    method = DesktopMethod.Create(this, mdData);
                }

                frame = new DesktopStackFrame(this, thread, context, sp, frameName, method);
            }
            else
            {
                ulong md = GetMethodDescFromIp(ip);
                frame = new DesktopStackFrame(this, thread, context, ip, sp, md);
            }

            return(frame);
        }
Exemplo n.º 3
0
        internal IEnumerable <ClrStackFrame> EnumerateStackFrames(DesktopThread thread)
        {
            using (ClrStackWalk stackwalk = _dacInterface.CreateStackWalk(thread.OSThreadId, 0xf))
            {
                if (stackwalk == null)
                {
                    yield break;
                }

                byte[] ulongBuffer = new byte[8];
                byte[] context     = ContextHelper.Context;
                do
                {
                    if (!stackwalk.GetContext(ContextHelper.ContextFlags, ContextHelper.Length, out uint size, context))
                    {
                        break;
                    }

                    ulong ip, sp;

                    if (PointerSize == 4)
                    {
                        ip = BitConverter.ToUInt32(context, ContextHelper.InstructionPointerOffset);
                        sp = BitConverter.ToUInt32(context, ContextHelper.StackPointerOffset);
                    }
                    else
                    {
                        ip = BitConverter.ToUInt64(context, ContextHelper.InstructionPointerOffset);
                        sp = BitConverter.ToUInt64(context, ContextHelper.StackPointerOffset);
                    }

                    ulong frameVtbl = stackwalk.GetFrameVtable();
                    if (frameVtbl != 0)
                    {
                        sp = frameVtbl;
                        ReadPointer(sp, out frameVtbl);
                    }

                    byte[] contextCopy = new byte[context.Length];
                    Buffer.BlockCopy(context, 0, contextCopy, 0, context.Length);

                    DesktopStackFrame frame = GetStackFrame(thread, contextCopy, ip, sp, frameVtbl);
                    yield return(frame);
                } while (stackwalk.Next());
            }
        }
Exemplo n.º 4
0
        internal unsafe void InitLocalData()
        {
            if (_corDebugInit)
            {
                return;
            }

            _corDebugInit = true;

            ICorDebugThread3   thread = (ICorDebugThread3)CorDebugThread;
            ICorDebugStackWalk stackwalk;

            thread.CreateStackWalk(out stackwalk);

            do
            {
                ICorDebugFrame frame;
                stackwalk.GetFrame(out frame);

                ICorDebugILFrame ilFrame = frame as ICorDebugILFrame;
                if (ilFrame == null)
                {
                    continue;
                }

                byte[] context = ContextHelper.Context;

                uint size;

                fixed(byte *ptr = context)
                stackwalk.GetContext(ContextHelper.ContextFlags, ContextHelper.Length, out size, new IntPtr(ptr));

                ulong ip = BitConverter.ToUInt32(context, ContextHelper.InstructionPointerOffset);
                ulong sp = BitConverter.ToUInt32(context, ContextHelper.StackPointerOffset);

                DesktopStackFrame result = _stackTrace.Where(frm => sp == frm.StackPointer && ip == frm.InstructionPointer).Select(p => (DesktopStackFrame)p).SingleOrDefault();
                if (result != null)
                {
                    result.CordbFrame = ilFrame;
                }
            } while (stackwalk.Next() == 0);
        }
Exemplo n.º 5
0
        protected override DesktopStackFrame GetStackFrame(DesktopThread thread, int res, ulong ip, ulong framePtr, ulong frameVtbl)
        {
            DesktopStackFrame frame;
            StringBuilder sb = new StringBuilder();
            sb.Capacity = 256;
            uint needed;
            if (res >= 0 && frameVtbl != 0)
            {
                ClrMethod innerMethod = null;
                string frameName = "Unknown Frame";
                if (_sos.GetFrameName(frameVtbl, (uint)sb.Capacity, sb, out needed) >= 0)
                    frameName = sb.ToString();

                ulong md = 0;
                if (_sos.GetMethodDescPtrFromFrame(framePtr, out md) == 0)
                {
                    V45MethodDescDataWrapper mdData = new V45MethodDescDataWrapper();
                    if (mdData.Init(_sos, md))
                        innerMethod = DesktopMethod.Create(this, mdData);
                }

                frame = new DesktopStackFrame(this, thread, framePtr, frameName, innerMethod);
            }
            else
            {
                ulong md;
                if (_sos.GetMethodDescPtrFromIP(ip, out md) >= 0)
                {
                    frame = new DesktopStackFrame(this, thread, ip, framePtr, md);
                }
                else
                {
                    frame = new DesktopStackFrame(this, thread, ip, framePtr, 0);
                }
            }

            return frame;
        }
Exemplo n.º 6
0
        internal IEnumerable <ClrStackFrame> EnumerateStackFrames(DesktopThread thread)
        {
            IXCLRDataProcess proc = GetClrDataProcess();
            object           tmp;

            int res = proc.GetTaskByOSThreadID(thread.OSThreadId, out tmp);

            if (res < 0)
            {
                yield break;
            }

            IXCLRDataTask      task      = null;
            IXCLRDataStackWalk stackwalk = null;

            try
            {
                task = (IXCLRDataTask)tmp;
                res  = task.CreateStackWalk(0xf, out tmp);
                if (res < 0)
                {
                    yield break;
                }

                stackwalk = (IXCLRDataStackWalk)tmp;
                byte[] ulongBuffer = new byte[8];
                byte[] context     = ContextHelper.Context;
                do
                {
                    uint size;
                    res = stackwalk.GetContext(ContextHelper.ContextFlags, ContextHelper.Length, out size, context);
                    if (res < 0 || res == 1)
                    {
                        break;
                    }

                    ulong ip = BitConverter.ToUInt32(context, ContextHelper.InstructionPointerOffset);
                    ulong sp = BitConverter.ToUInt32(context, ContextHelper.StackPointerOffset);

                    res = stackwalk.Request(0xf0000000, 0, null, (uint)ulongBuffer.Length, ulongBuffer);

                    ulong frameVtbl = 0;
                    if (res >= 0)
                    {
                        frameVtbl = BitConverter.ToUInt64(ulongBuffer, 0);
                        if (frameVtbl != 0)
                        {
                            sp = frameVtbl;
                            ReadPointer(sp, out frameVtbl);
                        }
                    }

                    DesktopStackFrame frame = GetStackFrame(thread, res, ip, sp, frameVtbl);
                    yield return(frame);
                } while (stackwalk.Next() == 0);
            }
            finally
            {
                if (task != null)
                {
                    Marshal.FinalReleaseComObject(task);
                }

                if (stackwalk != null)
                {
                    Marshal.FinalReleaseComObject(stackwalk);
                }
            }
        }
Exemplo n.º 7
0
        protected override DesktopStackFrame GetStackFrame(int res, ulong ip, ulong sp, ulong frameVtbl)
        {
            DesktopStackFrame frame;
            ClearBuffer();

            if (res >= 0 && frameVtbl != 0)
            {
                ClrMethod method = null;
                string frameName = "Unknown Frame";
                if (Request(DacRequests.FRAME_NAME, frameVtbl, _buffer))
                    frameName = BytesToString(_buffer);

                var mdData = GetMethodDescData(DacRequests.METHODDESC_FRAME_DATA, sp);
                if (mdData != null)
                    method = DesktopMethod.Create(this, mdData);

                frame = new DesktopStackFrame(this, sp, frameName, method);
            }
            else
            {
                ulong md = GetMethodDescFromIp(ip);
                frame = new DesktopStackFrame(this, ip, sp, md);
            }

            return frame;
        }