Merge branch 'develop'
[clinton/Virtual-Jaguar-Rx.git] / src / debugger / m68kDasmWin.cpp
index ec36938..de4fc82 100644 (file)
 // JPM  06/27/2016  Created this file\r
 // JPM  12/04/2016  Suport ELF debug information\r
 // JPM              Replacing the ELF support by the debugger information manager calls\r
+// JPM   Aug./2020  Display only the code related to the traced function, added different layouts & a status bar, Qt/HTML text format support\r
 //\r
 \r
 // STILL TO DO:\r
 //\r
 \r
-#include       <stdlib.h>\r
+#include <stdlib.h>\r
 #include "debugger/m68kDasmWin.h"\r
 #include "m68000/m68kinterface.h"\r
 #include "dsp.h"\r
 \r
 // \r
 m68KDasmWindow::m68KDasmWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog),\r
-       layout(new QVBoxLayout), text(new QTextBrowser),\r
-       memBase(0)\r
+layout(new QVBoxLayout),\r
+#if MD_LAYOUTFILE == 1\r
+statusbar(new QStatusBar),\r
+#endif\r
+#ifdef MD_LAYOUTTEXTS\r
+text(new QTextBrowser),\r
+#endif\r
+memBase(0)\r
 {\r
+       // Set font\r
        QFont fixedFont("Lucida Console", 8, QFont::Normal);\r
        fixedFont.setStyleHint(QFont::Monospace);   //TypeWriter\r
        fixedFont.setLetterSpacing(QFont::PercentageSpacing, 100);\r
+\r
+       // Set text in layout\r
+#ifdef MD_LAYOUTTEXTS\r
        text->setFont(fixedFont);\r
+       layout->addWidget(text);\r
+#endif\r
+\r
+       // Status bar\r
+#if MD_LAYOUTFILE == 1\r
+       layout->addWidget(statusbar);\r
        setLayout(layout);\r
+#endif\r
 \r
-       layout->addWidget(text);\r
+       // Set layout\r
+       setLayout(layout);\r
 }\r
 \r
 \r
@@ -49,157 +68,203 @@ void m68KDasmWindow::RefreshContents(void)
        size_t m68KPCNbrDisasmLines = 0;\r
        char *Symbol = NULL, *LineSrc, *CurrentLineSrc = NULL;\r
        bool m68kPCShow = false;\r
-       bool constant, adr, equal, Error;\r
+       bool constant, adr, equal;\r
+       DBGstatus Status;\r
        size_t j, i;\r
        size_t  nbr = vjs.nbrdisasmlines;\r
        char *PtrFullSource, *CurrentPtrFullSource = (char *)calloc(1, 1);\r
        size_t NumLine; // , CurrentNumLine = 0;\r
        size_t CurrentNumLine;\r
        char singleCharString[2] = { 0, 0 };\r
+#if MD_LAYOUTFILE == 1\r
+       bool In = true;\r
+#else\r
+#define In     true\r
+#endif\r
 \r
