- 首先创建 VMware 虚拟机配置脚本 `setup_vmware.bat`:
```batch
@echo off
:: setup_vmware.bat
:: 设置路径
set "REACTOS_BUILD=E:\Reactos_WinDriver\reactos-master\build"
set "VM_PATH=E:\VMs\ReactOS_Debug"
set "VMWARE_PATH=C:\Program Files (x86)\VMware\VMware Workstation"
:: 创建虚拟机目录
if not exist "%VM_PATH%" mkdir "%VM_PATH%"
:: 创建 VMware 虚拟机配置文件
echo Creating VMware configuration file...
(
echo .encoding = "windows-1252"
echo config.version = "8"
echo virtualHW.version = "16"
echo memsize = "2048"
echo numvcpus = "2"
echo displayName = "ReactOS_Debug"
echo guestOS = "other"
echo serial0.present = "TRUE"
echo serial0.fileType = "pipe"
echo serial0.fileName = "\\.\pipe\ReactOS_Debug"
echo serial0.pipe.endPoint = "server"
echo serial0.tryNoRxLoss = "FALSE"
echo debugStub.listen.guest32 = "TRUE"
echo debugStub.hideBreakpoints = "TRUE"
echo isolation.tools.hgfs.disable = "TRUE"
echo isolation.tools.dnd.disable = "TRUE"
echo isolation.tools.copy.enable = "TRUE"
echo isolation.tools.paste.enable = "TRUE"
echo scsi0.present = "TRUE"
echo scsi0.virtualDev = "lsilogic"
echo scsi0:0.present = "TRUE"
echo scsi0:0.fileName = "ReactOS.vmdk"
echo scsi0:0.deviceType = "scsi-hardDisk"
echo ide1:0.present = "TRUE"
echo ide1:0.fileName = "auto detect"
echo ide1:0.deviceType = "cdrom-raw"
echo ethernet0.present = "TRUE"
echo ethernet0.connectionType = "nat"
echo ethernet0.virtualDev = "e1000"
echo ethernet0.wakeOnPcktRcv = "FALSE"
echo ethernet0.addressType = "generated"
echo sound.present = "TRUE"
echo sound.virtualDev = "hdaudio"
echo pciBridge0.present = "TRUE"
echo pciBridge4.present = "TRUE"
echo pciBridge4.virtualDev = "pcieRootPort"
echo pciBridge4.functions = "8"
echo pciBridge5.present = "TRUE"
echo pciBridge5.virtualDev = "pcieRootPort"
echo pciBridge5.functions = "8"
echo pciBridge6.present = "TRUE"
echo pciBridge6.virtualDev = "pcieRootPort"
echo pciBridge6.functions = "8"
echo pciBridge7.present = "TRUE"
echo pciBridge7.virtualDev = "pcieRootPort"
echo pciBridge7.functions = "8"
) > "%VM_PATH%\ReactOS_Debug.vmx"
:: 创建虚拟硬盘
"%VMWARE_PATH%\vmware-vdiskmanager.exe" -c -s 20GB -t 0 -a lsilogic "%VM_PATH%\ReactOS.vmdk"
echo VMware virtual machine setup completed!
```
- 创建启动调试脚本 `start_vmware_debug.bat`:
```batch
@echo off
:: start_vmware_debug.bat
:: 设置路径
set "REACTOS_BUILD=E:\Reactos_WinDriver\reactos-master\build"
set "VM_PATH=E:\VMs\ReactOS_Debug"
set "VMWARE_PATH=C:\Program Files (x86)\VMware\VMware Workstation"
:: 确保调试管道不存在
if exist \\.\pipe\ReactOS_Debug (
echo Cleaning up existing debug pipe...
timeout /t 2 /nobreak > nul
)
:: 启动虚拟机
start "ReactOS VM" "%VMWARE_PATH%\vmware.exe" -x "%VM_PATH%\ReactOS_Debug.vmx"
:: 等待虚拟机启动
timeout /t 5 /nobreak
:: 启动调试器
start "WinDbg" "C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\windbg.exe" -k com:pipe,port=\\.\pipe\ReactOS_Debug,resets=0,reconnect
echo Debug environment started!
```
- 创建 VMware 工具检查脚本 `check_vmware_tools.bat`:
```batch
@echo off
:: check_vmware_tools.bat
:: 检查 VMware 安装
if not exist "C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe" (
echo VMware Workstation not found!
echo Please install VMware Workstation first.
exit /b 1
)
:: 检查必要工具
where windbg >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
echo WinDbg not found!
echo Please install Windows SDK or WDK.
exit /b 1
)
echo All required tools are available!
```
- 创建 VMware 专用的调试环境配置文件 `vmware_debug.conf`:
```ini
VMware Debug Configuration
[Virtual Machine]
Name=ReactOS_Debug
Memory=2048
Processors=2
HDD_Size=20GB
ISO_Path=E:\Reactos_WinDriver\reactos-master\build\bootcd.iso
[Debug]
Pipe_Name=\\.\pipe\ReactOS_Debug
Baud_Rate=115200
Debug_Port=COM1
[Symbols]
Path=E:\Reactos_WinDriver\reactos-master\build\symbols
Source_Path=E:\Reactos_WinDriver\reactos-master
```
- 创建完整的 VMware 调试环境启动脚本 `start_vmware_environment.bat`:
```batch
@echo off
:: start_vmware_environment.bat
setlocal enabledelayedexpansion
:: 检查环境
call check_vmware_tools.bat
if %ERRORLEVEL% NEQ 0 goto :error
:: 设置路径
set "REACTOS_BUILD=E:\Reactos_WinDriver\reactos-master\build"
set "VM_PATH=E:\VMs\ReactOS_Debug"
set "ISO_PATH=%REACTOS_BUILD%\bootcd.iso"
:: 检查 ISO 文件
if not exist "%ISO_PATH%" (
echo ReactOS ISO not found at: %ISO_PATH%
goto :error
)
:: 配置虚拟机
if not exist "%VM_PATH%\ReactOS_Debug.vmx" (
echo Setting up new VMware virtual machine...
call setup_vmware.bat
if %ERRORLEVEL% NEQ 0 goto :error
)
:: 更新 CD-ROM 配置
echo Updating CD-ROM configuration...
(
echo ide1:0.fileName = "%ISO_PATH%"
echo ide1:0.present = "TRUE"
echo ide1:0.deviceType = "cdrom-image"
) >> "%VM_PATH%\ReactOS_Debug.vmx"
:: 启动调试环境
call start_vmware_debug.bat
if %ERRORLEVEL% NEQ 0 goto :error
echo VMware debug environment started successfully!
goto :end
:error
echo Failed to start VMware debug environment!
exit /b 1
:end
endlocal
```
- 创建调试命令文件 `debug_commands.dbg`:
```
; debug_commands.dbg
; 加载符号
.sympath+ E:\Reactos_WinDriver\reactos-master\build\symbols
.reload
; 设置源码路径
.srcpath+ E:\Reactos_WinDriver\reactos-master
; 常用断点
bp ntoskrnl!KiSystemStartup "g"
bp ntoskrnl!IoInitSystem "g"
; 显示调试信息
!vm
!process 0 0
!drvobj
; 继续执行
g
```
使用说明:
- 准备工作:
```batch
:: 检查环境
call check_vmware_tools.bat
:: 设置虚拟机
call setup_vmware.bat
```
- 启动调试环境:
```batch
call start_vmware_environment.bat
```
- 在 WinDbg 中:
```
; 加载调试命令
\>a\< debug_commands.dbg \`\`\` 4. 调试提示: - 使用 \`Ctrl+Break\` 中断执行 - 使用 \`g\` 继续执行 - 使用 \`bp module!function\` 设置断点 - 使用 \`bl\` 查看所有断点 - 使用 \`k\` 查看调用栈 - 使用 \`!analyze -v\` 分析崩溃 5. 驱动调试: \`\`\` ; 在 ReactOS 中 load driver.sys ; 在 WinDbg 中 bp driver!DriverEntry g \`\`\`