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