Add custom Debugger checks for every line

Share your advanced PureBasic knowledge/code with the community.
User avatar
Deeem2031
Enthusiast
Enthusiast
Posts: 216
Joined: Sat Sep 20, 2003 3:57 pm
Location: Germany
Contact:

Add custom Debugger checks for every line

Post by Deeem2031 »

Related to [Feature Requests and Wishlists] Debugger check for PBHeap and [PureBasic Team Blog] Debugging tips - Part 1: Heap corruption i wrote an include-file which adds a heap check to every line and send an error-message to the debugger if the heaps are invalid.
So you can check this before the pb-team will add this as an option in future debugger versions. ;)

If you want you can also add your own checks that shall be called every line. You only have to add a constant in the first Enumeration. (something like "#DebuggerCheck_MyCheck = 1<<1"). And add the check after the ";- Insert checks for every line here"-comment.
Variables you may use:
DebuggerLineCheck_CurrentFile (string)
DebuggerLineCheck_CurrentLine (long)
DebuggerLineCheck_Flags (long) - the checks that are activated
Procedures you may use:
PB_DEBUGGER_SendError(msg.s)
PB_DEBUGGER_SendWarning(msg.s)

Download: http://www.deeem2031.de/PB/DebuggerLineChecks.zip

A test-code for the heapcheck:

Code: Select all

XIncludeFile "Includes\DebuggerLineChecks.pbi"

If DLC_Activate(#DebuggerCheck_Heap) = 0
  Debug "ActivateDebuggerLineChecks failed!"
  CallDebugger
EndIf

x = AllocateMemory(4096)
For i = x To x+10*1024
  Debug i-x
  PokeB(i,42)
Next
And a test code for the profiler:

Code: Select all

IncludePath "Includes" 
IncludeFile "DebuggerLineChecks.pbi" 
DLC_Activate(#DebuggerCheck_Profile) 

For i = 1 To 10000 
  x = Random(1000) 
Next 

DLC_ViewProfileResult()
Note that there is also a #DebuggerCheck_CheckPointer, which should check all pointer inside the programm if they are valid or null but because of this bug: http://www.purebasic.fr/english/viewtopic.php?t=37332 i cant continue developing this as it's impossible to handle interfaces correctly.
Last edited by Deeem2031 on Thu May 07, 2009 10:45 am, edited 8 times in total.
irc://irc.freenode.org/#purebasic
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

What would be the advantage of this over PB's debugging routines?
User avatar
Deeem2031
Enthusiast
Enthusiast
Posts: 216
Joined: Sat Sep 20, 2003 3:57 pm
Location: Germany
Contact:

Post by Deeem2031 »

Mistrel wrote:What would be the advantage of this over PB's debugging routines?
Sorry but I don't understand the question.. My code does not replace the PB debugging routines, it adds own checks. So the debugger still has it's full function.



Btw. fr34k was right, it's very slow checking the heaps every line - so you should only use this if you try to find a bug.
irc://irc.freenode.org/#purebasic
User avatar
Deeem2031
Enthusiast
Enthusiast
Posts: 216
Joined: Sat Sep 20, 2003 3:57 pm
Location: Germany
Contact:

Post by Deeem2031 »

I added a profiler to the LineChecks which does not only provide you with the amount of execution of every line - it also provides you with the time it consumed (just like the profiler/analyser of remi_meier).

Here is a small example:

Code: Select all

IncludePath "Includes"
IncludeFile "DebuggerLineChecks.pbi"
DLC_Activate(#DebuggerCheck_Profile)

For i = 1 To 10000
  x = Random(1000)
Next

DLC_ViewProfileResult()
irc://irc.freenode.org/#purebasic
Post Reply