SetLocation() private method

private SetLocation ( string file, int lineNumber ) : void
file string
lineNumber int
return void
Exemplo n.º 1
0
		public bool TryResolveLocation (StackFrameData sfData, SeqPointInfo seqPointInfo)
		{
			if (!assembly.MainModule.HasSymbols)
				return false;

			TypeDefinition type = null;
			var nested = sfData.TypeFullName.Split ('+');
			var types = assembly.MainModule.Types;
			foreach (var ntype in nested) {
				if (type == null) {
					// Use namespace first time.
					type = types.FirstOrDefault (t => t.FullName == ntype);
				} else {
					type = types.FirstOrDefault (t => t.Name == ntype);
				}

				if (type == null) {
					logger.LogWarning ("Could not find type: {0}", ntype);
					return false;
				}

				types = type.NestedTypes;
			}

			var parensStart = sfData.MethodSignature.IndexOf ('(');
			var methodName = sfData.MethodSignature.Substring (0, parensStart).TrimEnd ();
			var methodParameters = sfData.MethodSignature.Substring (parensStart);
			var method = type.Methods.FirstOrDefault (m => CompareName (m, methodName) && CompareParameters (m.Parameters, methodParameters));
			if (method == null) {
				logger.LogWarning ("Could not find method: {0}", methodName);
				return false;
			}

			int ilOffset;
			if (sfData.IsILOffset) {
				ilOffset = sfData.Offset;
			} else {
				if (seqPointInfo == null)
					return false;

				ilOffset = seqPointInfo.GetILOffset (method.MetadataToken.ToInt32 (), sfData.MethodIndex, sfData.Offset);
			}

			if (ilOffset < 0)
				return false;

			SequencePoint sp = null;
			foreach (var instr in method.Body.Instructions) {
				if (instr.SequencePoint != null)
					sp = instr.SequencePoint;
				
				if (instr.Offset >= ilOffset) {
					sfData.SetLocation (sp.Document.Url, sp.StartLine);
					return true;
				}
			}

			return false;
		}
Exemplo n.º 2
0
		public bool TryResolveLocation (StackFrameData sfData, SeqPointInfo seqPointInfo)
		{
			if (!assembly.MainModule.HasSymbols)
				return false;

			TypeDefinition type = null;
			string[] nested;
			if (sfData.TypeFullName.IndexOf ('/') >= 0)
				 nested = sfData.TypeFullName.Split ('/');
			else
				nested = sfData.TypeFullName.Split ('+');

			var types = assembly.MainModule.Types;
			foreach (var ntype in nested) {
				if (type == null) {
					// Use namespace first time.
					type = types.FirstOrDefault (t => t.FullName == ntype);
				} else {
					type = types.FirstOrDefault (t => t.Name == ntype);
				}

				if (type == null) {
					logger.LogWarning ("Could not find type: {0}", ntype);
					return false;
				}

				types = type.NestedTypes;
			}

			var parensStart = sfData.MethodSignature.IndexOf ('(');
			var methodName = sfData.MethodSignature.Substring (0, parensStart).TrimEnd ();
			var methodParameters = sfData.MethodSignature.Substring (parensStart);
			var methods = type.Methods.Where (m => CompareName (m, methodName) && CompareParameters (m.Parameters, methodParameters)).ToArray ();
			if (methods.Length == 0) {
				logger.LogWarning ("Could not find method: {0}", methodName);
				return false;
			}
			if (methods.Length > 1) {
				logger.LogWarning ("Ambiguous match for method: {0}", sfData.MethodSignature);
				return false;
			}
			var method = methods [0];

			int ilOffset;
			if (sfData.IsILOffset) {
				ilOffset = sfData.Offset;
			} else {
				if (seqPointInfo == null)
					return false;

				ilOffset = seqPointInfo.GetILOffset (method.MetadataToken.ToInt32 (), sfData.MethodIndex, sfData.Offset);
			}

			if (ilOffset < 0)
				return false;

			if (!method.DebugInformation.HasSequencePoints)
				return false;

			SequencePoint prev = null;
			foreach (var sp in method.DebugInformation.SequencePoints.OrderBy (l => l.Offset)) {
				if (sp.Offset >= ilOffset) {
					sfData.SetLocation (sp.Document.Url, sp.StartLine);
					return true;
				}

				prev = sp;
			}

			if (prev != null) {
				sfData.SetLocation (prev.Document.Url, prev.StartLine);
				return true;
			}

			return false;
		}
