Mono remote debugging from Visual Studio

2019-01-22 02:43发布

问题:

I would like to remote debug a C# console application running on Linux from Visual Studio. Here's what I found so far:

http://www.mono-project.com/Debugger

The Mono runtime implements a debugging interface that allows debuggers and IDEs to debug managed code. This is called the Soft Debugger and is supported by both MonoDevelop, Xamarin Studio and Visual Studio (when the appropriate plugins are installed) as well as the command line SDB client.

Mono provides an API to communicate with the debugger and create your own debugging UIs via the Mono.Debugger.Soft.dll assembly.

The page below discusses some issues of the current MonoVS debugger implementation, but they are all fine with me.

http://mono-project.com/Visual_Studio_Integration

The page also links to the Getting started guide for MonoVS:

http://mono-project.com/GettingStartedWithMonoVS

Which contains a download link for MonoTools:

http://mono-tools.com/download/

However, the download link now redirects to:

http://xamarin.com/download/

Where I'm offered to download Xamarin Studio Starter Edition. Clicking the Pricing link I see that I need at least the Business edition for Visual Studio Support, at $999 per year. Well, no thank you.

This is where I'm stuck. Some specifics of my environment:

Development environment:

  • Windows 7 64-bit
  • Visual Studio Pro 2013 (might use 2010 if that works better)

Target environment:

  • Raspberry Pi
  • Raspbian Wheezy
  • Mono 3.2.8
  • Running console application over SSH

回答1:

I know it is an old thread but just in case anyone (like me) hasn't found a solution for that yet, while searching today, I found this Visual Studio 2015 extension which works like a charm: MonoRemoteDebugger for Visual Studio 2015

See MonoRemoteDebugger v1.0.4 to fix conflict with Xamarin VS extension on VS2015 update2.

I hope it helps.

Have a happy debugging and thanks to the developer! :)



回答2:

I found this guide explaining how to perform remote debugging on Linux, from Windows, using Xamarin Studio which is now free except for iOS & Android development. I've expanded it with fixes for the problems I encountered while testing it on a Raspberry Pi Zero W running Raspbian Jessie Lite (2017-04-10).

  1. Download and install Xamarin Studio, GTK# for .NET and .NET Framework 4.6.2. Xamarin Studio requires .NET 4.5 but GTK# requires .NET 4.6. I used Xamarin Studio version 6.1.2 (build 44) and GTK# version 2.12.44.
  2. I installed Xamarin Studio on a virtual machine different from my VS2015 machine, so I needed to download and install MSBuild Tools 2013 and MSBuild Tools 2015 as well.
  3. Create an environment variable MONODEVELOP_SDB_TEST = 1 (My Computer -> Properties -> Advanced System Settings -> Environment Variables).
  4. Start Xamarin Studio. If no window is shown, check the log files in the folder %localappdata%\XamarinStudio-6.0\Logs to see what failed.
  5. I created a .NET 4.6 Console Application in Visual Studio 2015 and added the NuGet package Mono.Unofficial.pdb2mdb, I used version 4.2.3.4. The package Mono.pdb2mdb version 0.1.0.20130128 does not seem to work with assemblies built by VS2015 (PdbDebugException: Unknown custom metadata item kind: 6).
  6. Load the .sln or .csproj file from Visual Studio into Xamarin Studio. Build the solution and use the pdb2mdb tool from the NuGet packages folder to create a .mdb file: pdb2mdb MyProgram.exe
  7. I used WinSCP to copy MyProgram.exe and MyProgram.exe.mdb to my Raspberry Pi.
  8. I logged in with Putty using SSH and installed Mono version 3.2.8 on the Pi: sudo apt-get install mono-complete.
  9. Start the Mono runtime with debugger flags: mono --debug --debugger-agent=transport=dt_socket,address=0.0.0.0:12345,server=y /path/to/MyProgram.exe. This will start the program but halt execution until the Xamarin Studio debugger has connected.
  10. Set a breakpoint in Xamarin Studio and select the menu item Run -> Run with -> Custom Configuration... and select Run Action = Debug - Custom Command Mono Soft Debugger. Click Debug.
  11. Fill in the IP and Port fields with the IP address of your linux system and port 12345 as specified in the Mono command line. Click Connect and execution will begin, stopping at the breakpoint set.

It is possible to set conditional breakpoints, step into/out of/over code, watch primitives and objects etc and it's quite fast as well. I'd rather debug directly from Visual Studio, but this seems like a fully working solution.



回答3:

The solution that you need is coming this year with MonoDebugger.NET. The developer(s) "promises" that we can deploy to any Mono device, and debug it within Visual Studio (2010 to 2015).



回答4:

Building on Gutemberg Ribeiro's answer, I managed to get MonoRemoteDebugger working with VS2015 on a Raspberry Pi Zero W running Raspbian Jessie Lite (2017-04-10). The trick was to install a Mono version later than 3.2.8:

  1. Install the MonoRemoteDebugger Visual Studio extension, I used version 1.2.0.
  2. Create a .NET 4.6 Console Application in Visual Studio.
  3. If an older Mono version has been installed on the Raspberry Pi, remove it using the commands:

    sudo apt-get purge mono-complete

    sudo apt-get autoremove

  4. Install Mono version 4.0.2:

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

    echo "deb http://plugwash.raspbian.org/mono4 jessie-mono4 main" | sudo tee -a /etc/apt/sources.list

    sudo apt-get update

    sudo apt-get install mono-complete

  5. Install MonoRemoteDebugger server:

    wget https://github.com/techl/MonoRemoteDebugger/releases/download/v1.2.0/MonoRemoteDebugger.Server.zip

    unzip -d MonoRemoteDebugger.Server MonoRemoteDebugger.Server.zip

  6. Start MonoRemoteDebugger server:

    mono MonoRemoteDebugger.Server/MonoRemoteDebugger.Server.exe

  7. Set a breakpoint in Visual Studio and select the menu item MonoRemoteDebugger -> Debug with Mono (remote) in Visual Studio.
  8. Set Remote-IP to the IP address of the Raspberry Pi and click Connect. MonoRemoteDebugger will compile and transfer the program to the Raspberry Pi. No need to run pdb2mdb manually, the .mdb file will be created by the MonoRemoreDebugger server.

To be honest, the debugging capabilities are quite limited. Simple breakpoints and step into/out of/over code seems to work somewhat ok. Setting a breakpoint in a function and then stepping over that function call will not stop at the breakpoint.

Primitive types can be watched, but the objects I tried to watch can not be displayed. The Call Stack view is quite limited and the Threads view is empty. Exceptions are not catched but causes an "[ERROR] FATAL UNHANDLED EXCEPTION" message from the MonoRemoteDebuggerServer. But if you can live with these limitations, the setup is simpler than the Xamarin Studio route.



回答5:

There is a plugin for Xamarin Studio/MonoDevelop

https://github.com/logicethos/SSHDebugger