[Mono-dev] [PATCH] OS X debugger

jonas echterhoff jonas at unity3d.com
Wed Apr 29 03:34:53 EDT 2009


Here is an updated version of my mono debugger patch.

This is much more functional then the previously submitted patch, now  
working properly with multi-threaded apps.

Getting the threading to work as expected was a bit difficult, because  
the way ptrace works (or doesn't work) on OS X is that it will always  
trace a complete process, stopping all threads when one of them  
signals, and resuming all of them when one resumes. The other issue is  
that ptrace won't send any events when new threads are created or old  
ones are terminated. I have tried to mask these differences as good as  
possible, so the changes to the non-darwin specific files are minimal.

The wait function will detect which thread has signalled, and return a  
reference to it. Since Mach doesn't seem to have global pids for  
threads (light-weight-processes), I construct that reference (referred  
to as "pid" in the C# code) from the actual process pid, and an index  
for the thread in the high bits.

Since new threads aren't automatically detected, some changes to  
ThreadManager.cs were necessary to look for new threads, and to check  
if any threads have exited.

I added a function to query for functionality from the backend to  
enable this changes - so the linux version should still work from the  
same source.

It is necessary to code sign mono for this to work. See my previous  
post for information



Some known issues (probably many more unknown ones):

-The debugger will not follow forks on OS X.

-For some reason, when jiting some code which has breakpoints in it,  
the debugger gives an error message like:
Can't insert breakpoint 3 at 0x004de0bf: Already have breakpoint 3 at  
address 0x004de0bf.
This is because the MONO_DEBUGGER_EVENT_JIT_BREAKPOINT gets sent  
twice, once at mono-debug-debugger.c:209 and once at mono-debug- 
debugger.c:222. If Martin or anyone has an idea why that is, let me  
know. This doesn't cause any troubles, I just want to figure out what  
is wrong and causing the error message.

-Sometimes interrupting using ^C while a thread is in Thread.Sleep, it  
will not wake up again after resuming. It seems that the thread is  
executing some code (registers and frame change each time I  
interrupt), but it will never leave the Sleep function.



Some things I didn't test (because I didn't find out how they are  
supposed to work):

-Watchpoints

-Debugging Native applications

More information on these would be appreciated.


jonas

Diff files for mono and debugger repositories:

http://files.unity3d.com/jonas/mono.diff
http://files.unity3d.com/jonas/debugger.diff



More information about the Mono-devel-list mailing list