Debugger check for PBHeap
Posted: Tue Jul 01, 2008 10:48 pm
pcfreak just showed me this nice code from fr34k to validate the PBHeap:
Now it would be even better to have the debugger check this. Maybe this will slow down the program too much if all heaps are checked every line but with a switch to enable/disable this feature all would be fine I guess.
Code: Select all
Procedure ValidatePBHeap(LineNumber)
Protected StringHeap, MemoryHeap, InternalHeap
!extrn _PB_Memory_Heap
!extrn _PB_StringHeap
!mov eax, dword [_PB_MemoryBase]
!mov [p.v_InternalHeap], eax
!mov eax, dword [_PB_StringHeap]
!mov [p.v_StringHeap], eax
!mov eax, dword [_PB_Memory_Heap]
!mov [p.v_MemoryHeap], eax
If HeapValidate_(StringHeap, 0, 0) = 0
MessageRequester("Error", "String Heap invalid at Line: "+Str(LineNumber))
EndIf
If HeapValidate_(MemoryHeap, 0, 0) = 0
MessageRequester("Error", "Memory Heap invalid at Line: "+Str(LineNumber))
EndIf
If HeapValidate_(InternalHeap, 0, 0) = 0
MessageRequester("Error", "Internal Memory Heap invalid at Line: "+Str(LineNumber))
EndIf
EndProcedure
Macro _validate
ValidatePBHeap(#PB_Compiler_Line)
EndMacro