2018年8月7日 星期二

建置 Windows Debugger(WinDbg) 環境 via USB 3.0 cable

本篇文章參考
Debugging Tools for Windows

Preparation

Host Computer (with USB3.0 port)
  - windows-10-sdk
Target Computer (with USB3.0 Debug port)
USB 3.0 Debug Cable (A-A crossover, no VBus)

Setup Target Computer

1. 使用UsbView.exe來確認該port是否能Debug(Is Port Debug Capable: yes)。

2. 紀錄該port的xHCI Controller的Bus、Device和Function的number。

3. 使用系統管理員權限開啟command prompt,並輸入以下命令
bcdedit /debug on
bcdedit /dbgsettings usb targetname:TargetName
TargetName為自行命名。

4. 將step2 所記下的資訊帶入以下命令
bcdedit /set "{dbgsettings}" busparams b.d.f

5. 重新開機。

Setup Host Computer

1. 安裝Windows SDK

2. 安裝WinDbg的USB driver
(預設路徑:C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\usb)


使用WinDbg

1. 開啟WinDbg
(C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\windbg.exe)

2. 點選"File" > "Kernel Debugging"

3. 標籤頁切換到"USB",並輸入Setup Target Computer step 3的TargetName


3. 按下確定,開始執行WinDbg


設定Symbols

https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/symbol-path

.sympath
設定Debugger所要參考的symbol file的位置。

.sympath srv*c:\MyServerSymbols*https://msdl.microsoft.com/download/symbols 使用Microsoft Public Symbol Server https://msdl.microsoft.com/download/symbols 所提供的symbol並把local端的c:\MyServerSymbols 用來存放symbols。

或使用 "File" > "Symbol File Path ..." (Ctrl+S) 來設定。


2020/06/02 Note
最近嘗試用這樣的方式設symbol path會遇到ERROR_INTERNET_CANNOT_CONNECT無法 load symbol的情況。
所以參考how-to-specify-symbol-file-locations-from-the-command-line的方式,將
_NT_SYMBOL_PATH設成系統的環境變數,就能正常load到symbol。


Modules

lm
列出已載入的Modules

m PATTERN - 指定符合PATTERN的Module
ex: lm m a* 為列出所有a開頭的Modules

.reload
重新從Symbol Path載入Modules


2 則留言:

  1. Windbg support USB 3.0 , it is a very good news ,it is very fast. And if your PC donot support USB 3.0 debug .you can buy the related device and debug cable ,it is convenient for developer.I can share the related device and USB3.0 debug cable.

    You can buy them from the link and there are details how to setup the debug.
    USB 3.0 debug cable https://www.ebay.com/itm/402650436755
    PCIE to USB3.0 debug device https://www.ebay.com/itm/402677745334
    Good for me and good luck for you!

    回覆刪除
  2. 如果 Is Port Debug Capable是 No,但它的 companion port 是 debug capable 的話,那這個 port 能拿來除錯嗎?

    我發現手邊的機器實體孔位都沒對應到可除錯的 port。

    回覆刪除