Changed Qt debugger code so that only one debugger can be open at a time.

This commit is contained in:
mjbudd77 2021-07-08 22:00:32 -04:00
parent c7627d9d26
commit 27fc890977
4 changed files with 62 additions and 31 deletions

View File

@ -76,7 +76,7 @@ extern int vblankScanLines;
extern int vblankPixel; extern int vblankPixel;
debuggerBookmarkManager_t dbgBmMgr; debuggerBookmarkManager_t dbgBmMgr;
static std::list <ConsoleDebugger*> dbgWinList; static ConsoleDebugger* dbgWin = NULL;
static void DeleteBreak(int sel); static void DeleteBreak(int sel);
static bool waitingAtBp = false; static bool waitingAtBp = false;
@ -938,7 +938,7 @@ ConsoleDebugger::ConsoleDebugger(QWidget *parent)
windowUpdateReq = true; windowUpdateReq = true;
dbgWinList.push_back( this ); dbgWin = this;
periodicTimer = new QTimer( this ); periodicTimer = new QTimer( this );
@ -951,7 +951,6 @@ ConsoleDebugger::ConsoleDebugger(QWidget *parent)
periodicTimer->start( 100 ); // 10hz periodicTimer->start( 100 ); // 10hz
// If this is the first debug window to open, load breakpoints fresh // If this is the first debug window to open, load breakpoints fresh
if ( dbgWinList.size() == 1 )
{ {
int autoLoadDebug; int autoLoadDebug;
@ -973,20 +972,21 @@ ConsoleDebugger::~ConsoleDebugger(void)
//printf("Destroy Debugger Window\n"); //printf("Destroy Debugger Window\n");
periodicTimer->stop(); periodicTimer->stop();
for (it = dbgWinList.begin(); it != dbgWinList.end(); it++) if ( dbgWin == this )
{ {
if ( (*it) == this ) dbgWin = NULL;
{
dbgWinList.erase(it);
//printf("Removing Debugger Window\n");
break;
}
} }
if ( dbgWinList.size() == 0 ) if ( dbgWin == NULL )
{ {
saveGameDebugBreakpoints(); saveGameDebugBreakpoints();
debuggerClearAllBreakpoints(); debuggerClearAllBreakpoints();
debuggerClearAllBookmarks();
if ( waitingAtBp )
{
FCEUI_SetEmulationPaused(0);
}
} }
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -1498,6 +1498,8 @@ void ConsoleDebugger::delete_BM_CB(void)
dbgBmMgr.deleteBookmark( addr ); dbgBmMgr.deleteBookmark( addr );
bmListUpdate(true); bmListUpdate(true);
saveGameDebugBreakpoints(true);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void ConsoleDebugger::edit_BM_name( int addr ) void ConsoleDebugger::edit_BM_name( int addr )
@ -1646,6 +1648,11 @@ static void DeleteBreak(int sel)
fceuWrapperUnLock(); fceuWrapperUnLock();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void debuggerClearAllBookmarks(void)
{
dbgBmMgr.clear();
}
//----------------------------------------------------------------------------
void debuggerClearAllBreakpoints(void) void debuggerClearAllBreakpoints(void)
{ {
int i; int i;
@ -1697,6 +1704,8 @@ void ConsoleDebugger::delete_BP_CB(void)
delete item; delete item;
//delete bpTree->takeTopLevelItem(row); //delete bpTree->takeTopLevelItem(row);
//bpListUpdate( true ); //bpListUpdate( true );
saveGameDebugBreakpoints(true);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void ConsoleDebugger::breakOnBadOpcodeCB(bool value) void ConsoleDebugger::breakOnBadOpcodeCB(bool value)
@ -3042,9 +3051,9 @@ void FCEUD_DebugBreakpoint( int bpNum )
fceuWrapperUnLock(); fceuWrapperUnLock();
for (it=dbgWinList.begin(); it!=dbgWinList.end(); it++) if ( dbgWin )
{ {
(*it)->breakPointNotify( bpNum ); dbgWin->breakPointNotify( bpNum );
} }
while ( nes_shm->runEmulator && bpDebugEnable && while ( nes_shm->runEmulator && bpDebugEnable &&
@ -3077,7 +3086,17 @@ void FCEUD_DebugBreakpoint( int bpNum )
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool debuggerWindowIsOpen(void) bool debuggerWindowIsOpen(void)
{ {
return (dbgWinList.size() > 0); return dbgWin != NULL;
}
//----------------------------------------------------------------------------
void debuggerWindowSetFocus(bool val)
{
if ( dbgWin )
{
dbgWin->activateWindow();
dbgWin->raise();
dbgWin->setFocus();
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool debuggerWaitingAtBreakpoint(void) bool debuggerWaitingAtBreakpoint(void)
@ -3089,9 +3108,9 @@ void updateAllDebuggerWindows( void )
{ {
std::list <ConsoleDebugger*>::iterator it; std::list <ConsoleDebugger*>::iterator it;
for (it=dbgWinList.begin(); it!=dbgWinList.end(); it++) if ( dbgWin )
{ {
(*it)->queueUpdate(); dbgWin->queueUpdate();
} }
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -3142,7 +3161,7 @@ static int getGameDebugBreakpointFileName(char *filepath)
return 0; return 0;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void saveGameDebugBreakpoints(void) void saveGameDebugBreakpoints( bool force )
{ {
int i; int i;
FILE *fp; FILE *fp;
@ -3151,16 +3170,17 @@ void saveGameDebugBreakpoints(void)
debuggerBookmark_t *bm; debuggerBookmark_t *bm;
// If no breakpoints are loaded, skip saving // If no breakpoints are loaded, skip saving
if ( (numWPs == 0) && (dbgBmMgr.size() == 0) ) if ( !force && (numWPs == 0) && (dbgBmMgr.size() == 0) )
{ {
return; return;
} }
if ( getGameDebugBreakpointFileName( stmp ) ) if ( getGameDebugBreakpointFileName( stmp ) )
{ {
printf("Error: Failed to get save file name for debug\n");
return; return;
} }
//printf("Debug Save File: '%s' \n", stmp ); printf("Debug Save File: '%s' \n", stmp );
fp = fopen( stmp, "w"); fp = fopen( stmp, "w");
@ -3289,13 +3309,14 @@ void loadGameDebugBreakpoints(void)
char id[64], data[128]; char id[64], data[128];
// If no debug windows are open, skip loading breakpoints // If no debug windows are open, skip loading breakpoints
if ( dbgWinList.size() == 0 ) if ( dbgWin == NULL )
{ {
printf("No Debug Windows Open: Skipping loading of breakpoint data\n"); printf("No Debug Windows Open: Skipping loading of breakpoint data\n");
return; return;
} }
if ( getGameDebugBreakpointFileName( stmp ) ) if ( getGameDebugBreakpointFileName( stmp ) )
{ {
printf("Error: Failed to get load file name for debug\n");
return; return;
} }

View File

@ -348,11 +348,13 @@ class ConsoleDebugger : public QDialog
}; };
bool debuggerWindowIsOpen(void); bool debuggerWindowIsOpen(void);
void debuggerWindowSetFocus(bool val = true);
bool debuggerWaitingAtBreakpoint(void); bool debuggerWaitingAtBreakpoint(void);
void bpDebugSetEnable(bool val); void bpDebugSetEnable(bool val);
void saveGameDebugBreakpoints(void); void saveGameDebugBreakpoints( bool force = false );
void loadGameDebugBreakpoints(void); void loadGameDebugBreakpoints(void);
void debuggerClearAllBreakpoints(void); void debuggerClearAllBreakpoints(void);
void debuggerClearAllBookmarks(void);
void updateAllDebuggerWindows(void); void updateAllDebuggerWindows(void);
extern debuggerBookmarkManager_t dbgBmMgr; extern debuggerBookmarkManager_t dbgBmMgr;

View File

@ -2698,13 +2698,20 @@ void consoleWin_t::openRamSearch(void)
void consoleWin_t::openDebugWindow(void) void consoleWin_t::openDebugWindow(void)
{ {
ConsoleDebugger *debugWin;
//printf("Open GUI 6502 Debugger Window\n"); //printf("Open GUI 6502 Debugger Window\n");
if ( debuggerWindowIsOpen() )
{
debuggerWindowSetFocus();
}
else
{
ConsoleDebugger *debugWin;
debugWin = new ConsoleDebugger(this); debugWin = new ConsoleDebugger(this);
debugWin->show(); debugWin->show();
}
} }
void consoleWin_t::openHexEditor(void) void consoleWin_t::openHexEditor(void)

View File

@ -436,6 +436,7 @@ CloseGame(void)
hexEditorSaveBookmarks(); hexEditorSaveBookmarks();
saveGameDebugBreakpoints(); saveGameDebugBreakpoints();
debuggerClearAllBreakpoints(); debuggerClearAllBreakpoints();
debuggerClearAllBookmarks();
debugSymbolTable.save(); debugSymbolTable.save();
debugSymbolTable.clear(); debugSymbolTable.clear();