Debugger - Added "Set next statement"

This commit is contained in:
Souryo 2015-08-17 21:59:22 -04:00
parent 273c000c44
commit deb34b6ce9
10 changed files with 75 additions and 37 deletions

View file

@ -849,6 +849,9 @@ public:
static void ClearIRQSource(IRQSource source) { CPU::Instance->_state.IRQFlag &= ~(int)source; }
static void RunDMATransfer(uint8_t* spriteRAM, uint32_t &spriteRamAddr, uint8_t offsetValue);
static void StartDmcTransfer();
//Used by debugger for "Set Next Statement"
void SetDebugPC(uint16_t value) { SetPC(value); _state.DebugPC = value; }
void Reset(bool softReset);
void Exec();

View file

@ -189,32 +189,38 @@ void Debugger::BreakOnBreakpoint(MemoryOperationType type, uint32_t addr)
}
}
void Debugger::PrivateProcessRamOperation(MemoryOperationType type, uint32_t addr)
void Debugger::PrivateProcessRamOperation(MemoryOperationType type, uint16_t &addr)
{
_breakLock.Acquire();
_currentReadAddr = &addr;
//Check if a breakpoint has been hit and freeze execution if one has
bool breakDone = false;
int32_t absoluteAddr = _mapper->ToAbsoluteAddress(addr);
if(type == MemoryOperationType::ExecOpCode) {
_codeDataLogger->SetFlag(absoluteAddr, CdlPrgFlags::Code);
_disassembler->BuildCache(absoluteAddr, addr);
_lastInstruction = _memoryManager->DebugRead(addr);
UpdateCallstack(addr);
ProcessStepConditions(addr);
if(absoluteAddr >= 0) {
if(type == MemoryOperationType::ExecOpCode) {
_codeDataLogger->SetFlag(absoluteAddr, CdlPrgFlags::Code);
_disassembler->BuildCache(absoluteAddr, addr);
_lastInstruction = _memoryManager->DebugRead(addr);
breakDone = SleepUntilResume();
} else if(type == MemoryOperationType::ExecOperand) {
_codeDataLogger->SetFlag(absoluteAddr, CdlPrgFlags::Code);
} else {
_codeDataLogger->SetFlag(absoluteAddr, CdlPrgFlags::Data);
UpdateCallstack(addr);
ProcessStepConditions(addr);
breakDone = SleepUntilResume();
} else if(type == MemoryOperationType::ExecOperand) {
_codeDataLogger->SetFlag(absoluteAddr, CdlPrgFlags::Code);
} else {
_codeDataLogger->SetFlag(absoluteAddr, CdlPrgFlags::Data);
}
}
if(!breakDone) {
BreakOnBreakpoint(type, addr);
}
_currentReadAddr = nullptr;
_breakLock.Release();
}
@ -240,7 +246,7 @@ bool Debugger::SleepUntilResume()
return false;
}
void Debugger::PrivateProcessVramOperation(MemoryOperationType type, uint32_t addr)
void Debugger::PrivateProcessVramOperation(MemoryOperationType type, uint16_t addr)
{
int32_t absoluteAddr = _mapper->ToAbsoluteChrAddress(addr);
_codeDataLogger->SetFlag(absoluteAddr, type == MemoryOperationType::Read ? CdlChrFlags::Read : CdlChrFlags::Drawn);
@ -345,14 +351,22 @@ uint32_t Debugger::GetRelativeAddress(uint32_t addr)
return _mapper->FromAbsoluteAddress(addr);
}
void Debugger::ProcessRamOperation(MemoryOperationType type, uint32_t addr)
void Debugger::SetNextStatement(uint16_t addr)
{
if(_currentReadAddr) {
_cpu->SetDebugPC(addr);
*_currentReadAddr = addr;
}
}
void Debugger::ProcessRamOperation(MemoryOperationType type, uint16_t &addr)
{
if(Debugger::Instance) {
Debugger::Instance->PrivateProcessRamOperation(type, addr);
}
}
void Debugger::ProcessVramOperation(MemoryOperationType type, uint32_t addr)
void Debugger::ProcessVramOperation(MemoryOperationType type, uint16_t addr)
{
if(Debugger::Instance) {
Debugger::Instance->PrivateProcessVramOperation(type, addr);

View file

@ -54,6 +54,8 @@ private:
SimpleLock _bpLock;
SimpleLock _breakLock;
uint16_t *_currentReadAddr; //Used to alter the executing address via "Set Next Statement"
string _romFilepath;
string _outputCache;
atomic<int32_t> _stepCount;
@ -63,8 +65,8 @@ private:
atomic<int32_t> _stepOverAddr;
private:
void PrivateProcessRamOperation(MemoryOperationType type, uint32_t addr);
void PrivateProcessVramOperation(MemoryOperationType type, uint32_t addr);
void PrivateProcessRamOperation(MemoryOperationType type, uint16_t &addr);
void PrivateProcessVramOperation(MemoryOperationType type, uint16_t addr);
shared_ptr<Breakpoint> GetMatchingBreakpoint(BreakpointType type, uint32_t addr);
void UpdateCallstack(uint32_t addr);
void ProcessStepConditions(uint32_t addr);
@ -101,6 +103,8 @@ public:
CdlRatios GetCdlRatios();
void ResetCdlLog();
void SetNextStatement(uint16_t addr);
bool IsCodeChanged();
string GenerateOutput();
string* GetCode();
@ -108,6 +112,6 @@ public:
uint8_t GetMemoryValue(uint32_t addr);
uint32_t GetRelativeAddress(uint32_t addr);
static void ProcessRamOperation(MemoryOperationType type, uint32_t addr);
static void ProcessVramOperation(MemoryOperationType type, uint32_t addr);
static void ProcessRamOperation(MemoryOperationType type, uint16_t &addr);
static void ProcessVramOperation(MemoryOperationType type, uint16_t addr);
};

View file

@ -71,6 +71,7 @@
| System.Windows.Forms.Keys.F10)));
this.mnuSetNextStatement.Size = new System.Drawing.Size(258, 22);
this.mnuSetNextStatement.Text = "Set Next Statement";
this.mnuSetNextStatement.Click += new System.EventHandler(this.mnuSetNextStatement_Click);
//
// toolStripMenuItem1
//
@ -111,6 +112,7 @@
this.ctrlCodeViewer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.ctrlCodeViewer.ContextMenuStrip = this.contextMenuCode;
this.ctrlCodeViewer.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlCodeViewer.FontSize = 13F;
this.ctrlCodeViewer.Location = new System.Drawing.Point(0, 0);
this.ctrlCodeViewer.Name = "ctrlCodeViewer";
this.ctrlCodeViewer.Size = new System.Drawing.Size(379, 218);

