全部博文(45)
分类: WINDOWS
2012-07-11 15:59:11
转自:http://blog.sina.com.cn/s/blog_48ebca64010097hc.html
1. install
http://www.microsoft.com/whdc/devtools/debugging/default.mspx
download and install.
2. enable debug information in
building process
You can modify the Makefile, just
add option as below:
-MDd -Z7 -Od
Then the pdb file is
created which will be used when you want to debug
using windbg. Just for reference, I list the meaning of options of
cl as below:
C:\>cl \help
/O2 maximize speed
/Od disable optimizations (default)
/Zi enable debugging information
/Z7 enable old-style debug info
/MD link with
MSVCRT.LIB
/MDd link with MSVCRTD.LIB debug lib
3. set symbol path
set symbol path to be something like:
SRV*C:\myLocalSymols*
seperated by asterisk, the first one is your local path to save the
symbol files.
4. attach to running
process
In some OS(window 2008), only administrator
can attach to every process, Other users can not even if they
belong to admin group.
4.2 open binary file
You
can define arguments in the gui also.
5. load symbols
.reload /f
force debugger to reload symbols at once, the debugger's natural
behavior is lazy mode.
6. set breakpoint
bp funcName - break at function funcName
bp ClassName::funcName - break at function of class
bl - list all breakpoints
bc (number) - clear breakpoint
But I do not know how to set breakpoint on specific
line.
7. check/switch thread
~* - check all thread in current process
~1 s - switch to the first thread
8. show stack
kb
9. show
variable
e{b|d|D|f|p|q|w}
But it's not so convenient since each variable type need special
command, The windbg gui is preferable, please use
menu("view"->"locals").
For global variable, you can use this menu("view"->"watch")
10. trace
p or pa or pc - step
g - continue
"Debug->Break" - stop trace
11. quit
You shoud detach with the process if you don't want to kill
it.
[tips]: How to set breakpoint for daemon?
void setBreak()
{
volatile int iii = 1;
while(iii) {
sleep(1);
}
}
Here, we use keyword volatile to avoid optimize by
compiler.