Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug MonoDevelop add-ins with MonoDevelop?

The topic says it all. I cannot find any information on the monodevelop site or through google.

Even adding System.Diagnostics.Debugger.Break() and running with mono --debug MonoDevelop.exe doesn't seem to do anything..

like image 649
simendsjo Avatar asked Mar 09 '12 16:03

simendsjo


People also ask

Is MonoDevelop an IDE?

MonoDevelop is an IDE primarily designed for C# and other . NET languages. MonoDevelop enables developers to quickly write desktop and ASP.NET Web applications on Linux, Windows and Mac OSX.

What happened to MonoDevelop?

Visual Studio for Mac will replace MonoDevelop-Unity as the default C# IDE for using Unity on macOS, while Windows installations will continue to feature the free Visual Studio 2017 Community edition and will no longer include MonoDevelop-Unity as an alternative.


1 Answers

mono --debug doesn't have anything to do with the debugger, it simply causes Mono to track debug information so it can give you file/line/col information in backtraces.

The behaviour of System.Diagnostics.Debugger.Break() depends on your Mono version. AFAIK in its basic form it sets a hard breakpoint, so if your app's not running in a native hard debugger it will simply crash. If your app is running inside the Mono Soft Debugger with Mono 2.11 or later (which has not yet been released), it will set a soft breakpoint for the soft debugger and work as expected.

The basic way to enable debugging of addins is to set a custom execution command in your addin project. Open 'Project Options', got to the 'Run>Custom Commands' section, add a custom command for 'Execute'. Set the executable to MonoDevelop.exe and the working directory to be its containing directory. This means that when you run/debug your project, MD will actually execute that executable instead of executing your project directly. If MonoDevelop.exe loads your addin, then you'll be able to set breakpoints, step, etc.

The difficult part here is making MD load your addin. One way to do this would be to have your project output the addin dll into one of the directories that MD searches for addins, but that's a very hacky thing to do at development time. A better solution is to use the undocumented environment variable MONODEVELOP_DEV_ADDINS to specify an additional directory from which for MD to load addins. There isn't a UI in MD for setting env vars for custom commands, but it is supported internally - you'll have to manually edit the csproj file.

Find the part that looks like:

<CustomCommands>
  <CustomCommands>
    <Command type="Execute"
      command="..\..\..\monodevelop\main\build\bin\MonoDevelop.exe"
      workingdir="..\..\..\monodevelop\main\build\bin" />
  </CustomCommands>
</CustomCommands>

And change it to:

<CustomCommands>
  <CustomCommands>
    <Command type="Execute"
      command="..\..\..\monodevelop\main\build\bin\MonoDevelop.exe"
      workingdir="..\..\..\monodevelop\main\build\bin">
      <EnvironmentVariables>
        <Variable name="MONODEVELOP_DEV_ADDINS" value="${TargetDir}" />
      </EnvironmentVariables>
    </Command>
  </CustomCommands>
</CustomCommands>

If you're wondering why the <CustomCommands> elements are two-deep, that a known bug.

like image 118
Mikayla Hutchinson Avatar answered Oct 05 '22 13:10

Mikayla Hutchinson