Archive for July, 2009

Patch for Monodevelop 2.0 debugger for Mono 2.4.2.2

Sunday, July 26th, 2009

A while ago I posted a how-to on compiling Mono 2.4 from source on Ubuntu. After the release of a minor version update for mono, Mono 2.4.2.2 it was impossible to compile debugger support for Monodevelop 2.0 using Mono 2.4.2.2 sources.

The reason is because in mono 2.4.2.2 the mono-debugger was also updated, to version 2.4.2.1, breaking compatibility with monodevelop-debugger-mdb-2.0. I found a way to solve this and provide a patch.

Download the patch from here.

Applying the patch

Copy the patch from where you downloaded it, to the directory containing the source directory for monodevelop-debugger-mdb-2.0, e.g (~/src/mono-2.4.2.2).

And patch the sources like this:

patch -p0 < monodevelop-debugger-mdb-2.0.mono-debugger-2.4.2.1.patch

The resulting output  output should be something similar to this:

anirothan@lapitop:~/src/mdb-patch/original$ patch -p0 < monodevelop-debugger-mdb-2.0.mono-debugger-2.4.2.1.patch
patching file monodevelop-debugger-mdb-2.0/Mono.Debugging.Server.Mdb/RuntimeInvokeManager.cs
anirothan@lapitop:~/src/mdb-patch/original$

Now you can confiure & make & make install the sources as usual.

Monodevelop 2.0 debugger with Mono 2.4.2.2

Sunday, July 26th, 2009

A while ago I posted a how-to on compiling Mono 2.4 from source on Ubuntu. Well, the mono project released an update: mono 2.4.2.2 about a month ago. So, obviously people wanted to update their systems and tried to compile the new source packages. But there seems to be a problem. The debugger plugin for monodevelop 2.0 (monodevelop-debugger-mdb-2.0) failed to compile.

Responding to a series of comments on my blog mentioning this annoying problem I looked into the situation and I have produced a patch for monodevelop-debugger-mbd-2.0 sources. You can download the patch from here, and the instructions on applying it in this post.

As it turns out, in mono 2.4.2.2 there is a new version of the mono debugger, version 2.4.2.1. And with this new version came some breaking changes. Monodevelop uses the mono debugger through a plugin (contained in this source package: monodevelop-debugger-mdb-2.0.tar.bz2). The sources of the plugin were not updated for the new version of mono debugger so any attempt to compile them failed.

Following is an excerpt from the compilation indicating the problem:

./RuntimeInvokeManager.cs(49,50): warning CS0612: `Mono.Debugger.Thread.RuntimeInvoke(Mono.Debugger.Languages.TargetFunctionType, Mono.Debugger.Languages.TargetStructObject, Mono.Debugger.Languages.TargetObject[], bool, bool)' is obsolete
./RuntimeInvokeManager.cs(57,68): error CS1501: No overload for method `AbortInvocation' takes `0' arguments
./RuntimeInvokeManager.cs(78,60): error CS1501: No overload for method `AbortInvocation' takes `0' arguments
Compilation failed: 2 error(s), 2 warnings
make[1]: *** [../build/DebuggerServer.exe] Error 1
make[1]: Leaving directory `/home/anirothan/src/mono-2.4.2.2/monodevelop-debugger-mdb-2.0/Mono.Debugging.Server.Mdb'
make: *** [all-recursive] Error 1

The problem is with the monodevelop-debugger-mdb-2.0/Mono.Debugging.Server.Mdb/RuntimeInvokeManager.cs file. On line 49 the RuntimeInvoke() mehtod is deprecated in the new version of mono debugger as indicated by the warning message, and the two invocations to AbortInvocation() on lines 57 and 78 have incompatible signatures with the method’s definition.

Invocation of AbortInvocation in monodevelop-debugger-mdb-2.0/Mono.Debugging.Server.Mdb/RuntimeInvokeManager.cs lines 55-58 and 76-79:

res.Abort ();
res.CompletedEvent.WaitOne ();
ctx.Thread.AbortInvocation ();
WaitToStop (ctx.Thread);

The AbortInovacation() method is defined in the mono debugger package, in mono-debugger-2.4.2.1/classes/Thread.cs.  If you compare this method between mono-debugger-2.4 and mono-debugger-2.4.2.1 you will see that in 2.4 it is public whereas in 2.4.2.1 it is made internal. Therefore, we couldn’t just figure out what the parameter to AbortInvocation() should be since there would be now way of invoking it.

AbortInvocation() in mono-debugger-2.4

public void AbortInvocation ()
{
  CommandResult result;

  lock (this) {
    check_alive ();
    result = servant.AbortInvocation ();
  }

  result.Wait ();
}

AbortInvocation() in mono-debugger-2.4.2.1

internal void AbortInvocation (long rti_id)
{
  lock (this) {
    check_alive ();
    servant.AbortInvocation (rti_id);
  }
}

However, all is not lost. It seems that in RuntimeInvokeManager.cs there is an obvious code duplication in lines 55-58 and 76-79 where AbortInvocation() is called. It seems that these lines have been moved from the monodevelop debugger plugin to the mono debugger itself. Indeed, below is how Abort() is defined in the RuntimeInvokeResult class in mono-debugger-2.4.2.1/classes/Thread.cs and mono-debugger-2.4/classes/Thread.cs:

in 2.4:

public override void Abort ()
{
  thread.Stop ();
}

and in 2.4.2.1

public override void Abort ()
{
  Thread.AbortInvocation (ID);
  completed_event.WaitOne ();
}

There it goes! The offending call to AbortInvocation(), which caused the compilation to fail, has been moved to Abort(), which is already being called on lines 55 and 76.

So, all we need to do is delete lines 56, 57 and 77,78 from RuntimeInvokeManager.cs. If we try to compile monodevelop-debugger-mdb-2.0 after this simple change we will see no more error messages and the debugger will work in monodevelop 2.0.

RuntimeInvokeManager.cs