EXC_BAD_ACCESS in Xamarin.iOS app when debuggin native library with LLDB (Xcode5)

Hi,

I have a project which consists of a C++ library and a Xamarin.iOS app that statically links to it. I managed to set up the bindings so that the app runs well on both the device and the simulator. But as soon as I attach LLDB to the native code, I consistently get crashes at the managed-unmanaged boundary in the unmanaged side, in both directions. (EXC_BAD_ACCESS, code=2)

First use case:

I placed the call to the native library directly to Application.Main, like this:

    public class Application
    {
        static void Main(string[] args)
        {
            XBDLib.stuff("foo"); // <-- break on this line, attach LLDB, continue 

            UIApplication.Main(args, null, "AppDelegate");
        }
    }

In this case, the external function is called (I have verified it with a breakpoint) and the crash occurs when returning to managed.

Call stack (simulator):

(char *) $0 = 0x7919cfa0 " XBDTest.iOS.Application:Main (string[]) + 0x48 (0x8e47290 0x8e4734b) [0x8c92e00 - MonoTouch]"
(char *) $1 = 0x7919d270 " (wrapper runtime-invoke) <Module>:runtime_invoke_void_object (object,intptr,intptr,intptr) + 0x11f (0x8e47370 0x8e474b2) [0x8c92e00 - MonoTouch]"
XBDTestiOS`mono_jit_runtime_invoke + 790 at mini.c:6516
XBDTestiOS`mono_runtime_invoke + 127 at object.c:2827
XBDTestiOS`mono_runtime_exec_main + 435 at object.c:4052
XBDTestiOS`mono_runtime_run_main + 628 at object.c:3678
XBDTestiOS`mono_jit_exec + 93 at driver.g.c:962
XBDTestiOS`main + 2426 at main.m:486

Call stack (device):

XBDTestiOS`XBDTest.iOS.Application:Main + 200
XBDTestiOS`wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
XBDTestiOS`mono_jit_runtime_invoke + 1112 at mini.c:6506
XBDTestiOS`mono_runtime_invoke + 88 at object.c:2827
XBDTestiOS`mono_runtime_exec_main + 292 at object.c:4052
XBDTestiOS`mono_runtime_run_main + 424 at object.c:3678
XBDTestiOS`mono_jit_exec + 48 at driver.g.c:963
XBDTestiOS`main + 2480 at main.m:486

Second use case:

I placed the native call to a UI event handler:

public partial class MainViewController : UIViewController
{
    ...
    partial void showInfo(NSObject sender)
    {
        XBDLib.stuff("foo");  // <-- break on this line, attach LLDB, continue 
    }
}

This time the external function is not even executed, the app crashes somewhere in the runtime.

Call stack (simulator):

