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