Example #1
0
		public static bool TryParse (string line, out StackFrameData stackFrame)
		{
			stackFrame = null;

			var match = regex.Match (line);
			if (!match.Success)
				return false;

			string typeFullName, methodSignature;
			var methodStr = match.Groups ["Method"].Value.Trim ();
			if (!ExtractSignatures (methodStr, out typeFullName, out methodSignature))
				return false;

			var isILOffset = !string.IsNullOrEmpty (match.Groups ["IL"].Value);
			var offsetVarName = (isILOffset)? "IL" : "NativeOffset";
			var offset = int.Parse (match.Groups [offsetVarName].Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture);

			uint methodIndex = 0xffffff;
			if (!string.IsNullOrEmpty (match.Groups ["MethodIndex"].Value))
				methodIndex = uint.Parse (match.Groups ["MethodIndex"].Value, CultureInfo.InvariantCulture);

			var mvid = match.Groups ["MVID"].Value;
			var aotid = match.Groups ["AOTID"].Value;

			stackFrame = new StackFrameData (line, typeFullName, methodSignature, offset, isILOffset, methodIndex, mvid, aotid);

			return true;
		}
        internal bool TryResolveLocation(StackFrameData sfData, out Location location)
        {
            if (sfData.Mvid == null)
            {
                location = default;
                return(false);
            }

            var assemblyLocProvider = GetOrCreateAssemblyLocationProvider(sfData.Mvid);

            if (assemblyLocProvider == null)
            {
                location = default;
                return(false);
            }

            SeqPointInfo seqPointInfo = null;

            if (!sfData.IsILOffset && sfData.Aotid != null)
            {
                seqPointInfo = GetOrCreateSeqPointInfo(sfData.Aotid);
            }


            return(assemblyLocProvider.TryResolveLocation(sfData, seqPointInfo, out location));
        }
Example #3
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;
		}
Example #4
0
		internal bool TryResolveLocation (StackFrameData sfData, string mvid, string aotid)
		{
			if (mvid == null)
				return false;

			var assemblyLocProvider = GetOrCreateAssemblyLocationProvider (mvid);
			if (assemblyLocProvider == null)
				return false;

			SeqPointInfo seqPointInfo = null;
			if (!sfData.IsILOffset && aotid != null)
				seqPointInfo = GetOrCreateSeqPointInfo (aotid);

			return assemblyLocProvider.TryResolveLocation (sfData, seqPointInfo);
		}
Example #5
0
        public static StringBuilder Process(StreamReader reader, SymbolManager symbolManager)
        {
            List <StackFrameData>     stackFrames = new List <StackFrameData>();
            List <StackTraceMetadata> metadata    = new List <StackTraceMetadata>();
            StringBuilder             sb          = new StringBuilder();
            bool linesEnded = false;

            for (var line = reader.ReadLine(); line != null; line = reader.ReadLine())
            {
                StackFrameData sfData;
                if (!linesEnded && StackFrameData.TryParse(line, out sfData))
                {
                    stackFrames.Add(sfData);
                    continue;
                }

                if (stackFrames.Count > 0)
                {
                    linesEnded = true;

                    StackTraceMetadata stMetadata;
                    if (StackTraceMetadata.TryParse(line, out stMetadata))
                    {
                        metadata.Add(stMetadata);
                        continue;
                    }

                    DumpStackTrace(symbolManager, sb, stackFrames, metadata);

                    // Clear lists for next stack trace
                    stackFrames.Clear();
                    metadata.Clear();
                }

                linesEnded = false;

                // Append last line
                sb.AppendLine(line);
            }

            if (stackFrames.Count > 0)
            {
                DumpStackTrace(symbolManager, sb, stackFrames, metadata);
            }

            return(sb);
        }
Example #6
0
        private static void SymbolicateAction(List <string> args)
        {
            var msymDir   = args [0];
            var inputFile = args [1];

            var symbolManager = new SymbolManager(msymDir, logger);

            using (StreamReader r = new StreamReader(inputFile)) {
                for (var line = r.ReadLine(); line != null; line = r.ReadLine())
                {
                    if (StackFrameData.TryParse(line, out var sfData) && symbolManager.TryResolveLocation(sfData, out var location))
                    {
                        var sign = sfData.Line.Substring(0, sfData.Line.IndexOf(" in <", StringComparison.Ordinal));
                        line = $"{sign} in {location.File}:{location.Line}";
                    }

                    Console.WriteLine(line);
                }
            }
        }
Example #7
0
        private static void SymbolicateAction(List <string> args)
        {
            var msymDir   = args [0];
            var inputFile = args [1];

            var symbolManager = new SymbolManager(msymDir, logger);

            using (StreamReader r = new StreamReader(inputFile)) {
                for (var line = r.ReadLine(); line != null; line = r.ReadLine())
                {
                    StackFrameData sfData;
                    if (StackFrameData.TryParse(line, out sfData) &&
                        symbolManager.TryResolveLocation(sfData))
                    {
                        Console.WriteLine(sfData.ToString());
                        continue;
                    }

                    Console.WriteLine(line);
                }
            }
        }
Example #8
0
        public static bool TryParse(string line, out StackFrameData stackFrame)
        {
            stackFrame = null;

            var match = regex.Match(line);

            if (!match.Success)
            {
                if (line.Trim().StartsWith("at ", StringComparison.InvariantCulture))
                {
                    stackFrame = new StackFrameData(line);
                    return(true);
                }
                return(false);
            }

            string typeFullName, methodSignature;
            var    methodStr = match.Groups ["Method"].Value.Trim();

            if (!ExtractSignatures(methodStr, out typeFullName, out methodSignature))
            {
                return(false);
            }

            var isILOffset    = !string.IsNullOrEmpty(match.Groups ["IL"].Value);
            var offsetVarName = (isILOffset)? "IL" : "NativeOffset";
            var offset        = int.Parse(match.Groups [offsetVarName].Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture);

            uint methodIndex = 0xffffff;

            if (!string.IsNullOrEmpty(match.Groups ["MethodIndex"].Value))
            {
                methodIndex = uint.Parse(match.Groups ["MethodIndex"].Value, CultureInfo.InvariantCulture);
            }

            stackFrame = new StackFrameData(line, typeFullName, methodSignature, offset, isILOffset, methodIndex);

            return(true);
        }
Example #9
0
        internal bool TryResolveLocation(StackFrameData sfData, string mvid, string aotid)
        {
            if (mvid == null)
            {
                return(false);
            }

            var assemblyLocProvider = GetOrCreateAssemblyLocationProvider(mvid);

            if (assemblyLocProvider == null)
            {
                return(false);
            }

            SeqPointInfo seqPointInfo = null;

            if (!sfData.IsILOffset && aotid != null)
            {
                seqPointInfo = GetOrCreateSeqPointInfo(aotid);
            }

            return(assemblyLocProvider.TryResolveLocation(sfData, seqPointInfo));
        }
        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 #11
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 #12
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 #13
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);
        }