From 6b6d2183880516e2dbe5c306413b83cafea0ddf6 Mon Sep 17 00:00:00 2001 From: ugetab Date: Fri, 18 Sep 2009 03:29:44 +0000 Subject: [PATCH] Working Debugger list(.deb) Saving and Loading finished. It's even less of a hassle to use now than it is to use in FCEUXDSP. Debugger/watchpoints automatically reload on game change, no phantom information traversing .deb files, and it's compatible with the FCEUXDSP .deb files. Took a long time to write & debug the code, so there may still be errors I didn't catch. --- src/drivers/win/debugger.cpp | 6 ---- src/drivers/win/pref.cpp | 68 ++++++++++++++++++++++++++---------- src/fceu.cpp | 15 +++----- 3 files changed, 55 insertions(+), 34 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 530b63f3..5f3fcd80 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1016,12 +1016,6 @@ BOOL CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara } numWPs = myNumWPs; - - if (numWPs < 64) { - watchpoint[numWPs + 1].address = 0; - watchpoint[numWPs + 1].endaddress = 0; - watchpoint[numWPs + 1].flags = 0; - } } else diff --git a/src/drivers/win/pref.cpp b/src/drivers/win/pref.cpp index ab69181c..9eaa903d 100644 --- a/src/drivers/win/pref.cpp +++ b/src/drivers/win/pref.cpp @@ -127,7 +127,7 @@ int storePreferences(char* romname) FILE* f; char* filename; int result; - int Counter; + int Counter = 0; // Prevent any attempts at file usage if the debugger is open //if (inDebugger) return 0; @@ -143,13 +143,29 @@ int storePreferences(char* romname) Counter++; } - //while (inDebugger); - if (!debuggerWasActive) { return 0; } - + + /* + // With some work, this could be made to prevent writing empty .deb files. + // Currently, it doesn't account for fully-deleted lists when deciding to write. + int i; + int makeDebugFile = 0; + + for (i=0;i<65;i++) + { + if (watchpoint[i].address || watchpoint[i].endaddress || watchpoint[i].flags || hexBookmarks[i].address || hexBookmarks[i].description[0]) + makeDebugFile = 1; + } + + if (!makeDebugFile) + { + return 0; + } + */ + filename = (char*)malloc(strlen(romname) + 5); sprintf(filename, "%s.deb", romname); @@ -212,15 +228,15 @@ int loadDebuggerPreferences(FILE* f) // Read the length of the BP description if (fread(&len, sizeof(len), 1, f) != 1) return 1; + // Delete eventual older conditions + if (watchpoint[myNumWPs].condText) + free(watchpoint[myNumWPs].condText); + + watchpoint[myNumWPs].condText = (char*)malloc(len + 1); + watchpoint[myNumWPs].condText[len] = 0; if (len) { - // Delete eventual older conditions - if (watchpoint[myNumWPs].condText) - free(watchpoint[myNumWPs].condText); - // Read the breakpoint condition - watchpoint[myNumWPs].condText = (char*)malloc(len + 1); - watchpoint[myNumWPs].condText[len] = 0; if (fread(watchpoint[myNumWPs].condText, 1, len, f) != len) return 1; // TODO: Check return value @@ -230,19 +246,23 @@ int loadDebuggerPreferences(FILE* f) // Read length of the BP description if (fread(&len, sizeof(len), 1, f) != 1) return 1; + // Delete eventual older description + if (watchpoint[myNumWPs].desc) + free(watchpoint[myNumWPs].desc); + + watchpoint[myNumWPs].desc = (char*)malloc(len + 1); + watchpoint[myNumWPs].desc[len] = 0; if (len) { - // Delete eventual older description - if (watchpoint[myNumWPs].desc) - free(watchpoint[myNumWPs].desc); - // Read breakpoint description - watchpoint[myNumWPs].desc = (char*)malloc(len + 1); - watchpoint[myNumWPs].desc[len] = 0; if (fread(watchpoint[myNumWPs].desc, 1, len, f) != len) return 1; } - // Activate breapoint + watchpoint[i].address = 0; + watchpoint[i].endaddress = 0; + watchpoint[i].flags = 0; + + // Activate breakpoint if (start || end || flags) { watchpoint[myNumWPs].address = start; @@ -253,10 +273,11 @@ int loadDebuggerPreferences(FILE* f) } } - + return 0; } + /** * Loads HexView preferences from a file * @@ -295,6 +316,7 @@ int loadPreferences(char* romname) { FILE* f; int result; + int i; myNumWPs = 0; @@ -311,6 +333,16 @@ int loadPreferences(char* romname) fclose(f); } + // This prevents information from traveling between debugger interations. + // It needs to be run pretty much regardless of whether there's a .deb file or not, + // successful read or failure. Otherwise, it's basically leaving previous info around. + for (i=myNumWPs;i<=64;i++) + { + watchpoint[i].address = 0; + watchpoint[i].endaddress = 0; + watchpoint[i].flags = 0; + } + if (wasinDebugger){ DoDebug(0); } diff --git a/src/fceu.cpp b/src/fceu.cpp index 0b1261d6..9a46edbc 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -100,17 +100,12 @@ static void CloseGame(void) #ifdef WIN32 // ################################## Start of SP CODE ########################### - //This subroutine works if used here, but it randomly overwrites the - //list of opened games when those games are later closed, I believe. - // - //The problem may be a load issue, but the save is what commits the error. - // - //extern char LoadedRomFName[2048]; + extern char LoadedRomFName[2048]; - //if (storePreferences(LoadedRomFName)) - //{ - // FCEUD_PrintError("Couldn't store debugging data"); - //} + if (storePreferences(LoadedRomFName)) + { + FCEUD_PrintError("Couldn't store debugging data"); + } // ################################## End of SP CODE ########################### #endif