Commit | Line | Data |
---|---|---|
0203b5fd JPM |
1 | //\r |
2 | // localbrowser.cpp - Local variables\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 11/03/2017 Created this file\r | |
11 | //\r | |
12 | \r | |
13 | \r | |
14 | #include "debugger/localbrowser.h"\r | |
15 | #include "memory.h"\r | |
16 | #include "debugger/DBGManager.h"\r | |
17 | #include "settings.h"\r | |
18 | #include "m68000/m68kinterface.h"\r | |
19 | \r | |
20 | \r | |
21 | // \r | |
22 | LocalBrowserWindow::LocalBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog),\r | |
23 | layout(new QVBoxLayout), text(new QTextBrowser),\r | |
24 | // layout(new QVBoxLayout), text(new QLabel),\r | |
25 | // refresh(new QPushButton(tr("Refresh"))),\r | |
26 | // address(new QLineEdit),\r | |
27 | // go(new QPushButton(tr("Go"))),\r | |
28 | // memBase(0),\r | |
29 | NbLocal(0),\r | |
30 | FuncName((char *)calloc(1, 1)),\r | |
31 | LocalInfo(NULL)\r | |
32 | {\r | |
33 | setWindowTitle(tr("Local"));\r | |
34 | \r | |
35 | // address->setInputMask("hhhhhh");\r | |
36 | // QHBoxLayout * hbox1 = new QHBoxLayout;\r | |
37 | // hbox1->addWidget(refresh);\r | |
38 | // hbox1->addWidget(address);\r | |
39 | // hbox1->addWidget(go);\r | |
40 | \r | |
41 | // Need to set the size as well...\r | |
42 | // resize(560, 480);\r | |
43 | \r | |
44 | QFont fixedFont("Lucida Console", 8, QFont::Normal);\r | |
45 | // QFont fixedFont("", 8, QFont::Normal);\r | |
46 | fixedFont.setStyleHint(QFont::TypeWriter);\r | |
47 | text->setFont(fixedFont);\r | |
48 | //// layout->setSizeConstraint(QLayout::SetFixedSize);\r | |
49 | setLayout(layout);\r | |
50 | \r | |
51 | layout->addWidget(text);\r | |
52 | // layout->addWidget(refresh);\r | |
53 | // layout->addLayout(hbox1);\r | |
54 | \r | |
55 | // connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));\r | |
56 | // connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));\r | |
57 | }\r | |
58 | \r | |
59 | \r | |
60 | //\r | |
61 | LocalBrowserWindow::~LocalBrowserWindow(void)\r | |
62 | {\r | |
63 | free(LocalInfo);\r | |
64 | free(FuncName);\r | |
65 | // NbLocal = 0;\r | |
66 | }\r | |
67 | \r | |
68 | \r | |
69 | //\r | |
70 | bool LocalBrowserWindow::UpdateInfos(void)\r | |
71 | {\r | |
72 | size_t Adr;\r | |
73 | char *Ptr;\r | |
74 | \r | |
75 | if (NbLocal = DBGManager_GetNbLocalVariables(Adr = m68k_get_reg(NULL, M68K_REG_PC)))\r | |
76 | {\r | |
77 | if (Ptr = DBGManager_GetFunctionName(Adr))\r | |
78 | {\r | |
79 | if (strcmp(FuncName, Ptr))\r | |
80 | {\r | |
81 | FuncName = (char *)realloc(FuncName, strlen(Ptr) + 1);\r | |
82 | strcpy(FuncName, Ptr);\r | |
83 | \r | |
84 | LocalInfo = (WatchInfo *)realloc(LocalInfo, (sizeof(WatchInfo) * NbLocal));\r | |
85 | for (size_t i = 0; i < NbLocal; i++)\r | |
86 | {\r | |
87 | if (LocalInfo[i].PtrVariableName = DBGManager_GetLocalVariableName(Adr, i + 1))\r | |
88 | {\r | |
89 | LocalInfo[i].Op = DBGManager_GetLocalVariableOp(Adr, i + 1);\r | |
90 | LocalInfo[i].Adr = NULL;\r | |
91 | LocalInfo[i].TypeTag = DBGManager_GetLocalVariableTypeTag(Adr, i + 1);\r | |
92 | LocalInfo[i].PtrVariableBaseTypeName = DBGManager_GetLocalVariableTypeName(Adr, i + 1);\r | |
93 | LocalInfo[i].TypeEncoding = DBGManager_GetLocalVariableTypeEncoding(Adr, i + 1);\r | |
94 | LocalInfo[i].TypeByteSize = DBGManager_GetLocalVariableTypeByteSize(Adr, i + 1);\r | |
95 | LocalInfo[i].Offset = DBGManager_GetLocalVariableOffset(Adr, i + 1);\r | |
96 | }\r | |
97 | }\r | |
98 | }\r | |
99 | \r | |
100 | return true;\r | |
101 | }\r | |
102 | }\r | |
103 | \r | |
104 | *FuncName = 0;\r | |
105 | \r | |
106 | return false;\r | |
107 | }\r | |
108 | \r | |
109 | \r | |
110 | //\r | |
111 | void LocalBrowserWindow::RefreshContents(void)\r | |
112 | {\r | |
113 | char string[1024];\r | |
114 | // char buf[64];\r | |
115 | QString Local;\r | |
116 | char Value[100];\r | |
117 | char *PtrValue;\r | |
118 | // size_t NbWatch, Adr;\r | |
119 | // WatchInfo PtrLocalInfo;\r | |
120 | \r | |
121 | if (isVisible())\r | |
122 | {\r | |
123 | if (UpdateInfos())\r | |
124 | {\r | |
125 | //#ifdef _MSC_VER\r | |
126 | //#pragma message("Warning: !!! Need to check the memory desalocation for LocalInfo !!!")\r | |
127 | //#else\r | |
128 | //#warning "!!! Need to do the memory desalocation for LocalInfo !!!"\r | |
129 | //#endif // _MSC_VER\r | |
130 | //#ifdef _MSC_VER\r | |
131 | //#pragma message("Warning: !!! Need to check the memory desalocation for FuncName !!!")\r | |
132 | //#else\r | |
133 | //#warning "!!! Need to do the memory desalocation for FuncName !!!"\r | |
134 | //#endif // _MSC_VER\r | |
135 | \r | |
136 | for (size_t i = 0; i < NbLocal; i++)\r | |
137 | {\r | |
138 | if (LocalInfo[i].PtrVariableName)\r | |
139 | {\r | |
140 | if (((LocalInfo[i].Op >= DBG_OP_breg0) && (LocalInfo[i].Op <= DBG_OP_breg31)))\r | |
141 | {\r | |
142 | LocalInfo[i].Adr = m68k_get_reg(NULL, M68K_REG_A6) + LocalInfo[i].Offset;\r | |
143 | \r | |
144 | if ((LocalInfo[i].Adr >= 0) && (LocalInfo[i].Adr < vjs.DRAM_size))\r | |
145 | {\r | |
146 | PtrValue = DBGManager_GetVariableValueFromAdr(LocalInfo[i].Adr, LocalInfo[i].TypeEncoding, LocalInfo[i].TypeByteSize);\r | |
147 | }\r | |
148 | else\r | |
149 | {\r | |
150 | PtrValue = NULL;\r | |
151 | }\r | |
152 | }\r | |
153 | else\r | |
154 | {\r | |
155 | if ((LocalInfo[i].Op >= DBG_OP_reg0) && (LocalInfo[i].Op <= DBG_OP_reg31))\r | |
156 | {\r | |
157 | PtrValue = itoa(m68k_get_reg(NULL, (m68k_register_t)((size_t)M68K_REG_D0 + (LocalInfo[i].Op - DBG_OP_reg0))), Value, 10);\r | |
158 | }\r | |
159 | else\r | |
160 | {\r | |
161 | PtrValue = NULL;\r | |
162 | }\r | |
163 | }\r | |
164 | \r | |
165 | sprintf(string, "%i : %s | %s | ", (i + 1), (LocalInfo[i].PtrVariableBaseTypeName ? LocalInfo[i].PtrVariableBaseTypeName : (char *)"<font color='#ff0000'>N/A</font>"), LocalInfo[i].PtrVariableName);\r | |
166 | Local += QString(string);\r | |
167 | if ((unsigned int)LocalInfo[i].Adr)\r | |
168 | {\r | |
169 | sprintf(string, "0x%06X", (unsigned int)LocalInfo[i].Adr);\r | |
170 | }\r | |
171 | else\r | |
172 | {\r | |
173 | sprintf(string, "%s", (char *)"<font color='#ff0000'>N/A</font>");\r | |
174 | }\r | |
175 | Local += QString(string);\r | |
176 | sprintf(string, " | %s", (!PtrValue ? (char *)"<font color='#ff0000'>N/A</font>" : PtrValue));\r | |
177 | Local += QString(string);\r | |
178 | sprintf(string, "<br>");\r | |
179 | Local += QString(string);\r | |
180 | }\r | |
181 | }\r | |
182 | \r | |
183 | text->clear();\r | |
184 | text->setText(Local);\r | |
185 | }\r | |
186 | else\r | |
187 | {\r | |
188 | text->clear();\r | |
189 | }\r | |
190 | }\r | |
191 | }\r | |
192 | \r | |
193 | \r | |
194 | #if 0\r | |
195 | void LocalBrowserWindow::keyPressEvent(QKeyEvent * e)\r | |
196 | {\r | |
197 | if (e->key() == Qt::Key_Escape)\r | |
198 | hide();\r | |
199 | else if (e->key() == Qt::Key_PageUp)\r | |
200 | {\r | |
201 | memBase -= 480;\r | |
202 | \r | |
203 | if (memBase < 0)\r | |
204 | memBase = 0;\r | |
205 | \r | |
206 | RefreshContents();\r | |
207 | }\r | |
208 | else if (e->key() == Qt::Key_PageDown)\r | |
209 | {\r | |
210 | memBase += 480;\r | |
211 | \r | |
212 | if (memBase > (0x200000 - 480))\r | |
213 | memBase = 0x200000 - 480;\r | |
214 | \r | |
215 | RefreshContents();\r | |
216 | }\r | |
217 | else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)\r | |
218 | {\r | |
219 | memBase -= 16;\r | |
220 | \r | |
221 | if (memBase < 0)\r | |
222 | memBase = 0;\r | |
223 | \r | |
224 | RefreshContents();\r | |
225 | }\r | |
226 | else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)\r | |
227 | {\r | |
228 | memBase += 16;\r | |
229 | \r | |
230 | if (memBase > (0x200000 - 480))\r | |
231 | memBase = 0x200000 - 480;\r | |
232 | \r | |
233 | RefreshContents();\r | |
234 | }\r | |
235 | }\r | |
236 | #endif\r | |
237 | \r | |
238 | \r | |
239 | #if 0\r | |
240 | void LocalBrowserWindow::GoToAddress(void)\r | |
241 | {\r | |
242 | bool ok;\r | |
243 | QString newAddress = address->text();\r | |
244 | memBase = newAddress.toUInt(&ok, 16);\r | |
245 | RefreshContents();\r | |
246 | }\r | |
247 | #endif\r | |
248 | \r |