public static DebugWorkspace GetWorkspace() { string romName = EmuApi.GetRomInfo().GetRomName(); if (_workspace == null || _romName != romName) { if (_workspace != null) { SaveWorkspace(); } _romName = romName; _workspace = DebugWorkspace.GetWorkspace(); //Load watch entries WatchManager.GetWatchManager(CpuType.Cpu).WatchEntries = _workspace.WatchValues; WatchManager.GetWatchManager(CpuType.Spc).WatchEntries = _workspace.SpcWatchValues; WatchManager.GetWatchManager(CpuType.Sa1).WatchEntries = _workspace.Sa1WatchValues; WatchManager.GetWatchManager(CpuType.Gsu).WatchEntries = _workspace.GsuWatchValues; LabelManager.ResetLabels(); LabelManager.SetLabels(_workspace.CpuLabels); LabelManager.SetLabels(_workspace.SpcLabels); LabelManager.SetDefaultLabels(); ImportDbgFile(); LabelManager.RefreshLabels(); //Load breakpoints BreakpointManager.SetBreakpoints(_workspace.Breakpoints); } return(_workspace); }
public static DebugWorkspace GetWorkspace() { string romName = EmuApi.GetRomInfo().GetRomName(); if (_workspace != null) { SaveWorkspace(); } if (_workspace == null || _romName != romName) { _romName = romName; _workspace = DebugWorkspace.GetWorkspace(); //Load watch entries WatchManager.GetWatchManager(CpuType.Cpu).WatchEntries = _workspace.WatchValues; WatchManager.GetWatchManager(CpuType.Spc).WatchEntries = _workspace.SpcWatchValues; WatchManager.GetWatchManager(CpuType.Sa1).WatchEntries = _workspace.Sa1WatchValues; WatchManager.GetWatchManager(CpuType.Gsu).WatchEntries = _workspace.GsuWatchValues; WatchManager.GetWatchManager(CpuType.NecDsp).WatchEntries = _workspace.NecDspWatchValues; WatchManager.GetWatchManager(CpuType.Gameboy).WatchEntries = _workspace.GbWatchValues; LabelManager.ResetLabels(); LabelManager.SetLabels(_workspace.CpuLabels); LabelManager.SetLabels(_workspace.SpcLabels); LabelManager.SetLabels(_workspace.NecDspLabels); LabelManager.SetLabels(_workspace.GbLabels); LabelManager.SetDefaultLabels(); AutoImportSymbols(); } //Send breakpoints & labels to emulation core (even if the same game is running) LabelManager.RefreshLabels(); BreakpointManager.SetBreakpoints(_workspace.Breakpoints); return(_workspace); }
public void Import(string path, bool silent = false) { DbgFileStamp = File.GetLastWriteTime(path); string[] fileRows = File.ReadAllLines(path); string basePath = Path.GetDirectoryName(path); DbgPath = basePath; foreach (string row in fileRows) { try { if (LoadLines(row) || LoadSpans(row) || LoadSymbols(row) || LoadCSymbols(row) || LoadScopes(row) || LoadFiles(row, basePath) || LoadSegments(row)) { continue; } } catch { _errorCount++; } } LoadFileData(basePath); BuildCdlData(); foreach (LineInfo line in _lines.Values) { foreach (int spanID in line.SpanIDs) { SpanInfo span; if (_spans.TryGetValue(spanID, out span)) { SegmentInfo segment; if (_segments.TryGetValue(span.SegmentID, out segment) && !segment.IsRam) { for (int i = 0; i < span.Size; i++) { int prgAddress = segment.FileOffset - _headerSize + span.Offset + i; LineInfo existingLine; if (_linesByPrgAddress.TryGetValue(prgAddress, out existingLine) && existingLine.Type == LineType.External) { //Give priority to lines that come from C files continue; } _linesByPrgAddress[prgAddress] = line; if (i == 0 && spanID == line.SpanIDs[0]) { //Mark the first byte of the first span representing this line as the PRG address for this line of code FileInfo file = _files[line.FileID]; _prgAddressByLine[file.ID.ToString() + "_" + line.LineNumber.ToString()] = prgAddress; } } } } } } LoadLabels(); int labelCount = 0; DbgIntegrationConfig config = ConfigManager.Config.Debug.DbgIntegration; if (config.ImportCpuComments || config.ImportSpcComments) { LoadComments(); } List <CodeLabel> labels = new List <CodeLabel>(_romLabels.Count + _ramLabels.Count + _workRamLabels.Count + _saveRamLabels.Count); if (config.ImportCpuPrgRomLabels) { labels.AddRange(_romLabels.Values); labelCount += _romLabels.Count; } if (config.ImportCpuWorkRamLabels) { labels.AddRange(_workRamLabels.Values); labelCount += _workRamLabels.Count; } if (config.ImportCpuSaveRamLabels) { labels.AddRange(_saveRamLabels.Values); labelCount += _saveRamLabels.Count; } if (config.ImportSpcRamLabels) { labels.AddRange(_spcRamLabels.Values); labelCount += _spcRamLabels.Count; } if (ConfigManager.Config.Debug.DbgIntegration.ResetLabelsOnImport) { DebugWorkspaceManager.ResetLabels(); } LabelManager.SetLabels(labels, true); if (!silent) { if (_errorCount > 0) { _errorCount -= _filesNotFound.Count; string message = $"Import completed with {labelCount} labels imported"; if (_errorCount > 0) { message += $"and {_errorCount} errors - please file a bug report and attach the DBG file you tried to import."; } if (_filesNotFound.Count > 0) { message += Environment.NewLine + Environment.NewLine + "The following files could not be found:"; foreach (string file in _filesNotFound) { message += Environment.NewLine + file; } } MessageBox.Show(message, "Mesen", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show($"Import completed with {labelCount} labels imported.", "Mesen", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public void Import(string path, bool silent) { string basePath = Path.GetDirectoryName(path); string[] lines = File.ReadAllLines(path); Regex labelRegex = new Regex(@"^([0-9a-fA-F]{2}):([0-9a-fA-F]{4}) ([^\s]*)", RegexOptions.Compiled); Regex fileRegex = new Regex(@"^([0-9a-fA-F]{4}) ([0-9a-fA-F]{8}) (.*)", RegexOptions.Compiled); Regex addrRegex = new Regex(@"^([0-9a-fA-F]{2}):([0-9a-fA-F]{4}) ([0-9a-fA-F]{4}):([0-9a-fA-F]{8})", RegexOptions.Compiled); Dictionary <string, CodeLabel> labels = new Dictionary <string, CodeLabel>(); for (int i = 0; i < lines.Length; i++) { string str = lines[i].Trim(); if (str == "[labels]") { for (; i < lines.Length; i++) { if (lines[i].Length > 0) { Match m = labelRegex.Match(lines[i]); if (m.Success) { int bank = Int32.Parse(m.Groups[1].Value, System.Globalization.NumberStyles.HexNumber); int addr = (bank << 16) | Int32.Parse(m.Groups[2].Value, System.Globalization.NumberStyles.HexNumber); string label = m.Groups[3].Value; if (!LabelManager.LabelRegex.IsMatch(label)) { //ignore labels that don't respect the label naming restrictions continue; } AddressInfo relAddr = new AddressInfo() { Address = addr, Type = SnesMemoryType.CpuMemory }; AddressInfo absAddr = DebugApi.GetAbsoluteAddress(relAddr); if (absAddr.Address < 0) { continue; } string orgLabel = label; int j = 1; while (labels.ContainsKey(label)) { label = orgLabel + j.ToString(); j++; } labels[label] = new CodeLabel() { Label = label, Address = (UInt32)absAddr.Address, MemoryType = absAddr.Type, Comment = "", Flags = CodeLabelFlags.None, Length = 1 }; } } else { break; } } } else if (str == "[source files]") { for (; i < lines.Length; i++) { if (lines[i].Length > 0) { Match m = fileRegex.Match(lines[i]); if (m.Success) { int fileId = Int32.Parse(m.Groups[1].Value, System.Globalization.NumberStyles.HexNumber); //int fileCrc = Int32.Parse(m.Groups[2].Value, System.Globalization.NumberStyles.HexNumber); string filePath = m.Groups[3].Value; string fullPath = Path.Combine(basePath, filePath); _sourceFiles[fileId] = new SourceFileInfo() { Name = filePath, Data = File.Exists(fullPath) ? File.ReadAllLines(fullPath) : new string[0] }; } } else { break; } } } else if (str == "[addr-to-line mapping]") { for (; i < lines.Length; i++) { if (lines[i].Length > 0) { Match m = addrRegex.Match(lines[i]); if (m.Success) { int bank = Int32.Parse(m.Groups[1].Value, System.Globalization.NumberStyles.HexNumber); int addr = (bank << 16) | Int32.Parse(m.Groups[2].Value, System.Globalization.NumberStyles.HexNumber); int fileId = Int32.Parse(m.Groups[3].Value, System.Globalization.NumberStyles.HexNumber); int lineNumber = Int32.Parse(m.Groups[4].Value, System.Globalization.NumberStyles.HexNumber); if (lineNumber <= 1) { //Ignore line number 0 and 1, seems like bad data? continue; } AddressInfo absAddr = new AddressInfo() { Address = addr, Type = SnesMemoryType.PrgRom }; _addressByLine[_sourceFiles[fileId].Name + "_" + lineNumber.ToString()] = absAddr; _linesByAddress[absAddr.Type.ToString() + absAddr.Address.ToString()] = new SourceCodeLocation() { File = _sourceFiles[fileId], LineNumber = lineNumber }; } } else { break; } } } } LabelManager.SetLabels(labels.Values, true); }