View file

@ -13,8 +13,9 @@ namespace Mesen.GUI.Debugger
{
public partial class ctrlDebuggerCode : BaseScrollableTextboxUserControl
{
public delegate void WatchAddedEventHandler(WatchAddedEventArgs args);
public event WatchAddedEventHandler OnWatchAdded;
public delegate void AddressEventHandler(AddressEventArgs args);
public event AddressEventHandler OnWatchAdded;
public event AddressEventHandler OnSetNextStatement;
public ctrlDebuggerCode()
{
@ -182,7 +183,7 @@ namespace Mesen.GUI.Debugger
private void contextMenuCode_Opening(object sender, CancelEventArgs e)
{
mnuShowNextStatement.Enabled = _currentActiveAddress.HasValue;
mnuSetNextStatement.Enabled = false;
mnuSetNextStatement.Enabled = _currentActiveAddress.HasValue;
}
private void mnuShowNextStatement_Click(object sender, EventArgs e)
@ -206,15 +207,23 @@ namespace Mesen.GUI.Debugger
private void mnuAddToWatch_Click(object sender, EventArgs e)
{
if(this.OnWatchAdded != null) {
this.OnWatchAdded(new WatchAddedEventArgs() { Address = _lastClickedAddress});
this.OnWatchAdded(new AddressEventArgs() { Address = _lastClickedAddress});
}
}
private void mnuSetNextStatement_Click(object sender, EventArgs e)
{
if(this.OnSetNextStatement != null) {
this.OnSetNextStatement(new AddressEventArgs() { Address = (UInt32)this.ctrlCodeViewer.CurrentLine });
}
}
#endregion
#endregion
}
public class WatchAddedEventArgs : EventArgs
public class AddressEventArgs : EventArgs
{
public UInt32 Address { get; set; }
}

View file

@ -341,18 +341,11 @@ namespace Mesen.GUI.Debugger
protected override void OnMouseDown(MouseEventArgs e)
{
this.Focus();
int clickedLine = this.GetLineAtPosition(e.Y);
this.CursorPosition = this.ScrollPosition + clickedLine;
base.OnMouseDown(e);
}
protected override void OnMouseClick(MouseEventArgs e)
{
if(e.Button == System.Windows.Forms.MouseButtons.Left) {
int clickedLine = this.GetLineAtPosition(e.Y);
this.CursorPosition = this.ScrollPosition + clickedLine;
}
base.OnMouseClick(e);
}
private void DrawLine(Graphics g, int currentLine, int marginLeft, int positionY)
{
if(this.ShowLineNumbers) {

View file

@ -580,7 +580,8 @@
this.ctrlDebuggerCode.Name = "ctrlDebuggerCode";
this.ctrlDebuggerCode.Size = new System.Drawing.Size(546, 406);
this.ctrlDebuggerCode.TabIndex = 2;
this.ctrlDebuggerCode.OnWatchAdded += new Mesen.GUI.Debugger.ctrlDebuggerCode.WatchAddedEventHandler(this.ctrlDebuggerCode_OnWatchAdded);
this.ctrlDebuggerCode.OnWatchAdded += new Mesen.GUI.Debugger.ctrlDebuggerCode.AddressEventHandler(this.ctrlDebuggerCode_OnWatchAdded);
this.ctrlDebuggerCode.OnSetNextStatement += new Mesen.GUI.Debugger.ctrlDebuggerCode.AddressEventHandler(this.ctrlDebuggerCode_OnSetNextStatement);
this.ctrlDebuggerCode.Enter += new System.EventHandler(this.ctrlDebuggerCode_Enter);
//
// ctrlConsoleStatus
@ -601,7 +602,8 @@
this.ctrlDebuggerCodeSplit.Size = new System.Drawing.Size(1, 406);
this.ctrlDebuggerCodeSplit.TabIndex = 4;
this.ctrlDebuggerCodeSplit.Visible = false;
this.ctrlDebuggerCodeSplit.OnWatchAdded += new Mesen.GUI.Debugger.ctrlDebuggerCode.WatchAddedEventHandler(this.ctrlDebuggerCode_OnWatchAdded);
this.ctrlDebuggerCodeSplit.OnWatchAdded += new Mesen.GUI.Debugger.ctrlDebuggerCode.AddressEventHandler(this.ctrlDebuggerCode_OnWatchAdded);
this.ctrlDebuggerCodeSplit.OnSetNextStatement += new Mesen.GUI.Debugger.ctrlDebuggerCode.AddressEventHandler(this.ctrlDebuggerCode_OnSetNextStatement);
this.ctrlDebuggerCodeSplit.Enter += new System.EventHandler(this.ctrlDebuggerCodeSplit_Enter);
//
// ctrlWatch

View file

@ -178,11 +178,18 @@ namespace Mesen.GUI.Debugger
InteropEmu.DebugStepCycles(29780);
}
private void ctrlDebuggerCode_OnWatchAdded(WatchAddedEventArgs args)
private void ctrlDebuggerCode_OnWatchAdded(AddressEventArgs args)
{
this.ctrlWatch.AddWatch(args.Address);
}
private void ctrlDebuggerCode_OnSetNextStatement(AddressEventArgs args)
{
UInt16 addr = (UInt16)args.Address;
InteropEmu.DebugSetNextStatement(addr);
this.UpdateDebugger();
}
private void mnuFind_Click(object sender, EventArgs e)
{
_lastCodeWindow.OpenSearchBox();

View file

@ -82,6 +82,8 @@ namespace Mesen.GUI
[DllImport(DLLPath)] public static extern IntPtr DebugGetCode();
[DllImport(DLLPath)] public static extern Byte DebugGetMemoryValue(UInt32 addr);
[DllImport(DLLPath)] public static extern UInt32 DebugGetRelativeAddress(UInt32 addr);
[DllImport(DLLPath)] public static extern void DebugSetNextStatement(UInt16 addr);
[DllImport(DLLPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool DebugLoadCdlFile([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string cdlFilepath);
[DllImport(DLLPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool DebugSaveCdlFile([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string cdlFilepath);

View file

@ -33,6 +33,8 @@ extern "C"
DllExport int __stdcall DebugIsCodeChanged() { return _debugger->IsCodeChanged(); }
DllExport const char* __stdcall DebugGetCode() { return _debugger->GetCode()->c_str(); }
DllExport void __stdcall DebugSetNextStatement(uint16_t addr) { _debugger->SetNextStatement(addr); }
DllExport uint32_t __stdcall DebugGetMemoryState(uint32_t type, uint8_t *buffer) { return _debugger->GetMemoryState((DebugMemoryType)type, buffer); }
DllExport void __stdcall DebugGetNametable(uint32_t nametableIndex, uint32_t *frameBuffer, uint8_t *tileData, uint8_t *attributeData) { _debugger->GetNametable(nametableIndex, frameBuffer, tileData, attributeData); }
DllExport void __stdcall DebugGetChrBank(uint32_t bankIndex, uint32_t *frameBuffer, uint8_t palette) { _debugger->GetChrBank(bankIndex, frameBuffer, palette); }