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)

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


Attachments

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.

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