简体   繁体   English

远程调试托管应用程序

[英]Remote debugging managed applications

How do I remote debug a managed application from other machine which has visual studio. 如何从具有visual studio的其他计算机远程调试托管应用程序。 This is what I have tried: 这是我尝试过的:

  1. Copy the remote debug folder which comes part of visual studio into remote machine and run msvsmon.exe (64 bit version as both machines are 64 bit). 将Visual Studio中的远程调试文件夹复制到远程计算机并运行msvsmon.exe (64位版本,因为两台计算机都是64位)。
  2. Use the same windows login account in both machines. 在两台计算机中使用相同的Windows登录帐户。
  3. Then I start visual studio and use attach to process. 然后我启动visual studio并使用attach进行处理。 In the transport I select "Default" and in qualifier I give the hostname of the machine where msvsmon.exe is running. 在传输中,我选择“默认”,在限定符中,我给出了运行msvsmon.exe的机器的主机名。
  4. Then I press Refresh button to see the list of processes on that machine. 然后按“刷新”按钮查看该计算机上的进程列表。 I can see that on the other it says "User xyz is connected". 我可以看到另一方面它说“用户xyz已连接”。 However, the refresh fails and I get following error : 但是,刷新失败,我得到以下错误: 错误屏幕

What am I doing wrong here? 我在这做错了什么? I am trying with VS2008 Pro and OS on both systems is Windows Server 2008 R2 if it matters. 我正在尝试使用VS2008 Pro和两个系统上的操作系统是Windows Server 2008 R2,如果重要的话。

Note: I can debug unmanaged applications using Remote transport without any issues. 注意:我可以使用远程传输调试非托管应用程序而不会出现任何问题。

Even though your machines are 64 bit, make sure the applications you are running are 64 bit. 即使您的计算机是64位,请确保您运行的应用程序是64位。 For example if you are debugging a 32 bit application on the remote machine, you would want to run the 32 bit version of msvsmon.exe 例如,如果您在远程计算机上调试32位应用程序,则需要运行32位版本的msvsmon.exe

This may not be the answer, but something to check to make sure of. 这可能不是答案,但需要检查以确保。

Update in 2017 2017年更新

As I've been using remote debugging more over the past few years, I've noticed a few more issues that I usually have to work through. 由于过去几年我一直在使用远程调试,我已经注意到我通常需要解决的一些问题。

  1. Make sure the same version of msvsmon is being used on each machine. 确保在每台计算机上使用相同版本的msvsmon。
  2. Make sure authentication is correctly configured (try and get no authentication to work first, then turn it on later if you need it) 确保正确配置了身份验证(首先尝试进行身份验证,然后在需要时再打开身份验证)
  3. Make sure when you attach to process, you have the correct "Attach To" settings (ie Managed .NET version, Native code, etc.) 确保在附加到进程时,您具有正确的“附加到”设置(即托管.NET版本,本机代码等)
  4. Make sure the msvsmon is running as Admin OR as the same user identity as the application you want to debug 确保msvsmon作为Admin OR运行,并且与要调试的应用程序具有相同的用户标识

I also lost a lot of hours on this. 我也失去了很多时间。 The only way I've found to make it works 100%, is to use the same domain. 我发现让它100%工作的唯一方法是使用相同的域。 With VS2012 it's easier to connect without being in the same domain. 使用VS2012,无需在同一个域中即可轻松连接。

But for 2008, this is working for me (A = VS side, B = machine without VS) 但对于2008年,这对我有用(A = VS侧,B =没有VS的机器)

1) The machine A (where VS is) and B must be in the same domain. 1)机器A(其中VS是)和B必须在同一个域中。 You also need to download and install VS Remote Debugger monitor on B 您还需要在B上下载并安装VS Remote Debugger监视器

2) You need to start VS Remote debugger monitor on the B side, to allow incoming connection. 2)您需要在B侧启动VS Remote调试器监视器,以允许传入连接。 When you start it the 1st time, it'll configure the firewall to open the ports. 第一次启动时,它会配置防火墙以打开端口。 It also show you on which address it's listening, ie DOMAIN\\User@hostname_B 它还会显示它正在侦听的地址,即DOMAIN \\ User @ hostname_B

