Example #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;
		}
        public bool TryResolveLocation(StackFrameData sfData, SeqPointInfo seqPointInfo, out Location location)
        {
            var readerParameters = new ReaderParameters {
                ReadSymbols = true
            };

            using (var assembly = AssemblyDefinition.ReadAssembly(assemblyFullPath, readerParameters)) {
                if (!assembly.MainModule.HasSymbols)
                {
                    location = default;
                    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);
                        location = default;
                        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);
                    location = default;
                    return(false);
                }
                if (methods.Length > 1)
                {
                    logger.LogWarning("Ambiguous match for method: {0}", sfData.MethodSignature);
                    location = default;
                    return(false);
                }
                var method = methods [0];

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

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

                if (ilOffset < 0)
                {
                    location = default;
                    return(false);
                }

                if (!method.DebugInformation.HasSequencePoints)
                {
                    var async_method = GetAsyncStateMachine(method);
                    if (async_method?.ConstructorArguments?.Count == 1)
                    {
                        string state_machine = ((TypeReference)async_method.ConstructorArguments [0].Value).FullName;
                        return(TryResolveLocation(sfData.Relocate(state_machine, "MoveNext ()"), seqPointInfo, out location));
                    }

                    location = default;
                    return(false);
                }

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

                    prev = sp;
                }

                if (prev != null)
                {
                    location = new Location(prev.Document.Url, prev.StartLine);
                    return(true);
                }

                location = default;
                return(false);
            }
        }
Example #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;
		}
Example #4
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);
        }
Example #5
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);
        }