Windows Remote Debug

第一篇文章,先來個基本的教學設定好了~ 也方便自己做紀錄

首先,Windows  remote debug有三種方式
    1. COM Port
    2. 1394
    3. USB (需要USB跳線,或是轉換的裝置)

再來,要開啟Windows的Debug模式(client端(也就是被debug的機器)才需要設定)
這裡分為XP及Vista之後兩種方式


XP and before:修改boot.ini檔案
這個檔案位於C:下,是隱藏檔,所以需要去"資料夾選項"把隱藏系統檔案的選項勾掉(附註.此檔案有可能是唯讀,所以也要把唯獨屬性拿掉)

打開來看會長得像這樣:
[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect

這個時候只需要把最後一行copy下來,加上幾個tag:
"/debug /debugport=<COM Port No.> /baudrate=<Baud Rate>
最後會長得像這樣:
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional - Debug" /fastdetect /debug /debugport=com1 /baudrate=115200

變色部分是修改的部分,"Microsoft Windows XP Professional - Debug",這裡加Debug只是讓你在開機的時候方便識別而已,可以隨便寫
上面那行可以直接copy,在大部分的機器都是這樣設定,網路上有人建議,千萬不要自己key,因為會有typo...

重開機後,就會在開機選項看到第二個選項

Vista and later: bcdedit
首先,用run as admin 開啟cmd
1. 編輯 debugging settings
    bcdedit /dbgsettings {serial [baudrate:<value>] [debugport:<value>] | 1394 [channel:<value>] | USB}
    ex: bcdedit /dbgsettings serial baudrate:115200 debugport:1
2.產生一個新的entry
    bcdedit /copy {current} /d DebugEntry
    接著會看到:
    The entry was successfully copied to {b3262a5f-81f9-11de-9df0-98dbe9636033}.
   (b3262a5f-81f9-11de-9df0-98dbe9636033 --> 為後面的"ID"值)
3. 把新增的entry加到開機選項
    bcdedit /displayorder {current} {ID}
4.開啟debugging功能在新的entry
    bcdedit /debug {ID}  ON
*. 把debug entry當作預設選項
    bcdedit /default {ID}
5. 重開機!

順便分享一下在vista之後要如何顯示debug message
1.建立"Debug Print Filter"這個key
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Debug Print Filter 

2. 建立一個DWORD value, 名為"DEFAULT"(注意大小寫),值為0x8
3. 重開機
 

接下來,介紹一下如果client是VM,要怎麼設定
以上的設定都一樣,要增加的是在VM要開一個虛擬com port(serial port)
怎麼開就不教了,直接講解設定
重點在於:
1.要選擇named pipe,命名規則為 \\.\pipe\<PipeName>,這裡的<PipeName>要跟之後  Windbg的一樣
2.第二個選項要選擇"The other end is an application"
3.要選取"Yield CPU on poll"

這樣,client端的設定就都OK了
最後,我們看Windbg這邊怎麼設定
選擇"kernel Debug"

如果你client是用serial port(COM port),這邊就選COM的tag,裡面的baudrate、port就跟之前設定的一樣,記得!"pipe"要勾起

或是用command: windbg -b -k com:pipe,port=\\.\pipe\xp_clean,resets=0

成功的話,會看到:


參考資料:
http://keikoblog.blogspot.com/2009/03/windows-debugging-kernel-debugging-with.html

留言

這個網誌中的熱門文章

What's New in Ethereum Serenity (2.0)

瑞士滑雪分享2 - 策馬特

動手實做零知識 - circom