2 // heapallocatorbrowser.cpp: Memory heap allocation
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
9 // --- ---------- -----------------------------------------------------------
10 // JPM 01/08/2017 Created this file
11 // JPM 09/05/2018 Support of the DRAM size limit option
12 // JPM 09/05/2018 Use definitions for error instead of hard values
13 // JPM 09/05/2018 Detect if heap allocation shares space with SP (Stack)
17 // Better information display
21 #include "debugger/heapallocatorbrowser.h"
23 #include "debugger/DBGManager.h"
24 #include "m68000/m68kinterface.h"
27 HeapAllocatorBrowserWindow::HeapAllocatorBrowserWindow(QWidget
* parent
/*= 0*/) : QWidget(parent
, Qt::Dialog
),
28 layout(new QVBoxLayout
), text(new QTextBrowser
),
31 setWindowTitle(tr("Heap Allocation"));
33 QFont
fixedFont("Lucida Console", 8, QFont::Normal
);
34 fixedFont
.setStyleHint(QFont::TypeWriter
);
35 text
->setFont(fixedFont
);
38 layout
->addWidget(text
);
43 HeapAllocatorBrowserWindow::~HeapAllocatorBrowserWindow(void)
49 void HeapAllocatorBrowserWindow::RefreshContents(void)
54 size_t Error
= HA_NOERROR
;
55 HeapAllocation HeapAllocation
;
63 if ((Adr68K
>= 0x4000) && (Adr68K
< vjs
.DRAM_size
))
65 if (Adr68K
< m68k_get_reg(NULL
, M68K_REG_SP
))
67 memcpy(&HeapAllocation
, &jaguarMainRAM
[Adr68K
], sizeof(HeapAllocation
));
69 if (HeapAllocation
.size
= ((HeapAllocation
.size
& 0xff) << 24) + ((HeapAllocation
.size
& 0xff00) << 8) + ((HeapAllocation
.size
& 0xff0000) >> 8) + ((HeapAllocation
.size
& 0xff000000) >> 24))
71 if (HeapAllocation
.size
<= (vjs
.DRAM_size
- 0x4000))
73 if ((HeapAllocation
.used
= ((HeapAllocation
.used
& 0xff) << 8) + ((HeapAllocation
.used
& 0xff00) >> 8)) <= 1)
75 HeapAllocation
.nextalloc
= ((HeapAllocation
.nextalloc
& 0xff) << 24) + ((HeapAllocation
.nextalloc
& 0xff00) << 8) + ((HeapAllocation
.nextalloc
& 0xff0000) >> 8) + ((HeapAllocation
.nextalloc
& 0xff000000) >> 24);
77 if ((HeapAllocation
.nextalloc
>= 0x4000) && (HeapAllocation
.nextalloc
< vjs
.DRAM_size
))
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
);
80 Adr68K
= HeapAllocation
.nextalloc
;
84 sprintf(string
, "<br><font color='#ff0000'><b>Unable to determine the next memory allocation</b></font>");
85 Error
= HA_UNABLENEXTMEMORYALLOC
;
90 sprintf(string
, "<br><font color='#ff0000'><b>Unable to determine if the allocated memory is used or not</b></font>");
91 Error
= HA_UNABLEALLOCATEMEMORYUSAGE
;
96 sprintf(string
, "<br><font color='#ff0000'><b>Memory bloc size has a problem</b></font>");
97 Error
= HA_MEMORYBLOCKSIZEPROBLEM
;
102 sprintf(string
, "<br><font color='#0000ff'><b>Memory allocations browsing successfully completed</b></font>");
107 sprintf(string
, "<br><font color='#ff0000'><b>Memory allocations and Stack are sharing the same space</b></font>");
108 Error
= HA_HAANDSPSHARESPACE
;
113 sprintf(string
, "<br><font color='#ff0000'><b>Memory allocations may have a problem</b></font>");
114 Error
= HA_MEMORYALLOCATIONPROBLEM
;
117 HA
+= QString(string
);
120 while (HeapAllocation
.size
&& !Error
);
124 if (Adr
= DBGManager_GetAdrFromSymbolName((char *)"__HeapBase"))
126 if (Adr68K
= DBGManager_GetGlobalVariableAdrFromName((char *)"alloc"))
128 if (!(Adr68K
= (jaguarMainRAM
[Adr68K
] << 24) + (jaguarMainRAM
[Adr68K
+ 1] << 16) + (jaguarMainRAM
[Adr68K
+ 2] << 8) + (jaguarMainRAM
[Adr68K
+ 3])) || ((Adr68K
< 0x4000) || (Adr68K
>= 0x200000)))
130 sprintf(string
, "<font color='#ff0000'><b>Memory allocator not yet initialised</b></font>");
135 return RefreshContents();
140 sprintf(string
, "<font color='#ff0000'><b>Memory allocator is not compatible</b></font>");
146 sprintf(string
, "<font color='#ff0000'><b>Memory allocator doesn't exist</b></font>");
149 HA
+= QString(string
);
159 void HeapAllocatorBrowserWindow::Reset(void)
163 if (DBGManager_GetAdrFromSymbolName((char *)"__HeapBase"))
165 if (Adr68K
= DBGManager_GetGlobalVariableAdrFromName((char *)"alloc"))
167 jaguarMainRAM
[Adr68K
] = jaguarMainRAM
[Adr68K
+ 1] = jaguarMainRAM
[Adr68K
+ 2] = jaguarMainRAM
[Adr68K
+ 3] = 0;
175 void HeapAllocatorBrowserWindow::keyPressEvent(QKeyEvent
* e
)
177 if (e
->key() == Qt::Key_Escape
)