[Windbg] 在 Mac VirtualBox上設定 Windows kernel debugging 環境

[Windbg] 在 Mac VirtualBox上設定 Windows kernel debugging 環境

很久以前寫過一篇 設定 VMWare kernel debugging

那時候是用 Windows 版的 VMware Workstation,

但現在我的主要工作環境是在 Mac,常用的 VM 軟體也轉換成 VirtualBox,

因此在準備 Inside Windows Debugging 這本書的讀書會報告時,

也想用 VirtualBox 建立出 kernel debugging 的環境~

卻沒想到,在連線時遇到極大的問題!!花了非常久的時間才解決…

 

參考資料:

VirtualBox manual: Serial Ports

Kernel Debugging between two Windows VMs – Problems with COM

How To: Debug the WRK on Mac OS X Using VirtualBox

 

1. 準備好兩台 Windows 7 VM

我是用 Mac 上的 VirtualBox,將上面的一台 Windows 7 VM 作 link-clone,

一台做 Debugger 用 (跑 windbg 的機器),一台作 Debuggee 用 (被 debug 的機器)~

 

2. 設定 Debugger VM 的 COM port

在設定 kernel debug 環境時,我遇到一個很大的問題是:連線一直連不上!

後來爬一些文,有人建議要先確認 COM port 是正常的,

而這也成為解決 kernel debug 連線失敗的契機~

 

先將 VM 開機,到 Control panel > Device Manager > Ports (COM & LPT) 那邊,

把所有看得到的 COM port 都 Uninstall 掉…

這是為了避免有殘留無法正常運作的 COM port….

我不知道實際原因,但確實有看過移掉後再重新做 Hardware change scan,

COM port 從 COM2 變成 COM3 這種怪事出現…

2015-12-27 22_01_29  

 

接著將 VM 關機,到 Settings > Ports > Serial Ports > Port 1 那邊 Enable Serial Port~

Port Number 這邊先選 COM1,Port Mode 選 Host pipe,

Connect to existing pipe/socket 不要勾,

Path/Address 那邊設定成一個隨意路徑,例如 /tmp/serial~

Screen Shot 2015-12-28 at 11.19.21 AM 

 

設定完後,將 VM 開機,開完後一樣到 Control panel > Device Manager > Ports (COM & LPT),

看看有沒有設定的 COM port 跑出來…

最好跑出來的 COM port 跟你設定的是同一個,像我也遇過設定 COM3 但跑出 COM2 的…

最後在我的環境裡是設定成 COM4 時,Windows 7 裡面也是出現 COM4,看來比較令人放心:

2015-12-28 11_37_29      

 

3. 設定 Debuggee VM 的 COM port

這邊的設定方法和步驟 2 差不多,也是要先移除不必要的 COM port,

再到 VirtualBox 的 Ports 作設定,COM port 的選擇也是要多試幾次,

跟 Debugger VM 唯一的差別,是要把 Connect to existing pipe/socket 勾選起來:

Screen Shot 2015-12-28 at 11.19.32 AM    

 

4. 設定 Debugger VM 的 Kernel Debug 連線

將 Debugger VM 開機,再次確認 Device Manager 裡有出現指定的 COM port,

然後把 Windbg 執行起來,到 File > Kernel Debug > COM 分頁,

將 Baud Rate 設定成 115200,Port 就設定成剛選好的 COM port,將 Reconnect 打勾:

2015-12-28 00_30_33  

 

按下 OK 後,會出現 COM port 有 Opened 的訊息,

Waiting to reconnect 是在等 debuggee 電腦連線~

如果出現 Could not find the file path 這種錯誤訊息的話,

應該就是 COM port 沒有設定好,這種狀況下再怎麼設定 Windbg 也是沒用的:

2015-12-28 00_34_19  

 

5. 設定 Debuggee VM  的 Kernel Debug 連線

開機後,同樣再次確認 Device Manager 裡有出現指定的 COM port,

再執行 msconfig > Boot > Advanced options,

將 Debug, Debug port, 和 Baud rate 都勾起來,

Debug port 選擇剛設定好的 COM port,Baud rate 固定選 115200:

2015-12-28 23_23_44  

 

設定好之後,就可以重新開機~

當 Debuggee VM 重開機時,它就會開始去查看是否有 kernel debugger 想接上來,

有的話就會去接受連線了~

 

6. 在 Debugger VM 上對 Debuggee VM 作 kernel debugging

當 Debuggee VM 重開機後,在 Starting Windows 的畫面會停頓蠻久的,

開機的速度變得很慢,同時在 Debugger VM 上的 windbg 會出現一些訊息,

寫說 Connected to Windows… 以及 Kernel Debugger connection established 的字樣,

這就表示 kernel debugger 的連線成功了:

2015-12-28 23_33_15  

 

連線成功之後,預設似乎並不會立刻將 debuggee 停下來 (跟 user-mode 的 attach 不同),

這時可以隨時在 Debugger VM 上的 windbg 選單上選擇 Debug > Break (或是 Ctrl-Break),

就會中斷 debuggee VM 的執行,開始 kernel debugging:

2015-12-28 23_38_33  

 

作完 kernel debugging 之後,要記得在 windbg 中執行 g 指令讓 Debuggee VM 繼續運作,

不然 Debuggee VM 就會一直卡在那邊囉~

 

(本頁面已被瀏覽過 1,164 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料