Reputation: 3266
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:
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:
Target environment:
Upvotes: 33
Views: 19359
Reputation: 3266
I have finally found a good way to perform remote debugging of C# code running on my Raspberry Pi. I have switched from Mono to .NET Core and can now use Visual Studio to debug code running on the Raspberry Pi almost as easy as when running on my development machine.
The following steps were tested using Windows 10 version 1909, Visual Studio 2019 version 16.4.3, Raspbian Buster Lite version 2020-02-13 and a Raspberry Pi 2 Model B. .NET Core requires an ARMv7 CPU, so it will not run on Raspberry Pi 1 and Zero.
Go to https://dotnet.microsoft.com/download/dotnet-core and select .NET Core 3.1 (or later). Click the link for Linux ARM32 runtime binaries and copy the direct link displayed on the next page. (Do not right-click the ARM32 link and select copy link address, as you will end up with a webpage if you download that link.)
Open a SSH session to the Raspberry Pi, download and install the binaries:
ssh [email protected]
wget https://download.visualstudio.microsoft.com/download/pr/c11e9248-404f-4e5b-bd99-175079419d6f/83902a43e06f9fb4e45a4c6a6d5afc0b/dotnet-runtime-3.1.3-linux-arm.tar.gz
sudo mkdir /opt/dotnet
sudo tar zxf dotnet-runtime-3.1.3-linux-arm.tar.gz -C /opt/dotnet
sudo ln -s /opt/dotnet/dotnet /usr/bin/dotnet
Add the following line to ~/.bashrc
, logout and login again to activate:
export DOTNET_ROOT=/opt/dotnet
Check that .NET Core has been installed correctly:
dotnet --info
Create a *.NET Core Console App```lang-none in Visual Studio. Set Target framework = .NET Core 3.1 (or the version you downloaded to the Raspberry Pi). Make sure that Project → Properties → Build → Output → Advanced → Debugging information = Portable.
Build the project in Visual Studio and copy all *.dll, *.pdb, *.deps.json and *.runtimeconfig.json files from the development machine to the Pi. PuTTY's pscp command can be used:
cd bin\Debug\netcoreapp3.1
pscp -pw <password> *.dll *.pdb *.deps.json *.runtimeconfig.json [email protected]:/home/pi
Open a SSH session to the Raspberry Pi and run the program, or start it from the development machine using SSH:
ssh [email protected] dotnet /home/pi/MyProgram.dll
Attach to the remote process by selecting the Debug → Attach to Process menu item in Visual Studio. Select Connection type = SSH and in the Connection target textbox, type [email protected] and press Enter.
Enter password and click the Connect button.
Click the Select button.
Select Managed (.NET Core for Unix) and click the OK button.
Select the dotnet MyProgram.dll
process and click the Attach button. The first connection might take several minutes, but subsequent connections are much faster.
Enjoy setting breakpoints, adding watches, stepping through code and even using "Set Next Statement" - almost as fast as when debugging on the local machine. The only thing I'm missing so far is Edit and Continue, but not enough to investigate if it is possible to achieve.
Upvotes: 2
Reputation: 1533
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 Visual Studio extension on Visual Studio 2015 update2.
Upvotes: 17
Reputation: 3880
There is a plugin for Xamarin Studio/MonoDevelop
https://github.com/logicethos/SSHDebugger
Upvotes: 0
Reputation: 3266
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:
sudo apt-get purge mono-complete
sudo apt-get autoremove
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
wget https://github.com/techl/MonoRemoteDebugger/releases/download/v1.2.0/MonoRemoteDebugger.Server.zip
unzip -d MonoRemoteDebugger.Server MonoRemoteDebugger.Server.zip
mono MonoRemoteDebugger.Server/MonoRemoteDebugger.Server.exe
MonoRemoteDebugger -> Debug with Mono (remote)
in Visual Studio.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.
Upvotes: 0
Reputation: 3266
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).
MONODEVELOP_SDB_TEST = 1
(My Computer -> Properties -> Advanced System Settings -> Environment Variables).%localappdata%\XamarinStudio-6.0\Logs
to see what failed.PdbDebugException: Unknown custom metadata item kind: 6
).pdb2mdb MyProgram.exe
sudo apt-get install mono-complete
.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.Run -> Run with -> Custom Configuration...
and select Run Action = Debug - Custom Command Mono Soft Debugger
. Click Debug
.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.
Upvotes: 4
Reputation: 1061
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).
Upvotes: 0