Beispiel #1
0
        public CorDebugFunction GetFunctionFromTokenTinyCLR(uint tk)
        {
            if (HasSymbols)
            {
                return(GetFunctionFromToken(tk, m_htTokenTinyCLRToPdbx));
            }
            else
            {
                uint index = TinyCLR_TypeSystem.ClassMemberIndexFromTinyCLRToken(tk, this);

                WireProtocol.Commands.Debugging_Resolve_Method.Result resolvedMethod = this.Process.Engine.ResolveMethod(index);
                Debug.Assert(TinyCLR_TypeSystem.IdxAssemblyFromIndex(resolvedMethod.m_td) == this.Idx);

                uint tkMethod = TinyCLR_TypeSystem.SymbollessSupport.MethodDefTokenFromTinyCLRToken(tk);
                uint tkClass  = TinyCLR_TypeSystem.TinyCLRTokenFromTypeIndex(resolvedMethod.m_td);

                CorDebugClass c = GetClassFromTokenTinyCLR(tkClass);

                return(new CorDebugFunction(c, tkMethod));
            }
        }
        internal static StackFrame CreateFrame(MicroFrameworkDebuggerSession session, CorDebugFrame frame)
        {
            string file   = "";
            int    line   = 0;
            string method = "";
            string lang   = "";

            if (frame.FrameType == CorFrameType.ILFrame)
            {
                if (frame.Function != null)
                {
                    uint tk = TinyCLR_TypeSystem.SymbollessSupport.TinyCLRTokenFromMethodDefToken(frame.Function.Token);
                    uint md = TinyCLR_TypeSystem.ClassMemberIndexFromTinyCLRToken(tk, frame.Function.Assembly);
                    method = session.Engine.GetMethodName(md, true);
                    var debugData = frame.Function.GetMethodInfo(session)?.DebugInformation;
                    if (debugData != null)
                    {
                        SequencePoint prevSp = null;
                        foreach (var sp in debugData.SequencePoints)
                        {
                            if (sp.Offset > frame.IP)
                            {
                                break;
                            }
                            prevSp = sp;
                        }
                        if (prevSp.Offset != -1)
                        {
                            line = prevSp.StartLine;
                            file = prevSp.Document.Url;
                        }
                    }
                }
                lang = "Managed";
            }
//			else if(frame.FrameType == CorFrameType.NativeFrame)
//			{
//				frame.GetNativeIP(out address);
//				method = "<Unknown>";
//				lang = "Native";
//			}
            else if (frame.FrameType == CorFrameType.InternalFrame)
            {
                switch (((CorDebugInternalFrame)frame).FrameInternalType)
                {
                case CorDebugInternalFrameType.STUBFRAME_M2U:
                    method = "[Managed to Native Transition]";
                    break;

                case CorDebugInternalFrameType.STUBFRAME_U2M:
                    method = "[Native to Managed Transition]";
                    break;

                case CorDebugInternalFrameType.STUBFRAME_LIGHTWEIGHT_FUNCTION:
                    method = "[Lightweight Method Call]";
                    break;

                case CorDebugInternalFrameType.STUBFRAME_APPDOMAIN_TRANSITION:
                    method = "[Application Domain Transition]";
                    break;

                case CorDebugInternalFrameType.STUBFRAME_FUNC_EVAL:
                    method = "[Function Evaluation]";
                    break;
                }
            }
            if (method == null)
            {
                method = "<Unknown>";
            }
            var loc = new SourceLocation(method, file, line);

            return(new StackFrame((long)0, loc, lang));
        }
        internal static StackFrame CreateFrame(MicroFrameworkDebuggerSession session, CorDebugFrame frame)
        {
            string file   = "";
            int    line   = 0;
            string method = "";
            string lang   = "";

            if (frame.FrameType == CorFrameType.ILFrame)
            {
                if (frame.Function != null)
                {
                    uint tk = TinyCLR_TypeSystem.SymbollessSupport.TinyCLRTokenFromMethodDefToken(frame.Function.Token);
                    uint md = TinyCLR_TypeSystem.ClassMemberIndexFromTinyCLRToken(tk, frame.Function.Assembly);
                    method = session.Engine.GetMethodName(md, true);
                    var reader = frame.Function.Assembly.DebugData;
                    if (reader != null)
                    {
                        var sim = new MethodSymbols(new Mono.Cecil.MetadataToken(frame.Function.Token));
                        //Ugliest hack ever
                        if (reader is Mono.Cecil.Mdb.MdbReader)
                        {
                            for (int i = 0; i < 100; i++)
                            {
                                sim.Variables.Add(new VariableDefinition(null));
                            }
                        }
                        reader.Read(sim);
                        InstructionSymbol prevSp = new InstructionSymbol(-1, null);
                        foreach (var sp in sim.Instructions)
                        {
                            if (sp.Offset > frame.IP)
                            {
                                break;
                            }
                            prevSp = sp;
                        }
                        if (prevSp.Offset != -1)
                        {
                            line = prevSp.SequencePoint.StartLine;
                            file = prevSp.SequencePoint.Document.Url;
                        }
                    }
                }
                lang = "Managed";
            }
//			else if(frame.FrameType == CorFrameType.NativeFrame)
//			{
//				frame.GetNativeIP(out address);
//				method = "<Unknown>";
//				lang = "Native";
//			}
            else if (frame.FrameType == CorFrameType.InternalFrame)
            {
                switch (((CorDebugInternalFrame)frame).FrameInternalType)
                {
                case CorDebugInternalFrameType.STUBFRAME_M2U:
                    method = "[Managed to Native Transition]";
                    break;

                case CorDebugInternalFrameType.STUBFRAME_U2M:
                    method = "[Native to Managed Transition]";
                    break;

                case CorDebugInternalFrameType.STUBFRAME_LIGHTWEIGHT_FUNCTION:
                    method = "[Lightweight Method Call]";
                    break;

                case CorDebugInternalFrameType.STUBFRAME_APPDOMAIN_TRANSITION:
                    method = "[Application Domain Transition]";
                    break;

                case CorDebugInternalFrameType.STUBFRAME_FUNC_EVAL:
                    method = "[Function Evaluation]";
                    break;
                }
            }
            if (method == null)
            {
                method = "<Unknown>";
            }
            var loc = new SourceLocation(method, file, line);

            return(new StackFrame((long)0, loc, lang));
        }