Commit | Line | Data |
---|---|---|
0203b5fd | 1 | //\r |
570dad92 | 2 | // heapallocatorbrowser.cpp: Memory heap allocation\r |
0203b5fd JPM |
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 | |
5d765b04 JPM |
11 | // JPM 09/05/2018 Support of the DRAM size limit option\r |
12 | // JPM 09/05/2018 Use definitions for error instead of hard values\r | |
13 | // JPM 09/05/2018 Detect if heap allocation shares space with SP (Stack)\r | |
0203b5fd JPM |
14 | //\r |
15 | \r | |
16 | // STILL TO DO:\r | |
5d765b04 | 17 | // Better information display\r |
0203b5fd JPM |
18 | //\r |
19 | \r | |
5d765b04 | 20 | #include "settings.h"\r |
0203b5fd JPM |
21 | #include "debugger/heapallocatorbrowser.h"\r |
22 | #include "memory.h"\r | |
23 | #include "debugger/DBGManager.h"\r | |
24 | #include "m68000/m68kinterface.h"\r | |
25 | \r | |
26 | \r | |
27 | HeapAllocatorBrowserWindow::HeapAllocatorBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog),\r | |
28 | layout(new QVBoxLayout), text(new QTextBrowser),\r | |
0203b5fd | 29 | Adr(0)\r |
0203b5fd JPM |
30 | {\r |
31 | setWindowTitle(tr("Heap Allocation"));\r | |
32 | \r | |
0203b5fd | 33 | QFont fixedFont("Lucida Console", 8, QFont::Normal);\r |
0203b5fd JPM |
34 | fixedFont.setStyleHint(QFont::TypeWriter);\r |
35 | text->setFont(fixedFont);\r | |
0203b5fd JPM |
36 | setLayout(layout);\r |
37 | \r | |
38 | layout->addWidget(text);\r | |
0203b5fd JPM |
39 | }\r |
40 | \r | |
41 | \r | |
42 | //\r | |
43 | HeapAllocatorBrowserWindow::~HeapAllocatorBrowserWindow(void)\r | |
44 | {\r | |
0203b5fd JPM |
45 | }\r |
46 | \r | |
47 | \r | |
48 | //\r | |
49 | void HeapAllocatorBrowserWindow::RefreshContents(void)\r | |
50 | {\r | |
51 | char string[1024];\r | |
0203b5fd JPM |
52 | QString HA;\r |
53 | size_t Adr68K;\r | |
5d765b04 | 54 | size_t Error = HA_NOERROR;\r |
0203b5fd JPM |
55 | HeapAllocation HeapAllocation;\r |
56 | \r | |
57 | if (isVisible())\r | |
58 | {\r | |
59 | if (Adr68K = Adr)\r | |
60 | {\r | |
61 | do\r | |
62 | {\r | |
5d765b04 | 63 | if ((Adr68K >= 0x4000) && (Adr68K < vjs.DRAM_size))\r |
0203b5fd | 64 | {\r |
5d765b04 | 65 | if (Adr68K < m68k_get_reg(NULL, M68K_REG_SP))\r |
0203b5fd | 66 | {\r |
5d765b04 JPM |
67 | memcpy(&HeapAllocation, &jaguarMainRAM[Adr68K], sizeof(HeapAllocation));\r |
68 | \r | |
69 | if (HeapAllocation.size = ((HeapAllocation.size & 0xff) << 24) + ((HeapAllocation.size & 0xff00) << 8) + ((HeapAllocation.size & 0xff0000) >> 8) + ((HeapAllocation.size & 0xff000000) >> 24))\r | |
0203b5fd | 70 | {\r |
5d765b04 | 71 | if (HeapAllocation.size <= (vjs.DRAM_size - 0x4000))\r |
0203b5fd | 72 | {\r |
5d765b04 | 73 | if ((HeapAllocation.used = ((HeapAllocation.used & 0xff) << 8) + ((HeapAllocation.used & 0xff00) >> 8)) <= 1)\r |
0203b5fd | 74 | {\r |
5d765b04 JPM |
75 | HeapAllocation.nextalloc = ((HeapAllocation.nextalloc & 0xff) << 24) + ((HeapAllocation.nextalloc & 0xff00) << 8) + ((HeapAllocation.nextalloc & 0xff0000) >> 8) + ((HeapAllocation.nextalloc & 0xff000000) >> 24);\r |
76 | \r | |
77 | if ((HeapAllocation.nextalloc >= 0x4000) && (HeapAllocation.nextalloc < vjs.DRAM_size))\r | |
78 | {\r | |
79 | sprintf(string, "0x%06x | 0x%06x (%zi) | %s | 0x%06x<br>", Adr68K, HeapAllocation.size - sizeof(HeapAllocation), HeapAllocation.size - sizeof(HeapAllocation), HeapAllocation.used ? "Allocated" : "Free", HeapAllocation.nextalloc);\r | |
80 | Adr68K = HeapAllocation.nextalloc;\r | |
81 | }\r | |
82 | else\r | |
83 | {\r | |
84 | sprintf(string, "<br><font color='#ff0000'><b>Unable to determine the next memory allocation</b></font>");\r | |
85 | Error = HA_UNABLENEXTMEMORYALLOC;\r | |
86 | }\r | |
0203b5fd JPM |
87 | }\r |
88 | else\r | |
89 | {\r | |
5d765b04 JPM |
90 | sprintf(string, "<br><font color='#ff0000'><b>Unable to determine if the allocated memory is used or not</b></font>");\r |
91 | Error = HA_UNABLEALLOCATEMEMORYUSAGE;\r | |
0203b5fd JPM |
92 | }\r |
93 | }\r | |
94 | else\r | |
95 | {\r | |
5d765b04 JPM |
96 | sprintf(string, "<br><font color='#ff0000'><b>Memory bloc size has a problem</b></font>");\r |
97 | Error = HA_MEMORYBLOCKSIZEPROBLEM;\r | |
0203b5fd JPM |
98 | }\r |
99 | }\r | |
100 | else\r | |
101 | {\r | |
5d765b04 | 102 | sprintf(string, "<br><font color='#0000ff'><b>Memory allocations browsing successfully completed</b></font>");\r |
0203b5fd JPM |
103 | }\r |
104 | }\r | |
105 | else\r | |
106 | {\r | |
5d765b04 JPM |
107 | sprintf(string, "<br><font color='#ff0000'><b>Memory allocations and Stack are sharing the same space</b></font>");\r |
108 | Error = HA_HAANDSPSHARESPACE;\r | |
0203b5fd JPM |
109 | }\r |
110 | }\r | |
111 | else\r | |
112 | {\r | |
113 | sprintf(string, "<br><font color='#ff0000'><b>Memory allocations may have a problem</b></font>");\r | |
5d765b04 | 114 | Error = HA_MEMORYALLOCATIONPROBLEM;\r |
0203b5fd JPM |
115 | }\r |
116 | \r | |
117 | HA += QString(string);\r | |
118 | \r | |
5d765b04 JPM |
119 | }\r |
120 | while (HeapAllocation.size && !Error);\r | |
0203b5fd JPM |
121 | }\r |
122 | else\r | |
123 | {\r | |
124 | if (Adr = DBGManager_GetAdrFromSymbolName((char *)"__HeapBase"))\r | |
125 | {\r | |
126 | if (Adr68K = DBGManager_GetGlobalVariableAdrFromName((char *)"alloc"))\r | |
127 | {\r | |
128 | if (!(Adr68K = (jaguarMainRAM[Adr68K] << 24) + (jaguarMainRAM[Adr68K + 1] << 16) + (jaguarMainRAM[Adr68K + 2] << 8) + (jaguarMainRAM[Adr68K + 3])) || ((Adr68K < 0x4000) || (Adr68K >= 0x200000)))\r | |
129 | {\r | |
130 | sprintf(string, "<font color='#ff0000'><b>Memory allocator not yet initialised</b></font>");\r | |
131 | Adr = 0;\r | |
132 | }\r | |
133 | else\r | |
134 | {\r | |
135 | return RefreshContents();\r | |
0203b5fd JPM |
136 | }\r |
137 | }\r | |
138 | else\r | |
139 | {\r | |
140 | sprintf(string, "<font color='#ff0000'><b>Memory allocator is not compatible</b></font>");\r | |
141 | Adr = 0;\r | |
142 | }\r | |
143 | }\r | |
144 | else\r | |
145 | {\r | |
146 | sprintf(string, "<font color='#ff0000'><b>Memory allocator doesn't exist</b></font>");\r | |
147 | }\r | |
148 | \r | |
149 | HA += QString(string);\r | |
150 | }\r | |
151 | \r | |
152 | text->clear();\r | |
153 | text->setText(HA);\r | |
154 | }\r | |
155 | }\r | |
156 | \r | |
157 | \r | |
a2dfb8e5 JPM |
158 | // \r |
159 | void HeapAllocatorBrowserWindow::Reset(void)\r | |
160 | {\r | |
161 | size_t Adr68K;\r | |
162 | \r | |
163 | if (DBGManager_GetAdrFromSymbolName((char *)"__HeapBase"))\r | |
164 | {\r | |
165 | if (Adr68K = DBGManager_GetGlobalVariableAdrFromName((char *)"alloc"))\r | |
166 | {\r | |
167 | jaguarMainRAM[Adr68K] = jaguarMainRAM[Adr68K + 1] = jaguarMainRAM[Adr68K + 2] = jaguarMainRAM[Adr68K + 3] = 0;\r | |
168 | Adr = 0;\r | |
169 | }\r | |
170 | }\r | |
171 | }\r | |
172 | \r | |
173 | \r | |
174 | // \r | |
0203b5fd JPM |
175 | void HeapAllocatorBrowserWindow::keyPressEvent(QKeyEvent * e)\r |
176 | {\r | |
177 | if (e->key() == Qt::Key_Escape)\r | |
a2dfb8e5 | 178 | {\r |
0203b5fd | 179 | hide();\r |
a2dfb8e5 | 180 | }\r |
0203b5fd | 181 | }\r |
0203b5fd | 182 | \r |