(char *) $0 = 0x786a0a30 " XBDTest.iOS.MainViewController:showInfo (MonoTouch.Foundation.NSObject) + 0x53 (0x8eb8380 0x8eb875a) [0x8cf9e00 - MonoTouch]"
(char *) $1 = 0x78b364e0 " (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___object (object,intptr,intptr,intptr) + 0x127 (0x8eb8798 0x8eb88e2) [0x8cf9e00 - MonoTouch]"
XBDTestiOS`mono_jit_runtime_invoke + 790 at mini.c:6516
XBDTestiOS`mono_runtime_invoke + 127 at object.c:2827
XBDTestiOS`monotouch_trampoline + 4005 at monotouch-trampoline-invoke.inc:1
libobjc.A.dylib`-[NSObject performSelector:withObject:withObject:] + 77
UIKit`-[UIApplication sendAction:to:from:forEvent:] + 96
UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
UIKit`-[UIControl sendAction:to:forEvent:] + 66
UIKit`-[UIControl(Internal) _sendActionsForEvents:withEvent:] + 578
UIKit`-[UIControl touchesEnded:withEvent:] + 546
UIKit`-[UIWindow _sendTouchesForEvent:] + 846
UIKit`-[UIWindow sendEvent:] + 273
UIKit`-[UIApplication sendEvent:] + 436
UIKit`_UIApplicationHandleEvent + 9874
GraphicsServices`_PurpleEventCallback + 339
GraphicsServices`PurpleEventCallback + 46
CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
CoreFoundation`__CFRunLoopDoSource1 + 146
CoreFoundation`__CFRunLoopRun + 2118
CoreFoundation`CFRunLoopRunSpecific + 276
CoreFoundation`CFRunLoopRunInMode + 123
GraphicsServices`GSEventRunModal + 88
GraphicsServices`GSEventRun + 104
UIKit`UIApplicationMain + 1211
(char *) $2 = 0x786a1a40 " (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) + 0x1d2 (0x8eb02d8 0x8eb05af) [0x8cf9e00 - MonoTouch]"
(char *) $3 = 0x786a0ad0 " MonoTouch.UIKit.UIApplication:Main (string[],string,string) + 0x17c (0x8eae498 0x8eae62d) [0x8cf9e00 - MonoTouch]"
(char *) $4 = 0x788b2240 " XBDTest.iOS.Application:Main (string[]) + 0x40 (0x8eae290 0x8eae2e3) [0x8cf9e00 - MonoTouch]"
(char *) $5 = 0x788b0650 " (wrapper runtime-invoke) <Module>:runtime_invoke_void_object (object,intptr,intptr,intptr) + 0x11f (0x8eae2f0 0x8eae432) [0x8cf9e00 - MonoTouch]"
XBDTestiOS`mono_jit_runtime_invoke + 790 at mini.c:6516
XBDTestiOS`mono_runtime_invoke + 127 at object.c:2827
XBDTestiOS`mono_runtime_exec_main + 435 at object.c:4052
XBDTestiOS`mono_runtime_run_main + 628 at object.c:3678
XBDTestiOS`mono_jit_exec + 93 at driver.g.c:962
XBDTestiOS`main + 2426 at main.m:486

Call stack (device):

XBDTestiOS`XBDTest.iOS.MainViewController:showInfo + 180
XBDTestiOS`wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
XBDTestiOS`mono_jit_runtime_invoke + 1112 at mini.c:6506
XBDTestiOS`mono_runtime_invoke + 88 at object.c:2827
XBDTestiOS`native_to_managed_trampoline_XBDTest_iOS_MainViewController_showInfo + 318 at <stdin>:12815
UIKit`<redacted> + 72
UIKit`<redacted> + 120
UIKit`<redacted> + 72
UIKit`<redacted> + 30
UIKit`<redacted> + 44
UIKit`<redacted> + 502
UIKit`<redacted> + 488
UIKit`<redacted> + 524
UIKit`<redacted> + 380
UIKit`<redacted> + 6154
GraphicsServices`<redacted> + 590
GraphicsServices`<redacted> + 34
CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
CoreFoundation`__CFRunLoopDoSource1 + 138
CoreFoundation`__CFRunLoopRun + 1384
CoreFoundation`CFRunLoopRunSpecific + 356
CoreFoundation`CFRunLoopRunInMode + 104
GraphicsServices`GSEventRunModal + 74
UIKit`UIApplicationMain + 1120
XBDTestiOS`wrapper_managed_to_native_MonoTouch_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 272
XBDTestiOS`MonoTouch_UIKit_UIApplication_Main_string___string_string + 300

If LLDB is not attached, everything works flawlessly.

Configuration: OSX 10.9, Xamarin Studio 4.2.1 (build 1)

Runtime:
Mono 3.2.5 ((no/964e8f0)
GTK+ 2.24.20 theme: Raleigh
GTK# (2.12.0.0)
Package version: 302050000

Xcode: 5.0.1 (3335.23) Build 5A2053

Xamarin.iOS:
Version: 7.0.4.209 (Trial Edition)
Hash: 23a0827
Branch:
Build date: 2013-11-11 16:04:00-0500

We are currently evaluating Xamarin and it is crucial that we could debug native libraries somehow. Are you guys aware of this issue? Is there perhaps a fix on the way?

Thanks in advance.

Posts

  • KostubDeshmukhKostubDeshmukh USMember ✭✭

    Did you get an answer to this? I see this happening in my app as well. If lldb is not attached, it works fine.

    Thanks,
    Kostub

Sign In or Register to comment.