From: Rodrigo Kumpera Date: Tue, 12 May 2015 21:11:18 +0000 (-0400) Subject: Merge pull request #1668 from alexanderkyte/bug1856 X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=cc40e2e17dc6fd2dae6d3a4c7d7ab43570d63546;hp=a630299893a82bcb4e4be6731a3d6dd5fe0ace55;p=mono.git Merge pull request #1668 from alexanderkyte/bug1856 [runtime] Overwrite stacktrace for exception on re-throw. Fixes #1856. --- diff --git a/mono/mini/exceptions-amd64.c b/mono/mini/exceptions-amd64.c index 502015268f6..72342361fdc 100644 --- a/mono/mini/exceptions-amd64.c +++ b/mono/mini/exceptions-amd64.c @@ -332,8 +332,10 @@ mono_amd64_throw_exception (guint64 dummy1, guint64 dummy2, guint64 dummy3, guin if (mono_object_isinst (exc, mono_defaults.exception_class)) { MonoException *mono_ex = (MonoException*)exc; - if (!rethrow) + if (!rethrow) { mono_ex->stack_trace = NULL; + mono_ex->trace_ips = NULL; + } } /* adjust eip so that it point into the call instruction */ diff --git a/mono/mini/exceptions-arm.c b/mono/mini/exceptions-arm.c index 1ca59fcba44..7f57eea44ec 100644 --- a/mono/mini/exceptions-arm.c +++ b/mono/mini/exceptions-arm.c @@ -154,8 +154,10 @@ mono_arm_throw_exception (MonoObject *exc, mgreg_t pc, mgreg_t sp, mgreg_t *int_ if (mono_object_isinst (exc, mono_defaults.exception_class)) { MonoException *mono_ex = (MonoException*)exc; - if (!rethrow) + if (!rethrow) { mono_ex->stack_trace = NULL; + mono_ex->trace_ips = NULL; + } } mono_handle_exception (&ctx, exc); mono_restore_context (&ctx); diff --git a/mono/mini/exceptions-ia64.c b/mono/mini/exceptions-ia64.c index b8212c684bd..b8e1929e8cb 100644 --- a/mono/mini/exceptions-ia64.c +++ b/mono/mini/exceptions-ia64.c @@ -243,8 +243,10 @@ throw_exception (MonoObject *exc, guint64 rethrow) if (mono_object_isinst (exc, mono_defaults.exception_class)) { MonoException *mono_ex = (MonoException*)exc; - if (!rethrow) + if (!rethrow) { mono_ex->stack_trace = NULL; + mono_ex->trace_ips = NULL; + } } res = unw_getcontext (&unw_ctx); diff --git a/mono/mini/exceptions-mips.c b/mono/mini/exceptions-mips.c index f0158e5b7a9..dfb4a57d3b9 100644 --- a/mono/mini/exceptions-mips.c +++ b/mono/mini/exceptions-mips.c @@ -196,8 +196,10 @@ throw_exception (MonoObject *exc, unsigned long eip, unsigned long esp, gboolean if (mono_object_isinst (exc, mono_defaults.exception_class)) { MonoException *mono_ex = (MonoException*)exc; - if (!rethrow) + if (!rethrow) { mono_ex->stack_trace = NULL; + mono_ex->trace_ips = NULL; + } } mono_handle_exception (&ctx, exc); #ifdef DEBUG_EXCEPTIONS diff --git a/mono/mini/exceptions-ppc.c b/mono/mini/exceptions-ppc.c index 4b8d1642c16..b7c2e8d3a17 100644 --- a/mono/mini/exceptions-ppc.c +++ b/mono/mini/exceptions-ppc.c @@ -333,8 +333,10 @@ mono_ppc_throw_exception (MonoObject *exc, unsigned long eip, unsigned long esp, if (mono_object_isinst (exc, mono_defaults.exception_class)) { MonoException *mono_ex = (MonoException*)exc; - if (!rethrow) + if (!rethrow) { mono_ex->stack_trace = NULL; + mono_ex->trace_ips = NULL; + } } mono_handle_exception (&ctx, exc); mono_restore_context (&ctx); diff --git a/mono/mini/exceptions-s390x.c b/mono/mini/exceptions-s390x.c index 78fd645c785..ac1d0f2c921 100644 --- a/mono/mini/exceptions-s390x.c +++ b/mono/mini/exceptions-s390x.c @@ -259,8 +259,10 @@ throw_exception (MonoObject *exc, unsigned long ip, unsigned long sp, if (mono_object_isinst (exc, mono_defaults.exception_class)) { MonoException *mono_ex = (MonoException*)exc; - if (!rethrow) + if (!rethrow) { mono_ex->stack_trace = NULL; + mono_ex->trace_ips = NULL; + } } // mono_arch_handle_exception (&ctx, exc, FALSE); mono_handle_exception (&ctx, exc); diff --git a/mono/mini/exceptions-sparc.c b/mono/mini/exceptions-sparc.c index 3ebe2e7a29c..52a93ac1f13 100644 --- a/mono/mini/exceptions-sparc.c +++ b/mono/mini/exceptions-sparc.c @@ -180,8 +180,10 @@ throw_exception (MonoObject *exc, gpointer sp, gpointer ip, gboolean rethrow) if (mono_object_isinst (exc, mono_defaults.exception_class)) { MonoException *mono_ex = (MonoException*)exc; - if (!rethrow) + if (!rethrow) { mono_ex->stack_trace = NULL; + mono_ex->trace_ips = NULL; + } } mono_handle_exception (&ctx, exc); restore_context (&ctx); diff --git a/mono/mini/exceptions-x86.c b/mono/mini/exceptions-x86.c index 2e862f43f18..d7d4f72d299 100644 --- a/mono/mini/exceptions-x86.c +++ b/mono/mini/exceptions-x86.c @@ -472,8 +472,10 @@ mono_x86_throw_exception (mgreg_t *regs, MonoObject *exc, if (mono_object_isinst (exc, mono_defaults.exception_class)) { MonoException *mono_ex = (MonoException*)exc; - if (!rethrow) + if (!rethrow) { mono_ex->stack_trace = NULL; + mono_ex->trace_ips = NULL; + } } /* adjust eip so that it point into the call instruction */ diff --git a/mono/tests/Makefile.am b/mono/tests/Makefile.am index 82177d65d01..7d2e1acde39 100644 --- a/mono/tests/Makefile.am +++ b/mono/tests/Makefile.am @@ -90,6 +90,7 @@ BASE_TEST_CS_SRC= \ exception15.cs \ exception16.cs \ exception17.cs \ + exception18.cs \ typeload-unaligned.cs \ struct.cs \ valuetype-gettype.cs \ diff --git a/mono/tests/exception18.cs b/mono/tests/exception18.cs new file mode 100644 index 00000000000..8f1e492c0e9 --- /dev/null +++ b/mono/tests/exception18.cs @@ -0,0 +1,48 @@ +using System; + +class C +{ + static Exception e; + + static void Throw () + { + try { + int.Parse (null); + } catch (Exception ex) { + e = ex; + } + } + + static int FrameCount (Exception ex) + { + string fullTrace = ex.StackTrace; + string[] frames = fullTrace.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); + return frames.Length; + } + + public static void Main () + { + Throw (); + + try { + throw e; + } catch (Exception ex) { + int frames = FrameCount (ex); + if (frames != 1) + throw new Exception (String.Format("Exception carried {0} frames along with it when it should have reported one.", frames)); + } + + try { + try { + int.Parse (null); + } catch (Exception) { + throw; + } + } catch (Exception ex) { + int frames = FrameCount (ex); + if (frames != 4) + throw new Exception (String.Format("Exception carried {0} frames along with it when it should have reported four.", frames)); + } + + } +}