Added multiple breakpoints feature and their key bindings
[clinton/Virtual-Jaguar-Rx.git] / src / gui / mainwin.cpp
index 7b14d7e..031e6e3 100644 (file)
@@ -20,6 +20,7 @@
 // JPM  11/04/2017  Added the local window\r
 // JPM  08/31/2018  Added the call stack window\r
 // JPM  Sept./2018  Added the new Models and BIOS handler, a screenshot feature and source code files browsing\r
+// JPM   Oct./2018  Added search paths in the settings, breakpoints feature\r
 //\r
 \r
 // FIXED:\r
 #include "joystick.h"\r
 #include "m68000/m68kinterface.h"\r
 \r
+#include "debugger/DBGManager.h"\r
 //#include "debugger/VideoWin.h"\r
 //#include "debugger/DasmWin.h"\r
 #include "debugger/m68KDasmWin.h"\r
 #include "debugger/GPUDasmWin.h"\r
 #include "debugger/DSPDasmWin.h"\r
 #include "debugger/memory1browser.h"\r
-//#include "debugger/brkWin.h"\r
+#include "debugger/BreakpointsWin.h"\r
+#include "debugger/NewFnctBreakpointWin.h"\r
 #include "debugger/FilesrcListWin.h"\r
 #include "debugger/exceptionvectortablebrowser.h"\r
 #include "debugger/allwatchbrowser.h"\r
@@ -192,7 +195,8 @@ MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false),
                allWatchBrowseWin = new AllWatchBrowserWindow(this);\r
                LocalBrowseWin = new LocalBrowserWindow(this);\r
                heapallocatorBrowseWin = new HeapAllocatorBrowserWindow(this);\r
-               //brkWin = new BrkWindow(this);\r
+               BreakpointsWin = new BreakpointsWindow(this);\r
+               NewFunctionBreakpointWin = new NewFnctBreakpointWindow(this);\r
                exceptionvectortableBrowseWin = new ExceptionVectorTableBrowserWindow(this);\r
                CallStackBrowseWin = new CallStackBrowserWindow(this);\r
 \r
@@ -389,7 +393,7 @@ MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false),
                traceStepOverAct->setDisabled(true);\r
                connect(traceStepOverAct, SIGNAL(triggered()), this, SLOT(DebuggerTraceStepOver()));\r
 \r
-               // Trace into trace\r
+               // Trace into tracing\r
                traceStepIntoAct = new QAction(QIcon(":/res/debug-stepinto.png"), tr("&Step Into"), this);\r
                traceStepIntoAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBSTEPINTO].KBSettingValue)));\r
                traceStepIntoAct->setShortcutContext(Qt::ApplicationShortcut);\r
@@ -397,9 +401,18 @@ MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false),
                traceStepIntoAct->setDisabled(true);\r
                connect(traceStepIntoAct, SIGNAL(triggered()), this, SLOT(DebuggerTraceStepInto()));\r
 \r
-               //newBreakpointFunctionAct = new QAction(QIcon(""), tr("&Function Breakpoint"), this);\r
-               //newBreakpointFunctionAct->setShortcut(QKeySequence(tr("Ctrl+B")));\r
-               //connect(newBreakpointFunctionAct, SIGNAL(triggered()), this, SLOT(NewBreakpointFunction()));\r
+               // Function breakpoint\r
+               newFunctionBreakpointAct = new QAction(QIcon(""), tr("&Function Breakpoint"), this);\r
+               newFunctionBreakpointAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBFUNCTIONBREAKPOINT].KBSettingValue)));\r
+               connect(newFunctionBreakpointAct, SIGNAL(triggered()), this, SLOT(ShowNewFunctionBreakpointWin()));\r
+               BreakpointsAct = new QAction(QIcon(":/res/debug-breakpoints.png"), tr("&Breakpoints"), this);\r
+               BreakpointsAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBBREAKPOINTS].KBSettingValue)));\r
+               connect(BreakpointsAct, SIGNAL(triggered()), this, SLOT(ShowBreakpointsWin()));\r
+               deleteAllBreakpointsAct = new QAction(QIcon(":/res/debug-deleteallbreakpoints.png"), tr("&Delete All Breakpoints"), this);\r
+               deleteAllBreakpointsAct->setShortcut(QKeySequence(tr(vjs.KBContent[KBDELETEALLBREAKPOINTS].KBSettingValue)));\r
+               connect(deleteAllBreakpointsAct, SIGNAL(triggered()), this, SLOT(DeleteAllBreakpoints()));\r
+               disableAllBreakpointsAct = new QAction(QIcon(":/res/debug-disableallbreakpoints.png"), tr("&Disable All Breakpoints"), this);\r
+               connect(disableAllBreakpointsAct, SIGNAL(triggered()), this, SLOT(DisableAllBreakpoints()));\r
 \r
                //VideoOutputAct = new QAction(tr("Output Video"), this);\r
                //VideoOutputAct->setStatusTip(tr("Shows the output video window"));\r
