From ff284dd29cbea36c15ae18d52916c4c788d0024a Mon Sep 17 00:00:00 2001 From: ugetab Date: Thu, 27 May 2010 17:01:29 +0000 Subject: [PATCH] Made debugger able to break on and distinguish Stack reads/writes, regardless of the source of the stack change. Addresses bug 2809881, which asked for the address push from an NMI/IRQ to cause a break --- changelog.txt | 1 + src/debug.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/changelog.txt b/changelog.txt index fc104514..f3c88fed 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,4 @@ +27-may-2010 - ugetab - Win32 - Debugger - Made debugger able to break on and distinguish Stack reads/writes 24-may-2010 - adelikat - Win32 - Memwatch - ignore spaces at the beginnign of an address in the address boxes 24-may-2010 - mart0258 - Disable auto-savestates during turbo 24-may-2010 - mart0258 - Prevent .zip files containing no recognized files from causing crash diff --git a/src/debug.cpp b/src/debug.cpp index e80a538a..9faa5bc9 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -494,15 +494,17 @@ void BreakHit(bool force = false) { FCEUD_DebugBreakpoint(); } +uint8 StackAddrBackup = X.S; + ///fires a breakpoint void breakpoint() { - int i; + int i,j; uint16 A=0; uint8 brk_type,opcode[3] = {0}; //inspect the current opcode opcode[0] = GetMem(_PC); - + //if the current instruction is bad, and we are breaking on bad opcodes, then hit the breakpoint if(dbgstate.badopbreak && (opsize[opcode[0]] == 0)) BreakHit(true); @@ -593,12 +595,46 @@ void breakpoint() { } else if (((watchpoint[i].flags & (WP_R | WP_W)) && (watchpoint[i].address == A)) || ((watchpoint[i].flags & WP_X) && (watchpoint[i].address == _PC))) BreakHit(); + } else if (watchpoint[i].flags & WP_E) { + //brk_type independant coding + + //Stack mem breaks + if (X.S < StackAddrBackup) { + //Pushes to stack + if (watchpoint[i].flags & WP_W) { + for (j = (X.S|0x0100); j < (StackAddrBackup|0x0100); j++) { + if (watchpoint[i].endaddress) { + if ((watchpoint[i].address <= j) && (watchpoint[i].endaddress >= j)) + BreakHit(); + } + else if (watchpoint[i].address == j) + BreakHit(); + } + } + } + else if (StackAddrBackup < X.S) { + //Pulls from stack + if (watchpoint[i].flags & WP_R) { + for (j = (StackAddrBackup|0x0100); j < (X.S|0x0100); j++) { + if (watchpoint[i].endaddress) { + if ((watchpoint[i].address <= j) && (watchpoint[i].endaddress >= j)) + BreakHit(); + } + else if (watchpoint[i].address == j) + BreakHit(); + } + } + } + } } // ################################## Start of SP CODE ########################### } // ################################## End of SP CODE ########################### } + + //Update the stack address with the current one, now that changes have registered. + StackAddrBackup = X.S; } //bbit edited: this is the end of the inserted code