您的位置:首页 > 其它

[调试]_[初级]_[Windbg使用教程]

2014-11-28 10:34 183 查看

Windows:Windbg

1. 把.dmp文件和程序编译对应的.pdb文件放一起.
2. 启动Windbg,把dmp文件拖进windbg.
3. 在windbg控制台里输入.ecxr
3.1 如果.ecxr看不到对应的源码值, 两种情况, 一个是源文件路径没配置. 需要在File->Source File Path里设置源文件所在目录, 第二种情况是直接打开相关源文件.
如果还是显示不了源文件, 这个真没办法解决, 因为有些崩溃报告也是定为不到行(同版本)比如给0x0地址赋值时,没找到原因.
如果没有找到pdb文件,它会有提示说找不到xxx Symbol.并且是看不到函数调用栈的, 需要在File-> Symbol File Path, 这里也是设置pdb文件的目录,勾选Reload 确定重新加载.
3.2 当定位不到行时,可以用命令 !analyze -v 来分析这个dump文件, 能看到很多有用信息, 也能直接看到调用栈.
比如: 在
ire.cpp 668行的调用了fread崩溃

00000000`0021e810 000007fe`f3ddb58c : 00000000`72f82650 00000000`0021f250 00000001`3f2d32c3 000007fe`f3df2dbb : msvcr100!fread+0x18
00000000`0021e850 00000001`3f2c1d57 : 00000000`0000001a 00000000`0000001a 00000000`0000001a 00000000`002ebe70 : libIRE!PBASObserverCallbackFunc+0x7c [e:\work\xx\libxx\src\ire.cpp @ 667]


FILE* file = fopen("C:\\1.yy","r");
char buf[4];
fread(buf,4,1,file);


!analyze -v 分析的部分结果.
 0xf4af3590
00000000`0021e110 00000000`72f40468 : 00000000`00000002 00000000`00000000 00000000`00000000 ffffffff`ffffff00 : msvcr100!wmktemp+0x241
00000000`0021e720 00000000`72f404f6 : 00000002`00000001 00000000`1b484a8c 00000000`00000000 00000000`72ef20da : msvcr100!invoke_watson+0x18
00000000`0021e750 00000000`72f40519 : 00000000`00000000 00000000`0021e8f9 00000000`00000001 00000000`72efddba : msvcr100!invalid_parameter+0x6e
00000000`0021e790 00000000`72efeb91 : 00000000`00000180 00000000`00000003 00000000`01dc1300 00000000`002e89c0 : msvcr100!invalid_parameter_noinfo+0x19
00000000`0021e7d0 00000000`72efec00 : 00000000`0021f250 00000001`3f2d32c3 000007fe`f3df2dbb 00000000`0021f250 : msvcr100!fread_s+0x59
00000000`0021e810 000007fe`f3ddb58c : 00000000`72f82650 00000000`0021f250 00000001`3f2d32c3 000007fe`f3df2dbb : msvcr100!fread+0x18 00000000`0021e850 00000001`3f2c1d57 : 00000000`0000001a 00000000`0000001a 00000000`0000001a 00000000`002ebe70 : libIRE!PBASObserverCallbackFunc+0x7c [e:\work\xx\libxx\src\ire.cpp @ 667]
00000000`0021e960 00000001`3f2c3b46 : 00000000`00000000 000007fe`f3cdbb92 00000000`00000000 000007fe`f3cdbb92 : gui!std::_Tree<std::_Tmap_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,HICON__ * __ptr64,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,HICON__ * __ptr64> >,0> >::_Tidy+0x317
00000000`0021ea40 000007fe`f3cd8472 : 00000000`00000011 00000000`00000011 00000000`01dbc340 000007fe`f3ce1630 : gui!std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,HICON__ * __ptr64,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,HICON__ * __ptr64> > >::~map<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,HICON__ * __ptr64,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,HICON__ * __ptr64> > >+0x12a6
00000000`0021f230 000007fe`f3cd6e1c : 000007fe`f3ce1630 00000000`00000111 00000000`00001389 00000000`0000


4. 左边窗口会出现对应的源代码和出现的行.





5. 点击菜单View->Locals 查看局部变量.
6. 如果局部变量里看不到i 值,可以看寄存器变量值, eax,esi都是0,调用了idiv操作.

命令:
k : 看崩溃堆栈信息
.ecxr : (Display Exception Context Record)
.!analyze -v 分析dump文件
.frame 当前frame
.f+ 上一frame
.f- 下一frame
dv 显示局部变量值

备注: 要生成pdb文件,必须在Release模式下的 项目属性-> 配置属性-> 链接器->调试-> 生成调试信息 选(是)
其他更详尽的信息参考:

http://www.cnblogs.com/playerken/p/4000438.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: