public static bool RunSequence(ILoadProgressReporter reporter, IDebugStartService service, ISimpleGDBSession session, CustomStartupSequence sequence) { var espCmds = sequence.Steps; if (espCmds != null) { DateTime startTime = DateTime.Now; int total = 0, done = 0; foreach (var s in espCmds) { total += s.ProgressWeight; } for (int retry = 0; ; retry++) { try { foreach (var s in espCmds) { SimpleGDBCommandResult r = default(SimpleGDBCommandResult); foreach (var scmd in s.Commands) { r = session.RunGDBCommand(scmd); } bool failed = false; if (s.ResultVariable != null) { string val = session.EvaluateExpression(s.ResultVariable); if (val != "0") { failed = true; } } if (s.CheckResult && !failed) { failed = r.MainStatus != "^done"; } if (failed) { string msg = s.ErrorMessage ?? "Custom FLASH programming step failed"; if (s.CanRetry) { throw new RetriableException(msg); } else { throw new Exception(msg); } } done += s.ProgressWeight; reporter.ReportTaskProgress(done, total); } break; } catch (RetriableException) { if (retry < 2) { continue; } throw; } } reporter.ReportTaskCompletion(true); session.SendInformationalOutput("Loaded image in " + (int)(DateTime.Now - startTime).TotalMilliseconds + " ms"); } if (!string.IsNullOrEmpty(sequence.InitialHardBreakpointExpression)) { session.RequestInitialBreakpoint(service.ExpandProjectVariables(sequence.InitialHardBreakpointExpression, true, false)); } return(true); }
private SimpleGDBCommandResult ParseAndApplyIOAccessWidths(IDebugStartService service, ISimpleGDBSession session, SimpleGDBCommandResult result) { try { if (!File.Exists(_PeripheralFile)) { throw new Exception("Missing " + _PeripheralFile); } var doc = new XmlDocument(); doc.Load(_PeripheralFile); Dictionary <AccessKey, List <MemoryRange> > rangesByAccess = new Dictionary <AccessKey, List <MemoryRange> >(); foreach (var el in doc.DocumentElement.SelectNodes("moduletable/module/register").OfType <XmlElement>().OrderBy(e => TryParseAddress(e.GetAttribute("address")))) { int sizeinBytes; switch (el.GetAttribute("size") ?? "") { case "B": sizeinBytes = 1; break; case "W": sizeinBytes = 2; break; default: continue; } string addrString = el.GetAttribute("address"); int addr = TryParseAddress(addrString); var key = new AccessKey { Direction = el.GetAttribute("access"), Size = sizeinBytes }; if (!rangesByAccess.TryGetValue(key, out var list)) { rangesByAccess[key] = list = new List <MemoryRange>(); } bool found = false; foreach (var range in list) { if (range.TryAppendAddress(addr)) { found = true; break; } } if (!found) { list.Add(new MemoryRange(addr, key.Size)); } } foreach (var kv in rangesByAccess) { foreach (var range in Slice(kv.Value, 10)) { string cmd = $"monitor set_io_access_width,{kv.Key.Direction},{kv.Key.Size}," + string.Join(",", range.Select(r => r.ToString())); result = session.RunGDBCommand(cmd); } } } catch (Exception ex) { service.GUIService.LogToDiagnosticsConsole($"Failed to parse device peripheral list: " + ex.Message); } return(result); }