[LIB] DebugLib -> Call the debugger functions from code.

Share your advanced PureBasic knowledge/code with the community.
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

[LIB] DebugLib -> Call the debugger functions from code.

Post by superadnim »

I was sniffing the PB internals when I found a static library called "Debugger.lib", so I immediately opened it on notepad (to read the symbols, yes - I know, primitive way of doing so!) and began some testing, this came out:

Code: Select all

;begin->debuglib.pb

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
	CompilerSelect  #PB_Compiler_Debugger
		
		CompilerCase #True
			
			Import "Debugger.lib"
				DebugError( szError.s) 			As "_PB_DEBUGGER_SendError@4"
				DebugBreak()								As "_PB_DEBUGGER_Break@"
				DebugEnd() 									As "_PB_DEBUGGER_End@"
				DebugFileExists(szFile.s)		As "_PB_DEBUGGER_FileExists@4"
			EndImport
			
			Macro DebugFile(_name_, _msg_="File doesn't exist!")
				If Not DebugFileExists(_name_)
					DebugError(_msg_)
					DebugEnd()
				EndIf
			EndMacro
			
		CompilerDefault
			
			Macro DebugError(_dummy_) : EndMacro
			Macro DebugBreak() : EndMacro
			Macro DebugEnd() : EndMacro
			Macro DebugFileExists(_dummy_) : EndMacro
			Macro DebugFile(_dummy_) : EndMacro
			
		
	CompilerEndSelect
CompilerEndIf

;end->debuglib.pb

DebugFile("debuglib.pb")
DebugError("Your coffee mug is empty!")
DebugBreak()
DebugEnd()

;eof->true

After writing this little lib I ran to the forums to see if anyone else had done this before and, well... yes :lol: (that'll teach me!), but as it turns out I couldn't find any "real world" example, so I decided to post my code anyway.

I hope its of some use for you too.

If you spot anything out of place, please let me know as well, any useful additions would be appreciated :)

Too bad it's only windows, for now (I can't really test an X version anyway).


Cheers

Edit: I understand that DebugFile could/should indeed be called DebugIsFile, but to shorten things out I took the former label.