@@ -510,6 +523,7 @@ MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false),
                if (vjs.softTypeDebugger)\r
                {\r
                        debugWindowsMenu = debugMenu->addMenu(tr("&Windows"));\r
+                       debugWindowsMenu->addAction(BreakpointsAct);\r
                        debugWindowExceptionMenu = debugWindowsMenu->addMenu(tr("&Exception"));\r
                        debugWindowExceptionMenu->addAction(exceptionVectorTableBrowseAct);\r
                        debugWindowsMenu->addSeparator();\r
@@ -546,11 +560,11 @@ MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false),
                        debugMenu->addSeparator();\r
                        debugMenu->addAction(traceStepIntoAct);\r
                        debugMenu->addAction(traceStepOverAct);\r
-#if 0\r
                        debugMenu->addSeparator();\r
                        debugNewBreakpointMenu = debugMenu->addMenu(tr("&New Breakpoint"));\r
-                       debugNewBreakpointMenu->addAction(newBreakpointFunctionAct);\r
-#endif\r
+                       debugNewBreakpointMenu->addAction(newFunctionBreakpointAct);\r
+                       debugMenu->addAction(deleteAllBreakpointsAct);\r
+                       debugMenu->addAction(disableAllBreakpointsAct);\r
                        //debugMenu->addSeparator();\r
                        //debugMenu->addAction(DasmAct);\r
                }\r
@@ -605,6 +619,8 @@ MainWin::MainWin(bool autoRun): running(true), powerButtonOn(false),
                debuggerbar->addSeparator();\r
                debuggerbar->addAction(traceStepIntoAct);\r
                debuggerbar->addAction(traceStepOverAct);\r
+               debuggerbar->addSeparator();\r
+               debuggerbar->addAction(BreakpointsAct);\r
        }\r
 \r
        if (vjs.hardwareTypeAlpine)\r
@@ -1075,7 +1091,7 @@ static uint32_t ntscTickCount;
                // Otherwise, run the Jaguar simulation\r
                HandleGamepads();\r
                JaguarExecuteNew();\r
-               if (!vjs.softTypeDebugger)\r
+               //if (!vjs.softTypeDebugger)\r
                        videoWidget->HandleMouseHiding();\r
 \r
 static uint32_t refresh = 0;\r
@@ -1140,7 +1156,7 @@ void MainWin::TogglePowerState(void)
        if (!powerButtonOn)\r
        {\r
                // Restore the mouse pointer, if hidden:\r
-               if (!vjs.softTypeDebugger)\r
+               //if (!vjs.softTypeDebugger)\r
                {\r
                        videoWidget->CheckAndRestoreMouseCursor();\r
                }\r
@@ -1194,6 +1210,7 @@ void MainWin::TogglePowerState(void)
 \r
                WriteLog("GUI: Resetting Jaguar...\n");\r
                JaguarReset();\r
+               DeleteAllBreakpoints();\r
                DebuggerResetWindows();\r
                DACPauseAudioThread(false);\r
        }\r
@@ -1256,6 +1273,7 @@ void MainWin::ToggleRunState(void)
                }\r
 \r
                cpuBrowseWin->UnholdBPM();\r
+               BreakpointsWin->RefreshContents();\r
        }\r
 \r
        // Pause/unpause any running/non-running threads...\r