3) Run VS with a domain admin account on A, and you'll be able to remotely debug. 3)在A上使用域管理员帐户运行VS,您将能够远程调试。 To connect to B in debug, use the address shown in step 2 by the monitor 要在调试中连接到B,请使用监视器在步骤2中显示的地址

Hope it'll help you ! 希望它能帮到你!

从Visual Studio 2012开始,您可以使用远程(无身份验证)传输来调试托管代码(以前VS仅允许在远程模式下调试本机代码)。

Not a direct answer to the OP, but might be useful all the same and has dug me out of similar situations a number of times. 不是OP的直接答案,但可能都是有用的,并且已经多次从类似的情况中挖出我。

I'd suggest considering installing WinDBG (or similar), ensuring you've got the correct symbols \\ code setup use that to debug. 我建议考虑安装WinDBG (或类似的),确保你有正确的符号\\代码设置用于调试。 There's a pretty steep learning curve for WinDBG, but I believe it's worth it, even at a very high level. WinDBG有一个非常陡峭的学习曲线,但我相信它是值得的,即使在非常高的水平。 It's extremely lightweight, meaning its useful in the context of the original post + also usable in production, etc. where installing something like VS typically isn't an option. 它非常轻量级,这意味着它在原始帖子的上下文中很有用+也可用于生产等,其中安装类似VS的东西通常不是一种选择。

This probably isn't an option if you're in a rush, but it's worth doing in the long run. 如果你匆忙,这可能不是一个选择,但从长远来看它值得做。

Chris 克里斯

PS: There are some v. good courses on the web, especially on sites like Pluralsight (I've no relation, except being a happy customer) PS:网上有一些很好的课程,特别是在Pluralsight这样的网站上(我没有关系,除了是一个快乐的客户)

I've spent a lot of time making this work. 我花了很多时间来完成这项工作。 But I succeeded and now to fully debug my managed application. 但我成功了,现在完全调试我的托管应用程序。 I follow this list of task to make it work: 我按照此任务列表使其工作:

-Add target PC to domain and login with the same account as you use on PC with Visual Studio. - 将目标PC添加到域并使用与使用Visual Studio在PC上使用的帐户相同的帐户登录。

-Run correct Visual Studio Remote Debugger (msvsmon.exe), I use 2010 version. - 运行正确的Visual Studio远程调试器(msvsmon.exe),我使用的是2010版本。

-Turn off firewall on target PC. - 关闭目标PC上的防火墙。

-Add exception to Windows firewall for devenv.exe (Visual Studio exe) on develop computer. - 在开发计算机上为devenv.exe(Visual Studio exe)添加Windows防火墙例外。

-If you use OracleVM for virtual PC, the Network adapter can't be in NAT mode (I used Bridged Adapter). - 如果您将OracleVM用于虚拟PC,则网络适配器不能处于NAT模式(我使用过桥接适配器)。

-Debug address to use is: DOMAIN\\USER@PCNAME (eg MyGreatDomain\\Myself@DEBUGPC). - 要使用的调试地址是:DOMAIN \\ USER @ PCNAME(例如MyGreatDomain \\ Myself @ DEBUGPC)。

-If I use "Debug->Attach to Process" window to start debugging, I need to also use "Select" button to edit "Attach to:" - I required Managed (v4.0) code, Native code. - 如果我使用“Debug-> Attach to Process”窗口开始调试,我还需要使用“Select”按钮编辑“Attach to:” - 我需要Managed(v4.0)代码,Native代码。

-The pdb files must be in the same directory I use to run my exe. -pdb文件必须位于我用来运行我的exe的同一目录中。 I mapped the directory with my exe and pdb directly into the target computer. 我将目录与我的exe和pdb直接映射到目标计算机。

-In Visual Studio I also have to go to Tools->Options, expand Debugging->General. - 在Visual Studio中我还必须转到Tools-> Options,展开Debugging-> General。 And uncheck Enable Just My Code (Managed only). 并取消选中“启用我的代码”(仅限托管)。

It's really complicated to make it work, but it saves so much time later... 让它工作真的很复杂,但以后节省了这么多时间......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM