예제 #1
0
 public void LogWarning(StackFrameInfo stackFrame, string message)
 {
     if (stackFrame.IsEmpty)
         Log.LogWarning("{0}", message.Trim());
     else
         Log.LogWarning(null, null, null, stackFrame.FileName, stackFrame.LineNumber, 0, 0, 0, "{0}", message.Trim());
 }
예제 #2
0
        private static string BuildLineForStackFrame(StackFrameInfo frameInfo)
        {
            var builder = new StringBuilder("<pre>");
            var stackFrame = frameInfo.StackFrame;
            var method = stackFrame.GetMethod();

            // Special case: no method available
            if (method == null)
            {
                return null;
            }

            // First, write the type name
            var type = method.DeclaringType;
            if (type != null)
            {
                // Special-case ExceptionDispatchInfo.Throw()
                if (type == typeof(ExceptionDispatchInfo) && method.Name == "Throw")
                {
                    return @"<pre><span class=""faded"">--- exception rethrown ---</span></pre>";
                }

                string prefix, friendlyName;
                SplitTypeIntoPrefixAndFriendlyName(type, out prefix, out friendlyName);
                builder.AppendFormat(CultureInfo.InvariantCulture, @"<span class=""faded"">at {0}</span>", HtmlEncodeAndReplaceLineBreaks(prefix));
                builder.Append(HtmlEncodeAndReplaceLineBreaks(friendlyName));
            }

            // Next, write the method signature
            builder.Append(HtmlEncodeAndReplaceLineBreaks("." + method.Name));

            // Is this method generic?
            if (method.IsGenericMethod)
            {
                builder.Append(HtmlEncodeAndReplaceLineBreaks(BuildMethodGenericParametersUnescaped(method)));
            }

            // Build method parameters
            builder.AppendFormat(CultureInfo.InvariantCulture, @"<span class=""faded"">{0}</span>", HtmlEncodeAndReplaceLineBreaks(BuildMethodParametersUnescaped(method)));

            // Do we have source information for this frame?
            if (stackFrame.GetILOffset() != -1)
            {
                var filename = frameInfo.FilePath;
                if (!string.IsNullOrEmpty(filename))
                {
                    builder.AppendFormat(CultureInfo.InvariantCulture, " in {0}:line {1:D}", HtmlEncodeAndReplaceLineBreaks(filename), frameInfo.LineNumber);
                }
            }

            // Finish
            builder.Append("</pre>");
            return builder.ToString();
        }
예제 #3
0
        private static string BuildCodeSnippetDiv(StackFrameInfo frameInfo)
        {
            var filename = frameInfo.FilePath;
            if (!string.IsNullOrEmpty(filename))
            {
                int failingLineNumber = frameInfo.LineNumber;
                if (failingLineNumber >= 1)
                {
                    var lines = GetFailingCallSiteInFile(filename, failingLineNumber);
                    if (lines != null)
                    {
                        return @"<div class=""codeSnippet"">"
                            + @"<div class=""filename""><code>" + HtmlEncodeAndReplaceLineBreaks(filename) + "</code></div>" + Environment.NewLine
                            + string.Join(Environment.NewLine, lines) + "</div>" + Environment.NewLine;
                    }
                }
            }

            // fallback
            return null;
        }
 public void LogWarning(StackFrameInfo stackFrame, string message)
 {
     loggerHelper.LogWarning("{0}", message);
 }
 public void LogImportantMessage(StackFrameInfo stackFrame, string message)
 {
     loggerHelper.Log("{0}", message);
 }
 public void LogError(StackFrameInfo stackFrame, string message)
 {
     loggerHelper.LogError("{0}", message);
 }
예제 #7
0
 public void LogImportantMessage(StackFrameInfo stackFrame, string message)
 {
 }
예제 #8
0
 public void LogMessage(StackFrameInfo stackFrame, string message)
 {
     Log.LogMessage("{0}", message);
 }
예제 #9
0
 public void LogMessage(StackFrameInfo stackFrame, string message)
 {
     AddMessage("---", stackFrame, message);
 }
예제 #10
0
 public void LogImportantMessage(StackFrameInfo stackFrame, string message)
 {
     AddMessage("Imp", stackFrame, message);
 }
예제 #11
0
 public void LogError(StackFrameInfo stackFrame, string message)
 {
     AddMessage("Err", stackFrame, message);
 }
