Commit | Line | Data |
---|---|---|
0203b5fd JPM |
1 | //\r |
2 | // allwatch.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 01/08/2017 Created this file\r | |
11 | //\r | |
12 | \r | |
13 | // STILL TO DO:\r | |
14 | //\r | |
15 | \r | |
16 | #include "debugger/heapallocatorbrowser.h"\r | |
17 | #include "memory.h"\r | |
18 | #include "debugger/DBGManager.h"\r | |
19 | #include "m68000/m68kinterface.h"\r | |
20 | \r | |
21 | \r | |
22 | HeapAllocatorBrowserWindow::HeapAllocatorBrowserWindow(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 | // NbWatch(0),\r | |
30 | // PtrWatchInfo(NULL)\r | |
31 | Adr(0)\r | |
32 | //PtrAdr(NULL)\r | |
33 | {\r | |
34 | setWindowTitle(tr("Heap Allocation"));\r | |
35 | \r | |
36 | // address->setInputMask("hhhhhh");\r | |
37 | // QHBoxLayout * hbox1 = new QHBoxLayout;\r | |
38 | // hbox1->addWidget(refresh);\r | |
39 | // hbox1->addWidget(address);\r | |
40 | // hbox1->addWidget(go);\r | |
41 | \r | |
42 | // Need to set the size as well...\r | |
43 | // resize(560, 480);\r | |
44 | \r | |
45 | QFont fixedFont("Lucida Console", 8, QFont::Normal);\r | |
46 | // QFont fixedFont("", 8, QFont::Normal);\r | |
47 | fixedFont.setStyleHint(QFont::TypeWriter);\r | |
48 | text->setFont(fixedFont);\r | |
49 | //// layout->setSizeConstraint(QLayout::SetFixedSize);\r | |
50 | setLayout(layout);\r | |
51 | \r | |
52 | layout->addWidget(text);\r | |
53 | // layout->addWidget(refresh);\r | |
54 | // layout->addLayout(hbox1);\r | |
55 | \r | |
56 | // connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));\r | |
57 | // connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));\r | |
58 | }\r | |
59 | \r | |
60 | \r | |
61 | //\r | |
62 | HeapAllocatorBrowserWindow::~HeapAllocatorBrowserWindow(void)\r | |
63 | {\r | |
64 | // NbWatch = 0;\r | |
65 | // free(PtrAdr);\r | |
66 | }\r | |
67 | \r | |
68 | \r | |
69 | //\r | |
70 | void HeapAllocatorBrowserWindow::RefreshContents(void)\r | |
71 | {\r | |
72 | char string[1024];\r | |
73 | // char buf[64];\r | |
74 | QString HA;\r | |
75 | size_t Adr68K;\r | |
76 | size_t Error = 0;\r | |
77 | HeapAllocation HeapAllocation;\r | |
78 | \r | |
79 | if (isVisible())\r | |
80 | {\r | |
81 | if (Adr68K = Adr)\r | |
82 | {\r | |
83 | do\r | |
84 | {\r | |
85 | if ((Adr68K >= 0x4000) && (Adr68K < 0x200000))\r | |
86 | {\r | |
87 | memcpy(&HeapAllocation, &jaguarMainRAM[Adr68K], sizeof(HeapAllocation));\r | |
88 | \r | |
89 | if (HeapAllocation.size = ((HeapAllocation.size & 0xff) << 24) + ((HeapAllocation.size & 0xff00) << 8) + ((HeapAllocation.size & 0xff0000) >> 8) + ((HeapAllocation.size & 0xff000000) >> 24))\r | |
90 | {\r | |
91 | if (HeapAllocation.size <= (0x200000 - 0x4000))\r | |
92 | {\r | |
93 | if ((HeapAllocation.used = ((HeapAllocation.used & 0xff) << 8) + ((HeapAllocation.used & 0xff00) >> 8)) <= 1)\r | |
94 | {\r | |
95 | HeapAllocation.nextalloc = ((HeapAllocation.nextalloc & 0xff) << 24) + ((HeapAllocation.nextalloc & 0xff00) << 8) + ((HeapAllocation.nextalloc & 0xff0000) >> 8) + ((HeapAllocation.nextalloc & 0xff000000) >> 24);\r | |
96 | \r | |
97 | if ((HeapAllocation.nextalloc >= 0x4000) && (HeapAllocation.nextalloc < 0x200000))\r | |
98 | {\r | |
99 | sprintf(string, "0x%06x | 0x%06x (%i) | %s | 0x%06x<br>", Adr68K, HeapAllocation.size - sizeof(HeapAllocation), HeapAllocation.size - sizeof(HeapAllocation), HeapAllocation.used ? "Allocated" : "Free", HeapAllocation.nextalloc);\r | |
100 | Adr68K = HeapAllocation.nextalloc;\r | |
101 | }\r | |
102 | else\r | |
103 | {\r | |
104 | sprintf(string, "<br><font color='#ff0000'><b>Unable to determine the next memory allocation</b></font>");\r | |
105 | Error = 1;\r | |
106 | }\r | |
107 | }\r | |
108 | else\r | |
109 | {\r | |
110 | sprintf(string, "<br><font color='#ff0000'><b>Unable to determine if the allocated memory is used or not</b></font>");\r | |
111 | Error = 2;\r | |
112 | }\r | |
113 | }\r | |
114 | else\r | |
115 | {\r | |
116 | sprintf(string, "<br><font color='#ff0000'><b>Memory bloc size has a problem</b></font>");\r | |
117 | Error = 3;\r | |
118 | }\r | |
119 | }\r | |
120 | else\r | |
121 | {\r | |
122 | sprintf(string, "<br><font color='#0000ff'><b>Memory allocations browsing successfully completed</b></font>");\r | |
123 | }\r | |
124 | }\r | |
125 | else\r | |
126 | {\r | |
127 | sprintf(string, "<br><font color='#ff0000'><b>Memory allocations may have a problem</b></font>");\r | |
128 | Error = 4;\r | |
129 | }\r | |
130 | \r | |
131 | HA += QString(string);\r | |
132 | \r | |
133 | } while (HeapAllocation.size && !Error);\r | |
134 | }\r | |
135 | else\r | |
136 | {\r | |
137 | if (Adr = DBGManager_GetAdrFromSymbolName((char *)"__HeapBase"))\r | |
138 | {\r | |
139 | if (Adr68K = DBGManager_GetGlobalVariableAdrFromName((char *)"alloc"))\r | |
140 | {\r | |
141 | if (!(Adr68K = (jaguarMainRAM[Adr68K] << 24) + (jaguarMainRAM[Adr68K + 1] << 16) + (jaguarMainRAM[Adr68K + 2] << 8) + (jaguarMainRAM[Adr68K + 3])) || ((Adr68K < 0x4000) || (Adr68K >= 0x200000)))\r | |
142 | {\r | |
143 | sprintf(string, "<font color='#ff0000'><b>Memory allocator not yet initialised</b></font>");\r | |
144 | Adr = 0;\r | |
145 | }\r | |
146 | else\r | |
147 | {\r | |
148 | return RefreshContents();\r | |
149 | //sprintf(string, "<font color='#0000ff'><b>Memory allocator has been initialised</b></font>");\r | |
150 | }\r | |
151 | }\r | |
152 | else\r | |
153 | {\r | |
154 | sprintf(string, "<font color='#ff0000'><b>Memory allocator is not compatible</b></font>");\r | |
155 | Adr = 0;\r | |
156 | }\r | |
157 | }\r | |
158 | else\r | |
159 | {\r | |
160 | sprintf(string, "<font color='#ff0000'><b>Memory allocator doesn't exist</b></font>");\r | |
161 | }\r | |
162 | \r | |
163 | HA += QString(string);\r | |
164 | }\r | |
165 | \r | |
166 | text->clear();\r | |
167 | text->setText(HA);\r | |
168 | }\r | |
169 | }\r | |
170 | \r | |
171 | \r | |
172 | #if 0\r | |
173 | void HeapAllocatorBrowserWindow::keyPressEvent(QKeyEvent * e)\r | |
174 | {\r | |
175 | if (e->key() == Qt::Key_Escape)\r | |
176 | hide();\r | |
177 | else if (e->key() == Qt::Key_PageUp)\r | |
178 | {\r | |
179 | memBase -= 480;\r | |
180 | \r | |
181 | if (memBase < 0)\r | |
182 | memBase = 0;\r | |
183 | \r | |
184 | RefreshContents();\r | |
185 | }\r | |
186 | else if (e->key() == Qt::Key_PageDown)\r | |
187 | {\r | |
188 | memBase += 480;\r | |
189 | \r | |
190 | if (memBase > (0x200000 - 480))\r | |
191 | memBase = 0x200000 - 480;\r | |
192 | \r | |
193 | RefreshContents();\r | |
194 | }\r | |
195 | else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)\r | |
196 | {\r | |
197 | memBase -= 16;\r | |
198 | \r | |
199 | if (memBase < 0)\r | |
200 | memBase = 0;\r | |
201 | \r | |
202 | RefreshContents();\r | |
203 | }\r | |
204 | else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)\r | |
205 | {\r | |
206 | memBase += 16;\r | |
207 | \r | |
208 | if (memBase > (0x200000 - 480))\r | |
209 | memBase = 0x200000 - 480;\r | |
210 | \r | |
211 | RefreshContents();\r | |
212 | }\r | |
213 | }\r | |
214 | #endif\r | |
215 | \r | |
216 | \r | |
217 | #if 0\r | |
218 | void HeapAllocatorBrowserWindow::GoToAddress(void)\r | |
219 | {\r | |
220 | bool ok;\r | |
221 | QString newAddress = address->text();\r | |
222 | memBase = newAddress.toUInt(&ok, 16);\r | |
223 | RefreshContents();\r | |
224 | }\r | |
225 | #endif\r | |
226 | \r |