public override async Task <bool> StartAsync(IToolChain toolchain, IConsole console, IProject project) { var result = await base.StartAsync(toolchain, console, project); if (result) { asyncModeEnabled = (await new GDBSetCommand("mi-async", "on").Execute(this)).Response == ResponseCode.Done; await new SetCommand("new-console", "on").Execute(this); } return(result); }
public override async Task<bool> StartAsync(IToolChain toolchain, IConsole console, IProject project) { var result = await base.StartAsync(toolchain, console, project); if (result) { asyncModeEnabled = (await new GDBSetCommand("mi-async", "on").Execute(this)).Response == ResponseCode.Done; await new SetCommand("new-console", "on").Execute(this); } return result; }
public override async Task <bool> StartAsync(IToolChain toolchain, IConsole console, IProject project) { DebugMode = true; await base.StartAsync(toolchain, console, project, Path.Combine(BaseDirectory, "clrdbg" + Platform.ExecutableExtension), false, Path.GetDirectoryName(project.Executable)); await SafelyExecuteCommand(async() => await new EnablePrettyPrintingCommand().Execute(this)); await SafelyExecuteCommand(async() => await new ExecArgumentsCommand(Path.GetFileName(project.Executable)).Execute(this)); await SafelyExecuteCommand(async() => await new SetBreakPointCommand("Program.cs", 7).Execute(this)); return(true); }
public override async Task <bool> StartAsync(IToolChain toolchain, IConsole console, IProject project) { var result = await base.StartAsync(toolchain, console, project); if (result) { SetAsyncMode((await new GDBSetCommand("mi-async", "on").Execute(this)).Response == ResponseCode.Done); if (Platform.PlatformIdentifier == PlatformID.Win32NT) { await new SetCommand("new-console", "on").Execute(this); } } return(result); }
public async Task <bool> StartAsync(IToolChain toolChain, IConsole console, IProject project) { // Start compiled TypeScript program // IridiumJS is a dependency of the toolchain, so we will use it // For now we will assume `main.js` as the output file // Later it will have to be set in project settings, and read by toolchain scriptExecutionEngine = new JSEngine(); var jsScript = System.IO.File.ReadAllText(Path.Combine(project.LocationDirectory, "main.js")); // Inject console scriptExecutionEngine.VariableContext.console = new JSConsoleAdapter(console); scriptExecutionEngine.Execute(jsScript); //return true; return(false); // hack }
public override async Task <bool> StartAsync(IToolChain toolchain, IConsole console, IProject project) { var result = true; console.WriteLine("[OpenOCD] - Starting GDB Server..."); var settings = GetSettings(project); if (settings == null) { console.WriteLine( "[OpenOCD] - No configuration found for open ocd, check debugger settings for the selected project."); } if (settings.InterfaceConfigFile == null || settings.TargetConfigFile == string.Empty) { console.WriteLine("[OpenOCD] - No configuration file selected. Please configure debug settings for the project."); return(false); //TODO implement error message on the console. } var startInfo = new ProcessStartInfo(); startInfo.Arguments = string.Format("-f \"{0}\" -f \"{1}\"", settings.InterfaceConfigFile, settings.TargetConfigFile); startInfo.FileName = Path.Combine(BaseDirectory, "bin", "openocd" + Platform.ExecutableExtension); if (Path.IsPathRooted(startInfo.FileName) && !System.IO.File.Exists(startInfo.FileName)) { console.WriteLine("[OpenOCD] - Error unable to find executable."); return(false); } // Hide console window startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; startInfo.UseShellExecute = false; startInfo.CreateNoWindow = true; startInfo.WorkingDirectory = BaseDirectory; var processes = Process.GetProcessesByName("openocd"); foreach (var process in processes) { process.Kill(); } Task.Factory.StartNew(async() => { using (var process = Process.Start(startInfo)) { openOcdProcess = process; process.OutputDataReceived += (sender, e) => { if (!string.IsNullOrEmpty(e.Data)) { console.WriteLine("[OpenOCD] - " + e.Data); } }; process.ErrorDataReceived += (sender, e) => { if (DebugMode && !string.IsNullOrEmpty(e.Data)) { console.WriteLine("[OpenOCD] - " + e.Data); } ; }; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); await CloseAsync(); console.WriteLine("[OpenOCD] - GDB Server Closed."); openOcdProcess = null; result = false; } }); //Prevent stopped events until we have completed download and reset. StoppedEventIsEnabled = false; Thread.Sleep(500); //Only way to wait if openocd timesout. i.e. because already running? if (result) { result = await base.StartAsync(toolchain, console, project); if (result) { console.WriteLine("[OpenOCD] - Connecting..."); asyncModeEnabled = (await new GDBSetCommand("mi-async", "on").Execute(this)).Response == ResponseCode.Done; result = (await new TargetSelectCommand(":3333").Execute(this)).Response == ResponseCode.Done; if (result) { await new MonitorCommand("reset halt").Execute(this); await new MonitorCommand("speed 8000").Execute(this); await new TargetDownloadCommand().Execute(this); await new MonitorCommand("reset halt").Execute(this); console.WriteLine("[OpenOCD] - Connected."); } StoppedEventIsEnabled = true; } } if (!result) { console.WriteLine( "[OpenOCD] - Unable to connect. Ensure target is powered, connected and that debug settings are correct."); if (openOcdProcess != null && !openOcdProcess.HasExited) { openOcdProcess.Kill(); } } return(result); }
public ToolchainSettingsFormViewModel(CPlusPlusProject project) : base("Toolchain", project) { toolchains = new List <IToolChain>(IoC.Get <IShell>().ToolChains); selectedToolchain = project.ToolChain; }
public override async Task<bool> StartAsync(IToolChain toolchain, IConsole console, IProject project) { var result = true; console.WriteLine("[OpenOCD] - Starting GDB Server..."); var settings = GetSettings(project); if (settings == null) { console.WriteLine( "[OpenOCD] - No configuration found for open ocd, check debugger settings for the selected project."); } if (settings.InterfaceConfigFile == null || settings.TargetConfigFile == string.Empty) { console.WriteLine("[OpenOCD] - No configuration file selected. Please configure debug settings for the project."); return false; //TODO implement error message on the console. } var startInfo = new ProcessStartInfo(); startInfo.Arguments = string.Format("-f \"{0}\" -f \"{1}\"", settings.InterfaceConfigFile, settings.TargetConfigFile); startInfo.FileName = Path.Combine(BaseDirectory, "bin", "openocd" + Platform.ExecutableExtension); if (Path.IsPathRooted(startInfo.FileName) && !System.IO.File.Exists(startInfo.FileName)) { console.WriteLine("[OpenOCD] - Error unable to find executable."); return false; } // Hide console window startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; startInfo.UseShellExecute = false; startInfo.CreateNoWindow = true; startInfo.WorkingDirectory = BaseDirectory; var processes = Process.GetProcessesByName("openocd"); foreach (var process in processes) { process.Kill(); } Task.Factory.StartNew(async () => { using (var process = Process.Start(startInfo)) { openOcdProcess = process; process.OutputDataReceived += (sender, e) => { if (!string.IsNullOrEmpty(e.Data)) { console.WriteLine("[OpenOCD] - " + e.Data); } }; process.ErrorDataReceived += (sender, e) => { if (DebugMode && !string.IsNullOrEmpty(e.Data)) { console.WriteLine("[OpenOCD] - " + e.Data); } ; }; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); await CloseAsync(); console.WriteLine("[OpenOCD] - GDB Server Closed."); openOcdProcess = null; result = false; } }); //Prevent stopped events until we have completed download and reset. StoppedEventIsEnabled = false; Thread.Sleep(500); //Only way to wait if openocd timesout. i.e. because already running? if (result) { result = await base.StartAsync(toolchain, console, project); if (result) { console.WriteLine("[OpenOCD] - Connecting..."); asyncModeEnabled = (await new GDBSetCommand("mi-async", "on").Execute(this)).Response == ResponseCode.Done; result = (await new TargetSelectCommand(":3333").Execute(this)).Response == ResponseCode.Done; if (result) { await new MonitorCommand("reset halt").Execute(this); await new MonitorCommand("speed 8000").Execute(this); await new TargetDownloadCommand().Execute(this); await new MonitorCommand("reset halt").Execute(this); console.WriteLine("[OpenOCD] - Connected."); } StoppedEventIsEnabled = true; } } if (!result) { console.WriteLine( "[OpenOCD] - Unable to connect. Ensure target is powered, connected and that debug settings are correct."); if (openOcdProcess != null && !openOcdProcess.HasExited) { openOcdProcess.Kill(); } } return result; }
public override async Task <bool> StartAsync(IToolChain toolchain, IConsole console, IProject project) { var result = true; var settings = GetSettings(project); console.Clear(); console.WriteLine("[JLink] - Starting GDB Server..."); // TODO allow people to select the device. var startInfo = new ProcessStartInfo(); startInfo.Arguments = string.Format("-select USB -device {0} -if {1} -speed 12000 -noir", settings.TargetDevice, Enum.GetName(typeof(JlinkInterfaceType), settings.Interface)); startInfo.FileName = Path.Combine(BaseDirectory, "JLinkGDBServerCL" + Platform.ExecutableExtension); if (Path.IsPathRooted(startInfo.FileName) && !System.IO.File.Exists(startInfo.FileName)) { console.WriteLine("[JLink] - Error unable to find executable."); return(false); } // Hide console window startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; startInfo.UseShellExecute = false; startInfo.CreateNoWindow = true; var processes = Process.GetProcessesByName("JLinkGDBServerCL"); foreach (var process in processes) { process.Kill(); } Task.Factory.StartNew(async() => { using (var process = Process.Start(startInfo)) { jlinkProcess = process; process.OutputDataReceived += (sender, e) => { if (DebugMode && !string.IsNullOrEmpty(e.Data)) { console.WriteLine("[JLink] - " + e.Data); } }; process.ErrorDataReceived += (sender, e) => { if (!string.IsNullOrEmpty(e.Data)) { console.WriteLine("[JLink] - " + e.Data); } ; }; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); await CloseAsync(); console.WriteLine("[JLink] - GDB Server Closed."); jlinkProcess = null; result = false; } }); while (jlinkProcess == null) { Thread.Sleep(10); } StoppedEventIsEnabled = false; if (result) { result = await base.StartAsync(toolchain, console, project); if (result) { console.WriteLine("[JLink] - Connecting..."); asyncModeEnabled = (await new GDBSetCommand("mi-async", "on").Execute(this)).Response == ResponseCode.Done; result = (await new TargetSelectCommand(":2331").Execute(this)).Response == ResponseCode.Done; if (result) { await new MonitorCommand("halt").Execute(this); await new MonitorCommand("reset").Execute(this); //new MonitorCommand("reg r13 = (0x00000000)").Execute(this); //new MonitorCommand("reg pc = (0x00000004)").Execute(this); await new TargetDownloadCommand().Execute(this); console.WriteLine("[JLink] - Connected."); } StoppedEventIsEnabled = true; } } if (!result) { console.WriteLine( "[JLink] - Unable to connect. Ensure target is powered, connected and that debug settings are correct."); if (jlinkProcess != null && !jlinkProcess.HasExited) { jlinkProcess.Kill(); } } return(result); }
public virtual async Task <bool> StartAsync(IToolChain toolchain, IConsole console, IProject project) { this.console = console; var startInfo = new ProcessStartInfo(); console.WriteLine("[GDB] - Starting..."); // This information should be part of this extension... or configurable internally? // This maybe indicates that debuggers are part of toolchain? if (toolchain is GCCToolchain) { startInfo.FileName = (toolchain as GCCToolchain).GDBExecutable; } else { console.WriteLine("[GDB] - Error GDB is not able to debug projects compiled on this kind of toolchain (" + toolchain.GetType() + ")"); return(false); } startInfo.Arguments = string.Format("--interpreter=mi \"{0}\"", Path.Combine(project.CurrentDirectory, project.Executable).ToPlatformPath()); if (Path.IsPathRooted(startInfo.FileName) && !System.IO.File.Exists(startInfo.FileName)) { console.WriteLine("[GDB] - Error unable to find executable."); return(false); } // Hide console window startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; startInfo.RedirectStandardInput = true; startInfo.CreateNoWindow = true; process = Process.Start(startInfo); input = process.StandardInput; var attempts = 0; while (!Platform.FreeConsole() && attempts < 10) { Console.WriteLine(Marshal.GetLastWin32Error()); Thread.Sleep(10); attempts++; } attempts = 0; while (!Platform.AttachConsole(process.Id) && attempts < 10) { Thread.Sleep(10); attempts++; } while (!Platform.SetConsoleCtrlHandler(null, true)) { Console.WriteLine(Marshal.GetLastWin32Error()); Thread.Sleep(10); } TaskCompletionSource <JobRunner> transmitRunnerSet = new TaskCompletionSource <JobRunner>(); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Factory.StartNew(() => { transmitRunner = new JobRunner(); transmitRunnerSet.SetResult(transmitRunner); closeTokenSource = new CancellationTokenSource(); transmitRunner.RunLoop(closeTokenSource.Token); transmitRunner = null; }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed await transmitRunnerSet.Task; Task.Factory.StartNew(() => { console.WriteLine("[GDB] - Started"); process.OutputDataReceived += (sender, e) => { if (e.Data != null) { ProcessOutput(e.Data); } }; process.ErrorDataReceived += (sender, e) => { if (e.Data != null) { console.WriteLine("[GDB] - " + e.Data); } }; process.BeginOutputReadLine(); process.BeginErrorReadLine(); try { process.WaitForExit(); Platform.FreeConsole(); Platform.SetConsoleCtrlHandler(null, false); } catch (Exception e) { Console.WriteLine(e); } console.WriteLine("[GDB] - Closed"); closeTokenSource?.Cancel(); }); return(true); }
public virtual async Task<bool> StartAsync(IToolChain toolchain, IConsole console, IProject project) { this.console = console; var startInfo = new ProcessStartInfo(); console.WriteLine("[GDB] - Starting..."); // This information should be part of this extension... or configurable internally? // This maybe indicates that debuggers are part of toolchain? if (toolchain is GCCToolchain) { startInfo.FileName = (toolchain as GCCToolchain).GDBExecutable; } else { console.WriteLine("[GDB] - Error GDB is not able to debug projects compiled on this kind of toolchain (" + toolchain.GetType() + ")"); return false; } startInfo.Arguments = string.Format("--interpreter=mi \"{0}\"", Path.Combine(project.CurrentDirectory, project.Executable).ToPlatformPath()); if (Path.IsPathRooted(startInfo.FileName) && !System.IO.File.Exists(startInfo.FileName)) { console.WriteLine("[GDB] - Error unable to find executable."); return false; } // Hide console window startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; startInfo.RedirectStandardInput = true; startInfo.CreateNoWindow = true; process = Process.Start(startInfo); input = process.StandardInput; var attempts = 0; while (!Platform.FreeConsole() && attempts < 10) { Console.WriteLine(Marshal.GetLastWin32Error()); Thread.Sleep(10); attempts++; } attempts = 0; while (!Platform.AttachConsole(process.Id) && attempts < 10) { Thread.Sleep(10); attempts++; } while (!Platform.SetConsoleCtrlHandler(null, true)) { Console.WriteLine(Marshal.GetLastWin32Error()); Thread.Sleep(10); } TaskCompletionSource<JobRunner> transmitRunnerSet = new TaskCompletionSource<JobRunner>(); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Factory.StartNew(() => { transmitRunner = new JobRunner(); transmitRunnerSet.SetResult(transmitRunner); closeTokenSource = new CancellationTokenSource(); transmitRunner.RunLoop(closeTokenSource.Token); transmitRunner = null; }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed await transmitRunnerSet.Task; Task.Factory.StartNew(() => { console.WriteLine("[GDB] - Started"); process.OutputDataReceived += (sender, e) => { if (e.Data != null) { ProcessOutput(e.Data); } }; process.ErrorDataReceived += (sender, e) => { if (e.Data != null) { console.WriteLine("[GDB] - " + e.Data); } }; process.BeginOutputReadLine(); process.BeginErrorReadLine(); try { process.WaitForExit(); Platform.FreeConsole(); Platform.SetConsoleCtrlHandler(null, false); } catch (Exception e) { Console.WriteLine(e); } console.WriteLine("[GDB] - Closed"); closeTokenSource?.Cancel(); }); await SafelyExecuteCommand(async () => await new EnablePrettyPrintingCommand().Execute(this)); return true; }
public override async Task<bool> StartAsync(IToolChain toolchain, IConsole console, IProject project) { var result = true; var settings = GetSettings(project); console.Clear(); console.WriteLine("[JLink] - Starting GDB Server..."); // TODO allow people to select the device. var startInfo = new ProcessStartInfo(); startInfo.Arguments = string.Format("-select USB -device {0} -if {1} -speed 12000 -noir", settings.TargetDevice, Enum.GetName(typeof (JlinkInterfaceType), settings.Interface)); startInfo.FileName = Path.Combine(BaseDirectory, "JLinkGDBServerCL" + Platform.ExecutableExtension); if (Path.IsPathRooted(startInfo.FileName) && !System.IO.File.Exists(startInfo.FileName)) { console.WriteLine("[JLink] - Error unable to find executable."); return false; } // Hide console window startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; startInfo.UseShellExecute = false; startInfo.CreateNoWindow = true; var processes = Process.GetProcessesByName("JLinkGDBServerCL"); foreach (var process in processes) { process.Kill(); } Task.Factory.StartNew(async () => { using (var process = Process.Start(startInfo)) { jlinkProcess = process; process.OutputDataReceived += (sender, e) => { if (DebugMode && !string.IsNullOrEmpty(e.Data)) { console.WriteLine("[JLink] - " + e.Data); } }; process.ErrorDataReceived += (sender, e) => { if (!string.IsNullOrEmpty(e.Data)) { console.WriteLine("[JLink] - " + e.Data); } ; }; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); await CloseAsync(); console.WriteLine("[JLink] - GDB Server Closed."); jlinkProcess = null; result = false; } }); while (jlinkProcess == null) { Thread.Sleep(10); } StoppedEventIsEnabled = false; if (result) { result = await base.StartAsync(toolchain, console, project); if (result) { console.WriteLine("[JLink] - Connecting..."); asyncModeEnabled = (await new GDBSetCommand("mi-async", "on").Execute(this)).Response == ResponseCode.Done; result = (await new TargetSelectCommand(":2331").Execute(this)).Response == ResponseCode.Done; if (result) { await new MonitorCommand("halt").Execute(this); await new MonitorCommand("reset").Execute(this); //new MonitorCommand("reg r13 = (0x00000000)").Execute(this); //new MonitorCommand("reg pc = (0x00000004)").Execute(this); await new TargetDownloadCommand().Execute(this); console.WriteLine("[JLink] - Connected."); } StoppedEventIsEnabled = true; } } if (!result) { console.WriteLine( "[JLink] - Unable to connect. Ensure target is powered, connected and that debug settings are correct."); if (jlinkProcess != null && !jlinkProcess.HasExited) { jlinkProcess.Kill(); } } return result; }
public virtual async Task <bool> StartAsync(IToolChain toolchain, IConsole console, IProject project) { return(await StartAsync(toolchain, console, project, string.Empty)); }
public virtual async Task <bool> StartAsync(IToolChain toolchain, IConsole console, IProject project, string gdbExecutable = "", bool loadExecutableAsArgument = true, string workingDirectory = "") { this.console = console; var startInfo = new ProcessStartInfo(); console.WriteLine("[GDB] - Starting..."); // This information should be part of this extension... or configurable internally? // This maybe indicates that debuggers are part of toolchain? if (gdbExecutable == string.Empty) { if (toolchain is GCCToolchain) { startInfo.FileName = (toolchain as GCCToolchain).GDBExecutable; } else { console.WriteLine("[GDB] - Error GDB is not able to debug projects compiled on this kind of toolchain (" + toolchain.GetType() + ")"); return(false); } } else { startInfo.FileName = gdbExecutable; } startInfo.Arguments = "--interpreter=mi"; if (workingDirectory != string.Empty) { startInfo.WorkingDirectory = workingDirectory; } if (loadExecutableAsArgument) { startInfo.Arguments += string.Format(" \"{0}\"", Path.Combine(project.CurrentDirectory, project.Executable).ToPlatformPath()); } if (Path.IsPathRooted(startInfo.FileName) && !System.IO.File.Exists(startInfo.FileName)) { console.WriteLine("[GDB] - Error unable to find executable."); return(false); } // Hide console window startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; startInfo.RedirectStandardInput = true; startInfo.CreateNoWindow = true; process = Process.Start(startInfo); input = process.StandardInput; TaskCompletionSource <JobRunner> transmitRunnerSet = new TaskCompletionSource <JobRunner>(); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Factory.StartNew(() => { transmitRunner = new JobRunner(); transmitRunnerSet.SetResult(transmitRunner); closeTokenSource = new CancellationTokenSource(); transmitRunner.RunLoop(closeTokenSource.Token); transmitRunner = null; }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed await transmitRunnerSet.Task; Task.Factory.StartNew(() => { console.WriteLine("[GDB] - Started"); process.OutputDataReceived += (sender, e) => { if (e.Data != null) { ProcessOutput(e.Data); } }; process.ErrorDataReceived += (sender, e) => { if (e.Data != null) { console.WriteLine("[GDB] - " + e.Data); } }; process.BeginOutputReadLine(); process.BeginErrorReadLine(); try { process.WaitForExit(); if (!asyncModeEnabled && Platform.PlatformIdentifier == PlatformID.Win32NT) { Platform.FreeConsole(); Platform.SetConsoleCtrlHandler(null, false); } } catch (Exception e) { Console.WriteLine(e); } console.WriteLine("[GDB] - Closed"); closeTokenSource?.Cancel(); }); await SafelyExecuteCommand(async() => await new EnablePrettyPrintingCommand().Execute(this)); return(true); }