Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanding NSColor in debugger crashes app #5738

Closed
chamons opened this issue Mar 7, 2019 · 4 comments
Closed

Expanding NSColor in debugger crashes app #5738

chamons opened this issue Mar 7, 2019 · 4 comments
Labels
bug If an issue is a bug or a pull request a bug fix macOS Issues affecting Xamarin.Mac
Milestone

Comments

@chamons
Copy link
Contributor

chamons commented Mar 7, 2019

Steps to Reproduce

  1. New XM App
  2. NSColor color = NSColor.Red; and set breakpoint on line after
  3. Expand color in debugger
  4. Boom - https://gist.github.com/chamons/be71ccd1b887a7e246bd3b42910bef7b

Expected Behavior

We don't expand unsafe properties by default in IDE.

Actual Behavior

Environment

macios master

@chamons chamons added bug If an issue is a bug or a pull request a bug fix macOS Issues affecting Xamarin.Mac labels Mar 7, 2019
@chamons chamons added this to the Future milestone Mar 7, 2019
@spouliot
Copy link
Contributor

spouliot commented Mar 8, 2019

weird, the binding is annotated correctly

[Export ("blackComponent")]
nfloat BlackComponent { [MarshalNativeExceptions] get; }

and the right xamarin_* function was called

	2   CoreFoundation                      0x00007fff3bd0dc77 +[NSException raise:format:] + 193
	3   AppKit                              0x00007fff39822481 -[NSColorSpaceColor blackComponent] + 44
	4   NSColorCrash                        0x000000010206516d xamarin_nfloat_objc_msgSend + 29

but it did crash... maybe mono intercepted it before the native catch handler we generate ?

@rolfbjarne
Copy link
Member

We caught the NSException, and then decided to rethrow it:

0x7fff66e5a507 - /usr/lib/libobjc.A.dylib : objc_exception_throw
0x1020931f1 - [...]/NSColorCrash.app/Contents/MacOS/NSColorCrash : xamarin_process_nsexception_using_mode

which means we hit this case:

case MarshalObjectiveCExceptionModeUnwindManagedCode:
if (xamarin_is_gc_coop)
xamarin_assertion_message ("Cannot unwind managed frames for Objective-C exceptions when the GC is in cooperative mode.");
@throw ns_exception;
break;

and that crashes because there are no other Objective-C catch handlers further up the stack.

I suspect that passing --marshal-objectivec-exceptions=throwmanagedexception to mmp will fix the problem. Admittedly this should probably be the default when debugging.

chamons added a commit to chamons/xamarin-macios that referenced this issue Dec 30, 2019
- xamarin#5738
- There are a number of managed exceptions Apple can throw at you during
debugging, such as expanding a NSColor in the wrong colorspace
- Throwing a managed exception is a nicer debugging experience, and
during debug we don't care about any performance penality.
@chamons
Copy link
Contributor Author

chamons commented Dec 30, 2019

Nice idea Rolf - that fixed it and is a sensible default.

mandel-macaque pushed a commit that referenced this issue Jan 8, 2020
- #5738
- There are a number of managed exceptions Apple can throw at you during
debugging, such as expanding a NSColor in the wrong colorspace
- Throwing a managed exception is a nicer debugging experience, and
during debug we don't care about any performance penality.
@chamons
Copy link
Contributor Author

chamons commented Mar 27, 2020

This was fixed back in #7667 and never closed.

@chamons chamons closed this as completed Mar 27, 2020
@xamarin xamarin locked as resolved and limited conversation to collaborators May 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug If an issue is a bug or a pull request a bug fix macOS Issues affecting Xamarin.Mac
Projects
None yet
Development

No branches or pull requests

3 participants