@@ -1410,8 +1428,8 @@ void MainWin::LoadSoftware(QString file)
        }\r
        else\r
        {\r
-               // Prevent the Alpine mode to crash in case of software without a start address\r
-               if (vjs.hardwareTypeAlpine && !jaguarRunAddress)\r
+               // Prevent the launch in case of software without a start address and without BIOS presence\r
+               if (!vjs.useJaguarBIOS && !jaguarRunAddress)\r
                {\r
                        ToggleRunState();\r
                }\r
@@ -1438,10 +1456,36 @@ void MainWin::ToggleCDUsage(void)
 \r
 \r
 //\r
-void MainWin::NewBreakpointFunction(void)\r
+void MainWin::ShowBreakpointsWin(void)\r
+{\r
+       BreakpointsWin->show();\r
+       BreakpointsWin->RefreshContents();\r
+}\r
+\r
+\r
+//\r
+void MainWin::DeleteAllBreakpoints(void)\r
+{\r
+       cpuBrowseWin->ResetBPM();\r
+       m68k_brk_reset();\r
+       ShowBreakpointsWin();\r
+}\r
+\r
+\r
+//\r
+void MainWin::DisableAllBreakpoints(void)\r
 {\r
-       //brkWin->show();\r
-       //brkWin->RefreshContents();\r
+       cpuBrowseWin->DisableBPM();\r
+       m68k_brk_disable();\r
+       ShowBreakpointsWin();\r
+}\r
+\r
+\r
+//\r
+void MainWin::ShowNewFunctionBreakpointWin(void)\r
+{\r
+       NewFunctionBreakpointWin->show();\r
+       ShowBreakpointsWin();\r
 }\r
 \r
 \r
@@ -1459,7 +1503,7 @@ void MainWin::DebuggerTraceStepInto(void)
 }\r
 \r
 \r
-// Restart\r
+// Restart the Jaguar executable\r
 void MainWin::DebuggerRestart(void)\r
 {\r
 #if 1\r
@@ -1469,7 +1513,8 @@ void MainWin::DebuggerRestart(void)
        m68k_set_reg(M68K_REG_SP, vjs.DRAM_size);\r
 #endif\r
        m68k_set_reg(M68K_REG_A6, 0);\r
-\r
+       m68k_brk_hitcounts_reset();\r
+       bpmHitCounts = 0;\r
        DebuggerResetWindows();\r
        DebuggerRefreshWindows();\r
 #ifdef _MSC_VER\r
@@ -1763,6 +1808,7 @@ void MainWin::ReadSettings(void)
        // Read settings from the Debugger mode\r
        settings.beginGroup("debugger");\r
        strcpy(vjs.debuggerROMPath, settings.value("DefaultROM", "").toString().toUtf8().data());\r
+       strcpy(vjs.sourcefilesearchPaths, settings.value("SourceFileSearchPaths", "").toString().toUtf8().data());\r
        vjs.nbrdisasmlines = settings.value("NbrDisasmLines", 32).toUInt();\r
        vjs.disasmopcodes = settings.value("DisasmOpcodes", true).toBool();\r
        vjs.displayHWlabels = settings.value("DisplayHWLabels", true).toBool();\r
@@ -1788,13 +1834,15 @@ void MainWin::ReadSettings(void)
 \r
        // Write important settings to the log file\r
        WriteLog("MainWin: Paths\n");\r
-       WriteLog("     EEPROMPath = \"%s\"\n", vjs.EEPROMPath);\r
-       WriteLog("        ROMPath = \"%s\"\n", vjs.ROMPath);\r
-       WriteLog("  AlpineROMPath = \"%s\"\n", vjs.alpineROMPath);\r
-       WriteLog("DebuggerROMPath = \"%s\"\n", vjs.debuggerROMPath);\r
-       WriteLog("     absROMPath = \"%s\"\n", vjs.absROMPath);\r
-       WriteLog("ScreenshotsPath = \"%s\"\n", vjs.screenshotPath);\r
-       WriteLog("  Pipelined DSP = %s\n", (vjs.usePipelinedDSP ? "ON" : "off"));\r
+       WriteLog("           EEPROMPath = \"%s\"\n", vjs.EEPROMPath);\r
+       WriteLog("              ROMPath = \"%s\"\n", vjs.ROMPath);\r
+       WriteLog("        AlpineROMPath = \"%s\"\n", vjs.alpineROMPath);\r
+       WriteLog("      DebuggerROMPath = \"%s\"\n", vjs.debuggerROMPath);\r
+       WriteLog("           absROMPath = \"%s\"\n", vjs.absROMPath);\r
+       WriteLog("      ScreenshotsPath = \"%s\"\n", vjs.screenshotPath);\r
+       WriteLog("SourceFileSearchPaths = \"%s\"\n", vjs.sourcefilesearchPaths);\r
+       WriteLog("MainWin: Misc.\n");\r
+       WriteLog("   Pipelined DSP = %s\n", (vjs.usePipelinedDSP ? "ON" : "off"));\r
 \r
 #if 0\r
        // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *\r
@@ -1846,6 +1894,7 @@ void MainWin::ReadSettings(void)
        WriteLog("Read setting = Done\n");\r
 \r
        ReadProfiles(&settings);\r
+       DBGManager_SourceFileSearchPathsSet(vjs.sourcefilesearchPaths);\r
 }\r
 \r
 \r
