Heap allocation window uses the DRAM size limit option and detect if heap allocation...
[clinton/Virtual-Jaguar-Rx.git] / src / debugger / heapallocatorbrowser.cpp
index 7224be3..b65587b 100644 (file)
@@ -8,11 +8,16 @@
 // Who  When        What\r
 // ---  ----------  -----------------------------------------------------------\r
 // JPM  01/08/2017  Created this file\r
+// JPM  09/05/2018  Support of the DRAM size limit option\r
+// JPM  09/05/2018  Use definitions for error instead of hard values\r
+// JPM  09/05/2018  Detect if heap allocation shares space with SP (Stack)\r
 //\r
 \r
 // STILL TO DO:\r
+// Better information display\r
 //\r
 \r
+#include "settings.h"\r
 #include "debugger/heapallocatorbrowser.h"\r
 #include "memory.h"\r
 #include "debugger/DBGManager.h"\r
@@ -46,7 +51,7 @@ void HeapAllocatorBrowserWindow::RefreshContents(void)
        char string[1024];\r
        QString HA;\r
        size_t Adr68K;\r
-       size_t Error = 0;\r
+       size_t Error = HA_NOERROR;\r
        HeapAllocation HeapAllocation;\r
 \r
        if (isVisible())\r
@@ -55,55 +60,64 @@ void HeapAllocatorBrowserWindow::RefreshContents(void)
                {\r
                        do\r
                        {\r
-                               if ((Adr68K >= 0x4000) && (Adr68K < 0x200000))\r
+                               if ((Adr68K >= 0x4000) && (Adr68K < vjs.DRAM_size))\r
                                {\r
-                                       memcpy(&HeapAllocation, &jaguarMainRAM[Adr68K], sizeof(HeapAllocation));\r
-\r
-                                       if (HeapAllocation.size = ((HeapAllocation.size & 0xff) << 24) + ((HeapAllocation.size & 0xff00) << 8) + ((HeapAllocation.size & 0xff0000) >> 8) + ((HeapAllocation.size & 0xff000000) >> 24))\r
+                                       if (Adr68K < m68k_get_reg(NULL, M68K_REG_SP))\r
                                        {\r
-                                               if (HeapAllocation.size <= (0x200000 - 0x4000))\r
+                                               memcpy(&HeapAllocation, &jaguarMainRAM[Adr68K], sizeof(HeapAllocation));\r
+\r
+                                               if (HeapAllocation.size = ((HeapAllocation.size & 0xff) << 24) + ((HeapAllocation.size & 0xff00) << 8) + ((HeapAllocation.size & 0xff0000) >> 8) + ((HeapAllocation.size & 0xff000000) >> 24))\r
                                                {\r
-                                                       if ((HeapAllocation.used = ((HeapAllocation.used & 0xff) << 8) + ((HeapAllocation.used & 0xff00) >> 8)) <= 1)\r
+                                                       if (HeapAllocation.size <= (vjs.DRAM_size - 0x4000))\r
                                                        {\r
-                                                               HeapAllocation.nextalloc = ((HeapAllocation.nextalloc & 0xff) << 24) + ((HeapAllocation.nextalloc & 0xff00) << 8) + ((HeapAllocation.nextalloc & 0xff0000) >> 8) + ((HeapAllocation.nextalloc & 0xff000000) >> 24);\r
-\r
-                                                               if ((HeapAllocation.nextalloc >= 0x4000) && (HeapAllocation.nextalloc < 0x200000))\r
+                                                               if ((HeapAllocation.used = ((HeapAllocation.used & 0xff) << 8) + ((HeapAllocation.used & 0xff00) >> 8)) <= 1)\r
                                                                {\r
-                                                                       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
-                                                                       Adr68K = HeapAllocation.nextalloc;\r
+                                                                       HeapAllocation.nextalloc = ((HeapAllocation.nextalloc & 0xff) << 24) + ((HeapAllocation.nextalloc & 0xff00) << 8) + ((HeapAllocation.nextalloc & 0xff0000) >> 8) + ((HeapAllocation.nextalloc & 0xff000000) >> 24);\r
+\r
+                                                                       if ((HeapAllocation.nextalloc >= 0x4000) && (HeapAllocation.nextalloc < vjs.DRAM_size))\r
+                                                                       {\r
+                                                                               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
+                                                                               Adr68K = HeapAllocation.nextalloc;\r
+                                                                       }\r
+                                                                       else\r
+                                                                       {\r
+                                                                               sprintf(string, "<br><font color='#ff0000'><b>Unable to determine the next memory allocation</b></font>");\r
+                                                                               Error = HA_UNABLENEXTMEMORYALLOC;\r
+                                                                       }\r
                                                                }\r
                                                                else\r
                                                                {\r
-                                                                       sprintf(string, "<br><font color='#ff0000'><b>Unable to determine the next memory allocation</b></font>");\r
-                                                                       Error = 1;\r
+                                                                       sprintf(string, "<br><font color='#ff0000'><b>Unable to determine if the allocated memory is used or not</b></font>");\r
+                                                                       Error = HA_UNABLEALLOCATEMEMORYUSAGE;\r
                                                                }\r
                                                        }\r
                                                        else\r
                                                        {\r
-                                                               sprintf(string, "<br><font color='#ff0000'><b>Unable to determine if the allocated memory is used or not</b></font>");\r
-                                                               Error = 2;\r
+                                                               sprintf(string, "<br><font color='#ff0000'><b>Memory bloc size has a problem</b></font>");\r
+                                                               Error = HA_MEMORYBLOCKSIZEPROBLEM;\r
                                                        }\r
                                                }\r
                                                else\r
                                                {\r
-                                                       sprintf(string, "<br><font color='#ff0000'><b>Memory bloc size has a problem</b></font>");\r
-                                                       Error = 3;\r
+                                                       sprintf(string, "<br><font color='#0000ff'><b>Memory allocations browsing successfully completed</b></font>");\r
                                                }\r
                                        }\r
                                        else\r
                                        {\r
-                                               sprintf(string, "<br><font color='#0000ff'><b>Memory allocations browsing successfully completed</b></font>");\r
+                                               sprintf(string, "<br><font color='#ff0000'><b>Memory allocations and Stack are sharing the same space</b></font>");\r
+                                               Error = HA_HAANDSPSHARESPACE;\r
                                        }\r
                                }\r
                                else\r
                                {\r
                                        sprintf(string, "<br><font color='#ff0000'><b>Memory allocations may have a problem</b></font>");\r
-                                       Error = 4;\r
+                                       Error = HA_MEMORYALLOCATIONPROBLEM;\r
                                }\r
 \r
                                HA += QString(string);\r
 \r
-                       } while (HeapAllocation.size && !Error);\r
+                       }\r
+                       while (HeapAllocation.size && !Error);\r
                }\r
                else\r
                {\r