public IGDBStubInstance StartGDBStub(IDebugStartService startService, DebugStartContext context) { var settings = (RISCVOpenOCDSettings)context.Configuration; OpenOCDCommandLine cmdLine = OpenOCDCommandLine.Parse(settings.CommandLine, startService.CommandLineHelper); if (context.ResolvedDevices?.Interface != null) { if (context.ResolvedDevices.AllCompatibleDevices.Length > 1 || settings.AlwaysPassSerialNumber) { var db = new QuickSetupDatabase(false, context.Method.Directory); var matchingIface = db.AllInterfaces.FirstOrDefault(i => i.ID == context.ResolvedDevices.Interface.ID); if (matchingIface?.SerialNumberCommand != null) { cmdLine.InsertAfterInterfaceScript(new OpenOCDCommandLine.CommandItem { Command = $"{matchingIface.SerialNumberCommand} {EscapeSerialNumber(context.ResolvedDevices.BestMatch.Device.SerialNumber)}" }); } } } if (startService.Mode == EmbeddedDebugMode.Attach) { for (; ;) { var item = cmdLine.Items.OfType <OpenOCDCommandLine.CommandItem>().FirstOrDefault(c => c.Command.StartsWith("reset")); if (item == null) { break; } cmdLine.Items.Remove(item); } } int gdbPort, telnetPort; using (var allocator = startService.BeginAllocatingTCPPorts()) { gdbPort = PortAllocationHelper.AllocateUnusedTCPPort(allocator, "SYS:GDB_PORT", settings.PreferredGDBPort); telnetPort = PortAllocationHelper.AllocateUnusedTCPPort(allocator, "com.sysprogs.openocd.telnet_port", settings.PreferredTelnetPort); } cmdLine.Items.Insert(0, new OpenOCDCommandLine.CommandItem { Command = "gdb_port " + gdbPort }); cmdLine.Items.Insert(1, new OpenOCDCommandLine.CommandItem { Command = "telnet_port " + telnetPort }); cmdLine.Items.Add(new OpenOCDCommandLine.CommandItem { Command = "echo VisualGDB_OpenOCD_Ready" }); var tool = startService.LaunchCommandLineTool(new CommandLineToolLaunchInfo { Command = Path.Combine(GetOpenOCDDirectory(context.Method.Directory), "bin\\openocd.exe"), Arguments = cmdLine.ToString(), WorkingDirectory = Path.Combine(GetOpenOCDDirectory(context.Method.Directory), "share\\openocd\\scripts") }); return(CreateStub(context, settings, cmdLine, gdbPort, telnetPort, null, tool)); }
public IGDBStubInstance StartGDBStub(IDebugStartService startService, DebugStartContext context) { var settings = (RedLinkDebugSettings)context.Configuration ?? new RedLinkDebugSettings(); var cmdLine = new RedLinkServerCommandLine(settings.CommandLineArguments); int gdbPort; using (var allocator = startService.BeginAllocatingTCPPorts()) { gdbPort = allocator.AllocateUnusedTCPPort("SYS:GDB_PORT"); } var ideRoot = RegistrySettings.MCUXpressoPath ?? throw new Exception("Please specify the MCUXpresso directory via Debug Settings"); bool programNow; switch (settings.ProgramMode) { case ProgramMode.Disabled: programNow = false; break; case ProgramMode.Auto: programNow = !startService.IsCurrentFirmwareAlreadyProgrammed(); break; default: programNow = true; break; } var gdbServer = Path.Combine(ideRoot, @"binaries\crt_emu_cm_redlink.exe"); if (!File.Exists(gdbServer)) { throw new Exception("Could not find " + gdbServer); } var cmdLineText = cmdLine.CommandLine; if (cmdLineText.Contains(DeviceDirectoryVariableReference)) { var db = new RedLinkDeviceDatabase(); var device = cmdLine.Device ?? throw new Exception("RedLink command line does not specify the device (-pXXX)"); var vendor = cmdLine.Vendor ?? throw new Exception("RedLink command line does not specify the vendor (-vendor)"); device = startService.ExpandProjectVariables(device, true, false); vendor = startService.ExpandProjectVariables(vendor, true, false); var dev = db.ProvideDeviceDefinition(vendor, device) ?? throw new Exception($"Unknown vendor/device: {vendor}/{device}. Please use VisualGDB Project Properties -> Debug Settings to configure."); cmdLineText = cmdLineText.Replace(DeviceDirectoryVariableReference, TranslatePath(dev.DefinitionDirectory)); } if (cmdLineText.Contains(FLASHDriverDirectoryVariableReference)) { var pluginDir = Path.Combine(ideRoot, "plugins"); if (Directory.Exists(pluginDir)) { var toolsPlugin = Directory.GetDirectories(pluginDir, "com.nxp.mcuxpresso.tools.bin.win32*").FirstOrDefault(); if (toolsPlugin != null) { cmdLineText = cmdLineText.Replace(FLASHDriverDirectoryVariableReference, TranslatePath(Path.Combine(toolsPlugin, @"binaries\Flash"))); } } } string explicitSerialNumber = null; if (context.ResolvedDevices?.BestMatch.Device.SerialNumber != null) { if ((context.ResolvedDevices.AllCompatibleDevices?.Length ?? 0) > 1 || settings.AlwaysUseProbeSerialNumber) { explicitSerialNumber = context.ResolvedDevices.BestMatch.Device.SerialNumber; cmdLineText += " --probeserial " + explicitSerialNumber; } } int coreIndex = 0; if (cmdLine.Core is string core) { core = startService.ExpandProjectVariables(core, true, false); int.TryParse(core, out coreIndex); } var tool = startService.LaunchCommandLineTool(new CommandLineToolLaunchInfo { Command = gdbServer, Arguments = cmdLineText, WorkingDirectory = Path.GetDirectoryName(gdbServer) }); return(new RedLinkGDBStub(context, settings, cmdLine, gdbPort, tool, programNow, explicitSerialNumber, coreIndex)); }
public IGDBStubInstance StartGDBStub(IDebugStartService startService, DebugStartContext context) { int gdbPort; using (var allocator = startService.BeginAllocatingTCPPorts()) gdbPort = allocator.AllocateUnusedTCPPort("SYS:GDB_PORT"); var settings = context.Configuration as AVaRICEDebugSettings ?? throw new Exception("Invalid AVaRICE debug settings"); var exe = Path.Combine(context.Method.Directory, "avarice.exe"); if (!File.Exists(exe)) { exe = Path.GetFullPath(Path.Combine(context.Method.Directory, @"..\..\..\bin\avarice.exe")); } List <string> args = new List <string>(); if (!string.IsNullOrEmpty(settings.DebugInterface)) { args.Add(settings.DebugInterface); } if (!string.IsNullOrEmpty(settings.DebugBitrate)) { args.Add("-B " + settings.DebugBitrate); } if (context.ResolvedDevices?.Interface?.ID != null) { args.Add("-j usb"); int idx = context.ResolvedDevices.Interface.ID.IndexOf(':'); if (idx != -1) { args.Add(context.ResolvedDevices.Interface.ID.Substring(idx + 1)); } } else { if (!string.IsNullOrEmpty(settings.DebugAdapterType)) { args.Add(settings.DebugAdapterType); } if (!string.IsNullOrEmpty(settings.DebugPort)) { args.Add("-j " + settings.DebugPort.ToLower()); } } if (startService.Mode != EmbeddedDebugMode.Attach && startService.Mode != EmbeddedDebugMode.ConnectionTest && startService.TargetPath != null && (settings.EraseFLASH || settings.ProgramFLASH || settings.VerifyFLASH)) { args.Insert(0, $"--file \"{startService.TargetPath}\""); if (settings.EraseFLASH) { args.Add("--erase"); } if (settings.ProgramFLASH) { args.Add("--program"); } if (settings.VerifyFLASH) { args.Add("--verify"); } } if (!string.IsNullOrEmpty(settings.ExtraArguments)) { args.Add(settings.ExtraArguments); } args.Add(":" + gdbPort); var tool = startService.LaunchCommandLineTool(new CommandLineToolLaunchInfo { Command = exe, Arguments = string.Join(" ", args.ToArray()) }); return(new StubInstance(context, tool, gdbPort, settings)); }
public IGDBStubInstance StartGDBStub(IDebugStartService startService, DebugStartContext context) { var settings = (RenesasDebugSettings)context.Configuration ?? new RenesasDebugSettings(); var cmdLine = new RenesasGDBServerCommandLine(settings.CommandLineArguments); int gdbPort; using (var allocator = startService.BeginAllocatingTCPPorts()) { cmdLine.GDBPort = gdbPort = allocator.AllocateUnusedTCPPort("SYS:GDB_PORT"); cmdLine.AuxiliaryPort = allocator.AllocateUnusedTCPPort("com.sysprogs.renesas.auxiliary_port"); } string debugComponentLinkFile = Path.Combine(GetOpenOCDDirectory(context.Method.Directory), "DebugCompLink.txt"); if (!File.Exists(debugComponentLinkFile)) { throw new Exception($"{debugComponentLinkFile} does not exist"); } cmdLine.DeviceID = startService.MCU.ExpandedMCU.ID; if (cmdLine.DebugInterface == null) { cmdLine.DebugInterface = "EZ"; } bool programNow; switch (settings.ProgramMode) { case ProgramMode.Disabled: programNow = false; break; case ProgramMode.Auto: programNow = !startService.IsCurrentFirmwareAlreadyProgrammed(); break; default: programNow = true; break; } cmdLine.SetSeparatedValue("-ueraseRom=", programNow ? "1" : "0"); string debugComponentDir = File.ReadAllText(debugComponentLinkFile); string e2gdbServer = Path.Combine(debugComponentDir, "e2-server-gdb.exe"); if (!File.Exists(e2gdbServer)) { throw new Exception("Could not find " + e2gdbServer); } var tool = startService.LaunchCommandLineTool(new CommandLineToolLaunchInfo { Command = e2gdbServer, Arguments = cmdLine.CommandLine, WorkingDirectory = Path.GetDirectoryName(e2gdbServer) }); return(new RenesasGDBStub(context, settings, cmdLine, gdbPort, tool, $@"{debugComponentDir}\IoFiles\{startService.MCU.ExpandedMCU.ID}.sfrx", programNow)); }