Exemplo n.º 1
0
        public static CorDebugClass ClassFromRuntimeValue(RuntimeValue rtv, CorDebugAppDomain appDomain)
        {
            RuntimeValue_Reflection rtvf = rtv as RuntimeValue_Reflection;
            CorDebugClass           cls  = null;
            object objBuiltInKey         = null;

            Debug.Assert(!rtv.IsNull);

            if (rtvf != null)
            {
                objBuiltInKey = rtvf.ReflectionType;
            }
            else if (rtv.DataType == RuntimeDataType.DATATYPE_TRANSPARENT_PROXY)
            {
                objBuiltInKey = RuntimeDataType.DATATYPE_TRANSPARENT_PROXY;
            }
            else
            {
                cls = TinyCLR_TypeSystem.CorDebugClassFromTypeIndex(rtv.Type, appDomain);
            }

            if (objBuiltInKey != null)
            {
                CorDebugProcess.BuiltinType builtInType = appDomain.Process.ResolveBuiltInType(objBuiltInKey);

                cls = builtInType.GetClass(appDomain);

                if (cls == null)
                {
                    cls = new CorDebugClass(builtInType.GetAssembly(appDomain), builtInType.TokenCLR);
                }
            }

            return(cls);
        }
Exemplo n.º 2
0
        private static uint TinyCLRTokenFromIndex(TinyCLR_TypeSystem.CLR_TABLESENUM tbl, uint index)
        {
            uint idxAssembly = TinyCLR_TypeSystem.IdxAssemblyFromIndex(index);
            uint idxMethod   = TinyCLR_TypeSystem.IdxFromIndex(index);

            return(TinyCLR_TypeSystem.CLR_TkFromType(tbl, idxMethod));
        }
        int ICorDebugObjectValue.GetVirtualMethod(uint memberRef, out ICorDebugFunction ppFunction)
        {
            uint mdVirtual = Engine.GetVirtualMethod(TinyCLR_TypeSystem.ClassMemberIndexFromCLRToken(memberRef, this.m_class.Assembly), this.m_rtv);

            ppFunction = TinyCLR_TypeSystem.CorDebugFunctionFromMethodIndex(mdVirtual, this.m_appDomain);

            return(Utility.COM_HResults.S_OK);
        }
        int ICorDebugObjectValue.GetFieldValue(ICorDebugClass pClass, uint fieldDef, out ICorDebugValue ppValue)
        {
            //cache fields?
            RuntimeValue rtv = m_rtv.GetField(0, TinyCLR_TypeSystem.ClassMemberIndexFromCLRToken(fieldDef, ((CorDebugClass)pClass).Assembly));

            ppValue = CreateValue(rtv);

            return(Utility.COM_HResults.S_OK);
        }
Exemplo n.º 5
0
        int ICorDebugClass.GetStaticFieldValue(uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue)
        {
            //Cache, and invalidate when necessary???
            uint fd = TinyCLR_TypeSystem.ClassMemberIndexFromCLRToken(fieldDef, this.Assembly);

            this.Process.SetCurrentAppDomain(this.AppDomain);
            RuntimeValue rtv = this.Engine.GetStaticFieldValue(fd);

            ppValue = CorDebugValue.CreateValue(rtv, this.AppDomain);

            return(Utility.COM_HResults.S_OK);
        }
Exemplo n.º 6
0
        public static CorDebugFunction CorDebugFunctionFromMethodIndex(uint methodIndex, CorDebugAppDomain appDomain)
        {
            CorDebugFunction function = null;
            CorDebugAssembly assembly = appDomain.AssemblyFromIdx(TinyCLR_TypeSystem.IdxAssemblyFromIndex(methodIndex));

            if (assembly != null)
            {
                uint tk = TinyCLR_TypeSystem.TinyCLRTokenFromMethodIndex(methodIndex);
                function = assembly.GetFunctionFromTokenTinyCLR(tk);
            }

            return(function);
        }
