Example #1
0
        public async Task DeployAsync(CancellationToken cancellationToken, TextWriter outputPaneWriter)
        {
            // Kill all instances of PyOcd and OpenOcd because they affect the flash-tool and debugger
            await LlilumHelpers.TryKillPyocdAsync();

            await LlilumHelpers.TryKillOpenOcdAsync();

            var properties = await Properties.GetLlilumDebuggerPropertiesAsync();

            var deployTool = await properties.LlilumDeployTool.GetEvaluatedValueAtEndAsync();

            string deployToolPath = string.Empty;
            string binaryPath     = string.Empty;

            if (string.Compare(deployTool, "pyocdflashtool", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Deploy with pyOCD Flash Tool
                deployToolPath = await properties.LlilumFlashToolPath.GetEvaluatedValueAtEndAsync();

                deployToolPath = Path.GetFullPath(deployToolPath.Trim('"'));
                if (!File.Exists(deployToolPath))
                {
                    var msg = $"Flash programming tool not found: '{deployToolPath}'";
                    outputPaneWriter.Write(msg);
                    throw new FileNotFoundException(msg);
                }
            }
            else if (string.Compare(deployTool, "stlinkutility", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Deploy with ST-Link Utility
                deployToolPath = await properties.LlilumSTLinkUtilityPath.GetEvaluatedValueAtEndAsync();

                deployToolPath = Path.GetFullPath(deployToolPath.Trim('"'));
                if (!File.Exists(deployToolPath))
                {
                    var msg = $"STLink Utility not found: '{deployToolPath}'";
                    outputPaneWriter.Write(msg);
                    throw new FileNotFoundException(msg);
                }
            }
            else if (string.Compare(deployTool, "copytodrive", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Deploy by copying to the drive. Do nothing
            }
            else
            {
                // Deploy with GDB command, or Do Not Deploy
                return;
            }

            binaryPath = await properties.LlilumOutputBin.GetEvaluatedValueAtEndAsync( );

            binaryPath = Path.GetFullPath(binaryPath.Trim('"'));

            if (!File.Exists(binaryPath))
            {
                var msg = $"Flash binary file not found: '{binaryPath}'";
                outputPaneWriter.Write(msg);
                throw new FileNotFoundException(msg);
            }

            if (string.Compare(deployTool, "pyocdflashtool", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Deploy with pyOCD Flash Tool
                string flashToolArgs = await properties.LlilumFlashToolArgs.GetEvaluatedValueAtEndAsync();

                flashToolArgs = $"{EnsureQuotedPathIfNeeded(binaryPath)} {flashToolArgs}";

                await RunDeployTool(cancellationToken, outputPaneWriter, deployToolPath, flashToolArgs);
            }
            else if (string.Compare(deployTool, "stlinkutility", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Deploy with ST-Link Utility
                string stlinkConnectArgs = await properties.LlilumSTLinkUtilityConnectArgs.GetEvaluatedValueAtEndAsync();

                string stlinkEraseArgs = await properties.LlilumSTLinkUtilityEraseArgs.GetEvaluatedValueAtEndAsync();

                string stlinkProgramArgs = await properties.LlilumSTLinkUtilityProgramArgs.GetEvaluatedValueAtEndAsync();

                string stlinkDeployArgs = stlinkConnectArgs + " " + stlinkEraseArgs + " " + stlinkProgramArgs;

                await RunDeployTool(cancellationToken, outputPaneWriter, deployToolPath, stlinkDeployArgs);
            }
            else if (string.Compare(deployTool, "copytodrive", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Copy to the specified drive
                string drive = await properties.LlilumDriveToCopyTo.GetEvaluatedValueAtEndAsync();

                drive = drive.Trim();

                if (string.IsNullOrWhiteSpace(drive))
                {
                    throw new ArgumentNullException("Drive not specified");
                }

                // Get the properly formatted string for the drive letter
                DriveInfo driveInfo = new DriveInfo(drive);
                drive = driveInfo.RootDirectory.FullName;

                if (!Directory.Exists(drive))
                {
                    throw new DriveNotFoundException("The drive specified could not be located");
                }

                string[] binaryPathArr = binaryPath.Split('\\');
                string   binaryName    = binaryPathArr[binaryPathArr.Length - 1];
                string   destFile      = System.IO.Path.Combine(drive, binaryName);

                // Allow the copy to fail, and throw an exception on its own
                File.Copy(binaryPath, destFile, true);
            }
        }
        public override async Task <IReadOnlyList <IDebugLaunchSettings> > QueryDebugTargetsAsync(DebugLaunchOptions launchOptions)
        {
            var settings = new DebugLaunchSettings(launchOptions);

            // The properties that are available via DebuggerProperties are determined by the property XAML files in your project.
            var debuggerProperties = await this.DebuggerProperties.GetLlilumDebuggerPropertiesAsync();

            string dir = await debuggerProperties.LlilumDebuggerWorkingDirectory.GetEvaluatedValueAtEndAsync();

            string executable = await debuggerProperties.LlilumDebuggerCommand.GetEvaluatedValueAtEndAsync();

            string gdbPath = await debuggerProperties.LlilumGdbPath.GetEvaluatedValueAtEndAsync();

            string gdbArgs = await debuggerProperties.LlilumGdbArgs.GetEvaluatedValueAtEndAsync();

            var gdbServer = await debuggerProperties.LlilumGdbServerOption.GetEvaluatedValueAtEndAsync();

            settings.CurrentDirectory = dir;
            settings.Executable       = executable;

            // If we are going to deploy with GDB load command, create a script that will also load the elf file
            string debugScript = DebuggerScriptContentFormat;
            var    deployTool  = await debuggerProperties.LlilumDeployTool.GetEvaluatedValueAtEndAsync();

            if (string.Compare(deployTool, "gdbloadcommand", true) == 0)
            {
                debugScript = DebuggerLoadScriptContentFormat;
            }

            // Create the temporary file for passing to the debug engine
            string debuggerFile = CreateDebuggerFileIfNoneExist(dir, executable, gdbPath, gdbArgs, debugScript);

            settings.Options               = string.Format(DebuggerOptionsFormat, debuggerFile);
            settings.LaunchOperation       = DebugLaunchOperation.CreateProcess;
            settings.LaunchDebugEngineGuid = new Guid(Microsoft.MIDebugEngine.EngineConstants.EngineId);

            // Launch py_ocd to communicate with GDB
            string gdbServerPath = string.Empty;
            string gdbServerArgs = string.Empty;

            if (gdbServer.Equals("pyocd"))
            {
                gdbServerPath = await debuggerProperties.LlilumPyOcdPath.GetEvaluatedValueAtEndAsync();

                gdbServerArgs = await debuggerProperties.LlilumPyOcdArgs.GetEvaluatedValueAtEndAsync();
            }
            else if (gdbServer.Equals("openocd"))
            {
                gdbServerPath = await debuggerProperties.LlilumOpenOcdPath.GetEvaluatedValueAtEndAsync();

                gdbServerArgs = await debuggerProperties.LlilumOpenOcdArgs.GetEvaluatedValueAtEndAsync();
            }

            if (!string.IsNullOrWhiteSpace(gdbServerPath))
            {
                // Even though we did it in deploy, do it here just in case we go straight to debug
                await LlilumHelpers.TryKillPyocdAsync();

                await LlilumHelpers.TryKillOpenOcdAsync();

                ProcessStartInfo start = new ProcessStartInfo();
                start.FileName               = gdbServerPath;
                start.Arguments              = gdbServerArgs;
                start.UseShellExecute        = false;
                start.RedirectStandardOutput = true;
                Process gdbServerProcess = Process.Start(start);
            }

            return(new IDebugLaunchSettings[] { settings });
        }