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); }
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; }