| 1 | //\r |
| 2 | // allwatchbrowser.cpp - All Watch\r |
| 3 | //\r |
| 4 | // by Jean-Paul Mari\r |
| 5 | //\r |
| 6 | // JPM = Jean-Paul Mari <djipi.mari@gmail.com>\r |
| 7 | //\r |
| 8 | // Who When What\r |
| 9 | // --- ---------- -----------------------------------------------------------\r |
| 10 | // JPM 12/07/2017 Created this file\r |
| 11 | // JPM 09/14/2018 Added a status bar, better status report and set information values in a tab\r |
| 12 | // JPM 10/05/2018 Added a sorting filter \r |
| 13 | //\r |
| 14 | \r |
| 15 | // STILL TO DO:\r |
| 16 | // Better presentation\r |
| 17 | // To set the information display at the right\r |
| 18 | // Display arrays information\r |
| 19 | // Display structures information\r |
| 20 | //\r |
| 21 | \r |
| 22 | //#define AW_DEBUGNUMVARIABLE 4415 // Set the global variable number to debug\r |
| 23 | #ifndef AW_DEBUGNUMVARIABLE\r |
| 24 | #define AW_STARTNUMVARIABLE 0 // Must be kept to 0 in case of no debug is required\r |
| 25 | #else\r |
| 26 | #define AW_STARTNUMVARIABLE AW_DEBUGNUMVARIABLE - 1\r |
| 27 | #endif\r |
| 28 | \r |
| 29 | \r |
| 30 | #include "debugger/allwatchbrowser.h"\r |
| 31 | #include "memory.h"\r |
| 32 | #include "debugger/DBGManager.h"\r |
| 33 | \r |
| 34 | \r |
| 35 | // \r |
| 36 | AllWatchBrowserWindow::AllWatchBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog),\r |
| 37 | layout(new QVBoxLayout),\r |
| 38 | #ifdef AW_LAYOUTTEXTS\r |
| 39 | text(new QTextBrowser),\r |
| 40 | #else\r |
| 41 | TableView(new QTableView),\r |
| 42 | model(new QStandardItemModel),\r |
| 43 | #endif\r |
| 44 | NbWatch(0),\r |
| 45 | statusbar(new QStatusBar),\r |
| 46 | PtrWatchInfo(NULL)\r |
| 47 | {\r |
| 48 | setWindowTitle(tr("All Watch"));\r |
| 49 | \r |
| 50 | // Set the font\r |
| 51 | QFont fixedFont("Lucida Console", 8, QFont::Normal);\r |
| 52 | fixedFont.setStyleHint(QFont::TypeWriter);\r |
| 53 | \r |
| 54 | #ifdef AW_LAYOUTTEXTS\r |
| 55 | // Set original layout\r |
| 56 | text->setFont(fixedFont);\r |
| 57 | layout->addWidget(text);\r |
| 58 | #else\r |
| 59 | // Set the new layout with proper identation and readibility\r |
| 60 | model->setColumnCount(3);\r |
| 61 | model->setHeaderData(0, Qt::Horizontal, QObject::tr("Name"));\r |
| 62 | model->setHeaderData(1, Qt::Horizontal, QObject::tr("Value"));\r |
| 63 | model->setHeaderData(2, Qt::Horizontal, QObject::tr("Type"));\r |
| 64 | // Information table\r |
| 65 | TableView->setModel(model);\r |
| 66 | TableView->setEditTriggers(QAbstractItemView::NoEditTriggers);\r |
| 67 | TableView->setShowGrid(0);\r |
| 68 | TableView->setFont(fixedFont);\r |
| 69 | TableView->verticalHeader()->setDefaultSectionSize(TableView->verticalHeader()->minimumSectionSize());\r |
| 70 | TableView->verticalHeader()->setDefaultAlignment(Qt::AlignRight);\r |
| 71 | layout->addWidget(TableView);\r |
| 72 | #endif\r |
| 73 | \r |
| 74 | // Status bar\r |
| 75 | layout->addWidget(statusbar);\r |
| 76 | setLayout(layout);\r |
| 77 | }\r |
| 78 | \r |
| 79 | \r |
| 80 | //\r |
| 81 | AllWatchBrowserWindow::~AllWatchBrowserWindow(void)\r |
| 82 | {\r |
| 83 | Reset();\r |
| 84 | }\r |
| 85 | \r |
| 86 | \r |
| 87 | //\r |
| 88 | void AllWatchBrowserWindow::Reset(void)\r |
| 89 | {\r |
| 90 | free(PtrWatchInfo);\r |
| 91 | NbWatch = 0;\r |
| 92 | PtrWatchInfo = NULL;\r |
| 93 | }\r |
| 94 | \r |
| 95 | \r |
| 96 | //\r |
| 97 | void AllWatchBrowserWindow::RefreshContents(void)\r |
| 98 | {\r |
| 99 | char msg[100];\r |
| 100 | #ifdef AW_LAYOUTTEXTS\r |
| 101 | char string[1024];\r |
| 102 | #endif\r |
| 103 | QString WatchAll;\r |
| 104 | size_t Error = AW_NOERROR;\r |
| 105 | char *PtrValue;\r |
| 106 | \r |
| 107 | if (isVisible())\r |
| 108 | {\r |
| 109 | if (!NbWatch)\r |
| 110 | {\r |
| 111 | // Pre-catch the information for each global variables\r |
| 112 | if (NbWatch = DBGManager_GetNbGlobalVariables())\r |
| 113 | {\r |
| 114 | PtrWatchInfo = (WatchInfo *)calloc(NbWatch, sizeof(WatchInfo));\r |
| 115 | \r |
| 116 | for (uint32_t i = AW_STARTNUMVARIABLE; i < NbWatch; i++)\r |
| 117 | {\r |
| 118 | PtrWatchInfo[i].PtrVariableName = DBGManager_GetGlobalVariableName(i + 1);\r |
| 119 | PtrWatchInfo[i].TypeTag = DBGManager_GetGlobalVariableTypeTag(i + 1);\r |
| 120 | #ifdef AW_LAYOUTTEXTS\r |
| 121 | PtrWatchInfo[i].addr = DBGManager_GetGlobalVariableAdr(i + 1);\r |
| 122 | if (!strlen(PtrWatchInfo[i].PtrVariableBaseTypeName = DBGManager_GetGlobalVariableTypeName(i + 1)))\r |
| 123 | {\r |
| 124 | PtrWatchInfo[i].PtrVariableBaseTypeName = (char *)"<font color='#ff0000'>N/A</font>";\r |
| 125 | }\r |
| 126 | #else\r |
| 127 | PtrWatchInfo[i].PtrVariableBaseTypeName = DBGManager_GetGlobalVariableTypeName(i + 1);\r |
| 128 | #endif\r |
| 129 | }\r |
| 130 | }\r |
| 131 | }\r |
| 132 | #ifndef AW_LAYOUTTEXTS\r |
| 133 | TableView->setSortingEnabled(false);\r |
| 134 | model->setRowCount(0);\r |
| 135 | #endif\r |
| 136 | if (NbWatch)\r |
| 137 | {\r |
| 138 | for (uint32_t i = AW_STARTNUMVARIABLE; i < NbWatch; i++)\r |
| 139 | {\r |
| 140 | if ((PtrWatchInfo[i].TypeTag & (DBG_TAG_TYPE_array | DBG_TAG_TYPE_structure)))\r |
| 141 | {\r |
| 142 | #if defined(AW_SUPPORTARRAY) || defined(AW_SUPPORTSTRUCTURE)\r |
| 143 | //PtrValue = (char *)memcpy(Value, &jaguarMainRAM[PtrWatchInfo[i].addr], 20);\r |
| 144 | PtrValue = NULL;\r |
| 145 | #else\r |
| 146 | PtrValue = NULL;\r |
| 147 | #endif\r |
| 148 | }\r |
| 149 | else\r |
| 150 | {\r |
| 151 | PtrValue = DBGManager_GetGlobalVariableValue(i + 1);\r |
| 152 | }\r |
| 153 | #ifdef AW_LAYOUTTEXTS\r |
| 154 | if (i)\r |
| 155 | {\r |
| 156 | WatchAll += QString("<br>");\r |
| 157 | }\r |
| 158 | sprintf(string, "%i : %s | %s | 0x%06X | %s", (i + 1), PtrWatchInfo[i].PtrVariableBaseTypeName, PtrWatchInfo[i].PtrVariableName, (unsigned int)PtrWatchInfo[i].addr, PtrValue ? PtrValue : (char *)"<font color='#ff0000'>N/A</font>");\r |
| 159 | WatchAll += QString(string);\r |
| 160 | #else\r |
| 161 | model->insertRow(i);\r |
| 162 | model->setItem(i, 0, new QStandardItem(QString("%1").arg(PtrWatchInfo[i].PtrVariableName)));\r |
| 163 | model->setItem(i, 1, new QStandardItem(QString("%1").arg(PtrValue)));\r |
| 164 | model->setItem(i, 2, new QStandardItem(QString("%1").arg(PtrWatchInfo[i].PtrVariableBaseTypeName)));\r |
| 165 | #endif\r |
| 166 | }\r |
| 167 | #ifdef AW_LAYOUTTEXTS\r |
| 168 | text->clear();\r |
| 169 | text->setText(WatchAll);\r |
| 170 | #else\r |
| 171 | TableView->setSortingEnabled(true);\r |
| 172 | #endif\r |
| 173 | sprintf(msg, "Ready");\r |
| 174 | }\r |
| 175 | else\r |
| 176 | {\r |
| 177 | sprintf(msg, "No watches");\r |
| 178 | Error = AW_NOALLWATCH;\r |
| 179 | }\r |
| 180 | \r |
| 181 | // Display status bar\r |
| 182 | if (Error)\r |
| 183 | {\r |
| 184 | if ((Error & AW_WARNING))\r |
| 185 | {\r |
| 186 | statusbar->setStyleSheet("background-color: lightyellow; font: bold");\r |
| 187 | }\r |
| 188 | else\r |
| 189 | {\r |
| 190 | statusbar->setStyleSheet("background-color: tomato; font: bold");\r |
| 191 | }\r |
| 192 | }\r |
| 193 | else\r |
| 194 | {\r |
| 195 | statusbar->setStyleSheet("background-color: lightgreen; font: bold");\r |
| 196 | }\r |
| 197 | statusbar->showMessage(QString(msg));\r |
| 198 | }\r |
| 199 | }\r |
| 200 | \r |
| 201 | \r |
| 202 | // \r |
| 203 | void AllWatchBrowserWindow::keyPressEvent(QKeyEvent * e)\r |
| 204 | {\r |
| 205 | if (e->key() == Qt::Key_Escape)\r |
| 206 | {\r |
| 207 | hide();\r |
| 208 | }\r |
| 209 | }\r |
| 210 | \r |