Exemplo n.º 3
0
        public bool TryResolveLocation(StackFrameData sfData, SeqPointInfo seqPointInfo)
        {
            if (!assembly.MainModule.HasSymbols)
            {
                return(false);
            }

            TypeDefinition type = null;

            string[] nested;
            if (sfData.TypeFullName.IndexOf('/') >= 0)
            {
                nested = sfData.TypeFullName.Split('/');
            }
            else
            {
                nested = sfData.TypeFullName.Split('+');
            }

            var types = assembly.MainModule.Types;

            foreach (var ntype in nested)
            {
                if (type == null)
                {
                    // Use namespace first time.
                    type = types.FirstOrDefault(t => t.FullName == ntype);
                }
                else
                {
                    type = types.FirstOrDefault(t => t.Name == ntype);
                }

                if (type == null)
                {
                    logger.LogWarning("Could not find type: {0}", ntype);
                    return(false);
                }

                types = type.NestedTypes;
            }

            var parensStart      = sfData.MethodSignature.IndexOf('(');
            var methodName       = sfData.MethodSignature.Substring(0, parensStart).TrimEnd();
            var methodParameters = sfData.MethodSignature.Substring(parensStart);
            var methods          = type.Methods.Where(m => CompareName(m, methodName) && CompareParameters(m.Parameters, methodParameters)).ToArray();

            if (methods.Length == 0)
            {
                logger.LogWarning("Could not find method: {0}", methodName);
                return(false);
            }
            if (methods.Length > 1)
            {
                logger.LogWarning("Ambiguous match for method: {0}", sfData.MethodSignature);
                return(false);
            }
            var method = methods [0];

            int ilOffset;

            if (sfData.IsILOffset)
            {
                ilOffset = sfData.Offset;
            }
            else
            {
                if (seqPointInfo == null)
                {
                    return(false);
                }

                ilOffset = seqPointInfo.GetILOffset(method.MetadataToken.ToInt32(), sfData.MethodIndex, sfData.Offset);
            }

            if (ilOffset < 0)
            {
                return(false);
            }

            if (!method.DebugInformation.HasSequencePoints)
            {
                return(false);
            }

            SequencePoint prev = null;

            foreach (var sp in method.DebugInformation.SequencePoints.OrderBy(l => l.Offset))
            {
                if (sp.Offset >= ilOffset)
                {
                    sfData.SetLocation(sp.Document.Url, sp.StartLine);
                    return(true);
                }

                prev = sp;
            }

            if (prev != null)
            {
                sfData.SetLocation(prev.Document.Url, prev.StartLine);
                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        public bool TryResolveLocation(StackFrameData sfData, SeqPointInfo seqPointInfo)
        {
            if (!assembly.MainModule.HasSymbols)
            {
                return(false);
            }

            TypeDefinition type   = null;
            var            nested = sfData.TypeFullName.Split('+');
            var            types  = assembly.MainModule.Types;

            foreach (var ntype in nested)
            {
                if (type == null)
                {
                    // Use namespace first time.
                    type = types.FirstOrDefault(t => t.FullName == ntype);
                }
                else
                {
                    type = types.FirstOrDefault(t => t.Name == ntype);
                }

                if (type == null)
                {
                    logger.LogWarning("Could not find type: {0}", ntype);
                    return(false);
                }

                types = type.NestedTypes;
            }

            var parensStart      = sfData.MethodSignature.IndexOf('(');
            var methodName       = sfData.MethodSignature.Substring(0, parensStart).TrimEnd();
            var methodParameters = sfData.MethodSignature.Substring(parensStart);
            var method           = type.Methods.FirstOrDefault(m => CompareName(m, methodName) && CompareParameters(m.Parameters, methodParameters));

            if (method == null)
            {
                logger.LogWarning("Could not find method: {0}", methodName);
                return(false);
            }

            int ilOffset;

            if (sfData.IsILOffset)
            {
                ilOffset = sfData.Offset;
            }
            else
            {
                if (seqPointInfo == null)
                {
                    return(false);
                }

                ilOffset = seqPointInfo.GetILOffset(method.MetadataToken.ToInt32(), sfData.MethodIndex, sfData.Offset);
            }

            if (ilOffset < 0)
            {
                return(false);
            }

            SequencePoint sp = null;

            foreach (var instr in method.Body.Instructions)
            {
                if (instr.SequencePoint != null)
                {
                    sp = instr.SequencePoint;
                }

                if (instr.Offset >= ilOffset)
                {
                    sfData.SetLocation(sp.Document.Url, sp.StartLine);
                    return(true);
                }
            }

            return(false);
        }