예제 #12
0
        public VSCodeStackFrame(StackFrameInfo info, VSCodeThread thread, int index)
        {
            this.info   = info;
            this.thread = thread;
            this.Index  = index;
            frame       = new StackFrame()
            {
                Name = info.MethodName,
                Id   = GetHashCode()
            };
            FileLinePositionSpan span = default;

            if (!string.IsNullOrEmpty(info.DocumentName))
            {
                frame.Source = new Source()
                {
                    Name = Path.GetFileName(info.DocumentName), Path = info.DocumentName
                };
                frame.Line      = info.StartLine + 1;
                frame.EndLine   = info.EndLine + 1;
                frame.Column    = info.StartColumn + 1;
                frame.EndColumn = info.EndColumn + 1;

                if (File.Exists(info.DocumentName))
                {
                    using (var stream = File.OpenRead(info.DocumentName))
                    {
                        try
                        {
                            SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(SourceText.From(stream), path: info.DocumentName);
                            TextLine   textLine   = syntaxTree.GetText().Lines[info.StartLine];
                            Location   location   = syntaxTree.GetLocation(textLine.Span);
                            SyntaxTree sourceTree = location.SourceTree;
                            SyntaxNode node       = location.SourceTree.GetRoot().FindNode(location.SourceSpan, true, true);

                            bool isLambda = GetParentMethod <LambdaExpressionSyntax>(node.Parent) != null;
                            BaseMethodDeclarationSyntax method = GetParentMethod <MethodDeclarationSyntax>(node.Parent);
                            if (method == null)
                            {
                                method = GetParentMethod <ConstructorDeclarationSyntax>(node.Parent);
                            }
                            if (method != null)
                            {
                                span = syntaxTree.GetLineSpan(method.FullSpan);
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
            args   = new VSCodeScope(this, frame, Scope.PresentationHintValue.Arguments, info.ArgumentCount, 0, span);
            locals = new VSCodeScope(this, frame, Scope.PresentationHintValue.Locals, info.LocalVariables != null ? info.LocalVariables.Length - info.ArgumentCount : 0, info.ArgumentCount, span);

            foreach (var i in args.Variables)
            {
                propertyMapping[i.Variable.Name] = i;
            }
            foreach (var i in locals.Variables)
            {
                propertyMapping[i.Variable.Name] = i;
            }
        }
예제 #13
0
파일: MonCVMTool.cs 프로젝트: sfuller/MonC
        private static bool DebuggerLoop(VirtualMachine vm, Debugger debugger, VMDebugger vmDebugger)
        {
            Console.Write("(moncdbg) ");

            string line = Console.ReadLine();

            string[] args;
            if (line != null)
            {
                args = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                args = Array.Empty <string>();
            }

            string command = "";

            if (args.Length > 0)
            {
                command = args[0];
            }

            switch (command)
            {
            case "reg": {
                StackFrameInfo frame = vm.GetStackFrame(0);
                Console.WriteLine($"Function: {frame.Function}, PC: {frame.PC}");
                string sourcePath;
                int    lineNumber;
                if (debugger.GetSourceLocation(frame, out sourcePath, out lineNumber))
                {
                    Console.WriteLine($"File: {sourcePath}, Line: {lineNumber + 1}");
                }
            }
            break;

            case "read":
                StackFrameMemory memory = vm.GetStackFrameMemory(0);
                for (int i = 0, ilen = memory.Size; i < ilen; ++i)
                {
                    if (i % 4 == 0 && i != 0)
                    {
                        Console.WriteLine();
                    }

                    Console.Write(memory.Read(i) + "\t");
                }

                Console.WriteLine();
                break;

            case "bp": {
                if (args.Length < 2)
                {
                    Console.WriteLine("Not enough args");
                    break;
                }

                int breakpointLineNumber;
                int.TryParse(args[1], out breakpointLineNumber);
                StackFrameInfo frame = vm.GetStackFrame(0);
                string         sourcePath;
                if (!debugger.GetSourceLocation(frame, out sourcePath, out _))
                {
                    sourcePath = "";
                }

                Console.WriteLine($"Assuming source file is {sourcePath}");
                debugger.SetBreakpoint(sourcePath !, breakpointLineNumber - 1);
            }
            break;

            case "over":
                return(vmDebugger.StepOver());

            case "into":
                return(vmDebugger.StepInto());

            case "out":
                return(vmDebugger.StepOut());

            case "step":
                return(vmDebugger.Step());

            case "continue":
            case null:
                return(vmDebugger.Continue());

            case "":
                break;

            default:
                Console.Error.WriteLine($"moncdbg: unknown command {line}");
                break;
            }

            return(true);
        }
예제 #14
0
 public void LogWarning(StackFrameInfo stackFrame, string message)
 {
 }
예제 #15
0
 public void LogMessage(StackFrameInfo stackFrame, string message)
 {
 }
예제 #16
0
 public void LogError(StackFrameInfo stackFrame, string message)
 {
     Log.LogError(null, null, null, stackFrame.FileName, stackFrame.LineNumber, 0, 0, 0, "{0}", message.Trim());
 }
예제 #17
0
 public void LogImportantMessage(StackFrameInfo stackFrame, string message)
 {
     Log.LogMessage(MessageImportance.High, "{0}", message);
 }
예제 #18
0
 public void LogWarning(StackFrameInfo stackFrame, string message)
 {
     AddMessage("Wrn", stackFrame, message);
 }
예제 #19
0
 /// <summary>
 /// Logs a high-priority formatted message with stack frame.
 /// </summary>
 /// <param name="logger">The logger</param>
 /// <param name="stackFrame">The stack frame information</param>
 /// <param name="messageFormat">The format of the message to be logged</param>
 /// <param name="args">The format arguments</param>
 public static void LogImportantMessage(this IRunnerLogger logger, StackFrameInfo stackFrame, string messageFormat, params object[] args)
 {
     logger.LogImportantMessage(stackFrame, string.Format(messageFormat, args));
 }
예제 #20
0
 public void LogError(StackFrameInfo stackFrame, string message)
 {
 }