Remote debugging with Visual C++ 6
除了對 GUI 程式偵錯以外,有時候,像我這次一樣,必須對一台不能夠灌任何開發環境的電腦偵錯,這個時候,就需要用到 remote debugging。以下簡單整理一下,如何利用 Visual C++ 6[1] 進行 remote debugging。
- 若是 debug 版,要把
MSVCRTd.dll安裝到執行檔所在目錄,因為沒有灌開發環境的 Windows 裡,預設不會有 debug 版的 Microsoft Visual C++ run-time library,即MSVCRTd.dll[2]。 - 將執行檔所需的完整目錄環境,利用網路芳鄰,分享給遠端機器,成為一個連線磁碟機。我的習慣是,在本地端準備一個目錄叫 runtimes,然後利用 NTFS Junction 於
runtimes目錄下,建立指到各個專案執行目錄的 symbolic links。假設遠端機器看到的runtimes目錄是R:磁碟機,專案執行目錄就是R:\foo-rt。 - 執行下面附的 BATCH 程式,把準備在遠端執行,以便讓本地端可以用 debugger 遙控程式執行的工具程式,
MSVCMON.EXE安裝到指定的目錄下。我選擇裝到runtimes\remote-dbg目錄,這樣就可以直接在遠端執行R:\foo-rt\remote-dbg\MSVCMON.EXE。@ECHO OFF IF "%1"=="" GOTO :USAGE SET install_dir=%1 SET vs6_dir=%ProgramFiles%\Microsoft Visual Studio XCOPY "%vs6_dir%\Common\MSDev98\Bin\DM.dll" "%install_dir%" /Y /F /D XCOPY "%vs6_dir%\Common\MSDev98\Bin\MSDIS110.DLL" "%install_dir%" /Y /F /D XCOPY "%vs6_dir%\Common\MSDev98\Bin\MSVCMON.EXE" "%install_dir%" /Y /F /D XCOPY "%vs6_dir%\Common\MSDev98\Bin\TLN0T.DLL" "%install_dir%" /Y /F /D XCOPY "%SystemRoot%\system32\msvcp60.dll" "%install_dir%" /Y /F /D XCOPY "%SystemRoot%\system32\psapi.dll" "%install_dir%" /Y /F /D EXIT /B :USAGE ECHO Usage: vc6-remote_debugger.bat [install-dir] ECHO Install VC6 remote debugger files in directory [install-dir]. GOTO :EOF
- 從 VC6 選單 Build -> Debugger remote connection... 選 Network(TCP/IP),按 Settings... 鈕輸入遠端機器 ip,然後按 OK。
- 執行檔 project setting 的 Debug 頁,設定如下:
- Working directory:
R:\foo-rt(遠端觀點) - Remote executable path and file name:
R:\foo-rt\foo.exe(遠端觀點)
- Working directory:
- 在遠端機器執行
R:\remote-dbg\MSVCMON.exe,按下Connect...鈕。 - 按 F5 開始 happy remote debugging。
更詳細的說明,請參見《Remote Debugging in MSVC++ 6.0 - Step by step in the OnPaint message handler》這篇文章。基本上,使用 remote desktop 操控遠端,進行 debug,還蠻方便的。不過 bug 若還是一直找不到,那就不太能愉快了。
Random Posts
- None Found
Similar Posts
- None Found
Post a Comment