Bug 35948 - Sample program crashes when run from Xcode but not from command line
Summary: Sample program crashes when run from Xcode but not from command line
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: 4.2.0 (C6)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: João Matos
URL:
Depends on:
Blocks:
 
Reported: 2015-11-17 14:59 UTC by Marlin Prowell
Modified: 2015-12-07 16:02 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Marlin Prowell 2015-11-17 14:59:27 UTC
This bug report is likely related to https://bugzilla.xamarin.com/show_bug.cgi?id=35416 and https://bugzilla.xamarin.com/show_bug.cgi?id=34774. 
 
This test uses the beta channel of Xamarin Studio:

    === Xamarin Studio ===

    Version 5.10 (build 871)
    Installation UUID: 9dfe94aa-9f56-475c-94e1-361d1f0077f6
    Runtime:
      Mono 4.2.1 (explicit/6dd2d0d)
      GTK+ 2.24.23 (Raleigh theme)

      Package version: 402010102

    === Xamarin.Profiler ===

    Not Installed

    === Apple Developer Tools ===

    Xcode 7.1.1 (9081)
    Build 7B1005

    === Xamarin.Mac ===

    Version: 2.4.0.109 (Starter Edition)

    === Xamarin.iOS ===

    Not Installed

    === Xamarin.Android ===

    Not Installed

    === Xamarin Android Player ===

    Not Installed

    === Build Information ===

    Release ID: 510000871
    Git revision: 4e9c5abb5ffdae12ba02ac49da83f8b2011dbb88
    Build date: 2015-11-12 06:02:54-05
    Xamarin addins: 55007ed0e56436f385d8e26394a45be563abc7e8
    Build lane: monodevelop-lion-cycle6

    === Operating System ===

    Mac OS X 10.11.1
    Darwin MacBook-Air-HD-5000.local 15.0.0 Darwin Kernel Version 15.0.0
        Sat Sep 19 15:53:46 PDT 2015
        root:xnu-3247.10.11~1/RELEASE_X86_64 x86_64



Download https://github.com/abock/EmbeddedXamarinMac.
This project runs correctly if built with the included makefile.
  make
  make run
shows a C# dialog if the button is clicked.

This project will compile correctly if the Xcode project is opened and compiled with Xcode.  When the application is run from inside Xcode, it crashes in xamarin_initialize().  If the application (the version built by Xcode) is run from the Finder, then the application starts and runs as expected.  The application shows a C# dialog if the button is clicked.
Comment 1 Chris Hamons 2015-11-19 16:08:13 UTC
From looking at the runtime init code we're falling, it appears we're trying to mono_runtime_invoke a method we dug up and we're crashing, but only when Xcode is attached. Strange.
Comment 2 Chris Hamons 2015-11-19 16:09:52 UTC
Assigning to alexrp@xamarin.com since they have the other bug. At first glance, it looks like mono is doing something wrong when attached to Xcode.

I don't have great clarity on what goes on in mono here. Please ping me if I can help however.
Comment 3 João Matos 2015-12-07 15:55:49 UTC
Here's some more info I could gather from the attached repro.

(lldb) monobt
* thread #1
    frame #0: 0x101a61bd6 (wrapper managed-to-native) System.Environment:get_Platform () + 0x76 (0x101a61b60 0x101a61be2) [0x101b00000 - EmbeddedXamarinMac]
    frame #1: 0x000000010007d795 libmonosgen-2.0.dylib`mono_jit_runtime_invoke + 1765
    frame #2: 0x00000001002319be libmonosgen-2.0.dylib`mono_runtime_invoke + 110
    frame #3: 0x0000000100231ea4 libmonosgen-2.0.dylib`mono_runtime_class_init_full + 772
    frame #4: 0x00000001000782c8 libmonosgen-2.0.dylib`mono_jit_compile_method_inner + 2008
    frame #5: 0x000000010007a9b3 libmonosgen-2.0.dylib`mono_jit_compile_method_with_opt + 643
    frame #6: 0x000000010007a6ea libmonosgen-2.0.dylib`mono_jit_compile_method + 42
    frame #7: 0x0000000100077c6f libmonosgen-2.0.dylib`mono_jit_compile_method_inner + 383
    frame #8: 0x000000010007a9b3 libmonosgen-2.0.dylib`mono_jit_compile_method_with_opt + 643
    frame #9: 0x000000010007a6ea libmonosgen-2.0.dylib`mono_jit_compile_method + 42
    frame #10: 0x00000001001197b8 libmonosgen-2.0.dylib`common_call_trampoline + 1304
    frame #11: 0x00000001005a2189
    frame #12: 0x101a60ef1 ObjCRuntime.Runtime:Initialize (ObjCRuntime.Runtime/InitializationOptions&) + 0x71 (0x101a60e80 0x101a616de) [0x101b00000 - EmbeddedXamarinMac]
    frame #13: 0x101a618d1 (wrapper runtime-invoke) <Module>:runtime_invoke_void_intptr& (object,intptr,intptr,intptr) + 0xe1 (0x101a617f0 0x101a61918) [0x101b00000 - EmbeddedXamarinMac]
    frame #14: 0x000000010007d795 libmonosgen-2.0.dylib`mono_jit_runtime_invoke + 1765
    frame #15: 0x00000001002319be libmonosgen-2.0.dylib`mono_runtime_invoke + 110
    frame #16: 0x000000010002a4cc libxammac.dylib`mono_runtime_invoke_impl + 60
    frame #17: 0x000000010003aace libxammac.dylib`xamarin_initialize + 734
  * frame #18: 0x0000000100001f77 EmbeddedXamarinMac`main(argc=3, argv=0x00007fff5fbff6b0) + 583 at main.mm:53
    frame #19: 0x00007fff957bd5ad libdyld.dylib`start + 1

(lldb) disas -p
EmbeddedXamarinMac`main:
->  0x100001f77 <+583>: jmp    0x100001f7c               ; <+588> at main.mm:56
    0x100001f7c <+588>: leaq   0xb04(%rip), %rdi         ; "Xamarin.Mac.dll"
    0x100001f83 <+595>: callq  0x100002150               ; symbol stub for: xamarin_open_and_register
    0x100001f88 <+600>: movq   %rax, -0xd8(%rbp)


I suspect this is related to Xcode different TLS stack. See https://github.com/mono/mono/commit/3adcd34f783a870cc07ab8d9c3b2782328b0938f.

I just tried setting MONO_PREFIX on the Makefile to my own master build and the sample works as expected.