2 // allwatch.cpp - All Watch
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
),
24 // layout(new QVBoxLayout), text(new QLabel),
25 // refresh(new QPushButton(tr("Refresh"))),
26 // address(new QLineEdit),
27 // go(new QPushButton(tr("Go"))),
34 setWindowTitle(tr("Heap Allocation"));
36 // address->setInputMask("hhhhhh");
37 // QHBoxLayout * hbox1 = new QHBoxLayout;
38 // hbox1->addWidget(refresh);
39 // hbox1->addWidget(address);
40 // hbox1->addWidget(go);
42 // Need to set the size as well...
45 QFont
fixedFont("Lucida Console", 8, QFont::Normal
);
46 // QFont fixedFont("", 8, QFont::Normal);
47 fixedFont
.setStyleHint(QFont::TypeWriter
);
48 text
->setFont(fixedFont
);
49 //// layout->setSizeConstraint(QLayout::SetFixedSize);
52 layout
->addWidget(text
);
53 // layout->addWidget(refresh);
54 // layout->addLayout(hbox1);
56 // connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));
57 // connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));
62 HeapAllocatorBrowserWindow::~HeapAllocatorBrowserWindow(void)
70 void HeapAllocatorBrowserWindow::RefreshContents(void)
77 HeapAllocation HeapAllocation
;
85 if ((Adr68K
>= 0x4000) && (Adr68K
< 0x200000))
87 memcpy(&HeapAllocation
, &jaguarMainRAM
[Adr68K
], sizeof(HeapAllocation
));
89 if (HeapAllocation
.size
= ((HeapAllocation
.size
& 0xff) << 24) + ((HeapAllocation
.size
& 0xff00) << 8) + ((HeapAllocation
.size
& 0xff0000) >> 8) + ((HeapAllocation
.size
& 0xff000000) >> 24))
91 if (HeapAllocation
.size
<= (0x200000 - 0x4000))
93 if ((HeapAllocation
.used
= ((HeapAllocation
.used
& 0xff) << 8) + ((HeapAllocation
.used
& 0xff00) >> 8)) <= 1)
95 HeapAllocation
.nextalloc
= ((HeapAllocation
.nextalloc
& 0xff) << 24) + ((HeapAllocation
.nextalloc
& 0xff00) << 8) + ((HeapAllocation
.nextalloc
& 0xff0000) >> 8) + ((HeapAllocation
.nextalloc
& 0xff000000) >> 24);
97 if ((HeapAllocation
.nextalloc
>= 0x4000) && (HeapAllocation
.nextalloc
< 0x200000))
99 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
);
100 Adr68K
= HeapAllocation
.nextalloc
;
104 sprintf(string
, "<br><font color='#ff0000'><b>Unable to determine the next memory allocation</b></font>");
110 sprintf(string
, "<br><font color='#ff0000'><b>Unable to determine if the allocated memory is used or not</b></font>");
116 sprintf(string
, "<br><font color='#ff0000'><b>Memory bloc size has a problem</b></font>");
122 sprintf(string
, "<br><font color='#0000ff'><b>Memory allocations browsing successfully completed</b></font>");
127 sprintf(string
, "<br><font color='#ff0000'><b>Memory allocations may have a problem</b></font>");
131 HA
+= QString(string
);
133 } while (HeapAllocation
.size
&& !Error
);
137 if (Adr
= DBGManager_GetAdrFromSymbolName((char *)"__HeapBase"))
139 if (Adr68K
= DBGManager_GetExternalVariableAdrFromName((char *)"alloc"))
141 if (!(Adr68K
= (jaguarMainRAM
[Adr68K
] << 24) + (jaguarMainRAM
[Adr68K
+ 1] << 16) + (jaguarMainRAM
[Adr68K
+ 2] << 8) + (jaguarMainRAM
[Adr68K
+ 3])) || ((Adr68K
< 0x4000) || (Adr68K
>= 0x200000)))
143 sprintf(string
, "<font color='#ff0000'><b>Memory allocator not yet initialised</b></font>");
148 return RefreshContents();
149 //sprintf(string, "<font color='#0000ff'><b>Memory allocator has been initialised</b></font>");
154 sprintf(string
, "<font color='#ff0000'><b>Memory allocator is not compatible</b></font>");
160 sprintf(string
, "<font color='#ff0000'><b>Memory allocator doesn't exist</b></font>");
163 HA
+= QString(string
);
173 void HeapAllocatorBrowserWindow::keyPressEvent(QKeyEvent
* e
)
175 if (e
->key() == Qt::Key_Escape
)
177 else if (e
->key() == Qt::Key_PageUp
)
186 else if (e
->key() == Qt::Key_PageDown
)
190 if (memBase
> (0x200000 - 480))
191 memBase
= 0x200000 - 480;
195 else if (e
->key() == Qt::Key_Up
|| e
->key() == Qt::Key_Minus
)
204 else if (e
->key() == Qt::Key_Down
|| e
->key() == Qt::Key_Equal
)
208 if (memBase
> (0x200000 - 480))
209 memBase
= 0x200000 - 480;
218 void HeapAllocatorBrowserWindow::GoToAddress(void)
221 QString newAddress
= address
->text();
222 memBase
= newAddress
.toUInt(&ok
, 16);