VMware+WinDbg構成カーネルデバッグ

8770 ワード

VMwareを使用して、WinDbgを使用してスタンドアロンでデバッグする方法を実装します.
VMware Workstation 6.0,WinDbgをインストールします.具体的な手順は以下の通りである:1 VMwareの仮想com 1.1を設定してVMwareを実行し、「Edit virtual machine settings」1.2をクリックして「Add...」をクリックするVMwareのHardware Wizardを実行します
1.3「Serial Port」を選択し、「次へ」をクリックします.
1.4「Output to named pipe」を選択し、「次へ」をクリックします.
1.5最初のボックスにデフォルトの\.\pipe\com_1<====任意の名前の2番目のボックスで「This end is the server.」を選択します.3番目のボックスで「The other end is an application.」を選択します.「接続at Power on」を選択し、「Advanced>」をクリックします.
1.6「Yield CPU on poll」(VMware Supportで説明している)を選択し、ポイントを完了します.
1.7これで仮想comの設定が完了します.
1.8 VMを再起動します.2 VMwareが仮想化するguest osを設定現在power onが仮想化するguest os 2.1がbootを設定する.iniはc:の下でbootを見つけることができます.ini、手帳で開くことができます.WinDbgを使用してデバッグするにはguest osの起動項目にパラメータを追加する必要があります.既存の行の後ろに直接パラメータを追加できますが、新しい行をコピーし、新しい行の後ろにパラメータを追加することを強くお勧めします.これにより、デバッグ起動に問題がある場合、元の起動方式に簡単に戻ることができます.次は私が直したbootです.ini. ここで、「マルチ(0)disk(0)rdisk(0)partition(1)WINNT=」Microsoft Windows XP Professional"/fastdetectは元の行です.「マルチ(0)disk(0)rdisk(0)partition(1)WINNT=」Microsoft Windows XP Professional-debug"/fastdetect/noguiboot/debug/debugport=com 1/baudrate=115200」WinDbgデバッグ用の行に新たに追加されました.[boot loader] timeout=10 default=multi(0)disk(0)rdisk(0)partition(1)\WINNT [operating systems] multi(0)disk(0)rdisk(0)partition(1)\WINNT="Microsoft Windows XP Professional"/fastdetect multi(0)disk(0)rdisk(0)partition(1)\WINNT="Microsoft Windows XP Professional - debug"/fastdetect/debug/debugport=com 1/baudrate=115200----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------新しい行の後にパラメータ/debug/debugport=com 1/baudrate=115200が追加され、debugport=com 1、baudrate=115200が表示されます.パラメータの具体的な役割は、WinDbgのヘルプファイルを参照してください.
2.2 com 1ポートの速度を設定guest osのデバイスマネージャでcom 1ポートの速度である「毎秒ビット数」項目を、上記と同じ115200に設定します.
3 WinDbgを設定するには、pipeによる接続と接続の速度をWinDbgに伝える必要があります.コマンドプロンプト(cmd.exe)にパラメータ-b-k com:port=\.pipecom_1、baud=11520を追加し、pipeはWinDbgを実行します(VMware Supportではbaud=11520というパラメータは言及されていませんが、実はこれは比較的重要なパラメータです).より便利な方法はデスクトップでWinDbgのショートカットを作成することです.このショートカットのプロパティ、「ターゲット」ボックスに、パラメータ-k com:port=\.を追加します.\pipe\com_1,baud=11520,pipe .これでこのショートカットを実行して起動したWinDbgの設定が完了します.パラメータの具体的な役割は、WinDbgのヘルプファイルを参照してください.
4推奨の操作手順4.1まずVMwareを実行し、Guest OSを起動し、システムの起動選択まで、「Microsoft Windows XP Professional-debug」項目を選択し、先に押さないでください.4.2先ほど設定したショートカットでWinDbgを実行します.4.3 Guest OSで「Microsoft Windows XP Professional-debug」項目を選択し、を押して戻る.4.4少々お待ちください.長い間接続されていない場合は、WinDbgメニューの「Debug」->「Kernel Connection」->「Resynchronize」を押すことができます.<==コマンドオプションがあれば、これは発生しません.
4.5最後にWinDbgメニューの「Debug」->「Break」を押すと、WinDbgにコマンドを下すことができます.
? その他?1 VMware Supportでは、仮想マシンのプロファイルを変更することで仮想シリアルポートの速度を変更できることも言及されていますが、興味があればVMware Supportの方法を参考にすることができます.?2 WinDbgのメニュー項目「View」->「Show Version」には、いくつかの関連情報が表示されます.参照Driver Debugging with WinDbg and VMWarehttp://silverstr.ufies.org/lotr0/windbg-vmware.htmlVMwareSupport関連部分http://www.vmware.com/support/ws3/doc/ws32_devices3.html
One of the first useful things you will want to do when in the bowels of ring 0 is attack the thing from a debugger point of view. In my case I like using Windows Debugger [windbg] (hey its free, fully functional and does remote debugging really well), and found it neccessary to find a way to have it work with VMWare.
The trick to get it to work in VMWare is to get the host OS to believe it is able to connect to a serial port. Through VMWare, to accomplish this, you need to create a named pipe. The following steps will guide you to configuring VMWare (in my case v3.2):
  • Open up the Configuration Editor (Settings->Configuration Editor)  
  • Click Add to run the Hardware Wizard  
  • Select Serial Port, and then click theNext button  
  • Select the Use named pipe radio button  
  • Use the default pipe name. It SHOULD be \\.\pipe\com_1. If it is not, change it to that.  
  • Select This end is the Server.  
  • Select The other end is an application.  
  • Click the Advanced Button.  
  • Select the Yield CPU on poll checkbox This is an important step as the Kernel in the target virtual machine uses the port in polled mode, not interrupt mode.  
  • Click the Finish button, and then clickOk to close the Configuration Editor. Once you have configured your VMWare session, you need to power it on. You will be able to confirm that the new virtual serial port is added by clicking on theDevices->serial0 menu item. You should note it is saying"Connecting". This means its now ready for a remote connection. Once the actual virtual machine is configured, you need to configure the target operating system installed in the virtual machine to support remote debugging. This is accomplished by editing theboot.ini found in the root of the C:\drive. To do this, you need to add a/debugport=some_com_port/baudrate=some_baud_rate to the end of an[operating systems] line. I would not recommend doing it to the one that is there. It would be better to copy the line and paste it with the ammendments, and then use the OS's menu selection to determine which mode you would like to boot into. This is what my boot.ini looks like for XP Pro as the operating system in the virtual machine:  
    [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" /fastdetect
            multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional - Debug" /fastdetect /debugport=com1 /baudrate=115200
    
            

    You will notice that the second option sets the debugport to com1, and sets the baudrate to 115200. I am told you can tweak this out to get even more speed out. But it seems fine for me at this speed, so I haven't mucked with it at all. If you do try this, drop me an email and let me know how it works out. If you set up your boot.ini fine, save it and reboot. You should be prompted with something that looks like this: At this point you have completed setting up the VMWare side of things. Now you need to set up the host to connect to it. This is actually rather easy. You just need to tell windbg at the command like to connect to the pipe, like this:
    windbg -k com:port=\\.\pipe\com_1,pipe
            
    If you are using WinDbg 6.x or newer, a better alternative is to use:
    windbg -b -k com:pipe,port=\\.\pipe\com_1,resets=0
            
    Thanks needs to go to Randhir Dugal for pointing out the new format for the latest Windbg version. I am a rather anal type guy when it comes to security, so I actually made a shortcut on my desktop to WinDbg and added these command line arguments to theTarget line. Originally this was so I could run WinDbg with differnet credentials as I do not run with administrator privileges on a day to day basis. I found that with XP's normal security settings for com ports, you can still work in a least privileged environment while doing the development WITHOUT having to use 'runas'. (You are logged into W2K/XP as a least priviledged environment aren't you? If not, you really should read myarticle on how, and why this is important to do so.) At this point fire up the debugger. With any luck you should see something that looks like this: If you are using a WinDbg version earlier than 6.x, you will find one issue with this approach. If you cannot seem to connect right away, close Windbg and restart it... it will then work. Seems flaky to me. But it works. And thats a Good Thing™. With the latest versions of WIndbg (6.x and newer) a new resets flag prevents this sort of hanging. That is all there is to it. At this point, you can now go nuts with remote debugging. To make sure it works for ya just add someDbgPrint() messages to your ring 0 driver and watch them echo to the screen. Past that, I will leave it to your imagination how to use the debugger :) Good luck!

  • http://wenku.baidu.com/view/5a3199553c1ec5da50e2703a.html