Debugger sources code clean-up
[clinton/Virtual-Jaguar-Rx.git] / src / debugger / heapallocatorbrowser.cpp
... / ...
CommitLineData
1//\r
2// heapallocatorbrowser.cpp: Memory heap allocation\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
22HeapAllocatorBrowserWindow::HeapAllocatorBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog),\r
23layout(new QVBoxLayout), text(new QTextBrowser),\r
24Adr(0)\r
25{\r
26 setWindowTitle(tr("Heap Allocation"));\r
27\r
28 QFont fixedFont("Lucida Console", 8, QFont::Normal);\r
29 fixedFont.setStyleHint(QFont::TypeWriter);\r
30 text->setFont(fixedFont);\r
31 setLayout(layout);\r
32\r
33 layout->addWidget(text);\r
34}\r
35\r
36\r
37//\r
38HeapAllocatorBrowserWindow::~HeapAllocatorBrowserWindow(void)\r
39{\r
40}\r
41\r
42\r
43//\r
44void HeapAllocatorBrowserWindow::RefreshContents(void)\r
45{\r
46 char string[1024];\r
47 QString HA;\r
48 size_t Adr68K;\r
49 size_t Error = 0;\r
50 HeapAllocation HeapAllocation;\r
51\r
52 if (isVisible())\r
53 {\r
54 if (Adr68K = Adr)\r
55 {\r
56 do\r
57 {\r
58 if ((Adr68K >= 0x4000) && (Adr68K < 0x200000))\r
59 {\r
60 memcpy(&HeapAllocation, &jaguarMainRAM[Adr68K], sizeof(HeapAllocation));\r
61\r
62 if (HeapAllocation.size = ((HeapAllocation.size & 0xff) << 24) + ((HeapAllocation.size & 0xff00) << 8) + ((HeapAllocation.size & 0xff0000) >> 8) + ((HeapAllocation.size & 0xff000000) >> 24))\r
63 {\r
64 if (HeapAllocation.size <= (0x200000 - 0x4000))\r
65 {\r
66 if ((HeapAllocation.used = ((HeapAllocation.used & 0xff) << 8) + ((HeapAllocation.used & 0xff00) >> 8)) <= 1)\r
67 {\r
68 HeapAllocation.nextalloc = ((HeapAllocation.nextalloc & 0xff) << 24) + ((HeapAllocation.nextalloc & 0xff00) << 8) + ((HeapAllocation.nextalloc & 0xff0000) >> 8) + ((HeapAllocation.nextalloc & 0xff000000) >> 24);\r
69\r
70 if ((HeapAllocation.nextalloc >= 0x4000) && (HeapAllocation.nextalloc < 0x200000))\r
71 {\r
72 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
73 Adr68K = HeapAllocation.nextalloc;\r
74 }\r
75 else\r
76 {\r
77 sprintf(string, "<br><font color='#ff0000'><b>Unable to determine the next memory allocation</b></font>");\r
78 Error = 1;\r
79 }\r
80 }\r
81 else\r
82 {\r
83 sprintf(string, "<br><font color='#ff0000'><b>Unable to determine if the allocated memory is used or not</b></font>");\r
84 Error = 2;\r
85 }\r
86 }\r
87 else\r
88 {\r
89 sprintf(string, "<br><font color='#ff0000'><b>Memory bloc size has a problem</b></font>");\r
90 Error = 3;\r
91 }\r
92 }\r
93 else\r
94 {\r
95 sprintf(string, "<br><font color='#0000ff'><b>Memory allocations browsing successfully completed</b></font>");\r
96 }\r
97 }\r
98 else\r
99 {\r
100 sprintf(string, "<br><font color='#ff0000'><b>Memory allocations may have a problem</b></font>");\r
101 Error = 4;\r
102 }\r
103\r
104 HA += QString(string);\r
105\r
106 } while (HeapAllocation.size && !Error);\r
107 }\r
108 else\r
109 {\r
110 if (Adr = DBGManager_GetAdrFromSymbolName((char *)"__HeapBase"))\r
111 {\r
112 if (Adr68K = DBGManager_GetGlobalVariableAdrFromName((char *)"alloc"))\r
113 {\r
114 if (!(Adr68K = (jaguarMainRAM[Adr68K] << 24) + (jaguarMainRAM[Adr68K + 1] << 16) + (jaguarMainRAM[Adr68K + 2] << 8) + (jaguarMainRAM[Adr68K + 3])) || ((Adr68K < 0x4000) || (Adr68K >= 0x200000)))\r
115 {\r
116 sprintf(string, "<font color='#ff0000'><b>Memory allocator not yet initialised</b></font>");\r
117 Adr = 0;\r
118 }\r
119 else\r
120 {\r
121 return RefreshContents();\r
122 }\r
123 }\r
124 else\r
125 {\r
126 sprintf(string, "<font color='#ff0000'><b>Memory allocator is not compatible</b></font>");\r
127 Adr = 0;\r
128 }\r
129 }\r
130 else\r
131 {\r
132 sprintf(string, "<font color='#ff0000'><b>Memory allocator doesn't exist</b></font>");\r
133 }\r
134\r
135 HA += QString(string);\r
136 }\r
137\r
138 text->clear();\r
139 text->setText(HA);\r
140 }\r
141}\r
142\r
143\r
144// \r
145void HeapAllocatorBrowserWindow::Reset(void)\r
146{\r
147 size_t Adr68K;\r
148\r
149 if (DBGManager_GetAdrFromSymbolName((char *)"__HeapBase"))\r
150 {\r
151 if (Adr68K = DBGManager_GetGlobalVariableAdrFromName((char *)"alloc"))\r
152 {\r
153 jaguarMainRAM[Adr68K] = jaguarMainRAM[Adr68K + 1] = jaguarMainRAM[Adr68K + 2] = jaguarMainRAM[Adr68K + 3] = 0;\r
154 Adr = 0;\r
155 }\r
156 }\r
157}\r
158\r
159\r
160// \r
161void HeapAllocatorBrowserWindow::keyPressEvent(QKeyEvent * e)\r
162{\r
163 if (e->key() == Qt::Key_Escape)\r
164 {\r
165 hide();\r
166 }\r
167}\r
168\r