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...
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
Depends on:
Reported: 2017-08-15 17:38 UTC by Rolf Bjarne Kvinge [MSFT]
Modified: 2017-08-17 17:19 UTC (History)
4 users (show)

See Also:
Is this bug a regression?: Yes
Last known good build:


Description Rolf Bjarne Kvinge [MSFT] 2017-08-15 17:38:58 UTC

* 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

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


> Mono JIT compiler version (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
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.

Note You need to log in before you can comment on or make changes to this bug.