public void TestExecute() { Mock<IDebugClient> mockClient=new Mock<IDebugClient>(); Debugger debug = new Debugger(mockClient.Object); }
public static string Execute(string args, IDebugClient debugClient) { if(CSDebugger==null) { IDebugClient client; debugClient.CreateClient(out client); mngdDebugClient = client; var windbgDebugger = new Debugger(client); CSDebugger = windbgDebugger; } //testig the execute function //string interoutput = windbgDebugger.Execute("k"); //windbgDebugger.OutputLine(interoutput); bool persistSession = true; //windbgDebugger.OutputLine("starting {0} ", "Execute"); Output = string.Empty; try { ArgumentsHelper arguments = new ArgumentsHelper(args); if (!arguments.HasArgument("-help")) { ScriptContext context = new ScriptContext(); Debugger.Current.Context = context; context.Debug = IsDebugMode; if (arguments.HasArgument("-file")) { isScript = false; ParsedPath = arguments["-file"]; context.Args = arguments; context.ScriptLocation = Path.GetDirectoryName(ParsedPath); persistSession = true; } else if (arguments.HasArgument("-debug")) { if (IsDebugMode) { IsDebugMode = false; Debugger.Current.Output("Script debug mode is off\n"); } else { IsDebugMode = true; Debugger.Current.Output("Script debug mode is on\n"); } return ""; } else if (arguments.HasArgument("-clear")) { Session = null; DebuggerScriptEngine.Clear(); Debugger.Current.Output("Script session cleared\n"); Output = string.Empty; return "Session cleared"; } else { isScript = true; CSScript = args; } var session = CreateSession(CSDebugger, persistSession); //session.Execute("using WindbgManagedExt;"); //Submission<Object> CSession = session.CompileSubmission<Object>(CSScript); //var references = CSession.Compilation.References; //foreach (MetadataReference reference in references) //{ // if (reference.Display.Contains("ExtCS.Debugger")) // CSession.Compilation.RemoveReferences(reference); //} if (isScript) session.Execute(CSScript); else { if (CSDebugger.Context.Debug) DebuggerScriptEngine.Execute(session, ParsedPath); else session.ExecuteFile(ParsedPath); } } else ShowHelp(arguments["-help"]); } catch (Exception ex) { Session = null; CSDebugger.OutputError("\n\nException while executing the script {0}", ex.Message); CSDebugger.OutputDebugInfo("\n Details: {0} \n", ex.ToString()); } //windbgDebugger.OutputLine("ending Execute"); CSDebugger.Output(Output); CSDebugger.Output("\n"); Output = ""; return Output; }
private static Session CreateSession(Debugger currentDebugger,bool getOldSession) { //CSScript = script; //var s = new CommonScriptEngine(); if (getOldSession && Session != null) return Session; var asm = System.Reflection.Assembly.GetExecutingAssembly(); var csharpEngine = new ScriptEngine(null, null); //csharpEngine.AddReference("System.Diagnostics"); csharpEngine.ImportNamespace("System"); csharpEngine.ImportNamespace("System.Collections.Generic"); //csharpEngine.ImportNamespace("System.Linq"); csharpEngine.ImportNamespace("System.Text"); csharpEngine.ImportNamespace("System.IO"); //csharpEngine.ImportNamespace("System.Diagnostics"); csharpEngine.SetReferenceSearchPaths(asm.Location); csharpEngine.AddReference(typeof(System.Diagnostics.Debug).Assembly); csharpEngine.AddReference(typeof(System.Dynamic.DynamicObject).Assembly); csharpEngine.AddReference(asm); csharpEngine.ImportNamespace("ExtCS.Debugger"); Session = csharpEngine.CreateSession(currentDebugger); return Session; }