Page 1 of 1

Debugger check for PBHeap

Posted: Tue Jul 01, 2008 10:48 pm
by Deeem2031
pcfreak just showed me this nice code from fr34k to validate the PBHeap:

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
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.

Posted: Tue Jul 01, 2008 10:58 pm
by freak
Yes, it would be dead slow with the check at every line, but there is also this:
msdn wrote:Validating a heap may degrade performance, especially on symmetric multiprocessing (SMP) computers. The side effects may last until the process ends.
http://msdn.microsoft.com/en-us/library ... S.85).aspx

Also, heap corruption errors don't happen that often, which is why i have been hesitating to add this as a debugger option.