private void btnStartLogging_Click(object sender, EventArgs e) { using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.SetFilter("Trace logs (*.txt)|*.txt"); sfd.FileName = "Trace.txt"; sfd.InitialDirectory = ConfigManager.DebuggerFolder; if (sfd.ShowDialog() == DialogResult.OK) { _lastFilename = sfd.FileName; SetOptions(); DebugApi.StartTraceLogger(sfd.FileName); btnStartLogging.Enabled = false; btnStopLogging.Enabled = true; btnOpenTrace.Enabled = false; _loggingEnabled = true; } } }
public void RefreshViewer() { int height = _isGameboyMode ? 256 : 240; if (_previewImage == null || _previewImage.Height != height) { _previewData = new byte[256 * height * 4]; _previewImage = new Bitmap(256, height, PixelFormat.Format32bppPArgb); ctrlImagePanel.ImageSize = new Size(256, height); ctrlImagePanel.Image = _previewImage; } ctrlSpriteList.SetData(_state, _oamRam, _state.Ppu.OamMode, _isGameboyMode); if (_isGameboyMode) { DebugApi.GetGameboySpritePreview(_options, _state.Gameboy.Ppu, _vram, _oamRam, _previewData); } else { DebugApi.GetSpritePreview(_options, _state.Ppu, _vram, _oamRam, _cgram, _previewData); } using (Graphics g = Graphics.FromImage(_previewImage)) { GCHandle handle = GCHandle.Alloc(_previewData, GCHandleType.Pinned); Bitmap source = new Bitmap(256, height, 4 * 256, PixelFormat.Format32bppPArgb, handle.AddrOfPinnedObject()); g.DrawImage(source, 0, 0); handle.Free(); } if (_options.SelectedSprite >= 0) { ctrlImagePanel.Selection = GetSpriteInfo(_options.SelectedSprite).GetBounds(); } else { ctrlImagePanel.Selection = Rectangle.Empty; } ctrlImagePanel.Refresh(); }
public void RefreshViewer() { EventViewerDisplayOptions options = ConfigManager.Config.Debug.EventViewer.GetInteropOptions(); if (this.CpuType == CpuType.Gameboy) { _baseWidth = 456 * 2; _xRatio = 0.5; } else { _baseWidth = 1364 / 2; _xRatio = 2; } _pictureData = DebugApi.GetEventViewerOutput(this.CpuType, _baseWidth, ScanlineCount, options); int picHeight = (int)ScanlineCount * 2; if (_screenBitmap == null || _screenBitmap.Height != picHeight || _screenBitmap.Width != _baseWidth) { _screenBitmap = new Bitmap(_baseWidth, picHeight, PixelFormat.Format32bppPArgb); _overlayBitmap = new Bitmap(_baseWidth, picHeight, PixelFormat.Format32bppPArgb); _displayBitmap = new Bitmap(_baseWidth, picHeight, PixelFormat.Format32bppPArgb); } GCHandle handle = GCHandle.Alloc(this._pictureData, GCHandleType.Pinned); try { Bitmap source = new Bitmap(_baseWidth, (int)ScanlineCount * 2, _baseWidth * 4, PixelFormat.Format32bppPArgb, handle.AddrOfPinnedObject()); using (Graphics g = Graphics.FromImage(_screenBitmap)) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None; g.DrawImageUnscaled(source, 0, 0); } } finally { handle.Free(); } UpdateDisplay(true); }
private void UpdateActionAvailability() { UInt32 startAddress = (UInt32)SelectionStartAddress; UInt32 endAddress = (UInt32)SelectionEndAddress; string address = "$" + startAddress.ToString("X4"); string addressRange; if (startAddress != endAddress) { addressRange = "$" + startAddress.ToString("X4") + "-$" + endAddress.ToString("X4"); } else { addressRange = address; } mnuEditLabel.Text = $"Edit Label ({address})"; mnuEditBreakpoint.Text = $"Edit Breakpoint ({addressRange})"; mnuAddToWatch.Text = $"Add to Watch ({addressRange})"; if (_memoryType == SnesMemoryType.CpuMemory || _memoryType == SnesMemoryType.SpcMemory) { AddressInfo relAddress = new AddressInfo() { Address = (int)startAddress, Type = _memoryType }; AddressInfo absAddress = DebugApi.GetAbsoluteAddress(relAddress); mnuEditLabel.Enabled = absAddress.Address != -1 && absAddress.Type.SupportsLabels(); mnuAddToWatch.Enabled = _memoryType.SupportsWatch(); } else { mnuEditLabel.Enabled = _memoryType.SupportsLabels(); mnuAddToWatch.Enabled = false; } mnuEditBreakpoint.Enabled = true; }
private void EditLabel(LocationInfo location) { if (location.Symbol != null) { //Don't allow edit label on symbols return; } if (location.Label != null) { using (frmEditLabel frm = new frmEditLabel(location.Label)) { frm.ShowDialog(); } } else if (location.Address >= 0) { AddressInfo relAddress = new AddressInfo() { Address = location.Address, Type = _manager.RelativeMemoryType }; AddressInfo absAddress = DebugApi.GetAbsoluteAddress(relAddress); if (absAddress.Address >= 0) { CodeLabel label = LabelManager.GetLabel((uint)absAddress.Address, absAddress.Type); if (label == null) { label = new CodeLabel() { Address = (uint)absAddress.Address, MemoryType = absAddress.Type }; } using (frmEditLabel frm = new frmEditLabel(label)) { frm.ShowDialog(); } } } }
private void RefreshDebugger(BreakEvent evt) { DebugState state = DebugApi.GetState(); int activeAddress; switch (_cpuType) { case CpuType.Cpu: activeAddress = (int)((state.Cpu.K << 16) | state.Cpu.PC); break; case CpuType.Spc: activeAddress = (int)state.Spc.PC; break; case CpuType.NecDsp: activeAddress = (int)(state.NecDsp.PC * 3); break; case CpuType.Sa1: activeAddress = (int)((state.Sa1.Cpu.K << 16) | state.Sa1.Cpu.PC); break; case CpuType.Gsu: activeAddress = (int)((state.Gsu.ProgramBank << 16) | state.Gsu.R[15]); break; case CpuType.Cx4: activeAddress = (int)((state.Cx4.Cache.Address[state.Cx4.Cache.Page] + (state.Cx4.PC * 2)) & 0xFFFFFF); break; case CpuType.Gameboy: activeAddress = (int)(state.Gameboy.Cpu.PC & 0xFFFF); break; default: throw new Exception("Unsupported cpu type"); } this.BeginInvoke((MethodInvoker)(() => { ProcessBreakEvent(evt, state, activeAddress); if (_firstBreak) { _firstBreak = false; if (!ConfigManager.Config.Debug.Debugger.BreakOnOpen) { DebugApi.ResumeExecution(); } if (_destAddress >= 0) { GoToAddress(_destAddress); } } })); }
/*public static void CreateAutomaticJumpLabels() * { * byte[] cdlData = InteropEmu.DebugGetPrgCdlData(); * List<CodeLabel> labelsToAdd = new List<CodeLabel>(); * for(int i = 0; i < cdlData.Length; i++) { * if((cdlData[i] & (byte)CdlPrgFlags.JumpTarget) != 0 && LabelManager.GetLabel((uint)i, SnesMemoryType.PrgRom) == null) { * labelsToAdd.Add(new CodeLabel() { Flags = CodeLabelFlags.AutoJumpLabel, Address = (uint)i, SnesMemoryType = SnesMemoryType.PrgRom, Label = "L" + i.ToString("X4"), Comment = "" }); * } * } * if(labelsToAdd.Count > 0) { * LabelManager.SetLabels(labelsToAdd, true); * } * }*/ private static void RefreshDisassembly(CodeLabel label) { if (label.MemoryType.ToCpuType() == CpuType.Spc) { DebugApi.RefreshDisassembly(CpuType.Spc); } else if (label.MemoryType.ToCpuType() == CpuType.NecDsp) { DebugApi.RefreshDisassembly(CpuType.NecDsp); } else if (label.MemoryType.ToCpuType() == CpuType.Gameboy) { DebugApi.RefreshDisassembly(CpuType.Gameboy); } else { DebugApi.RefreshDisassembly(CpuType.Cpu); DebugApi.RefreshDisassembly(CpuType.Sa1); DebugApi.RefreshDisassembly(CpuType.Gsu); } }
private void SaveRomAs(bool saveAsIps, CdlStripOption cdlStripOption) { using (SaveFileDialog sfd = new SaveFileDialog()) { if (saveAsIps) { sfd.SetFilter("IPS files (*.ips)|*.ips"); sfd.FileName = EmuApi.GetRomInfo().GetRomName() + ".ips"; } else { sfd.SetFilter("SFC files (*.sfc)|*.sfc"); sfd.FileName = EmuApi.GetRomInfo().GetRomName() + "_Modified.sfc"; } sfd.InitialDirectory = ConfigManager.DebuggerFolder; if (sfd.ShowDialog() == DialogResult.OK) { DebugApi.SaveRomToDisk(sfd.FileName, saveAsIps, cdlStripOption); } } }
private void ToggleBreakpoint(int address) { if (address >= 0) { AddressInfo relAddress = new AddressInfo() { Address = address, Type = _manager.RelativeMemoryType }; AddressInfo absAddress = DebugApi.GetAbsoluteAddress(relAddress); if (absAddress.Address < 0) { BreakpointManager.ToggleBreakpoint(relAddress, _manager.CpuType); } else { BreakpointManager.ToggleBreakpoint(absAddress, _manager.CpuType); } } }
protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); DebugApi.ResumeExecution(); DebugWindowManager.CloseAll(); EmuApi.Stop(); if (_notifListener != null) { _notifListener.Dispose(); _notifListener = null; } ConfigManager.Config.WindowLocation = this.WindowState == FormWindowState.Normal ? this.Location : this.RestoreBounds.Location; ConfigManager.Config.WindowSize = this.WindowState == FormWindowState.Normal ? this.Size : this.RestoreBounds.Size; ConfigManager.ApplyChanges(); EmuApi.Release(); }
protected override void OnClosing(CancelEventArgs e) { if (!SavePrompt()) { e.Cancel = true; return; } if (_scriptId >= 0) { DebugApi.RemoveScript(_scriptId); } ScriptWindowConfig cfg = ConfigManager.Config.Debug.ScriptWindow; cfg.WindowSize = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Size : this.Size; cfg.WindowLocation = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Location : this.Location; cfg.SaveScriptBeforeRun = mnuSaveBeforeRun.Checked; if (mnuAutoLoadLastScript.Checked) { cfg.ScriptStartupBehavior = ScriptStartupBehavior.LoadLastScript; } else if (mnuTutorialScript.Checked) { cfg.ScriptStartupBehavior = ScriptStartupBehavior.ShowTutorial; } else { cfg.ScriptStartupBehavior = ScriptStartupBehavior.ShowBlankWindow; } cfg.CodeWindowHeight = ctrlSplit.Panel2.Height <= 2 ? Int32.MaxValue : ctrlSplit.SplitterDistance; cfg.Zoom = txtScriptContent.Zoom; cfg.FontFamily = txtScriptContent.OriginalFont.FontFamily.Name; cfg.FontStyle = txtScriptContent.OriginalFont.Style; cfg.FontSize = txtScriptContent.OriginalFont.Size; cfg.AutoLoadLastScript = mnuAutoLoadLastScript.Checked; ConfigManager.ApplyChanges(); base.OnClosing(e); }
private List <StackInfo> GetStackInfo(CpuType cpuType) { _stackFrames = DebugApi.GetCallstack(cpuType); DebugState state = DebugApi.GetState(); if (cpuType == CpuType.Cpu) { _programCounter = (uint)(state.Cpu.K << 16) | state.Cpu.PC; } else { _programCounter = (uint)state.Spc.PC; } int relDestinationAddr = -1; List <StackInfo> stack = new List <StackInfo>(); for (int i = 0, len = _stackFrames.Length; i < len; i++) { int relSubEntryAddr = i == 0 ? -1 : (int)_stackFrames[i - 1].Target; stack.Add(new StackInfo() { SubName = this.GetFunctionName(relSubEntryAddr, i == 0 ? StackFrameFlags.None : _stackFrames[i - 1].Flags), Address = _stackFrames[i].Source, }); relDestinationAddr = (int)_stackFrames[i].Target; } //Add current location stack.Add(new StackInfo() { SubName = this.GetFunctionName(relDestinationAddr, _stackFrames.Length == 0 ? StackFrameFlags.None : _stackFrames[_stackFrames.Length - 1].Flags), Address = _programCounter, }); return(stack); }
private void AddGameboyTypes(bool excludeCpuMemory) { if (DebugApi.GetMemorySize(SnesMemoryType.GbPrgRom) > 0) { if (this.Items.Count > 0) { this.Items.Add("-"); } if (!excludeCpuMemory) { this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GameboyMemory)); } this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbPrgRom)); this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbWorkRam)); if (DebugApi.GetMemorySize(SnesMemoryType.GbCartRam) > 0) { this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbCartRam)); } this.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbVideoRam)); } }
public void RefreshData() { _state = DebugApi.GetState(); if (EmuApi.GetRomInfo().CoprocessorType == CoprocessorType.Gameboy) { _cgram = ctrlPaletteViewer.GetGameboyPalette(); } else { _cgram = DebugApi.GetMemoryState(SnesMemoryType.CGRam); } byte[] source = DebugApi.GetMemoryState(_memoryType); int size = Math.Min(source.Length - _address, _options.PageSize); _tileSource = new byte[0x40000]; Array.Copy(source, _address, _tileSource, 0, size); ctrlPaletteViewer.RefreshData(); }
private void RefreshViewer() { ctrlSpriteList.SetData(_oamRam, _state.OamMode); DebugApi.GetSpritePreview(_options, _state, _vram, _oamRam, _cgram, _previewData); using (Graphics g = Graphics.FromImage(_previewImage)) { GCHandle handle = GCHandle.Alloc(_previewData, GCHandleType.Pinned); Bitmap source = new Bitmap(256, 240, 4 * 256, PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject()); g.DrawImage(source, 0, 0); handle.Free(); } if (_options.SelectedSprite >= 0) { ctrlImagePanel.Selection = SpriteInfo.GetSpriteInfo(_oamRam, _state.OamMode, _options.SelectedSprite).GetBounds(); } else { ctrlImagePanel.Selection = Rectangle.Empty; } }
private void tmrLog_Tick(object sender, EventArgs e) { tmrLog.Stop(); if (_scriptId >= 0) { string newLog = DebugApi.GetScriptLog(_scriptId); if (txtLog.Text != newLog) { txtLog.SuspendLayout(); txtLog.Text = newLog; txtLog.SelectionStart = newLog.Length; txtLog.ScrollToCaret(); txtLog.ResumeLayout(); } } mnuSave.Enabled = txtScriptContent.Text != _originalText; if (_filePath != null && File.Exists(_filePath) && mnuAutoReload.Checked) { if (_lastTimestamp < File.GetLastWriteTime(_filePath)) { if (_originalText != txtScriptContent.Text) { DialogResult result = MessageBox.Show("You have unsaved changes for this script and the file has been modified by another process - would you like to discard the changes and reload the script from the disk?", "Script Window", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { LoadScriptFile(_filePath, true, true); } } else { LoadScriptFile(_filePath, true, true); } _lastTimestamp = File.GetLastWriteTime(_filePath); } } tmrLog.Start(); }
public frmEditLabel(CodeLabel label) { InitializeComponent(); _originalLabel = label; Entity = label.Clone(); AddBinding(nameof(CodeLabel.MemoryType), cboType); AddBinding(nameof(CodeLabel.Address), txtAddress); AddBinding(nameof(CodeLabel.Label), txtLabel); AddBinding(nameof(CodeLabel.Comment), txtComment); AddBinding(nameof(CodeLabel.Length), nudLength); CpuType cpuType = label.MemoryType.ToCpuType(); cboType.Items.Clear(); if (cpuType == CpuType.Cpu) { if (DebugApi.GetMemorySize(SnesMemoryType.PrgRom) > 0) { cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.PrgRom)); } if (DebugApi.GetMemorySize(SnesMemoryType.WorkRam) > 0) { cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.WorkRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.SaveRam) > 0) { cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SaveRam)); } cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Register)); } else if (cpuType == CpuType.Spc) { cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpcRam)); cboType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpcRom)); } }
protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); InBackgroundHelper.StopBackgroundTimer(); if (_notifListener != null) { _notifListener.Dispose(); _notifListener = null; } if (!_shuttingDown && Program.IsMono) { //This appears to prevent Mono from locking up when closing the form DebugApi.ResumeExecution(); DebugWindowManager.CloseAll(); Task.Run(() => { EmuApi.Stop(); _shuttingDown = true; this.BeginInvoke((Action)(() => this.Close())); }); e.Cancel = true; return; } DebugApi.ResumeExecution(); DebugWindowManager.CloseAll(); ConfigManager.Config.WindowLocation = this.WindowState == FormWindowState.Normal ? this.Location : this.RestoreBounds.Location; ConfigManager.Config.WindowSize = this.WindowState == FormWindowState.Normal ? this.Size : this.RestoreBounds.Size; ConfigManager.ApplyChanges(); ConfigManager.SaveConfig(); EmuApi.Stop(); EmuApi.Release(); }
private void SetOptions() { _entityBinder.UpdateObject(); TraceLoggerOptions options = (TraceLoggerOptions)_entityBinder.Entity; InteropTraceLoggerOptions interopOptions = new InteropTraceLoggerOptions(); interopOptions.LogCpu = options.LogCpu; interopOptions.LogSpc = options.LogSpc; interopOptions.IndentCode = options.IndentCode; interopOptions.ShowExtraInfo = options.ShowExtraInfo; interopOptions.UseLabels = options.UseLabels; interopOptions.UseWindowsEol = options.UseWindowsEol; interopOptions.ExtendZeroPage = options.ExtendZeroPage; interopOptions.Condition = Encoding.UTF8.GetBytes(txtCondition.Text); Array.Resize(ref interopOptions.Condition, 1000); interopOptions.Format = Encoding.UTF8.GetBytes(txtFormat.Text.Replace("\t", "\\t")); Array.Resize(ref interopOptions.Format, 1000); DebugApi.SetTraceOptions(interopOptions); }
protected override bool ValidateInput() { if (txtCondition.Text.Trim().Length > 0) { EvalResultType resultType; DebugApi.EvaluateExpression(txtCondition.Text.Replace(Environment.NewLine, " "), _cpuType, out resultType, false); if (resultType == EvalResultType.Invalid) { picExpressionWarning.Visible = true; return(false); } } picExpressionWarning.Visible = false; SnesMemoryType type = cboBreakpointType.GetEnumValue <SnesMemoryType>(); int maxValue = DebugApi.GetMemorySize(type) - 1; if (radSpecificAddress.Checked) { if (ValidateAddress(txtAddress, maxValue) < 0) { return(false); } } else if (radRange.Checked) { int start = ValidateAddress(txtFrom, maxValue); int end = ValidateAddress(txtTo, maxValue); if (start < 0 || end < 0 || end < start) { return(false); } } return(chkRead.Checked || chkWrite.Checked || (chkExec.Checked && Breakpoint.IsTypeCpuBreakpoint(type)) || txtCondition.Text.Length > 0); }
protected override void OnFormClosing(FormClosingEventArgs e) { _notifListener?.Dispose(); tmrUpdateLog.Stop(); while (_refreshRunning) { System.Threading.Thread.Sleep(50); } base.OnFormClosing(e); TraceLoggerInfo config = ConfigManager.Config.Debug.TraceLogger; config.AutoRefresh = mnuAutoRefresh.Checked; config.LineCount = _lineCount; config.WindowSize = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Size : this.Size; config.WindowLocation = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Location : this.Location; config.FontFamily = txtTraceLog.BaseFont.FontFamily.Name; config.FontSize = txtTraceLog.BaseFont.Size; config.FontStyle = txtTraceLog.BaseFont.Style; config.TextZoom = txtTraceLog.TextZoom; _entityBinder.UpdateObject(); //Disable logging when we close the trace logger _interopOptions = GetInteropOptions(true); SetCoreOptions(); ConfigManager.ApplyChanges(); if (_loggingEnabled) { DebugApi.StopTraceLogger(); } }
private void lstCounters_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e) { AddressCounters counts = _counts[e.ItemIndex]; ListViewItem item = new ListViewItem("$" + counts.Address.ToString("X4")); item.Selected = false; item.Focused = false; item.SubItems.Add("$" + DebugApi.GetMemoryValue(_memoryType, counts.Address).ToString("X2")); item.SubItems.Add(FormatNumber(counts.ReadCount)); item.SubItems.Add(counts.ReadStamp > 0 ? FormatNumber(_masterClock - counts.ReadStamp) : "n/a"); item.SubItems.Add(FormatNumber(counts.WriteCount)); item.SubItems.Add(counts.WriteStamp > 0 ? FormatNumber(_masterClock - counts.WriteStamp) : "n/a"); item.SubItems.Add(FormatNumber(counts.ExecCount)); item.SubItems.Add(counts.ExecStamp > 0 ? FormatNumber(_masterClock - counts.ExecStamp) : "n/a"); item.SubItems.Add(counts.UninitRead != 0 ? "☑" : "☐"); if (counts.ReadCount == 0 && counts.WriteCount == 0 && counts.ExecCount == 0) { item.ForeColor = Color.Gray; } e.Item = item; }
public frmBreakpoint(Breakpoint breakpoint) { InitializeComponent(); Entity = breakpoint; switch (breakpoint.AddressType) { case BreakpointAddressType.AnyAddress: radAnyAddress.Checked = true; break; case BreakpointAddressType.SingleAddress: radSpecificAddress.Checked = true; break; case BreakpointAddressType.AddressRange: radRange.Checked = true; break; } AddBinding(nameof(Breakpoint.MemoryType), cboBreakpointType); AddBinding(nameof(Breakpoint.Enabled), chkEnabled); AddBinding(nameof(Breakpoint.MarkEvent), chkMarkOnEventViewer); AddBinding(nameof(Breakpoint.Address), txtAddress); AddBinding(nameof(Breakpoint.StartAddress), txtFrom); AddBinding(nameof(Breakpoint.EndAddress), txtTo); AddBinding(nameof(Breakpoint.BreakOnRead), chkRead); AddBinding(nameof(Breakpoint.BreakOnWrite), chkWrite); AddBinding(nameof(Breakpoint.BreakOnExec), chkExec); AddBinding(nameof(Breakpoint.Condition), txtCondition); _cpuType = breakpoint.CpuType; cboBreakpointType.Items.Clear(); if (_cpuType == CpuType.Cpu || _cpuType == CpuType.Sa1 || _cpuType == CpuType.Gsu || _cpuType == CpuType.Cx4) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(_cpuType.ToMemoryType())); cboBreakpointType.Items.Add("-"); if (DebugApi.GetMemorySize(SnesMemoryType.PrgRom) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.PrgRom)); } if (_cpuType == CpuType.Cpu && DebugApi.GetMemorySize(SnesMemoryType.WorkRam) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.WorkRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.SaveRam) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SaveRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.Sa1InternalRam) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.Sa1InternalRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.GsuWorkRam) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GsuWorkRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.BsxPsRam) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.BsxPsRam)); } if (DebugApi.GetMemorySize(SnesMemoryType.BsxMemoryPack) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.BsxMemoryPack)); } if (_cpuType == CpuType.Cpu) { if (cboBreakpointType.Items.Count > 2) { cboBreakpointType.Items.Add("-"); } cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.VideoRam)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpriteRam)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.CGRam)); } } else if (_cpuType == CpuType.Spc) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpcMemory)); cboBreakpointType.Items.Add("-"); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpcRam)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.SpcRom)); } else if (_cpuType == CpuType.NecDsp) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.DspProgramRom)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.DspDataRom)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.DspDataRam)); } else if (_cpuType == CpuType.Gameboy) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GameboyMemory)); cboBreakpointType.Items.Add("-"); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbPrgRom)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbWorkRam)); cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbHighRam)); if (DebugApi.GetMemorySize(SnesMemoryType.GbCartRam) > 0) { cboBreakpointType.Items.Add(ResourceHelper.GetEnumText(SnesMemoryType.GbCartRam)); } } this.toolTip.SetToolTip(this.picExpressionWarning, "Condition contains invalid syntax or symbols."); this.toolTip.SetToolTip(this.picHelp, frmBreakpoint.GetConditionTooltip(false)); }
private void btnReset_Click(object sender, EventArgs e) { DebugApi.ResetProfiler(this.CpuType); lstFunctions.Items.Clear(); RefreshData(); }
public void RefreshData() { _newData = DebugApi.GetProfilerData(this.CpuType); }
public void Prepare(long firstByteIndex, long lastByteIndex) { int visibleByteCount = (int)(lastByteIndex - firstByteIndex + 1); if (_highlightBreakpoints) { Breakpoint[] breakpoints = BreakpointManager.Breakpoints.ToArray(); _breakpointTypes = new BreakpointTypeFlags[visibleByteCount]; for (int i = 0; i < visibleByteCount; i++) { int byteIndex = i + (int)firstByteIndex; foreach (Breakpoint bp in breakpoints) { if (bp.Enabled && bp.Matches((uint)byteIndex, _memoryType, null)) { _breakpointTypes[i] = bp.BreakOnExec ? BreakpointTypeFlags.Execute : (bp.BreakOnWrite ? BreakpointTypeFlags.Write : BreakpointTypeFlags.Read); break; } } } } else { _breakpointTypes = null; } _counters = DebugApi.GetMemoryAccessCounts((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType); _cdlData = null; if (_highlightDataBytes || _highlightCodeBytes) { switch (_memoryType) { case SnesMemoryType.CpuMemory: case SnesMemoryType.Sa1Memory: case SnesMemoryType.Cx4Memory: case SnesMemoryType.GsuMemory: case SnesMemoryType.GameboyMemory: case SnesMemoryType.PrgRom: case SnesMemoryType.GbPrgRom: _cdlData = DebugApi.GetCdlData((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType); break; } } _hasLabel = new bool[visibleByteCount]; if (_highlightLabelledBytes) { if (_memoryType <= SnesMemoryType.SpcMemory) { AddressInfo addr = new AddressInfo(); addr.Type = _memoryType; for (long i = 0; i < _hasLabel.Length; i++) { addr.Address = (int)(firstByteIndex + i); _hasLabel[i] = !string.IsNullOrWhiteSpace(LabelManager.GetLabel(addr)?.Label); } } else if (_memoryType == SnesMemoryType.PrgRom || _memoryType == SnesMemoryType.WorkRam || _memoryType == SnesMemoryType.SaveRam) { for (long i = 0; i < _hasLabel.Length; i++) { _hasLabel[i] = !string.IsNullOrWhiteSpace(LabelManager.GetLabel((uint)(firstByteIndex + i), _memoryType)?.Label); } } } _state = DebugApi.GetState(); }
public bool SaveToStream(Stream ModuleStream) { MEMORY_BASIC_INFORMATION64 mbi = new MEMORY_BASIC_INFORMATION64(); mbi = DebugApi.AddressType(BaseAddress); if (mbi.Protect == PAGE.NOACCESS && !DebugApi.IsIDNA) { DebugApi.WriteLine("Unable to read memory at %p", BaseAddress); return(false); } bool bIsImage = DebugApi.IsIDNA || (mbi.Type == MEM.IMAGE || mbi.Type == MEM.PRIVATE); IMAGE_DOS_HEADER dosHeader = DOSHeader; if (!dosHeader.isValid) { return(false); } // NT PE Headers ulong dwAddr = BaseAddress; ulong dwEnd = 0; uint nRead; IMAGE_SECTION_HEADER section = new IMAGE_SECTION_HEADER(); ulong sectionAddr = 0; int nSection = 0; if (FileImageType == ImageType.Pe64bit) { sectionAddr = BaseAddress + (ulong)dosHeader.e_lfanew + (ulong)Marshal.OffsetOf(typeof(IMAGE_NT_HEADERS64), "OptionalHeader") + NTHeader.FileHeader.SizeOfOptionalHeader; nSection = NTHeader.FileHeader.NumberOfSections; dwEnd = BaseAddress + NTHeader.OptionalHeader.SizeOfHeaders; } if (FileImageType == ImageType.Pe32bit) { sectionAddr = BaseAddress + (ulong)dosHeader.e_lfanew + (ulong)Marshal.OffsetOf(typeof(IMAGE_NT_HEADERS32), "OptionalHeader") + NTHeader32.FileHeader.SizeOfOptionalHeader; nSection = NTHeader32.FileHeader.NumberOfSections; dwEnd = BaseAddress + NTHeader32.OptionalHeader.SizeOfHeaders; } MemLocation[] memLoc = new MemLocation[nSection]; int indxSec = -1; int slot; for (int n = 0; n < nSection; n++) { if (!DebugApi.ReadMemory <IMAGE_SECTION_HEADER>(sectionAddr, out section)) { DebugApi.WriteLine("[IMAGE_SECTION_HEADER] Fail to read PE section info at %p\n", sectionAddr); return(false); } for (slot = 0; slot <= indxSec; slot++) { if ((ulong)section.PointerToRawData < (ulong)memLoc[slot].FileAddr) { break; } } for (int k = indxSec; k >= slot; k--) { memLoc[k + 1] = memLoc[k]; } memLoc[slot].VAAddr = (IntPtr)section.VirtualAddress; memLoc[slot].VASize = (IntPtr)section.VirtualSize; memLoc[slot].FileAddr = (IntPtr)section.PointerToRawData; memLoc[slot].FileSize = (IntPtr)section.SizeOfRawData; indxSec++; sectionAddr += (ulong)Marshal.SizeOf(section); } uint pageSize; DebugApi.Control.GetPageSize(out pageSize); byte[] buffer = new byte[pageSize]; IDebugDataSpaces3 data = (IDebugDataSpaces3)DebugApi.Client; while (dwAddr < dwEnd) { nRead = pageSize; if (dwEnd - dwAddr < nRead) { nRead = (uint)(dwEnd - dwAddr); } if (data.ReadVirtual(dwAddr, buffer, nRead, out nRead) == (int)HRESULT.S_OK) { ModuleStream.Write(buffer, 0, (int)nRead); } else { DebugApi.WriteLine("Fail to read memory\n"); return(false); } dwAddr += nRead; } for (slot = 0; slot <= indxSec; slot++) { //if (!DebugApi.IsTaget64Bits) //{ if (bIsImage) { dwAddr = BaseAddress + (ulong)memLoc[slot].VAAddr; } else { dwAddr = BaseAddress + (ulong)memLoc[slot].FileAddr; } //} //else // dwAddr = BaseAddress + (ulong)memLoc[slot].FileAddr; dwEnd = (ulong)memLoc[slot].FileSize + dwAddr - 1; while (dwAddr <= dwEnd) { nRead = pageSize; if (dwEnd - dwAddr + 1 < pageSize) { nRead = (uint)(dwEnd - dwAddr + 1); } if (data.ReadVirtual(dwAddr, buffer, nRead, out nRead) == (int)HRESULT.S_OK) { ModuleStream.Write(buffer, 0, (int)nRead); } else { DebugApi.WriteLine("Fail to read memory\n"); return(false); } dwAddr += pageSize; } } return(true); }
public ulong RvaToOffset(ulong Rva) { var sectionId = SectionStart; uint sections = 0; MEMORY_BASIC_INFORMATION64 mbi = new MEMORY_BASIC_INFORMATION64(); mbi = DebugApi.AddressType(BaseAddress); if (!DebugApi.IsIDNA && mbi.Protect == PAGE.NOACCESS) { DebugApi.WriteLine("Unable to read memory at %p", BaseAddress); return(0); } bool bIsImage = (DebugApi.IsIDNA || mbi.Type == MEM.IMAGE || mbi.Type == MEM.PRIVATE); if (FileImageType == ImageType.Pe32bit) { sections = NTHeader32.FileHeader.NumberOfSections; sectionId += (ulong)Marshal.OffsetOf(typeof(IMAGE_NT_HEADERS32), "OptionalHeader") + NTHeader32.FileHeader.SizeOfOptionalHeader; } if (FileImageType == ImageType.Pe64bit) { sections = NTHeader.FileHeader.NumberOfSections; sectionId += (ulong)Marshal.OffsetOf(typeof(IMAGE_NT_HEADERS64), "OptionalHeader") + NTHeader.FileHeader.SizeOfOptionalHeader; } for (int i = 0; i < sections; i++) { IMAGE_SECTION_HEADER section = new IMAGE_SECTION_HEADER(); if (!DebugApi.ReadMemory <IMAGE_SECTION_HEADER>(sectionId, out section)) { Debug.WriteLine("[RVA] Unable to read IMAGE_SECTION_HEADER"); return(0); } if ((Rva >= section.VirtualAddress) && (Rva < (section.VirtualAddress + section.SizeOfRawData))) { // RVA is in this section, we can now resolve it. ulong start = 0; if (bIsImage) { start = section.VirtualAddress; } else { start = section.PointerToRawData; } ulong address = BaseAddress + (ulong)Rva - (ulong)section.VirtualAddress + start; // (ulong)section.PointerToRawData; return(address); } // Next section sectionId += (uint)Marshal.SizeOf(typeof(IMAGE_SECTION_HEADER)); } // RVA could not be found return(0); }
public byte GetValue() { return(DebugApi.GetMemoryValue(this.MemoryType, this.Address)); }
public AddressInfo GetRelativeAddress(CpuType cpuType) { return(DebugApi.GetRelativeAddress(GetAbsoluteAddress(), cpuType)); }