Debug with WinDBG
WinDBG is a powerful debugging tool for Microsoft Windows.
You can debugging with Visual Studio, but you can’t install a Visual Studio to every target machines.
WinDBG is light and easy to debugging so that it can be find bug easily.
1. Install WinDBG .
Installing a latest Platform SDK on your computer, WinDBG will be installed by default.
But WinDBG can be update latest version.
So on this page, I recommend install latest version
You can download following page.
WinDBG Download :
http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx
2. Install Symbol package.
Symbol files has debugging informations. Like a registry status or function address.
We can debugging program that we’ve programmed codes with *.pdb files. Also We need system dll’s *.pdb files for debugging correctly.
Bunch of system dll’s debugging information files are symbol package.
You can download following page.
Symbol File Download :
http://www.microsoft.com/whdc/DevTools/Debugging/symbolpkg.mspx
3. WinDBG Setting.
After install a WinDBG, setting an environment for WinDBG.
On registry editor (regedit.exe), add new registry key “WinDBG” on
HKLM\Software\Microsoft\Windows\CurrentVersion\App Path\
Then change a default value to "WinDBG.exe" Installed directory.
That can make a start WinDBG , entering a “WinDBG” keyword on “Run” without entering a full path.
Next, add(or modify) a environment variable that symbol file path and symbol server.
On Control Panel>>System>>Advanced>>Environment Variables,
Add(or modify) “_NT_SYMBOL_PATH” value to
“srv*c:\Symbols*http://msdl.microsoft.com/download/symbols” .
Entering an “WinDBG –I” on “Run…” , WinDBG is became a postmortem debugger.
(You can change postmortem debugger to Visual Studio, check items on Visual Studio>>Tools>>Options>>Debugging>>Just-In-Time tab)
Start Debugging.
Now I’ll show debugging with WinDBG using program that occurring an error.
I’ve create a SDI Application project and added following codes on
CWinDBGTestApp::InitInstance() function.
TCHAR p[5] = {0,};
TCHAR* txt = _T("Memory Overrun");
CopyMemory(p,txt, _tcslen(txt)*sizeof(TCHAR)); //Actually should be
// occurre an error this line.
//Visual C++ 6 does not. So I added following line.
delete txt;
Executing a program, following error box will be shown.
Pressing a “Retry” button , WinDBG will execute.
WinDBG printed loaded modules and registry values.
For more specific results, re-setting a symbol path with following command.
(You do not need to doing this every time.)
.sympath cache… has WinDBG response time to do update new symbol files faster.
After this, re-load symbols with .reload command.
And print stack back traces with “K*” command.
On this page, we can find which line makes an error using “kb” command.
We can notify that there is some problem on 97th line on "WinDBGTest.cpp".
TCHAR p[5] = {0,};
TCHAR* txt = _T("Memory Overrun");
CopyMemory(p,txt, _tcslen(txt)*sizeof(TCHAR)); //This line is also wrong code
delete txt; //97th line
This sample shown an error on “delete txt” line on VC++6. On Visual Studio 2005(or upper) , occure an error on CopyMemory(…) Line. If you want to know more specific information, read a WinDBG manual on ("% WinDBG Installed %\debugger.chm”) or msdn page.
**Referenced data
http://msdn.microsoft.com/en-us/library/cc266370.aspx
http://www.microsoft.com/whdc/devtools/debugging/default.mspx
WinDBG manual.
Debugging Applications for Microsoft .NET and Microsoft Windows
-MS Press-
Advanced Windows Debugging
-Addison Wesley-
No comments:
Post a Comment