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 | |
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 | |
0203b5fd | 24 | Adr(0)\r |
0203b5fd JPM |
25 | {\r |
26 | setWindowTitle(tr("Heap Allocation"));\r | |
27 | \r | |
0203b5fd | 28 | QFont fixedFont("Lucida Console", 8, QFont::Normal);\r |
0203b5fd JPM |
29 | fixedFont.setStyleHint(QFont::TypeWriter);\r |
30 | text->setFont(fixedFont);\r | |
0203b5fd JPM |
31 | setLayout(layout);\r |
32 | \r | |
33 | layout->addWidget(text);\r | |
0203b5fd JPM |
34 | }\r |
35 | \r | |
36 | \r | |
37 | //\r | |
38 | HeapAllocatorBrowserWindow::~HeapAllocatorBrowserWindow(void)\r | |
39 | {\r | |
0203b5fd JPM |
40 | }\r |
41 | \r | |
42 | \r | |
43 | //\r | |
44 | void HeapAllocatorBrowserWindow::RefreshContents(void)\r | |
45 | {\r | |
46 | char string[1024];\r | |
0203b5fd JPM |
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 | |
0203b5fd JPM |
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 | |
a2dfb8e5 JPM |
144 | // \r |
145 | void 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 | |
0203b5fd JPM |
161 | void HeapAllocatorBrowserWindow::keyPressEvent(QKeyEvent * e)\r |
162 | {\r | |
163 | if (e->key() == Qt::Key_Escape)\r | |
a2dfb8e5 | 164 | {\r |
0203b5fd | 165 | hide();\r |
a2dfb8e5 | 166 | }\r |
0203b5fd | 167 | }\r |
0203b5fd | 168 | \r |