Ejemplo n.º 1
0
        private string GetFrameInformation(ClrThread thread, ClrStackFrame frame, ClrStackFrame firstFrame)
        {
            // get the method call from the given frame
            string info           = "";
            var    sourceLocation = frame.GetFileAndLineNumber();

            if (sourceLocation == null)
            {
                info = frame.DisplayString;
            }
            else  // it seems that GetFileAndLineNumber() does not work --> need to figure out what is the other ClrMD API to dig into the symbols
            {
                info = frame.DisplayString + "[" + sourceLocation.FilePath + ", Line " + sourceLocation.LineNumber.ToString() + "]";
            }

            // look for locking information
            if (firstFrame.Method.Name.Contains("Wait") || (firstFrame.Method.Name == "Enter") && (firstFrame.Method.Type.Name == "System.Threading.Monitor"))
            {
                // special case for MonitorEnter --> not a WaitHandle to wait on
                bool isMonitorEnter = (firstFrame.Method.Name == "Enter") && (firstFrame.Method.Type.Name == "System.Threading.Monitor");

                info = info + "\r\n                             => " + firstFrame.Method.Type.Name + "." + firstFrame.Method.Name;

                // look for object used as lock
                int maxStackObjects = 10;
                foreach (var so in thread.EnumerateStackObjects(true))
                {
                    if (so == null)
                    {
                        continue;
                    }

                    var type = so.Type;
                    if (so.Type == null)
                    {
                        continue;
                    }

                    string typeName = so.Type.Name;
                    if (typeName.Contains("WaitHandle") || isMonitorEnter)
                    {
                        info = info + string.Format("({0} = 0x{1:X16})\r\n", typeName, so.Object);
                        break;
                    }
                    else
                    {
                    }

                    maxStackObjects--;
                    if (maxStackObjects == 0)
                    {
                        break;
                    }
                }
            }

            return(info);
        }
Ejemplo n.º 2
0
        public SourceLocation GetFileAndLineNumberSafe(ClrStackFrame frame)
        {
            if (frame.Method == null || frame.Method.Type == null || frame.Method.Type.Module == null)
            {
                return(null);
            }

            string moduleName = frame.Method.Type.Module.Name;

            if (_failedToLoadSymbols.Contains(moduleName))
            {
                return(null);
            }

            // ClrStackFrame.GetFileAndLineNumber throws occasionally when something is wrong with the module.
            try
            {
                var location = frame.GetFileAndLineNumber();
                if (location == null)
                {
                    _failedToLoadSymbols.Add(moduleName);
                }

                return(location);
            }
            catch (ClrDiagnosticsException)
            {
                _failedToLoadSymbols.Add(moduleName);
                return(null);
            }
            catch (InvalidOperationException)
            {
                _failedToLoadSymbols.Add(moduleName);
                return(null);
            }
        }