sundajade

博客园 首页 联系 订阅 管理

远程调试分为两种

1.直接调试

直接远程调试只支持Visual Studio 远程调试器上的windows身份验证调试模式,不支持将远程调试作为被调试机的服务和匿名远程调试

 

步骤:

  1. 在被调试机上把程序目录设置为共享目录.

  1. 本机VS中项目生成属性设置

  1. 本机VS中项目调试属性设置

2.附加进程方式

附加进程调试又分为两种:

(1)默认模式[Window身份验证远程调试]

此模式需要验证调试机的身份,有两种使用方法验证:

  1. 调试机和远程被调试机上使用相同用户名和密码
  2. 将远程调试作为被调试机的服务

因为在设置windows服务的时候会要求输入允许进行调试的机器的登录名和密码,一般都是临时使用调试,因此不要作为服务运行,为了减少安全的配置,最好把防火墙临时关闭,调试结束后再开启.

 

(2)匿名远程调试[远程(无身份验证时仅限本机)]

这个模式实际上指的是匿名远程调试需要输入被调试的主机名和端口号,使用匿名远程调试有个问题,附加进程上的被调试机进程没有用户名,导致VS上设置的断点全不起作用,感觉匿名远程调试如同虚设。

远程调试的时候如果在msvsmon上没有选择“允许任何用户进行调试”复选框,那么仍然有:“调试机和被调试机上使用相同用户名和密码的Windows账户”这个限制,但是就算是在匿名远程调试下使用相同的用户名和密码你还是会发现附加进程里出现的被调试机进程还是没有用户名,这仍然说明设置断点不起作用

 

使用附加进程远程调试:

1. 拷贝VS安装目录下的远程调试工具到被远程调试机上.示例:C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Remote Debugger\x86目录到被调试机.x64可调试3264位程序,x86只能调试32程序

2.关闭防火墙或打开相应的端口,一般是4015

3.调试机和被调试机的本地安全策略中的网络访问必须改为“经典,本地用户以自己的身份验证”,路径为控制面板->用户管理->本地安全设置->本地策略->安全选项->网络访问(XP系统通常必须设置)

4.调试机和被调试机都在一个局域网内,且必须在一个网段

5.调试机和被调试机必须登录相同的用户,用户名必须一直

 

使用匿名

1.被调试机的msvsmon下选择工具->选项,点击无身份验证模式(只限本机)

2.之后可以看到主机名和IP,一般是hostname:4015的形式

3.调试机打开VS,选择附加到进程

4.传输选择远程(无身份验证时仅限本机)

5.限定符选择hostname:4015,之后刷新就可以看到进程列表了

 

Window身份验证调试

1.被调试机的msvsmon下选择工具->选项,点击windows身份验证

2.调试机打开VS,选择附加到进程

3.传输选择默认

4.限定符选择,之后刷新就可以看到进程列表了

 

注:

以下是来自MSDN的帮助说明

在远程计算机上运行 Visual Studio 远程调试监视器

  1. 请确保远程计算机具有访问 Visual Studio 远程调试监视器的权限。
    1. 如果调试的是 Windows 客户端应用程序,应在 Visual Studio 计算机上创建一个文件共享并从此文件共享运行远程调试器。请确保远程计算机具有访问该文件共享的权限。
    2. 如果调试的是 ASP.NET 应用程序或其他服务器应用程序,则应在远程计算机上运行 Visual Studio 远程调试器安装程序,并使用“Visual Studio 远程调试器配置”向导启用远程调试器服务。
      有关详细信息,请参阅在设备上安装远程工具
  2. 在远程计算机上启动 Visual Studio 远程调试监视器。有关详细信息,请参阅启动远程调试监视器

在 Windows 7 中启用文件和打印机共享

  1. 打开“网络和共享中心”。为此,请单击“开始”,单击“控制面板”,单击“网络和 Internet”,然后单击“网络和共享中心”。
  2. 单击“选择家庭组和共享选项”,单击“更改高级共享设置”,然后单击“启用文件和打印机共享”。
  3. 单击“保存更改”。

在 Windows Server 2008 或 Windows Vista 中启用文件和打印机共享

  1. 打开“网络和共享中心”。为此,请单击“开始”,单击“控制面板”,单击“网络和 Internet”,然后单击“网络和共享中心”。
  2. 如果没有启用文件共享,请单击箭头按钮以展开相应部分,单击“启用文件共享”,然后单击“应用”。如果提示您输入管理员密码或进行确认,请键入密码或进行确认。

在 Windows XP Service Pack 2 (SP2) 或 Windows 2003 Service Pack 1 中启用文件和打印机共享

  1. 打开“Windows 防火墙”。为此,请单击“开始”,单击“控制面板”,单击“Windows 防火墙”。
  2. 单击“例外”选项卡,然后选择“文件和打印机共享”。
  3. 单击“确定”。

 

来自 <https://msdn.microsoft.com/zh-cn/library/ms164726.aspx>

 

Configure the remote debugger

You can change some aspects of the configuration of the remote debugger after you have started it for the first time.

  • To enable other users to connect to the remote debugger, choose Tools / Permissions. You must have administrator privileges to grant or deny permissions.
  • To change the Authentication mode or the port number, or to specify a timeout value for the remote tools: choose Tools / Options.
    For a listing of the port numbers used by default, see Remote Debugger Port Assignments.

Warning

You can choose to run the remote tools in No Authentication mode, but this mode is strongly discouraged. There is no network security when you run in this mode. Choose the No Authentication mode only if you are sure that the network is not at risk from malicious or hostile traffic.

Configure the remote debugger as a service

For debugging in ASP.NET and other server environments, you need to run the remote debugger as a service.

  1. Find the Remote Debugger Configuration Wizard (rdbgwiz.exe). (This is a separate application from the Remote Debugger.) It is available only when you install the remote tools. It is not installed with Visual Studio.
  2. Start running the configuration wizard. When the first page comes up, click Next.
  3. Check the Run the Visual Studio 2015 Remote Debugger as a service checkbox.
  4. Add the name of the user account and password.
    You may need to add the Log on as a service user right to this account. (Find Local Security Policy (secpol.msc) in the Start page or window (or type secpol at a command prompt). When the window appears, double-click User Rights Assignment, then find Log on as a service in the right pane. Double-click it. Add the user account to the Properties window and click OK.) Click Next.
  5. Select the type of network that you want the remote tools to communicate with. At least one network type must be selected. If the computers are connected through a domain, you should choose the first item. If the computers are connected through a workgroup or homegroup, you should choose the second or third items. Click Next.
  6. If the service can be started, you will see You have successfully completed the Visual Studio Remote Debugger Configuration Wizard. If the service cannot be started, you will see Failed to complete the Visual Studio Remote Debugger Configuration Wizard. The page also gives some tips to follow to get the service to start.
  7. Click Finish.

At this point the remote debugger is running as a service. You can verify this by going to Control Panel / Services and looking for Visual Studio 2015 Remote Debugger.

You can stop and start the remote debugger service from Control Panel / Services.

Running the remote debugger with different user accounts

It is possible to run the remote debugger under a user account that differs from the user account you are using on the Visual Studio computer, but you must add the different user account to the remote debugger’s permissions.

  • You can start the remote debugger from the command line with the /allow <username> parameter: msvsmon /allow <username@computer>.
  • You can add the user to the remote debugger's permissions (in the remote debugger window(Tools / Permissions).

 

来自 <https://msdn.microsoft.com/en-us/library/y7f5zaaa.aspx

posted on 2016-04-27 20:50  sundajade  阅读(1132)  评论(0)    收藏  举报