Re: Visual C++ Tips & Tricks Count BPs
Stop on the Nth iteration
To Help find N:
Set BP w/ very large count (C==10000)
Run until your app crashes
Look at count value (X)
Set count BP on C-X-1
By Name
Stays put through edits (as opposed to F9, for
file/line number BPs)
Memory Leaks
Docs are confusing
Indexed entries talk about MFC
No clear description
Go to "Visual C++ Documentation/Using Visual C++/Visual
C++ Programmers Guide/Debugging/Debugging
Techniques.Problems and Solutions/Solving Buffer
Overwrites and Memory Leaks" (6.0)
Include order is important
Some things redefine malloc and free, etc.
Step 1, include in global header file
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
Step 2, enable checks in WinMain:
// Enables tracking and reporting on shutdown.
_CrtSetDbgFlag (
_CRTDBG_ALLOC_MEM_DF |
_CRTDBG_LEAK_CHECK_DF);
_CrtSetReportMode ( _CRT_ERROR,
_CRTDBG_MODE_DEBUG);
It may list file/line number
Will list leak number
set {,,msvcrtd.dll}_crtBreakAlloc = n (leak number)
Or, look for ASCII clues.
Memory Corruption
Heap Corruption
Enable heap checking (slow)
{,,msvcrtd.dll}_crtDbgFlag = 5
Data BPs may be useful
Optimized Code
It's hard
Compile with /Zi
Variables vanish or are wrong
Use disassembly window for truth
Arguments usually OK except
this
fastcall
Just find your bugs in Debug! 8)
Casting in the debugger
Need correct type name
Debugger doesn't know typedefs
To find the true typename,
Add variable to watch, RClick, choose properties
Scoping:
variable defined in current DLL, type defined in another
DLL:
{,,foo.dll}(CMyClass *){*}pObject
pObject is local, CMyClass defined in foo.dll
Modules Window
Debug.Modules
Sort by:
Module name
Address range
Useful for finding out what module you're in
Find DLL of EIP
Full path
Ensure you're using the correct DLL
Load order (default)
__________________
harshley
|