Remote debugging with Mono
When you run your .NET app on Mac or Linux using Mono, you will probably notice some differences in the application behavior or get some strange exceptions, which do not reproduce when you run the same app on a Windows machine. Here is when remote debugging may come in handy.
Debug information
When you build your project in the Debug mode, MSBuild generates a PDB file with debug information, which basically links binary code in the compiled assembly with the source code. Depending on the Mono version, you will need different PDBs:
Versions 5.x support portable PDB format, so make sure that the project is built with portable PDB.
To do so, right-click the project and choose Properties, then, in the dialog that opens, select a build configuration and choose Portable in the Debug type selector.
Earlier versions require debug information in the .mdb format.
You can use the pdb2mdb tool to convert .pdb to .mdb.
However, JetBrains Rider enables external-code debugging, so if Enable external source debug on the page of JetBrains Rider settings Control+Alt+S is selected (which it is by default), you will be able to debug the remote Mono app even without debug information.
Debugging options
When you open the application source code in JetBrains Rider and copy its binary executable or assemblies to the remote machine, you can start debugging the app.
First, create a run/debug configuration of the Mono Remote type. In the configuration options, you need to specify host and port for the connection depending on how you want to connect to the remote app:
The remote app acts as a server with the debugging agent (with the
server=y
flag).In this case, you start the app on the remote machine first, and then start this run/debug configuration to connect to it. Here is an example of the command-line parameters on the remote machine:
mono --debugger-agent=address=X.X.X.X:12345,server=y,transport=dt_socket --debug MyDotNet.exeYou will need to set Host and Port values of the run/debug configuration as host/port of the remote machine, that is if you start the remote app with the above command line, specify
X.X.X.X
in the Host field and1234
in the Port field.The remote app acts as a client and JetBrains Rider functions as a Mono debugger server, so that you could start this run/debug configuration first and wait for the remote Mono application to actively connect to the debugger.
For example, you can connect to a remote Mono application this way if you want to debug the application's startup. Here is an example of the command-line parameters on the remote machine:
mono --debugger-agent=address=Y.Y.Y.Y:34567,server=n,transport=dt_socket --debug MyDotNet.exeIn this case, you will need to set Host and Port values as host/port of the machine where JetBrains Rider is running, that is if you start the remote app with the above command line, specify
Y.Y.Y.Y
in the Host field and34567
in the Port field.
By default this run/debug configuration will start a Mono debugger client. To make it work as a server, select the Listen for incoming connections checkbox.