This all has so much improved since we switched to GitHub, so I started a really cool weekend-project which involves some huge MDB refactoring and also some cool new stuff :-)
The first thing I did was make MDB's "server" part (the unmanaged "libmonodebuggerserver.la" library) actually a "server" (a stand-alone executable called "mdb-server.exe"). This has three main advantages:
- It gives me complete control over the process - I deal with signal handlers, signal blocking masks, threads and such as I want and there's no Mono or user-code getting into my way. One major problem in the current debugger code is that I have to call waitpid (and also interrupt it somehow) without knowing what some other user-created thread might be doing at the moment. This was a major headache when embedding MDB and also set some restrictions you might not even know about (for instance, it's strictly forbidden to use fork(), sigprocmask(), waitpid() and some other system calls inside the MDB process - if you need any of these, or can't guarantee they're not used, then you need to wrap the Mono.Debugger.dll library and use it in an external process).
- It makes it possible to debug MDB's C# code with an IDE such as MonoDevelop, Visual Studio / MonoVS or even MDB itself.
All operating systems that I can think of have this restriction of not letting you debug a debugger - this goes away by putting the "debugger" part of MDB into a separate process.
- It makes it much easier to port MDB to other operating systems and/or hardware since you don't have to deploy the entire C# development environment to that machine - all you need is one statically linked binary ... which can even be cross-compiled from Linux.
I already set things up so that you can build the server independently from the C# pieces - my plan is to add some MonoDebugger.csproj in near future and then use xbuild to build the managed libraries. Long-term, I'd really like to use MonoDevelop to build, develop and debug MDB.
On the C# side, there's now a new abstract class called Mono.Debugger.Server.DebuggerServer which has two implementations - NativeDebuggerServer for the local [DllInvoke]'d library and RemoteDebuggerServer to talk to the external process. As part of this refactoring, I moved all [DllInvoke]s into the NativeDebuggerServer implementation and some other classes like ThreadManager have become abstract.
In this new server, we can also use a new event loop model for Linux. Since I now have full control about signal masks in all threads, I don't have to use hacks to interrupt waitpid() anymore. Instead, I now simply block SIGCHLD in all threads (there's only the main thread at the moment), sigwait() for it in one background thread and turn the signal into a select()-able event by using the "self-pipe trick".
The second big task is porting MDB to Windows and Android.
Windows is actually a bit more difficult on the server side because it requires me to build a different main event loop, whereas Android is Linux based and can thus reuse most of the Linux code.
The big difference between Windows and Linux is that the latter sends events for individual threads while the former always treats the entire process as being stopped or running.
From the C# code's perspective, there isn't so much of a difference since we now simply get an event from the remote server and don't need to worry about how it got it. There also isn't any managed wait loop anymore.
I'm really excited about this new code - I got basic single stepping almost working for all three platforms (breakpoints aren't done on ARM yet) and my next step is getting multi-threaded applications working.
It's certainly a very complex and time consuming challenge - but as I said earlier, there's no need to worry, it's all on GitHub in a private fork, no patches which might get lost over time ...