I am writing a mono app for OSX that needs to use AppleScript. I am using the
AppleScript class from the Monodevelop source which works fine most of the time, but every now and then it causes a SIGSEGV and my program crashes.
Being new to both Mono and OSX I am not sure how to debug this problem. MonoDevelop doesn’t break even if I am running through the debugger and C# exception handling doesn’t seem to help anything. Is there any way to figure out what’s going on? Right now it seems that the only way I can protect my program is to actually spawn a separate process for the AppleScript code.
The script that I run is always the same and 99% of the time it runs without problems.
This is the stack trace:
Stacktrace:
at (wrapper managed-to-native) MonoDevelop.MacInterop.AppleScript.OSACompile (MonoDevelop.MacInterop.ComponentInstance,MonoDevelop.MacInterop.AEDesc&,MonoDevelop.MacInterop.OsaMode,MonoDevelop.MacInterop.OsaId&) <IL 0x00028, 0xffffffff>
at MonoDevelop.MacInterop.AppleScript.Run (bool,MonoDevelop.MacInterop.AEDesc&,string&) [0x0007f] in /Users/kristian/Repositories/Kristian/projects/CherryTomato_NT/mono_osx/CherryTomato.Core_OSX/MacInterop/AppleScript.cs:131
at MonoDevelop.MacInterop.AppleScript.Run (bool,MonoDevelop.MacInterop.AEDesc&) [0x00000] in /Users/kristian/Repositories/Kristian/projects/CherryTomato_NT/mono_osx/CherryTomato.Core_OSX/MacInterop/AppleScript.cs:103
at MonoDevelop.MacInterop.AppleScript.Run (string) [0x00010] in /Users/kristian/Repositories/Kristian/projects/CherryTomato_NT/mono_osx/CherryTomato.Core_OSX/MacInterop/AppleScript.cs:83
...
There is a bunch of other information in the output which I can post if necessary but it looks rather generic.
To debug native crashes (SIGSEGV) you need to use gdb (attach gdb to your program (
gdb program #PID), run it, and execution will stop when you hit the SIGSEGV).Here are a few hints to using gdb with mono: http://www.mono-project.com/Debugging#Debugging_with_GDB (in particular you’ll want to create the .gdbinit file as explained there).