2 // heapallocatorbrowser.cpp: Memory heap allocation
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
9 // --- ---------- -----------------------------------------------------------
10 // JPM 01/08/2017 Created this file
16 #include "debugger/heapallocatorbrowser.h"
18 #include "debugger/DBGManager.h"
19 #include "m68000/m68kinterface.h"
22 HeapAllocatorBrowserWindow::HeapAllocatorBrowserWindow(QWidget
* parent
/*= 0*/) : QWidget(parent
, Qt::Dialog
),
23 layout(new QVBoxLayout
), text(new QTextBrowser
),
26 setWindowTitle(tr("Heap Allocation"));
28 QFont
fixedFont("Lucida Console", 8, QFont::Normal
);
29 fixedFont
.setStyleHint(QFont::TypeWriter
);
30 text
->setFont(fixedFont
);
33 layout
->addWidget(text
);
38 HeapAllocatorBrowserWindow::~HeapAllocatorBrowserWindow(void)
44 void HeapAllocatorBrowserWindow::RefreshContents(void)
50 HeapAllocation HeapAllocation
;
58 if ((Adr68K
>= 0x4000) && (Adr68K
< 0x200000))
60 memcpy(&HeapAllocation
, &jaguarMainRAM
[Adr68K
], sizeof(HeapAllocation
));
62 if (HeapAllocation
.size
= ((HeapAllocation
.size
& 0xff) << 24) + ((HeapAllocation
.size
& 0xff00) << 8) + ((HeapAllocation
.size
& 0xff0000) >> 8) + ((HeapAllocation
.size
& 0xff000000) >> 24))
64 if (HeapAllocation
.size
<= (0x200000 - 0x4000))
66 if ((HeapAllocation
.used
= ((HeapAllocation
.used
& 0xff) << 8) + ((HeapAllocation
.used
& 0xff00) >> 8)) <= 1)
68 HeapAllocation
.nextalloc
= ((HeapAllocation
.nextalloc
& 0xff) << 24) + ((HeapAllocation
.nextalloc
& 0xff00) << 8) + ((HeapAllocation
.nextalloc
& 0xff0000) >> 8) + ((HeapAllocation
.nextalloc
& 0xff000000) >> 24);
70 if ((HeapAllocation
.nextalloc
>= 0x4000) && (HeapAllocation
.nextalloc
< 0x200000))
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
;
77 sprintf(string
, "<br><font color='#ff0000'><b>Unable to determine the next memory allocation</b></font>");
83 sprintf(string
, "<br><font color='#ff0000'><b>Unable to determine if the allocated memory is used or not</b></font>");
89 sprintf(string
, "<br><font color='#ff0000'><b>Memory bloc size has a problem</b></font>");
95 sprintf(string
, "<br><font color='#0000ff'><b>Memory allocations browsing successfully completed</b></font>");
100 sprintf(string
, "<br><font color='#ff0000'><b>Memory allocations may have a problem</b></font>");
104 HA
+= QString(string
);
106 } while (HeapAllocation
.size
&& !Error
);
110 if (Adr
= DBGManager_GetAdrFromSymbolName((char *)"__HeapBase"))
112 if (Adr68K
= DBGManager_GetGlobalVariableAdrFromName((char *)"alloc"))
114 if (!(Adr68K
= (jaguarMainRAM
[Adr68K
] << 24) + (jaguarMainRAM
[Adr68K
+ 1] << 16) + (jaguarMainRAM
[Adr68K
+ 2] << 8) + (jaguarMainRAM
[Adr68K
+ 3])) || ((Adr68K
< 0x4000) || (Adr68K
>= 0x200000)))
116 sprintf(string
, "<font color='#ff0000'><b>Memory allocator not yet initialised</b></font>");
121 return RefreshContents();
126 sprintf(string
, "<font color='#ff0000'><b>Memory allocator is not compatible</b></font>");
132 sprintf(string
, "<font color='#ff0000'><b>Memory allocator doesn't exist</b></font>");
135 HA
+= QString(string
);
145 void HeapAllocatorBrowserWindow::Reset(void)
149 if (DBGManager_GetAdrFromSymbolName((char *)"__HeapBase"))
151 if (Adr68K
= DBGManager_GetGlobalVariableAdrFromName((char *)"alloc"))
153 jaguarMainRAM
[Adr68K
] = jaguarMainRAM
[Adr68K
+ 1] = jaguarMainRAM
[Adr68K
+ 2] = jaguarMainRAM
[Adr68K
+ 3] = 0;
161 void HeapAllocatorBrowserWindow::keyPressEvent(QKeyEvent
* e
)
163 if (e
->key() == Qt::Key_Escape
)