免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4069 | 回复: 1
打印 上一主题 下一主题

使用 vmware+windbg+bochs 调试 vista 内核 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-25 18:23 |只看该作者 |倒序浏览
用 google 可以搜出很多“如何使用 windbg 调试 windows 内核的”的教程。基本都差不多

我根据搜出的教程,再总结一下将自己实验过程写出来:

1、我的 vmware 版本是: 6.0.4 build-93057

2、64 位 windbg 版本是:6.9.003.113 AMD64

3、bochs 版本是:2.3.7

-------------------------------------------------------------------------------------------------------

使用 vmware + windbg 就可以调试 windows 内核了,但是我喜欢还开上 bochs ,使用 bochs 很方便灵活。
vmware 里的 guest OS 作为被调试对象,Host OS 里使用 windbg 作为调试者
guest OS 和 Host OS 通过 serial port 以 named pipe 方式作为联线。



一、在我的 vmware 上装上了两个 windows:  vista 32  和最新的 windows 7 64bit-beta
本来是只想装 windows 7 64bit - beta 版玩的,但是 bochs 装上 windows 7 64bit-beta 老有问题装不上,只能装上 vista32 了。


1、vmware 的设置

打开相应 vmware 虚拟机上的 “Virtaul Machine Settings ” ---> “Hardware ”选项中 ----> 点击“Add" 添加一个串口设备 Seiall Port  ----> "Next" ----> 在 "Serial Port" 里选中 “Output to named pipe"  ----> "next"  ----> "Finish"
最后,回到 "Virtual Machine Settings" 页面时,在“I/O Mode” 里选中“Yield CPU on poll“
这样 vmware 的设置就好了。


2、windbg 的使用
在桌面上建一个便捷方式,命令行是:
"C:\Program Files\Debugging Tools for Windows 64-bit\windbg.exe" -b -k com:port=\\.\pipe\com_1,baud=115200,pipe

这样在开启 vmware 中的 vista 后运行这个便捷方式,windbg 与 guest OS "vista" 就建立成联线方式。




二、guest OS - vista 中设定


1、在 bootmgr 中下断点

vista 及后续的 windows 已经取消了 ntldr 模块进行引导,转而以 bootmgr 模块进行引导系统。
在 vista 中要设定在哪个部分进行调试。 
vista 可调试部分有 4 个: bootmgr 模块、 winload 模块、WinResume 模块以及 windows 内核模块 Nt 模块
可以在这4个模块下断点进行调式

例:在 bootmgr 下断点的话,可使用以下命令进行:

(1) 以管理员身份运行“命令提示符”
(2) 在“命令提示符”窗口中,输入以下命令:
bcdedit /set {bootmgr} bootdebug on                  
bcdedit /set {bootmgr} debugtype serial
bcdedit /set {bootmgr} debugport 1
bcdedit /set {bootmgr} baudrate 115200

在提示命令成功后,这样就在 vista 中的 bootmgr 模块建立起可调试的机制。
在运行 vista 时到达 bootmgr 时就停止加载,vmware 中是黑屏,它正等待 serial port 的响应,
运行 windbg 后,windbg 就和 vista 中的 bootmgr 建立起联线了


下面是我的 windbg 的响应信息:
-----------------------------------------------------------------------------------------------------------------------------------------
Microsoft (R) Windows Debugger Version 6.9.0003.113 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.

Opened \\.\pipe\com_1
Waiting to reconnect...
BD: Boot Debugger Initialized
Connected to Windows Boot Debugger 6000 x86 compatible target, ptr64 FALSE
Kernel Debugger connection established.  (Initial Breakpoint requested)
Symbol search path is: *** Invalid ***
****************************************************************************
* Symbol loading may be unreliable without a symbol search path.           *
* Use .symfix to have the debugger choose a symbol path.                   *
* After setting your symbol path, use .reload to refresh symbol locations. *
****************************************************************************
Executable search path is:
*********************************************************************
* Symbols can not be loaded because symbol path is not initialized. *
*                                                                   *
* The Symbol Path can be set by:                                    *
*   using the _NT_SYMBOL_PATH environment variable.                 *
*   using the -y <symbol_path> argument when starting the debugger. *
*   using .sympath and .sympath+                                    *
*********************************************************************
*** ERROR: Module load completed but symbols could not be loaded for bootmgr
Windows Boot Debugger Kernel Version 6000 UP Free x86 compatible
Primary image base = 0x00400000 Loaded module list = 0x004ffff8
System Uptime: not available
Break instruction exception - code 80000003 (first chance)
bootmgr+0x37ea4:
00437ea4 cc              int     3

-----------------------------------------------------------------------------------------------------------------------------------------

这段信息中,看到:
(1) Opened \\.\pipe\com_1         
     打开了 serial port
(2) Symbol search path is: *** Invalid ***      
      符号不可用
(3) Primary image base = 0x00400000 Loaded module list = 0x004ffff8
     bootmgr 被加载到基地址是 0x00400000




2、在 winload 模块下断点

同样在“命令提示符”中使用命令

bcdedit /enum                            这条命令显示当前可用的 GUID

在我的系统上显示是:
Windows 启动管理器
------------------
标识符      {bootmgr}
device              partition=C:
description         Windows Boot Manager
locale              zh-CN
inherit             {globalsettings}
default             {current}
displayorder        {current}
toolsdisplayorder   {memdiag}
timeout              30


Windows 启动加载器
------------------
标识符      {current}
device              partition=C:
path                \Windows\system32\winload.exe
description         Microsoft Windows Vista
locale              zh-CN
inherit             {bootloadersettings}
osdevice            partitions=C:
systemroot          \Windows
... ...

winload 的 GUID 为 current

所以,用以下命令:
bcdedit /set {current} bootdebug on                  
bcdedit /set {current} debugtype serial
bcdedit /set {current} debugport 1
bcdedit /set {current} baudrate 115200

这样就在 winload 模块下了断点




3、在内核模块 Nt 模块下断点

打开 vista 的“控制面板”----> “管理工具”  ---> “系统配置” --->  打开“启动”页面  --->  点击“高级选项”
-----> 在高级启动选项里,选中“调试” ----> 点击“确定”就行了

这样就在 nt 模块下了断点




三、 windbg 加载符号


在 windbg 的 "File" ---> "Symbol File path"  ---> 设定为 SRV*d:\symbols*http://msdl.microsoft.com/download/symbols

回到 windbg 命令行,使用命令 .reload 命令,可以自动加载符号




四、用 bochs 配合 windbg  调试

bochs 做单独调试,与 windbg 无联系,但 bochs 可以在整个启动过程中设断点,这一点 windbg 做不到。
windbg 的优点是可以查看符号。bochs 中看不符号,bochs+windbg 配合使用可以观察 vista 启动的每个流程




五:参考一篇文章:http://advdbg.org/blogs/advdbg_system/articles/784.aspx

评分

参与人数 1可用积分 +15 收起 理由
prolj + 15 原创内容

查看全部评分

论坛徽章:
0
2 [报告]
发表于 2009-01-26 00:38 |只看该作者
看到牛人了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP