一. vmware 下安裝:windows 7 ultimate x86 中文版
1、vmware (請使用盡可能新的版本以對tools的支持) 的設置
打開相應 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 的設置就好了。
注意看清楚:Serial Port 1還是Serial Port 2,接下來會用到。
2、windbg 的使用
創建windbg.exe所在目錄的環境變量后,在桌面寫個批處理,保存為vmware_win7.bat 內容如下:
在桌面上建一個便捷方式,命令行是:
windbg -b -k com:port=//./pipe/com_1,baud=115200,pipe
這樣在開啟 vmware 中的 windows 7 后運行這個便捷方式,windbg 與 guest OS “win7” 就建立成聯線方式。
二、guest OS - win7 中設定
1、在 bootmgr 中下斷點
在 vista 及后續的 windows 已經取消了 ntldr 模塊管理引導,轉而以 bootmgr 模塊管理引導系統。
在我的 windows 7中要設定在哪個部分進行調試。
windws 7 可調試部分有 4 個:bootmgr 模塊、winload 模塊、WinResume 模塊以及 windows 內核模塊 Nt 模塊
可以在上述的 4 個模塊下斷點進行調式
(1) 以管理員身份運行“命令提示符”
(2) 在“命令提示符”窗口中,輸入以下命令:
bcdedit /set {bootmgr} bootdebug on
bcdedit /set {bootmgr} debugtype serial
bcdedit /set {bootmgr} debugport 1
bcdedit /set {bootmgr} baudrate 115200
注意一個細節,bcdedit /set {bootmgr} debugport 1這一行最后的1 對應Serial Port 1,
所以如果是Serial Port 2 則設置為bcdedit /set {bootmgr} debugport 2 否則連不上。
bcdedit /set {bootmgr} bootdebug on |
在提示命令成功后,這樣就在 windows7 中的 bootmgr 模塊建立起可調試的機制。
在運行 windows7 時到達 bootmgr 時就停止加載,vmware 中是黑屏,它正等待 serial port 的響應,
運行 windbg 后,windbg 就和 windws 7 中的 bootmgr 建立起聯線了
下面是我的 windbg 在 bootmgr 模式下斷點的響應信息:
Microsoft (R) Windows Debugger Version 6.11.0001.404 X86
Copyright (c) Microsoft Corporation. All rights reserved.
Opened //./pipe/com_1
Waiting to reconnect...
BD: Boot Debugger Initialized
Connected to Windows Boot Debugger 7600 x86 compatible target at (Mon May 9 13:25:27.631 2011 (GMT+8)), ptr64 FALSE
Kernel Debugger connection established. (Initial Breakpoint requested)
Symbol search path is: SRV*c:/symbols*http://msdl.microsoft.com/download/symbols
Executable search path is:
Windows Boot Debugger Kernel Version 7600 UP Free x86 compatible
Machine Name:
Primary image base = 0x00400000 Loaded module list = 0x00491b80
System Uptime: not available
Break instruction exception - code 80000003 (first chance)
bootmgr!RtlpBreakWithStatusInstruction:
004436bc cc int 3
;====================================
Primary image base = 0x00400000 Loaded module list = 0x00491b80
bootmgr 被加載到基地址是 0x00400000
bootmgr!RtlpBreakWithStatusInstruction:
目前處在 bootmgr 模塊中
查看:
kd> x bootmgr!*
00430724 bootmgr!TpmApiAuthSessCreateOSAP = <no type information>
0045dc5c bootmgr!CmpGetIndexElementSize = <no type information>
004689a4 bootmgr!RcConsoleBaudRates = <no type information>
004356cd bootmgr!OsxmlBrowser::~OsxmlBrowser = <no type information>
00437683 bootmgr!XslStylesheet::getContents = <no type information>
0040d032 bootmgr!BlockIoPcatConventionalInt13 = <no type information>
00420202 bootmgr!BlLogData = <no type information>
0041cda5 bootmgr!NetClose = <no type information>
0043bf31 bootmgr!XslTemplate::getContents = <no type information>
0042ab94 bootmgr!MmTrSelectPageTableMappingAddress = <no type information>
0041796b bootmgr!FileIoOpen = <no type information>
......
2、在 winload 模塊下斷點
同樣在“命令提示符”中使用命令
bcdedit /enum |
這條命令顯示當前可用模塊的 GUID
Microsoft Windows [版本 6.1.7600]
版權所有 (c) 2009 Microsoft Corporation。保留所有權利。
C:/Windows/system32>bcdedit /enum
Windows 啟動管理器
--------------------
標識符 {bootmgr}
device partition=C:
description Windows Boot Manager
locale zh-CN
inherit {globalsettings}
debugtype Serial
debugport 2
baudrate 115200
bootdebug Yes
default {current}
resumeobject {8bf63dd6-79ea-11e0-9d42-db726cb22836}
displayorder {current}
toolsdisplayorder {memdiag}
timeout 30
Windows 啟動加載器
-------------------
標識符 {current}
device partition=C:
path /Windows/system32/winload.exe
description Windows 7
locale zh-CN
inherit {bootloadersettings}
recoverysequence {8bf63dd8-79ea-11e0-9d42-db726cb22836}
recoveryenabled Yes
osdevice partition=C:
systemroot /Windows
resumeobject {8bf63dd6-79ea-11e0-9d42-db726cb22836}
nx OptIn
3、在內核模塊 Nt 模塊下斷點
打開 windws 7 的“控制面板”----> “管理工具” ---> “系統配置” ---> 打開“引導”頁面 ---> 點擊“高級選項”
----> 在高級啟動選項里,選中“調試” ----> 點擊“確定”就行了。
注意端口的選擇同上。com1或com2對應。
這樣就在 nt 模塊下了斷點
Microsoft (R) Windows Debugger Version 6.11.0001.404 X86
Copyright (c) Microsoft Corporation. All rights reserved.
Opened //./pipe/com_1
Waiting to reconnect...
Connected to Windows 7 7600 x86 compatible target at (Mon May 9 14:37:37.001 2011 (GMT+8)), ptr64 FALSE
Kernel Debugger connection established. (Initial Breakpoint requested)
Symbol search path is: SRV*c:/symbols*http://msdl.microsoft.com/download/symbols
Executable search path is:
Windows 7 Kernel Version 7600 MP (1 procs) Free x86 compatible
Product: WinNt, suite: TerminalServer SingleUserTS
Built by: 7600.16385.x86fre.win7_rtm.090713-1255
Machine Name:
Kernel base = 0x83c47000 PsLoadedModuleList = 0x83d8f810
Debug session time: Mon May 9 14:37:32.656 2011 (GMT+8)
System Uptime: 0 days 0:00:04.828
Break instruction exception - code 80000003 (first chance)
*******************************************************************************
* *
* You are seeing this message because you pressed either *
* CTRL+C (if you run kd.exe) or, *
* CTRL+BREAK (if you run WinDBG), *
* on your debugger machine's keyboard. *
* *
* THIS IS NOT A BUG OR A SYSTEM CRASH *
* *
* If you did not intend to break into the debugger, press the "g" key, then *
* press the "Enter" key now. This message might immediately reappear. If it *
* does, press "g" and "Enter" again. *
* *
*******************************************************************************
nt!RtlpBreakWithStatusInstruction:
83cb2394 cc int 3
kd> g
Break instruction exception - code 80000003 (first chance)
*******************************************************************************
* *
* You are seeing this message because you pressed either *
* CTRL+C (if you run kd.exe) or, *
* CTRL+BREAK (if you run WinDBG), *
* on your debugger machine's keyboard. *
* *
* THIS IS NOT A BUG OR A SYSTEM CRASH *
* *
* If you did not intend to break into the debugger, press the "g" key, then *
* press the "Enter" key now. This message might immediately reappear. If it *
* does, press "g" and "Enter" again. *
* *
*******************************************************************************
nt!RtlpBreakWithStatusInstruction:
83cb2394 cc int 3
kd> g
KDTARGET: Refreshing KD connection
三、 windbg 加載符號
在 windbg 的 "File" ---> "Symbol File path" ---> 設定為: SRV*d:/symbols*http://msdl.microsoft.com/download/symbols
回到 windbg 命令行,使用命令 .reload 命令,可以自動加載符號
相關命令:
C:/Users>bcdedit /?
BCDEDIT - 啟動配置數據存儲編輯器
Bcdedit.exe 命令行工具用於修改啟動配置數據存儲。
啟動配置數據存儲包含啟動配置參數並控制操作系統的啟動方式。這些參數以前位於
Boot.ini 文件中(在基於 BIOS 的操作系統中)或位於穩定 RAM 項中(在基於可擴展
固件接口的操作系統中)。可以使用 Bcdedit.exe 在啟動配置數據存儲中添加、刪除、
編輯和附加項。
有關命令和選項的詳細信息,請鍵入 bcdedit.exe /? <command>。
例如,若要顯示有關 /createstore 命令的詳細信息,請鍵入:
bcdedit.exe /? /createstore
有關本幫助文件中按字母順序排列的主題列表,請運行 "bcdedit /? TOPICS"。
對存儲執行的命令
================================
/createstore 新建空的啟動配置數據存儲。
/export 將系統存儲的內容導出到文件。以后可以使用該文件還原系統
存儲的狀態。
/import 使用 /export 命令創建的備份文件來還原系統存儲的狀態。
/sysstore 設置系統存儲設備(僅影響 EFI 系統,在重新啟動后不再有效,
且僅用於系統存儲設備不確定的情況下)。
對存儲中的項執行的命令
===========================================
/copy 復制存儲中的項。
/create 在存儲中新建項。
/delete 刪除存儲中的項。
/mirror 創建存儲中項的鏡像。
運行 bcdedit /? ID 可獲得有關這些命令使用的標識符的信息。
對項選項執行的命令
======================================
/deletevalue 刪除存儲中的項選項。
/set 設置存儲中的項選項值。
運行 bcdedit /? TYPES 可獲得這些命令使用的數據類型的列表。
運行 bcdedit /? FORMATS 可獲得有效數據格式的列表。
控制輸出的命令
============================
/enum 列出存儲中的項。
/v 命令行選項,完整顯示項標識符,而不是使用已知標識符的名稱。
單獨使用命令 /v 可完整顯示活動類型的項標識符。
單獨運行 "bcdedit" 等同於運行 "bcdedit /enum ACTIVE"。
控制啟動管理器的命令
======================================
/bootsequence 為啟動管理器設置一次性啟動序列。
/default 設置啟動管理器將使用的默認項。
/displayorder 設置啟動管理器顯示多重引導菜單的順序。
/timeout 設置啟動管理器的超時值。
/toolsdisplayorder 設置啟動管理器顯示工具菜單的順序。
控制啟動應用程序緊急管理服務的命令
==========================================================================
/bootems 啟用或禁用啟動應用程序的緊急管理服務。
/ems 啟用或禁用操作系統項的緊急管理服務。
/emssettings 設置全局緊急管理服務參數。
控制調試的命令
==============================
/bootdebug 啟用或禁用啟動應用程序的啟動調試。
/dbgsettings 設置全局調試程序參數。
/debug 啟用或禁用操作系統項的內核調試。
/hypervisorsettings 設置虛擬機監控程序的參數。
C:/Users>bcdedit /set /?
此命令設置引導配置數據存儲中的項選項值。
bcdedit [/store <filename>] /set [{<id>}] <datatype> <value> [ /addfirst | /addlast | /remove ]
<filename> 指定要使用的存儲。如果未指定此選項,則使用系統存儲。
有關詳細信息,請運行 "bcdedit /? store"。
<id> 指定要修改的項的標識符。如果未指定,則使用 {current}。
有關標識符的詳細信息,請運行 "bcdedit /? ID"。
<datatype> 指定將創建或修改的選項數據類型。
有關數據類型的詳細信息,請運行 "bcdedit /? TYPES"。
<value> 指定應分配給該選項的值。<value> 的格式取決於指定的數據類型。
有關數據格式的詳細信息,請運行 "bcdedit /? FORMATS"。
/addfirst 僅當數據類型是對象列表時才能使用此開關。
將指定的項標識符添加到列表的頂部。
如果已指定此開關,則只能指定一個項標識符。
如果所指定的標識符已在列表中,請將它移到列表頂部。
/addlast 僅當數據類型是對象列表時才能使用此開關。
將指定的項標識符添加到列表的結尾。
如果已指定此開關,則只能指定一個項標識符。
如果所指定的標識符已在列表中,它將被移到列表結尾。
/remove 僅當數據類型是對象列表時才能使用此開關。
請從列表中刪除指定的項標識符。
如果已指定此開關,則只能指定一個項標識符。
如果此標識符不在列表中,則操作無效。
如果正在刪除最后一項,則此數據類型值也將被刪除。
示例:
對於指定的操作系統項,下列命令將應用程序設備設置到 C: 分區:
注意: 使用 "hd_partiton=" 語法顯式禁用自動 VHD 檢測,並
創建與啟動虛擬機兼容的項目,例如,
bcdedit /store Foocd /set {default} device hd_partition=F:
對於指定的操作系統項,下列命令將操作系統設備設置到 VHD 文件(C:/vdisks/vdisk01.vhd)
bcdedit /set {cbd971bf-b7b8-4885-951a-fa03044f5d71} osdevice vhd=[C:]/vdisks/disk01.vhd
對於指定的操作系統項,下列命令將應用程序路徑設置到 /windows/system32/winload.exe
:
bcdedit /set {cbd971bf-b7b8-4885-951a-fa03044f5d71} path /windows/system32/winload.exe
對於當前的操作系統啟動項,下列命令將 NX 策略設置到 OptIn。
bcdedit /set nx optin
C:/Users>bcdedit /? ID
標識符
很多 Bcdedit 命令需要標識符。標識符可以唯一標識存儲中包含的項。標識符采取
全局唯一標識符的形式,或稱為 GUID。GUID 具有以下格式,其中每個“x”代表
一個十六進制數。
{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
例如:
{d2b69192-8f14-11da-a31f-ea816ab185e9}
破折號(-)的放置以及 GUID 開頭和結尾的括號是必需的。
已知標識符可以標識多個項。如果某個項具有已知標識符,則 BCDedit 將其顯示
在輸出中,除非使用了 /v 命令行開關。
有關詳細信息,請運行 "bcdedit /? /v"。
已知標識符如下所示:
{bootmgr} 指定 Windows 啟動管理器項。
{fwbootmgr} 指定固件啟動管理器項,特別是在實現可擴展固件
接口(EFI)規格的系統上。
{memdiag} 指定內存診斷應用程序項。
{ntldr} 指定可用於啟動早於 Windows Vista 版本的操作
系統的 OS 加載程序(Ntldr)。
{current} 指定與當前運行的操作系統的操作系統啟動項
對應的虛擬標識符。
{default} 指定與啟動管理器默認應用程序項對應的虛擬
標識符。
{ramdiskoptions} 包含啟動管理器所需的其他的 RAM 磁盤設備
選項。
{dbgsettings} 包含可由任意啟動應用程序項繼承的全局調試
程序設置。
{emssettings} 包含可由任意啟動應用程序項繼承的全局緊急
管理服務設置。
{badmemory} 包含可由任意啟動應用程序項繼承的全局 RAM
故障列表。
{globalsettings} 包含所有啟動應用程序項應繼承的全局設置的
集合。
{bootloadersettings} 包含所有 Windows 啟動加載程序應用程序項
應繼承的全局設置的集合。
{resumeloadersettings} 包含所有 Windows 從休眠狀態恢復應用程序項
應繼承的全局設置的集合。
{hypervisorsettings} 包含可由任意 OS 加載程序項繼承的虛擬機
監控程序設置。
參考:http://www.mouseos.com/win7/windbg.html