Exemplo n.º 1
0
		public CorBacktrace (CorThread thread, CorDebuggerSession session): base (session.ObjectAdapter)
		{
			this.session = session;
			this.thread = thread;
			threadId = thread.Id;
			frames = new List<CorFrame> (GetFrames (thread));
			evalTimestamp = CorDebuggerSession.EvaluationTimestamp;
		}
Exemplo n.º 2
0
 public CorBacktrace(CorThread thread, CorDebuggerSession session) : base(session.ObjectAdapter)
 {
     this.session  = session;
     this.thread   = thread;
     threadId      = thread.Id;
     frames        = new List <CorFrame> (GetFrames(thread));
     evalTimestamp = CorDebuggerSession.EvaluationTimestamp;
 }
Exemplo n.º 3
0
		internal static StackFrame CreateFrame (CorDebuggerSession session, CorFrame frame)
		{
			uint address = 0;
			string file = "";
			int line = 0;
			string method = "";
			string lang = "";
			string module = "";
			string type = "";

			if (frame.FrameType == CorFrameType.ILFrame) {
				if (frame.Function != null) {
					module = frame.Function.Module.Name;
					CorMetadataImport importer = new CorMetadataImport (frame.Function.Module);
					MethodInfo mi = importer.GetMethodInfo (frame.Function.Token);
					method = mi.DeclaringType.FullName + "." + mi.Name;
					type = mi.DeclaringType.FullName;
					ISymbolReader reader = session.GetReaderForModule (frame.Function.Module.Name);
					if (reader != null) {
						ISymbolMethod met = reader.GetMethod (new SymbolToken (frame.Function.Token));
						if (met != null) {
							uint offset;
							CorDebugMappingResult mappingResult;
							frame.GetIP (out offset, out mappingResult);
							SequencePoint prevSp = null;
							foreach (SequencePoint sp in met.GetSequencePoints ()) {
								if (sp.Offset > offset)
									break;
								prevSp = sp;
							}
							if (prevSp != null) {
								line = prevSp.Line;
								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 (frame.InternalFrameType) {
					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) address, loc, lang);
		}
Exemplo n.º 4
0
 internal CorEvaluationContext(CorDebuggerSession session, CorBacktrace backtrace, int index, DC.EvaluationOptions ops) : base(ops)
 {
     Session        = session;
     base.Adapter   = session.ObjectAdapter;
     frameIndex     = index;
     this.backtrace = backtrace;
     evalTimestamp  = CorDebuggerSession.EvaluationTimestamp;
     Evaluator      = session.GetEvaluator(CorBacktrace.CreateFrame(session, Frame));
 }
Exemplo n.º 5
0
		internal CorEvaluationContext (CorDebuggerSession session, CorBacktrace backtrace, int index, DC.EvaluationOptions ops): base (ops)
		{
			Session = session;
			base.Adapter = session.ObjectAdapter;
			frameIndex = index;
			this.backtrace = backtrace;
			evalTimestamp = CorDebuggerSession.EvaluationTimestamp;
			Evaluator = session.GetEvaluator (CorBacktrace.CreateFrame (session, Frame));
		}
Exemplo n.º 6
0
        public static Type GetTypeInfo(this CorType type, CorDebuggerSession session)
        {
            Type t;

            if (CorMetadataImport.CoreTypes.TryGetValue(type.Type, out t))
            {
                return(t);
            }

            if (type.Type == CorElementType.ELEMENT_TYPE_ARRAY || type.Type == CorElementType.ELEMENT_TYPE_SZARRAY)
            {
                List <int> sizes    = new List <int> ();
                List <int> loBounds = new List <int> ();
                for (int n = 0; n < type.Rank; n++)
                {
                    sizes.Add(1);
                    loBounds.Add(0);
                }
                return(MetadataType.MakeArray(type.FirstTypeParameter.GetTypeInfo(session), sizes, loBounds));
            }

            if (type.Type == CorElementType.ELEMENT_TYPE_BYREF)
            {
                return(MetadataType.MakeByRef(type.FirstTypeParameter.GetTypeInfo(session)));
            }

            if (type.Type == CorElementType.ELEMENT_TYPE_PTR)
            {
                return(MetadataType.MakePointer(type.FirstTypeParameter.GetTypeInfo(session)));
            }

            CorMetadataImport mi = session.GetMetadataForModule(type.Class.Module.Name);

            if (mi != null)
            {
                t = mi.GetType(type.Class.Token);
                CorType[] targs = type.TypeParameters;
                if (targs.Length > 0)
                {
                    List <Type> types = new List <Type> ();
                    foreach (CorType ct in targs)
                    {
                        types.Add(ct.GetTypeInfo(session));
                    }
                    return(MetadataType.MakeGeneric(t, types));
                }
                else
                {
                    return(t);
                }
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 7
0
        public static ISymbolMethod GetSymbolMethod(this CorFunction func, CorDebuggerSession session)
        {
            ISymbolReader reader = session.GetReaderForModule(func.Module.Name);

            if (reader == null)
            {
                return(null);
            }
            return(reader.GetMethod(new SymbolToken(func.Token)));
        }
Exemplo n.º 8
0
		public static ISymbolMethod GetSymbolMethod (this CorFunction func, CorDebuggerSession session)
		{
			ISymbolReader reader = session.GetReaderForModule (func.Module.Name);
			if (reader == null)
				return null;
			return reader.GetMethod (new SymbolToken (func.Token));
		}
Exemplo n.º 9
0
        public static System.Reflection.MethodInfo GetMethodInfo(this CorFunction func, CorDebuggerSession session)
        {
            CorMetadataImport mi = session.GetMetadataForModule(func.Module.Name);

            if (mi != null)
            {
                return(mi.GetMethodInfo(func.Token));
            }
            else
            {
                return(null);
            }
        }
		public static SequencePoint GetSequencePoint(CorDebuggerSession session, CorFrame frame)
		{
			ISymbolReader reader = session.GetReaderForModule (frame.Function.Module.Name);
			if (reader == null)
				return null;

			ISymbolMethod met = reader.GetMethod (new SymbolToken (frame.Function.Token));
			if (met == null)
				return null;

			int SequenceCount = met.SequencePointCount;
			if (SequenceCount <= 0)
				return null;

			CorDebugMappingResult mappingResult;
			uint ip;
			frame.GetIP (out ip, out mappingResult);
			if (mappingResult == CorDebugMappingResult.MAPPING_NO_INFO || mappingResult == CorDebugMappingResult.MAPPING_UNMAPPED_ADDRESS)
				return null;

			int[] offsets = new int[SequenceCount];
			int[] lines = new int[SequenceCount];
			int[] endLines = new int[SequenceCount];
			int[] columns = new int[SequenceCount];
			int[] endColumns = new int[SequenceCount];
			ISymbolDocument[] docs = new ISymbolDocument[SequenceCount];
			met.GetSequencePoints (offsets, docs, lines, columns, endLines, endColumns);

			if ((SequenceCount > 0) && (offsets [0] <= ip)) {
				int i;
				for (i = 0; i < SequenceCount; ++i) {
					if (offsets [i] >= ip) {
						break;
					}
				}

				if ((i == SequenceCount) || (offsets [i] != ip)) {
					--i;
				}

				if (lines [i] == SpecialSequencePoint) {
					int j = i;
					// let's try to find a sequence point that is not special somewhere earlier in the code
					// stream.
					while (j > 0) {
						--j;
						if (lines [j] != SpecialSequencePoint) {
							return new SequencePoint () {
								IsSpecial = true,
								Offset = offsets [j],
								StartLine = lines [j],
								EndLine = endLines [j],
								StartColumn = columns [j],
								EndColumn = endColumns [j],
								Document = docs [j]
							};
						}
					}
					// we didn't find any non-special seqeunce point before current one, let's try to search
					// after.
					j = i;
					while (++j < SequenceCount) {
						if (lines [j] != SpecialSequencePoint) {
							return new SequencePoint () {
								IsSpecial = true,
								Offset = offsets [j],
								StartLine = lines [j],
								EndLine = endLines [j],
								StartColumn = columns [j],
								EndColumn = endColumns [j],
								Document = docs [j]
							};
						}
					}

					// Even if sp is null at this point, it's a valid scenario to have only special sequence 
					// point in a function.  For example, we can have a compiler-generated default ctor which
					// doesn't have any source.
					return null;
				} else {
					return new SequencePoint () {
						IsSpecial = false,
						Offset = offsets [i],
						StartLine = lines [i],
						EndLine = endLines [i],
						StartColumn = columns [i],
						EndColumn = endColumns [i],
						Document = docs [i]
					};
				}
			}
			return null;
		}
Exemplo n.º 11
0
		internal static StackFrame CreateFrame (CorDebuggerSession session, CorFrame frame)
		{
			// TODO: Fix remaining.
			uint address = 0;
			//string typeFQN;
			//string typeFullName;
			string addressSpace = "";
			string file = "";
			int line = 0;
			int column = 0;
			string method = "";
			string lang = "";
			string module = "";
			string type = "";
			bool hasDebugInfo = false;
			bool hidden = false;
			bool external = true;

			if (frame.FrameType == CorFrameType.ILFrame) {
				if (frame.Function != null) {
					module = frame.Function.Module.Name;
					CorMetadataImport importer = new CorMetadataImport (frame.Function.Module);
					MethodInfo mi = importer.GetMethodInfo (frame.Function.Token);
					method = mi.DeclaringType.FullName + "." + mi.Name;
					type = mi.DeclaringType.FullName;
					addressSpace = mi.Name;
					ISymbolReader reader = session.GetReaderForModule (frame.Function.Module.Name);
					if (reader != null) {
						ISymbolMethod met = reader.GetMethod (new SymbolToken (frame.Function.Token));
						if (met != null) {
							CorDebugMappingResult mappingResult;
							frame.GetIP (out address, out mappingResult);
							SequencePoint prevSp = null;
							foreach (SequencePoint sp in met.GetSequencePoints ()) {
								if (sp.Offset > address)
									break;
								prevSp = sp;
							}
							if (prevSp != null) {
								line = prevSp.Line;
								column = prevSp.Offset;
								file = prevSp.Document.URL;
								address = (uint)prevSp.Offset;
							}
						}
					}
					// FIXME: Still steps into.
					//hidden = mi.GetCustomAttributes (true).Any (v => v is System.Diagnostics.DebuggerHiddenAttribute);
				}
				lang = "Managed";
				hasDebugInfo = true;
			}
			else if (frame.FrameType == CorFrameType.NativeFrame) {
				frame.GetNativeIP (out address);
				method = "<Unknown>";
				lang = "Native";
			}
			else if (frame.FrameType == CorFrameType.InternalFrame) {
				switch (frame.InternalFrameType) {
					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, column);
			return new StackFrame ((long) address, addressSpace, loc, lang, external, hasDebugInfo, hidden, null, null);
		}
Exemplo n.º 12
0
        internal static StackFrame CreateFrame(CorDebuggerSession session, CorFrame frame)
        {
            uint   address = 0;
            string file    = "";
            int    line    = 0;
            string method  = "";
            string lang    = "";
            string module  = "";

            if (frame.FrameType == CorFrameType.ILFrame)
            {
                if (frame.Function != null)
                {
                    module = frame.Function.Module.Name;
                    CorMetadataImport importer = new CorMetadataImport(frame.Function.Module);
                    MethodInfo        mi       = importer.GetMethodInfo(frame.Function.Token);
                    method = mi.DeclaringType.FullName + "." + mi.Name;
                    ISymbolReader reader = session.GetReaderForModule(frame.Function.Module.Name);
                    if (reader != null)
                    {
                        ISymbolMethod met = reader.GetMethod(new SymbolToken(frame.Function.Token));
                        if (met != null)
                        {
                            uint offset;
                            CorDebugMappingResult mappingResult;
                            frame.GetIP(out offset, out mappingResult);
                            SequencePoint prevSp = null;
                            foreach (SequencePoint sp in met.GetSequencePoints())
                            {
                                if (sp.Offset > offset)
                                {
                                    break;
                                }
                                prevSp = sp;
                            }
                            if (prevSp != null)
                            {
                                line = prevSp.Line;
                                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 (frame.InternalFrameType)
                {
                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>";
            }
            return(new StackFrame((long)address, module, method, file, line, lang));
        }
        public static SequencePoint GetSequencePoint(CorDebuggerSession session, CorFrame frame)
        {
            ISymbolReader reader = session.GetReaderForModule(frame.Function.Module.Name);

            if (reader == null)
            {
                return(null);
            }

            ISymbolMethod met = reader.GetMethod(new SymbolToken(frame.Function.Token));

            if (met == null)
            {
                return(null);
            }

            int SequenceCount = met.SequencePointCount;

            if (SequenceCount <= 0)
            {
                return(null);
            }

            CorDebugMappingResult mappingResult;
            uint ip;

            frame.GetIP(out ip, out mappingResult);
            if (mappingResult == CorDebugMappingResult.MAPPING_NO_INFO || mappingResult == CorDebugMappingResult.MAPPING_UNMAPPED_ADDRESS)
            {
                return(null);
            }

            int[]             offsets    = new int[SequenceCount];
            int[]             lines      = new int[SequenceCount];
            int[]             endLines   = new int[SequenceCount];
            int[]             columns    = new int[SequenceCount];
            int[]             endColumns = new int[SequenceCount];
            ISymbolDocument[] docs       = new ISymbolDocument[SequenceCount];
            met.GetSequencePoints(offsets, docs, lines, columns, endLines, endColumns);

            if ((SequenceCount > 0) && (offsets [0] <= ip))
            {
                int i;
                for (i = 0; i < SequenceCount; ++i)
                {
                    if (offsets [i] >= ip)
                    {
                        break;
                    }
                }

                if ((i == SequenceCount) || (offsets [i] != ip))
                {
                    --i;
                }

                if (lines [i] == SpecialSequencePoint)
                {
                    int j = i;
                    // let's try to find a sequence point that is not special somewhere earlier in the code
                    // stream.
                    while (j > 0)
                    {
                        --j;
                        if (lines [j] != SpecialSequencePoint)
                        {
                            return(new SequencePoint()
                            {
                                IsSpecial = true,
                                Offset = offsets [j],
                                StartLine = lines [j],
                                EndLine = endLines [j],
                                StartColumn = columns [j],
                                EndColumn = endColumns [j],
                                Document = docs [j]
                            });
                        }
                    }
                    // we didn't find any non-special seqeunce point before current one, let's try to search
                    // after.
                    j = i;
                    while (++j < SequenceCount)
                    {
                        if (lines [j] != SpecialSequencePoint)
                        {
                            return(new SequencePoint()
                            {
                                IsSpecial = true,
                                Offset = offsets [j],
                                StartLine = lines [j],
                                EndLine = endLines [j],
                                StartColumn = columns [j],
                                EndColumn = endColumns [j],
                                Document = docs [j]
                            });
                        }
                    }

                    // Even if sp is null at this point, it's a valid scenario to have only special sequence
                    // point in a function.  For example, we can have a compiler-generated default ctor which
                    // doesn't have any source.
                    return(null);
                }
                else
                {
                    return(new SequencePoint()
                    {
                        IsSpecial = false,
                        Offset = offsets [i],
                        StartLine = lines [i],
                        EndLine = endLines [i],
                        StartColumn = columns [i],
                        EndColumn = endColumns [i],
                        Document = docs [i]
                    });
                }
            }
            return(null);
        }
        internal static StackFrame CreateFrame(CorDebuggerSession session, CorFrame frame)
        {
            // TODO: Fix remaining.
            uint address = 0;
            //string typeFQN;
            //string typeFullName;
            string addressSpace = "";
            string file         = "";
            int    line         = 0;
            int    column       = 0;
            string method       = "";
            string lang         = "";
            string module       = "";
            string type         = "";
            bool   hasDebugInfo = false;
            bool   hidden       = false;
            bool   external     = true;

            if (frame.FrameType == CorFrameType.ILFrame)
            {
                if (frame.Function != null)
                {
                    module = frame.Function.Module.Name;
                    CorMetadataImport importer = new CorMetadataImport(frame.Function.Module);
                    MethodInfo        mi       = importer.GetMethodInfo(frame.Function.Token);
                    method       = mi.DeclaringType.FullName + "." + mi.Name;
                    type         = mi.DeclaringType.FullName;
                    addressSpace = mi.Name;

                    var sp = GetSequencePoint(session, frame);
                    if (sp != null)
                    {
                        line    = sp.StartLine;
                        column  = sp.StartColumn;
                        file    = sp.Document.URL;
                        address = (uint)sp.Offset;
                    }

                    if (session.IsExternalCode(file))
                    {
                        external = true;
                    }
                    else
                    {
                        if (session.Options.ProjectAssembliesOnly)
                        {
                            external = mi.GetCustomAttributes(true).Any(v =>
                                                                        v is System.Diagnostics.DebuggerHiddenAttribute ||
                                                                        v is System.Diagnostics.DebuggerNonUserCodeAttribute);
                        }
                        else
                        {
                            external = mi.GetCustomAttributes(true).Any(v =>
                                                                        v is System.Diagnostics.DebuggerHiddenAttribute);
                        }
                    }
                    hidden = mi.GetCustomAttributes(true).Any(v => v is System.Diagnostics.DebuggerHiddenAttribute);
                }
                lang         = "Managed";
                hasDebugInfo = true;
            }
            else if (frame.FrameType == CorFrameType.NativeFrame)
            {
                frame.GetNativeIP(out address);
                method = "<Unknown>";
                lang   = "Native";
            }
            else if (frame.FrameType == CorFrameType.InternalFrame)
            {
                switch (frame.InternalFrameType)
                {
                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, column);

            return(new StackFrame((long)address, addressSpace, loc, lang, external, hasDebugInfo, hidden, null, null));
        }
Exemplo n.º 15
0
		public static System.Reflection.MethodInfo GetMethodInfo (this CorFunction func, CorDebuggerSession session)
		{
			CorMetadataImport mi = session.GetMetadataForModule (func.Module.Name);
			if (mi != null)
				return mi.GetMethodInfo (func.Token);
			else
				return null;
		}
Exemplo n.º 16
0
        internal static StackFrame CreateFrame(CorDebuggerSession session, CorFrame frame)
        {
            // TODO: Fix remaining.
            uint address = 0;
            //string typeFQN;
            //string typeFullName;
            string addressSpace = "";
            string file         = "";
            int    line         = 0;
            int    column       = 0;
            string method       = "";
            string lang         = "";
            string module       = "";
            string type         = "";
            bool   hasDebugInfo = false;
            bool   hidden       = false;
            bool   external     = true;

            if (frame.FrameType == CorFrameType.ILFrame)
            {
                if (frame.Function != null)
                {
                    module = frame.Function.Module.Name;
                    CorMetadataImport importer = new CorMetadataImport(frame.Function.Module);
                    MethodInfo        mi       = importer.GetMethodInfo(frame.Function.Token);
                    method       = mi.DeclaringType.FullName + "." + mi.Name;
                    type         = mi.DeclaringType.FullName;
                    addressSpace = mi.Name;
                    ISymbolReader reader = session.GetReaderForModule(frame.Function.Module.Name);
                    if (reader != null)
                    {
                        ISymbolMethod met = reader.GetMethod(new SymbolToken(frame.Function.Token));
                        if (met != null)
                        {
                            CorDebugMappingResult mappingResult;
                            frame.GetIP(out address, out mappingResult);
                            SequencePoint prevSp = null;
                            foreach (SequencePoint sp in met.GetSequencePoints())
                            {
                                if (sp.Offset > address)
                                {
                                    break;
                                }
                                prevSp = sp;
                            }
                            if (prevSp != null)
                            {
                                line    = prevSp.Line;
                                column  = prevSp.Offset;
                                file    = prevSp.Document.URL;
                                address = (uint)prevSp.Offset;
                            }
                        }
                    }
                    // FIXME: Still steps into.
                    //hidden = mi.GetCustomAttributes (true).Any (v => v is System.Diagnostics.DebuggerHiddenAttribute);
                }
                lang         = "Managed";
                hasDebugInfo = true;
            }
            else if (frame.FrameType == CorFrameType.NativeFrame)
            {
                frame.GetNativeIP(out address);
                method = "<Unknown>";
                lang   = "Native";
            }
            else if (frame.FrameType == CorFrameType.InternalFrame)
            {
                switch (frame.InternalFrameType)
                {
                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, column);

            return(new StackFrame((long)address, addressSpace, loc, lang, external, hasDebugInfo, hidden, null, null));
        }
Exemplo n.º 17
0
		public static Type GetTypeInfo (this CorType type, CorDebuggerSession session)
		{
			Type t;
			if (CorMetadataImport.CoreTypes.TryGetValue (type.Type, out t))
				return t;

			if (type.Type == CorElementType.ELEMENT_TYPE_ARRAY || type.Type == CorElementType.ELEMENT_TYPE_SZARRAY) {
				List<int> sizes = new List<int> ();
				List<int> loBounds = new List<int> ();
				for (int n = 0; n < type.Rank; n++) {
					sizes.Add (1);
					loBounds.Add (0);
				}
				return MetadataType.MakeArray (type.FirstTypeParameter.GetTypeInfo (session), sizes, loBounds);
			}

			if (type.Type == CorElementType.ELEMENT_TYPE_BYREF)
				return MetadataType.MakeByRef (type.FirstTypeParameter.GetTypeInfo (session));

			if (type.Type == CorElementType.ELEMENT_TYPE_PTR)
				return MetadataType.MakePointer (type.FirstTypeParameter.GetTypeInfo (session));

			CorMetadataImport mi = session.GetMetadataForModule (type.Class.Module.Name);
			if (mi != null) {
				t = mi.GetType (type.Class.Token);
				CorType[] targs = type.TypeParameters;
				if (targs.Length > 0) {
					List<Type> types = new List<Type> ();
					foreach (CorType ct in targs)
						types.Add (ct.GetTypeInfo (session));
					return MetadataType.MakeGeneric (t, types);
				}
				else
					return t;
			}
			else
				return null;
		}
		internal static StackFrame CreateFrame (CorDebuggerSession session, CorFrame frame)
		{
			// TODO: Fix remaining.
			uint address = 0;
			//string typeFQN;
			//string typeFullName;
			string addressSpace = "";
			string file = "";
			int line = 0;
			int endLine = 0;
			int column = 0;
			int endColumn = 0;
			string method = "";
			string lang = "";
			string module = "";
			string type = "";
			bool hasDebugInfo = false;
			bool hidden = false;
			bool external = true;

			if (frame.FrameType == CorFrameType.ILFrame) {
				if (frame.Function != null) {
					module = frame.Function.Module.Name;
					CorMetadataImport importer = new CorMetadataImport (frame.Function.Module);
					MethodInfo mi = importer.GetMethodInfo (frame.Function.Token);
					method = mi.DeclaringType.FullName + "." + mi.Name;
					type = mi.DeclaringType.FullName;
					addressSpace = mi.Name;
					
					var sp = GetSequencePoint (session, frame);
					if (sp != null) {
						line = sp.StartLine;
						column = sp.StartColumn;
						endLine = sp.EndLine;
						endColumn = sp.EndColumn;
						file = sp.Document.URL;
						address = (uint)sp.Offset;
					}

					if (session.IsExternalCode (file)) {
						external = true;
					} else {
						if (session.Options.ProjectAssembliesOnly) {
							external = mi.GetCustomAttributes (true).Any (v => 
								v is System.Diagnostics.DebuggerHiddenAttribute ||
							v is System.Diagnostics.DebuggerNonUserCodeAttribute);
						} else {
							external = mi.GetCustomAttributes (true).Any (v => 
								v is System.Diagnostics.DebuggerHiddenAttribute);
						}
					}
					hidden = mi.GetCustomAttributes (true).Any (v => v is System.Diagnostics.DebuggerHiddenAttribute);
				}
				lang = "Managed";
				hasDebugInfo = true;
			} else if (frame.FrameType == CorFrameType.NativeFrame) {
				frame.GetNativeIP (out address);
				method = "<Unknown>";
				lang = "Native";
			} else if (frame.FrameType == CorFrameType.InternalFrame) {
				switch (frame.InternalFrameType) {
				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, column, endLine, endColumn);
			return new StackFrame ((long)address, addressSpace, loc, lang, external, hasDebugInfo, hidden, null, null);
		}