-       for (i = 0; i < nbr; i++)\r
+       for (i = 0; (i < nbr) && In; i++)\r
        {\r
                oldpc = pc;\r
                adr = constant = equal = false;\r
 \r
                // Display source filename based on the program address\r
-               if (vjs.displayFullSourceFilename && (PtrFullSource = DBGManager_GetFullSourceFilenameFromAdr(oldpc, &Error)) && strcmp(CurrentPtrFullSource, PtrFullSource))\r
+               if (vjs.displayFullSourceFilename && (PtrFullSource = DBGManager_GetFullSourceFilenameFromAdr(oldpc, &Status)) && strcmp(CurrentPtrFullSource, PtrFullSource))\r
                {\r
-#if 0\r
-                       if (strcmp(OldPtrFullSource, PtrFullSource))\r
+#if defined(MD_LAYOUTFILE)\r
+                       if (i)\r
+#if MD_LAYOUTFILE != 1\r
+                       {\r
+                               // add an empty line for the display of the new filename\r
+                               nbr++;\r
+                               s += QString("<br>");\r
+                       }\r
+#else\r
+                       {\r
+                               In = false;\r
+                       }\r
+                       else\r
+#endif\r
 #endif\r
                        {\r
-                               if (i)\r
-                               {\r
-                                       nbr++;\r
-                                       s += QString("<br>");\r
-                               }\r
-\r
                                CurrentNumLine = DBGManager_GetNumLineFromAdr(pc, DBG_NO_TAG) - 1;\r
-                               nbr++;\r
                                CurrentPtrFullSource = (char *)realloc(CurrentPtrFullSource, strlen(PtrFullSource) + 1);\r
                                strcpy(CurrentPtrFullSource, PtrFullSource);\r
-                               if (!Error)\r
+#if defined(MD_LAYOUTFILE)\r
+                               if (Status)\r
                                {\r
+                                       // Referenced filename doesn't exist\r
                                        sprintf(string, "<font color='#ff0000'><b>%s</b></font><br>", PtrFullSource);\r
+#if MD_LAYOUTFILE == 1\r
+                                       // Display status bar\r
+                                       if ((Status & DBGSTATUS_OUTDATEDFILE))\r
+                                       {\r
+                                               statusbar->setStyleSheet("background-color: lightyellow; font: bold");\r
+                                               statusbar->showMessage(QString("Outdated source file"));\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               statusbar->setStyleSheet("background-color: tomato; font: bold");\r
+                                               statusbar->showMessage(QString("Unavailable source file"));\r
+                                       }\r
+#endif\r
                                }\r
                                else\r
                                {\r
+                                       // Referenced filename does exist\r
                                        sprintf(string, "<font color='#00ff00'><b>%s</b></font><br>", PtrFullSource);\r
+#if MD_LAYOUTFILE == 1\r
+                                       // Display status bar\r
+                                       statusbar->setStyleSheet("background-color: transparent; font: bold");\r
+                                       statusbar->showMessage(QString(""));\r
+#endif\r
                                }\r
+                               nbr++;\r
                                s += QString(string);\r
+#endif\r
                        }\r
                }\r
-\r
-               // Display line number based on the program address\r
-               if ((NumLine = DBGManager_GetNumLineFromAdr(oldpc, DBG_NO_TAG)) && ((signed)NumLine > (signed)CurrentNumLine))\r
+               else\r
                {\r
-                       if ((signed)CurrentNumLine < 0)\r
+                       // Display line number based on the program address\r
+                       if ((NumLine = DBGManager_GetNumLineFromAdr(oldpc, DBG_NO_TAG)) && ((signed)NumLine > (signed)CurrentNumLine) && !Status)\r
                        {\r
-                               CurrentNumLine = NumLine - 1;\r
+#if MD_LAYOUTFILE != 1\r
+                               if ((signed)CurrentNumLine < 0)\r
+                               {\r
+                                       CurrentNumLine = NumLine - 1;\r
+                               }\r
+#endif\r
+                               sprintf(string, "| <font color='#006400'>%5u</font> | ", (unsigned int)++CurrentNumLine);               // (CurrentNumLine = NumLine));\r
+                       }\r
+                       else\r
+                       {\r
+                               sprintf(string, "|      | ");\r
                        }\r
-                       sprintf(string, "| <font color='#006400'>%5u</font> | ", (unsigned int)++CurrentNumLine);               // (CurrentNumLine = NumLine));\r
-               }\r
-               else\r
-               {\r
-                       sprintf(string, "|      | ");\r
-               }\r
-               s += QString(string);\r
-\r
-               // Display line source based on the program address\r
-               if (((signed)CurrentNumLine > 0) && (LineSrc = DBGManager_GetLineSrcFromNumLineBaseAdr(oldpc, CurrentNumLine)) && (LineSrc != CurrentLineSrc))\r
-               {\r
-                       sprintf(string, "<font color='#006400'>%s</font><br>", (CurrentLineSrc = LineSrc));\r
                        s += QString(string);\r
-                       nbr++;\r
-               }\r
-               else\r
-               {\r
-                       // Display symbol, or line source, based on the program address\r
-                       if (!CurrentLineSrc && !Symbol && (Symbol = DBGManager_GetSymbolNameFromAdr(oldpc)))\r
+\r
+                       // Display line source based on the program address\r
+                       if (((signed)CurrentNumLine > 0) && (LineSrc = DBGManager_GetLineSrcFromNumLineBaseAdr(oldpc, CurrentNumLine)) && (LineSrc != CurrentLineSrc))\r
                        {\r
-                               sprintf(string, "%s:<br>", Symbol);\r
+#if 0\r
+                               // add a color on the line text\r
+                               sprintf(string, "<font color='#006400'>%s</font><br>", (CurrentLineSrc = LineSrc));\r
                                s += QString(string);\r
+#else\r
+                               // add a color on the line text with HTML encoding\r
+                               s += QString("<font color='#006400'>");\r
+                               s += QString(QString((CurrentLineSrc = LineSrc)).toHtmlEscaped());\r
+                               s += QString("</font><br>");\r
+#endif\r
                                nbr++;\r
                        }\r
-                       // Display the assembly line based on the current PC\r
                        else\r
                        {\r
-                               pc += m68k_disassemble(buffer, (unsigned int)pc, 0, vjs.disasmopcodes);\r
-\r
-                               if (m68kPC == oldpc)\r
+                               // Display symbol, or line source, based on the program address\r
+                               if (!CurrentLineSrc && !Symbol && (Symbol = DBGManager_GetSymbolNameFromAdr(oldpc)))\r
                                {\r
-                                       sprintf(string, "-> <u>%06X: %s</u><br>", (unsigned int)oldpc, buffer);\r
-                                       m68kPCShow = true;\r
-                                       m68KPCNbrDisasmLines = i;\r
+                                       sprintf(string, "%s:<br>", Symbol);\r
+                                       s += QString(string);\r
+                                       nbr++;\r
                                }\r
+                               // Display the assembly line based on the current PC\r
                                else\r
                                {\r
-                                       sprintf(string, "   %06X: %s<br>", (unsigned int)oldpc, buffer);\r
-                               }\r
+                                       pc += m68k_disassemble(buffer, (unsigned int)pc, 0, vjs.disasmopcodes);\r
 \r
-                               buffer[0] = 0;  // Clear string\r
-\r
-                               for (j = 0; j < strlen(string); j++)\r
-                               {\r
-                                       if (string[j] == ' ')\r
+                                       if (m68kPC == oldpc)\r
                                        {\r
-                                               strcat(buffer, "&nbsp;");\r
-                                               adr = constant = false;\r
+                                               sprintf(string, "-> <u>%06X: %s</u><br>", (unsigned int)oldpc, buffer);\r
+                                               m68kPCShow = true;\r
+                                               m68KPCNbrDisasmLines = i;\r
                                        }\r
                                        else\r
                                        {\r
-                                               switch (string[j])\r
-                                               {\r
-                                               case    '#':\r
-                                                       constant = true;\r
-                                                       break;\r
-\r
-                                               case    '$':\r
-                                                       adr = true;\r
-                                                       break;\r
+                                               sprintf(string, "   %06X: %s<br>", (unsigned int)oldpc, buffer);\r
+                                       }\r
 \r
-                                               case    ',':\r
-                                                       constant = adr = equal = false;\r
-                                                       break;\r
+                                       buffer[0] = 0;  // Clear string\r
 \r
-                                               case    '=':\r
-                                                       equal = true;\r
-                                                       break;\r
+                                       for (j = 0; j < strlen(string); j++)\r
+                                       {\r
+                                               if (string[j] == ' ')\r
+                                               {\r
+                                                       strcat(buffer, "&nbsp;");\r
+                                                       adr = constant = false;\r
                                                }\r
-\r
-                                               if (!constant && adr && !equal)\r
+                                               else\r
                                                {\r
-                                                       int l = 0;\r
-                                                       char *p;\r
-                                                       do\r
+                                                       switch (string[j])\r
                                                        {\r
-                                                               adresse[l++] = string[++j];\r
-                                                       } while ((string[(j + 1)] >= '0') && (string[(j + 1)] <= '9') || (string[(j + 1)] >= 'A') && (string[(j + 1)] <= 'F'));\r
-                                                       adresse[l] = 0;\r
+                                                       case    '#':\r
+                                                               constant = true;\r
+                                                               break;\r
+\r
+                                                       case    '$':\r
+                                                               adr = true;\r
+                                                               break;\r
 \r
-                                                       if (Symbol = DBGManager_GetSymbolNameFromAdr(strtoul(adresse, &p, 16)))\r
+                                                       case    ',':\r
+                                                               constant = adr = equal = false;\r
+                                                               break;\r
+\r
+                                                       case    '=':\r
+                                                               equal = true;\r
+                                                               break;\r
+                                                       }\r
+\r
+                                                       if (!constant && adr && !equal)\r
                                                        {\r
-                                                               strcat(buffer, Symbol);\r
+                                                               int l = 0;\r
+                                                               char *p;\r
+                                                               do\r
+                                                               {\r
+                                                                       adresse[l++] = string[++j];\r
+                                                               } while ((string[(j + 1)] >= '0') && (string[(j + 1)] <= '9') || (string[(j + 1)] >= 'A') && (string[(j + 1)] <= 'F'));\r
+                                                               adresse[l] = 0;\r
+\r
+                                                               if (Symbol = DBGManager_GetSymbolNameFromAdr(strtoul(adresse, &p, 16)))\r
+                                                               {\r
+                                                                       strcat(buffer, Symbol);\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       strcat(buffer, "$");\r
+                                                                       strcat(buffer, adresse);\r
+                                                               }\r
+\r
+                                                               adr = false;\r
                                                        }\r
                                                        else\r
                                                        {\r
-                                                               strcat(buffer, "$");\r
-                                                               strcat(buffer, adresse);\r
+                                                               singleCharString[0] = string[j];\r
+                                                               strcat(buffer, singleCharString);\r
                                                        }\r
-\r
-                                                       adr = false;\r
-                                               }\r
-                                               else\r
-                                               {\r
-                                                       singleCharString[0] = string[j];\r
-                                                       strcat(buffer, singleCharString);\r
                                                }\r
                                        }\r
-                               }\r
 \r
-                               Symbol = NULL;\r
-                               s += QString(buffer);\r
+                                       Symbol = NULL;\r
+                                       s += QString(buffer);\r
+                               }\r
                        }\r
                }\r
        }\r
@@ -231,7 +296,7 @@ void m68KDasmWindow::RefreshContents(void)
 \r
 \r
 // Set mem base PC address using the 68K pc current address\r
-void   m68KDasmWindow::Use68KPCAddress(void)\r
+void m68KDasmWindow::Use68KPCAddress(void)\r
 {\r
        memBase = m68k_get_reg(NULL, M68K_REG_PC);\r
 }\r