@@ -1974,6 +2023,19 @@ void MainWin::ReadUISettings(void)
                size = settings.value("CallStackBrowseWinSize", QSize(400, 400)).toSize();\r
                CallStackBrowseWin->resize(size);\r
 \r
+               // Breakpoints UI information\r
+               pos = settings.value("BreakpointsWinPos", QPoint(200, 200)).toPoint();\r
+               BreakpointsWin->move(pos);\r
+               settings.value("BreakpointsWinIsVisible", false).toBool() ? ShowBreakpointsWin() : void();\r
+               size = settings.value("BreakpointsWinSize", QSize(400, 400)).toSize();\r
+               BreakpointsWin->resize(size);\r
+               // New function breakpoint UI information\r
+               pos = settings.value("NewFunctionBreakpointWinPos", QPoint(200, 200)).toPoint();\r
+               NewFunctionBreakpointWin->move(pos);\r
+               settings.value("NewFunctionBreakpointWinIsVisible", false).toBool() ? ShowNewFunctionBreakpointWin() : void();\r
+               size = settings.value("NewFunctionBreakpointWinSize", QSize(400, 400)).toSize();\r
+               NewFunctionBreakpointWin->resize(size);\r
+\r
                // Memories browser UI information\r
                for (i = 0; i < vjs.nbrmemory1browserwindow; i++)\r
                {\r
@@ -2049,6 +2111,7 @@ void MainWin::WriteSettings(void)
        settings.setValue("displayFullSourceFilename", vjs.displayFullSourceFilename);\r
        settings.setValue("NbrMemory1BrowserWindow", (unsigned int)vjs.nbrmemory1browserwindow);\r
        settings.setValue("DefaultROM", vjs.debuggerROMPath);\r
+       settings.setValue("SourceFileSearchPaths", vjs.sourcefilesearchPaths);\r
        settings.endGroup();\r
 \r
        // Write settings from the Keybindings\r
@@ -2106,6 +2169,7 @@ void MainWin::WriteSettings(void)
 #endif\r
 \r
        WriteProfiles(&settings);\r
+       DBGManager_SourceFileSearchPathsSet(vjs.sourcefilesearchPaths);\r
 }\r
 \r
 \r
@@ -2172,6 +2236,12 @@ void MainWin::WriteUISettings(void)
                settings.setValue("CallStackBrowseWinPos", CallStackBrowseWin->pos());\r
                settings.setValue("CallStackBrowseWinIsVisible", CallStackBrowseWin->isVisible());\r
                settings.setValue("CallStackBrowseWinSize", CallStackBrowseWin->size());\r
+               settings.setValue("BreakpointsWinPos", BreakpointsWin->pos());\r
+               settings.setValue("BreakpointsWinIsVisible", BreakpointsWin->isVisible());\r
+               settings.setValue("BreakpointsWinSize", BreakpointsWin->size());\r
+               settings.setValue("NewFunctionBreakpointWinPos", NewFunctionBreakpointWin->pos());\r
+               settings.setValue("NewFunctionBreakpointWinIsVisible", NewFunctionBreakpointWin->isVisible());\r
+               settings.setValue("NewFunctionBreakpointWinSize", NewFunctionBreakpointWin->size());\r
                for (i = 0; i < vjs.nbrmemory1browserwindow; i++)\r
                {\r
                        sprintf(mem1Name, "mem1BrowseWinPos[%i]", (unsigned int)i);\r
@@ -2208,6 +2278,7 @@ void MainWin::DebuggerResetWindows(void)
                FilesrcListWin->Reset();\r
                allWatchBrowseWin->Reset();\r
                heapallocatorBrowseWin->Reset();\r
+               BreakpointsWin->Reset();\r
 \r
                //ResetAlpineWindows();\r
        }\r
@@ -2229,6 +2300,7 @@ void MainWin::DebuggerRefreshWindows(void)
                LocalBrowseWin->RefreshContents();\r
                CallStackBrowseWin->RefreshContents();\r
                heapallocatorBrowseWin->RefreshContents();\r
+               BreakpointsWin->RefreshContents();\r
                for (i = 0; i < vjs.nbrmemory1browserwindow; i++)\r
                {\r
                        mem1BrowseWin[i]->RefreshContents(i);\r