Exemplo n.º 7
0
        public static CorDebugClass CorDebugClassFromTypeIndex(uint typeIndex, CorDebugAppDomain appDomain)
        {
            CorDebugClass cls = null;

            CorDebugAssembly assembly = appDomain.AssemblyFromIdx(TinyCLR_TypeSystem.IdxAssemblyFromIndex(typeIndex));

            if (assembly != null)
            {
                uint typedef = TinyCLR_TypeSystem.CLR_TkFromType(TinyCLR_TypeSystem.CLR_TABLESENUM.TBL_TypeDef, TinyCLR_TypeSystem.IdxFromIndex(typeIndex));
                cls = assembly.GetClassFromTokenTinyCLR(typedef);
            }

            return(cls);
        }
Exemplo n.º 8
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));
            }
        }
		private static uint TinyCLRTokenFromIndex (TinyCLR_TypeSystem.CLR_TABLESENUM tbl, uint index)
		{
			uint idxAssembly = TinyCLR_TypeSystem.IdxAssemblyFromIndex (index);
			uint idxMethod = TinyCLR_TypeSystem.IdxFromIndex (index);

			return TinyCLR_TypeSystem.CLR_TkFromType (tbl, idxMethod);
		}
Exemplo n.º 10
0
 public void SetJmcStatus(bool fJMC)
 {
     if (this.HasSymbols)
     {
         if (this.Process.Engine.Info_SetJMC(fJMC, ReflectionDefinition.Kind.REFLECTION_ASSEMBLY, TinyCLR_TypeSystem.IndexFromIdxAssemblyIdx(this.Idx)))
         {
             if (!this.m_isFrameworkAssembly)
             {
                 //now update the debugger JMC state...
                 foreach (Pdbx.Class c in this.m_pdbxAssembly.Classes)
                 {
                     foreach (Pdbx.Method m in c.Methods)
                     {
                         m.IsJMC = fJMC;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 11
0
 public static CorDebugAssembly AssemblyFromIndex(uint index, ArrayList assemblies)
 {
     return(AssemblyFromIdx(TinyCLR_TypeSystem.IdxAssemblyFromIndex(index), assemblies));
 }
Exemplo n.º 12
0
 public static CorDebugAssembly AssemblyFromIndex(CorDebugAppDomain appDomain, uint index)
 {
     return(appDomain.AssemblyFromIdx(TinyCLR_TypeSystem.IdxAssemblyFromIndex(index)));
 }
Exemplo n.º 13
0
        int ICorDebugModule2.SetJMCStatus(int bIsJustMyCode, uint cTokens, ref uint pTokens)
        {
            Debug.Assert(cTokens == 0);

            bool fJMC = Utility.Boolean.IntToBool(bIsJustMyCode);

            int hres = fJMC ? Utility.COM_HResults.E_FAIL : Utility.COM_HResults.S_OK;

            Debug.Assert(Utility.FImplies(fJMC, this.HasSymbols));

            if (this.HasSymbols)
            {
                if (this.Process.Engine.Info_SetJMC(fJMC, ReflectionDefinition.Kind.REFLECTION_ASSEMBLY, TinyCLR_TypeSystem.IndexFromIdxAssemblyIdx(this.Idx)))
                {
                    if (!this.m_isFrameworkAssembly)
                    {
                        //now update the debugger JMC state...
                        foreach (Pdbx.Class c in this.m_pdbxAssembly.Classes)
                        {
                            foreach (Pdbx.Method m in c.Methods)
                            {
                                m.IsJMC = fJMC;
                            }
                        }
                    }
                    hres = Utility.COM_HResults.S_OK;
                }
            }

            return(hres);
        }
Exemplo n.º 14
0
 public static uint TinyCLRTokenFromTypeDefToken(uint token)
 {
     Debug.Assert((token & (uint)CorTokenType.mdtTypeDef) != 0);
     return(TinyCLR_TypeSystem.CLR_TkFromType(CLR_TABLESENUM.TBL_TypeDef, token & 0x00ffffff));
 }
Exemplo n.º 15
0
        public static uint ClassMemberIndexFromTinyCLRToken(uint token, CorDebugAssembly assembly)
        {
            uint idx = TinyCLR_TypeSystem.CLR_DataFromTk(token);

            return(TinyCLR_TypeSystem.IndexFromIdxAssemblyIdx(assembly.Idx, idx));
        }
Exemplo n.º 16
0
        public bool UpdateAssemblies()
        {
            uint[] assemblies = null;
            List <ManagedCallbacks.ManagedCallback> callbacks = new System.Collections.Generic.List <ManagedCallbacks.ManagedCallback> ();

            if (this.Process.Engine.Capabilities.AppDomains)
            {
                WireProtocol.Commands.Debugging_Resolve_AppDomain.Reply reply = this.Process.Engine.ResolveAppDomain(m_id);

                if (reply != null)
                {
                    m_name     = reply.Name;
                    assemblies = reply.m_data;
                }

                if (assemblies == null)
                {
                    //assembly is already unloaded
                    assemblies = new uint[0];
                }
            }
            else
            {
                WireProtocol.Commands.Debugging_Resolve_Assembly[] reply = this.Process.Engine.ResolveAllAssemblies();
                assemblies = new uint[reply.Length];

                for (int iAssembly = 0; iAssembly < assemblies.Length; iAssembly++)
                {
                    assemblies [iAssembly] = reply [iAssembly].m_idx;
                }
            }

            //Convert Assembly Index to Idx.
            for (uint iAssembly = 0; iAssembly < assemblies.Length; iAssembly++)
            {
                assemblies [iAssembly] = TinyCLR_TypeSystem.IdxAssemblyFromIndex(assemblies [iAssembly]);
            }

            //Unload dead assemblies
            for (int iAssembly = m_assemblies.Count - 1; iAssembly >= 0; iAssembly--)
            {
                CorDebugAssembly assembly = (CorDebugAssembly)m_assemblies [iAssembly];

                if (Array.IndexOf(assemblies, assembly.Idx) < 0)
                {
                    callbacks.Add(new ManagedCallbacks.ManagedCallbackAssembly(assembly, ManagedCallbacks.ManagedCallbackAssembly.EventType.UnloadModule));
                    callbacks.Add(new ManagedCallbacks.ManagedCallbackAssembly(assembly, ManagedCallbacks.ManagedCallbackAssembly.EventType.UnloadAssembly));

                    m_assemblies.RemoveAt(iAssembly);
                }
            }

            //Load new assemblies
            for (int i = 0; i < assemblies.Length; i++)
            {
                uint idx = assemblies [i];

                CorDebugAssembly assembly = AssemblyFromIdx(idx);

                if (assembly == null)
                {
                    //Get the primary assembly from CorDebugProcess
                    assembly = this.Process.AssemblyFromIdx(idx);

                    Debug.Assert(assembly != null);

                    //create a new CorDebugAssemblyInstance
                    assembly = assembly.CreateAssemblyInstance(this);

                    Debug.Assert(assembly != null);

                    m_assemblies.Add(assembly);

                    //cpde expects mscorlib to be the first assembly it hears about
                    int index = (assembly.Name == "mscorlib") ? 0 : callbacks.Count;

                    callbacks.Insert(index, new ManagedCallbacks.ManagedCallbackAssembly(assembly, ManagedCallbacks.ManagedCallbackAssembly.EventType.LoadAssembly));
                    callbacks.Insert(index + 1, new ManagedCallbacks.ManagedCallbackAssembly(assembly, ManagedCallbacks.ManagedCallbackAssembly.EventType.LoadModule));
                }
            }

            this.Process.EnqueueEvents(callbacks);

            return(callbacks.Count > 0);
        }
        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));
        }
Exemplo n.º 18
0
        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));
        }
Exemplo n.º 19
0
 public CorDebugValue GetFieldValue(uint metadataToken)
 {
     return(CreateValue(m_rtv.GetField(0, TinyCLR_TypeSystem.ClassMemberIndexFromCLRToken(metadataToken, m_class.Assembly))));
 }