Windbg源码调试
Windbg提供比VS2008丰富很多的调试命令,尤其是调试多线程程序。
今天试着怎么使用源代码方式调试。为了说明调试命令,《C++标准库》一书里的例子做示范。
// testcast.cpp #include <stdio.h>
#include <iostream> struct A {
virtual void test() {
printf_s("in A\n");
}
}; struct B : A {
virtual void test() {
printf_s("in B\n");
} void test2() {
printf_s("test2 in B\n");
}
}; struct C : B {
virtual void test() {
printf_s("in C\n");
} void test2() {
printf_s("test2 in C\n");
}
}; void Globaltest(A& a) {
try {
C &c = dynamic_cast<C&>(a);
printf_s("in GlobalTest\n");
}
catch(std::bad_cast) {
printf_s("Can't cast to C\n");
}
} int main() {
A *pa = new C;
A *pa2 = new B; pa->test(); B * pb = dynamic_cast<B *>(pa);
if (pb)
pb->test2(); C * pc = dynamic_cast<C *>(pa2);
if (pc)
pc->test2(); C ConStack;
Globaltest(ConStack); // will fail because B knows nothing about C
B BonStack;
Globaltest(BonStack);
}
使用命令编译并连接
cl.exe testcast.cpp /Zi
link testcast.obj /DEBUG
确保系统已经安装了windbg和symbol。
在命令行窗体,cd testcast.exe所在目录
Windbg testcast.exe
打开Windbg窗体,进入到用户模式调试
命令行交互如下(蓝色为注释):
Microsoft (R) Windows Debugger Version 6.2.9200.20512 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.
CommandLine: testcast.exe
Symbol search path is: C:\Symbols;d:\Code\Exercise\C++
C:\Symbols为Windows Symbols目录,使用.symfix 可以恢复sympath为微软网站上的symbol存储位置
.sympath 查看当前symbol目录
.sympath+ D:\Code\Exercise\C++ 将“D:\Code\Exercise\C++ ”添加到symbol搜索路径中
.srcpath 查看源码搜索路径
.srcpath+ D:\Code\Exercise\C++ 将“D:\Code\Exercise\C++ ” 添加到源码搜索路径中
Executable search path is:
ModLoad: 00000000`00ac0000 00000000`00af1000 testcast.exe
ModLoad: 00000000`77b40000 00000000`77cec000 ntdll.dll
ModLoad: 00000000`77d20000 00000000`77ea0000 ntdll32.dll
ModLoad: 00000000`73e80000 00000000`73ebf000 C:\Windows\SYSTEM32\wow64.dll
ModLoad: 00000000`73e20000 00000000`73e7c000 C:\Windows\SYSTEM32\wow64win.dll
ModLoad: 00000000`73e10000 00000000`73e18000 C:\Windows\SYSTEM32\wow64cpu.dll
(1a58.b40): Break instruction exception - code 80000003 (first chance)
*** ERROR: Symbol file could not be found. Defaulted to export symbols for ntdll.dll -
ntdll!CsrSetPriorityClass+0x40:
00000000`77bf0fe0 cc int 3
0:000> bl bl用于显示断点列表
0:000> bp testcast!main 在testcast模块的main函数开头下断点
*** WARNING: Unable to verify checksum for testcast.exe
0:000> bp testcast!Globaltest 在testcast模块的Globaltest函数开头下断点
0:000> g 执行
ModLoad: 00000000`77920000 00000000`77a3f000 WOW64_IMAGE_SECTION
ModLoad: 00000000`75930000 00000000`75a40000 WOW64_IMAGE_SECTION
ModLoad: 00000000`77920000 00000000`77a3f000 NOT_AN_IMAGE
ModLoad: 00000000`77a40000 00000000`77b3a000 NOT_AN_IMAGE
ModLoad: 00000000`75930000 00000000`75a40000 C:\Windows\syswow64\kernel32.dll
ModLoad: 00000000`758e0000 00000000`75927000 C:\Windows\syswow64\KERNELBASE.dll
(1a58.b40): WOW64 breakpoint - code 4000001f (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
*** ERROR: Symbol file could not be found. Defaulted to export symbols for ntdll32.dll -
ntdll32!LdrVerifyImageMatchesChecksum+0x6ce:
77dc0e0b cc int 3
0:000:x86> g
Breakpoint 0 hit
testcast!main:
00ac1100 55 push ebp
0:000:x86> p 单步执行
testcast!main+0x6:
00ac1106 6a04 push 4
0:000:x86> t 单步跟踪
testcast!operator new:
00ac1fd9 8bff mov edi,edi
0:000:x86> t
testcast!operator new+0x2:
00ac1fdb 55 push ebp
0:000:x86> t
testcast!operator new+0x3:
00ac1fdc 8bec mov ebp,esp
0:000:x86> p
testcast!operator new+0x5:
00ac1fde 83ec10 sub esp,10h
0:000:x86> p
testcast!operator new+0x8:
00ac1fe1 eb0d jmp testcast!operator new+0x17 (00ac1ff0)
0:000:x86> p
testcast!operator new+0x17:
00ac1ff0 ff7508 push dword ptr [ebp+8] ss:002b:003bfd20=04000000
0:000:x86> p
testcast!operator new+0x1a:
00ac1ff3 e8293a0000 call testcast!malloc (00ac5a21)
……
0:000:x86> p
testcast!Globaltest+0x4e:
00ac10be 68d84eae00 push offset testcast!std::_Iosb<int>::end+0x4 (00ae4ed8)
0:000:x86> g
Breakpoint 1 hit
testcast!Globaltest:
00ac1070 55 push ebp
0:000:x86> g
(1a58.b40): C++ EH exception - code e06d7363 (first chance)
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Windows\SYSTEM32\wow64.dll -
ntdll!ZwTerminateProcess+0xa: 一直执行到进程退出
00000000`77b8f97a c3 ret
0:000> g
^ No runnable debuggees error in 'g'
调试过程截图 
Windbg源码调试的更多相关文章
- windbg源码驱动调试 + 无源码驱动调试
windbg源码驱动调试 环境信息 虚拟机:win7 32位 windbg:6.12(版本不存在太大影响) 设置过程 windbg与虚拟机连接:链接 配置windbg 配置好双机调试后,点击win ...
- 开启Tomcat 源码调试
开启Tomcat 源码调试 因为工作的原因,需要了解Tomcat整个架构是如何设计的,正如要使用Spring MVC进行Web开发,需要了解Spring是如何设计的一样,有哪些主要的类,分别是用于干什 ...
- 在Eclipse中进行HotSpot的源码调试--转
原文地址:http://www.linuxidc.com/Linux/2015-05/117250.htm 在阅读OpenJDK源码的过程中,经常需要运行.调试程序来帮助理解.我们现在已经可以编译出一 ...
- [原创]在Windows和Linux中搭建PostgreSQL源码调试环境
张文升http://ode.cnblogs.comEmail:wensheng.zhang#foxmail.com 配图太多,完整pdf下载请点这里 本文使用Xming.Putty和VMWare几款工 ...
- SpringMVC DispatcherServlet 启动和加载过程(源码调试)
在阅读本文前,最好先阅读以下内容(当然,如果对 Servlet 已经有所了解,则可跳过): http://www.cnblogs.com/cyhbyw/p/8682078.html http://ww ...
- 《k8s-1.13版本源码分析》-源码调试
源码分析系列文章已经开源到github,地址如下: github:https://github.com/farmer-hutao/k8s-source-code-analysis gitbook:ht ...
- SpringBoot自动配置源码调试
之前对SpringBoot的自动配置原理进行了较为详细的介绍(https://www.cnblogs.com/stm32stm32/p/10560933.html),接下来就对自动配置进行源码调试,探 ...
- HashMap源码调试——认识"put"操作
前言:通常大家都知道HashMap的底层数据结构为数组加链表的形式,但其put操作具体是怎样执行的呢,本文通过调试HashMap的源码来阐述这一问题. 注:jdk版本:jdk1.7.0_51 1.pu ...
- .net源码调试 http://referencesource.microsoft.com/
其实关于.net源码调试 网上的资料已经很多了,我以前转载的文章有 VS2010下如何调试Framework源代码(即FCL) 和 如何使你的应用程序调试进.NET Framework 4.5源代码内 ...
随机推荐
- Webstorm10.0.4注册码
分享几个Webstorm10的注册码: (1) user name :EMBRACE ===== LICENSE BEGIN =====17739-1204201000002KkN!4z2O8JEyj ...
- 1034: [ZJOI2008]泡泡堂BNB - BZOJ
Description 第XXXX届NOI期间,为了加强各省选手之间的交流,组委会决定组织一场省际电子竞技大赛,每一个省的代表队由n名选手组成,比赛的项目是老少咸宜的网络游戏泡泡堂.每一场比赛前,对阵 ...
- asp.net单点登录(SSO)解决方案
前些天一位朋友要我帮忙做一单点登录,其实这个概念早已耳熟能详,但实际应用很少,难得最近轻闲,于是决定通过本文来详细描述一个SSO解决方案,希望对大家有所帮助.SSO的解决方案很多,但搜索结果令人大失所 ...
- What the hell is Rotate?
- The 5th Zhejiang Provincial Collegiate Programming Contest------ProblemK:Kinds of Fuwas
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1974 题意:问四个角都有同一个福娃的矩形有多少个. #include<b ...
- 让wordpress投稿作者在后台只看到自己的文章
wordpress支持多作者撰写,让更多的人参与网站内容的创建是个不错的想法,UGC(User-generated content)使网站主题更丰富,不同的内容吸引不同的受众,一个好的网站应该多产生U ...
- struts2 标签的使用之一 s:if
struts2 的web 项目中为了方便的编写jsp,标签是最好的选择 1:struts2 标签库的定义在**-core-版本号.jar META-INF 路径下找到struts-tags.tld文件 ...
- Java泛型:泛型类、泛型接口和泛型方法
根据<Java编程思想 (第4版)>中的描述,泛型出现的动机在于: 有许多原因促成了泛型的出现,而最引人注意的一个原因,就是为了创建容器类. 泛型类 容器类应该算得上最具重用性的类库之一. ...
- SRM588
250: 有n首歌每首歌有duration和tone,连续唱m首歌会消耗每首歌的duration以及相邻两首歌的tone的差的绝对值的和,给个T,问说在T时间内最对能唱多少歌. 将歌按tone排序后发 ...
- Armitage初始化
Kali2.0 Armitage初始化步骤如下 (1)点击页面的Armitage按钮 (2)提示Metasploit RPC server is not running,是否启动该服务,选择是 (3) ...