GDI Debugger
The purpose of GDI Debugger, is to demonstrate how code can recognize, locate and
diagnose bugs, plus
hopefully make recommendations or fix them. For now, it locates them
and occassionally
gives advice.
The GDI debugging wrappers trap calls to some Win32API
functions which are related
to graphics. They test the parameters sent to them and log any errors
they find.
A "final report" can also be generated.
This will hopefully be expanded to cover many other bug-prone
programming categories.
To use:
Make sure you don't have the "#Tools
Off" statement anywhere, or you won't
get a trace file.
* * *
* *
Place the following four lines before
any other #Include statements:
%GdiDebug = 1
#If %Def(%GdiDebug)
%NOGDI = 1
#EndIf
* * *
* *
Instead of #Include-ing "Win32API.inc"
as usual, use the following conditionals.
Note that "Win32API_DB.inc" is a file
you'll have to prepare from a copy of
"Win32API.inc" by REM-ing out the
declares for the wrapped functions which aren't
imported from GDI32.DLL. You'll be
alerted to any errors in this when you try to
compile because the Sub "VerifyWrappers"
can't get CodePtrs to imported functions.
#If %Def(%GdiDebug)
#Include "Win32API_DB.inc"
#Include "GDI_Declares.inc" 'this
contains declares for non-wrapped GDI functions
#Else
#Include "Win32API.inc"
#EndIf
#If %Def(%GdiDebug)
#Include
"GDI_Debug.inc" 'this contains the
wrappers
#EndIf
* * *
* *
Finally, place the following three lines
just before "End Function" in WinMain:
#If %Def(%GdiDebug)
GdiDebugFinalReport
#EndIf
Currently
included wrappers:
BeginPaint
EndPaint
CreateCompatibleBitmap
CreateFont
CreatePen
CreateSolidBrush
CreateCompatibleDC
CreateDC
DeleteDC
GetDC
ReleaseDC
DeleteObject
SelectObject
SetROP2
SetTextColor
(Some of these were selected because they
appeared in a project that needed
testing)
What it does:
GdiDebugger doesn't interfere with your
program. Your Win32API calls are merely monitored
and checked for: bad parameters,
programming mistakes and errors returned by Windows.
* * *
* *
Shows error messages when the actual API
calls fail.
* * *
* *
It verifies that all window handles are
currently valid, and warns if the screen's
window handle is used (it's okay, but
sometimes it's done by mistake).
* * *
* *
It tracks all DC handles encountered to
be sure they are valid and to be sure they are
eventually released or deleted.
* * *
* *
It checks DC's for the existence of
non-default objects selected into them when your
program tries to release or delete them.
* * *
* *
It recognizes attempts to select a
bitmap into more than one DC at a time.
* * *
* *
It alerts you to attempts to delete a
window DC or to release a memory DC.
* * *
* *
It includes object type names ("pen",
"font",...) with every comment about them, so you
needn't keep track of them.
* * *
* *
Monitors the balancing of "BeginPaint"
and "EndPaint" calls.
* * *
* *
It verifies that calls to "BeginPaint"
and "EndPaint" are in response to %WM_PAINT messages
(this is the recommended practice).
* * *
* *
When errors are found, the call stack is
listed with parameters in HEX.
* * *
* *
When "WndProc" is found in a call stack,
the messages are translated to their standard equate
names. For example: WNDPROC(
&H0, &H2, &H0, &H0
) %WM_DESTROY
For this feature to work The equate:
"$WndProc" must be set to the upper-cased name of your
window's message handler, plus an
opening parenthesis. For example: $WndProc = "WNDPROC("
* * *
* *
Window handle, DC handle and object
handle values are checked to see if they could have been
accidentally passed "ByRef" instead of
"ByVal". This is done by checking against value ranges
and making an API call to get the status
of memory at the addresses.
* * *
* *
There's no need to change the names of
the API calls in your code. The names of the calls in
the API declares have been changed in
GdiDebugger. The parameters are passed unmodified, to
the actual Win32API imports.
* * *
* *
Shows a list of all the currently active
wrappers. This feature will also help you guard
against mistakes in configuring your
#Includes, because otherwise, a declaration in the
standard Win32API.inc could override it
if it's not REMed out.
* * *
* *
Generates a "GdiDebugger Final Report",
which includes:
A "Window Handle Report", "Window DC
Report", "Memory DC Report" and an "Object Creation
and Deletion Report"
These reports include:
The total numbers of window handles,
window DCs and memory DCs encountered.
Lists of all the window handles, window
DCs and memory DCs encountered.
Undeleted objects.
* * *
* *
Lists the total numbers of calls to each
wrapper.
The GDI Debugger source code is in the "gdidebug" folder of the CVS directory
Browse CVS
Website Home
Project Summary Page at SourceForge.net
This project is sponsored by TheirCorp
(formerly TheirWare Corporation)