用Visual Studio调试VMware中的程序

终于把笔记从单位带回来了。

1.设置Host Machine与Virtual Machine的共享文件夹。
在Host Machine上将待调试的程序和其pdb文件拷到某文件夹,如D:\SharedFolder\Software。
将VS的msvsmon.exe调试工具拷到文件夹如D:\SharedFolder\Tool,注意根据自己要调试的程序是x86还是x64的选择对应的工具。
在Virtual Machine上设置共享文件夹路径,VM->Settings->Options->Shared Folders,添加目录D:\SharedFolder。

2.更改Virtual Machine的网络设置,使其有独立IP。
VM->Settings->Hardware->Network Adapter->Network connection
选择NAT: Used to share the host’s IP address。
此时在Virtual Machine上Ctrl+R,输入cmd,输入ipconfig,可以看到当前Virtual Machine的IP,如192.168.10.10,记下。

3.在Virtual Machine上设置调试工具。
在Virtual Machine上打开msvsmon.exe,在Tools->Options里选择No Authentication (native only),并勾选Allow any user to debug。

4.在Host Machine的Visual Studio中设置符号路径。
在VS的Tools->Options->Debugging->Symbols中,添加Host Machine共享文件夹里程序和pdb文件所在路径,即D:\SharedFolder\Software。

5.在Host Machine的Visual Studio中Attach运行于Virtual Machine上的程序并调试。
在Virtual Machine上打开待调试程序,如D:\SharedFolder\Software\test.exe。
在Host Machine上的VS里,Tools->Attach to Process,选择Transport: Remote(Native only with no authentication),Qualifier处填写Virtual Machine的IP,即192.168.10.10,在Available Processes中选择待选程序,点Attach即可。