Bug 58782 - Exception stack traces are deleted when reaching the native-to-managed wrapper in a reverse invoke
Summary: Exception stack traces are deleted when reaching the native-to-managed wrappe...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: JIT (show other bugs)
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Ludovic Henry
URL:
Depends on:
Blocks:
 
Reported: 2017-08-15 17:38 UTC by Rolf Bjarne Kvinge [MSFT]
Modified: 2017-08-17 17:19 UTC (History)
4 users (show)

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

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 Rolf Bjarne Kvinge [MSFT] 2017-08-15 17:38:58 UTC
Repro:

* Use test case from bug #58780.
* Run "make plainthrow"
Comment 1 Rolf Bjarne Kvinge [MSFT] 2017-08-15 17:44:55 UTC
The problem is that there's an implicit try/catch handler in the native-to-managed wrapper, and that try/catch handler throws the exception again (instead of rethrowing it, which would preserve the stack trace): https://github.com/mono/mono/blob/83020f1270ecbdfcbdf02cee687beadcba7c89ae/mono/metadata/marshal.c#L12369

Implementing a mono_reraise_exception and using that instead fixes the bug: https://gist.github.com/rolfbjarne/79ef3ca886743b4811f09b182609be6c
Comment 2 Rolf Bjarne Kvinge [MSFT] 2017-08-15 17:47:58 UTC
Works:

> Mono JIT compiler version 5.0.0.100 (2017-02/9667aa6 Fri May  5 09:12:57 EDT 2017)

Fails:

> Mono JIT compiler version 5.2.0.220 (2017-04/161f032 Wed Jul 26 15:23:07 EDT 2017)
> Mono JIT compiler version 5.7.0 (master/b89b696e71f Tue Aug 15 19:38:06 CEST 2017)
Comment 3 Ludovic Henry 2017-08-16 16:29:29 UTC
https://github.com/mono/mono/pull/5384
Comment 4 Ludovic Henry 2017-08-17 17:19:43 UTC
This is fixed on master with https://github.com/mono/mono/commit/ab90246c67d5d12ec9fabae5e490a05db2c0be6b

It is backported to 5.4 and 5.6 with https://github.com/mono/mono/pull/5394 and https://github.com/mono/mono/pull/5395 respectively.