[Mono-bugs] [Bug 36800][Nor] New - Mono handles exceptions in C# callbacks from C++ incorrectly.

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Wed, 15 Jan 2003 23:29:03 -0500 (EST)

Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by mathpup@mylinuxisp.com.


--- shadow/36800	Wed Jan 15 23:29:03 2003
+++ shadow/36800.tmp.16728	Wed Jan 15 23:29:03 2003
@@ -0,0 +1,97 @@
+Bug#: 36800
+Product: Mono/Runtime
+Version: unspecified
+OS Details: 
+Status: NEW   
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: mathpup@mylinuxisp.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+Summary: Mono handles exceptions in C# callbacks from C++ incorrectly.
+Description of Problem: 
+When an C++ (unmanaged) function invokes a C# delegate, and the delegate uses a 
+throw statement to raise an exception, the actual exception that should have been 
+raise is lost and mono instead reports a null reference exception. 
+This only seems to occur when the call-stack is non-trivial. For example, in the 
+relatively simple case where a C# method calls a C++ function, the C++ function 
+calls a C# delegate method, and the C# method throws an exception, things work 
+fine. But in a real program, like Qt, where the stack is far more complicated, this bug 
+reveals itself. 
+In the attached program, clicking the button should cause an ArgumentException to 
+be throw. Running the problem with mono --trace reveals that a null reference 
+exception occurs just after ArgumentException's constructor exits. Running the 
+program in gdb gives 
+program received signal SIGSEGV, Segmentation fault. 
+[Switching to Thread 1024 (LWP 7163)] 
+0x4025dcc6 in uw_frame_state_for (context=0xbfffe724, fs=0xbfffe664) 
+    at ../../gcc-3.2/gcc/unwind-dw2.c:910 
+910     ../../gcc-3.2/gcc/unwind-dw2.c: No such file or directory. 
+        in ../../gcc-3.2/gcc/unwind-dw2.c 
+(gdb) bt 
+#0  0x4025dcc6 in uw_frame_state_for (context=0xbfffe724, fs=0xbfffe664) 
+    at ../../gcc-3.2/gcc/unwind-dw2.c:910 
+#1  0x4025de21 in __frame_state_for (pc_target=0x65, state_in=0xbfffe834) 
+    at ../../gcc-3.2/gcc/unwind-dw2.c:982 
+#2  0x4023567b in __frame_state_for () from /lib/libc.so.6 
+#3  0x080af0f7 in x86_unwind_native_frame (domain=0x816af50, 
+    jit_tls=0x8147c60, ctx=0xbfffea24, new_ctx=0xbfffe954, lmf=0xbffff3b8, 
+    trace=0xbfffe9bc) at exception.c:264 
+#4  0x080aff4b in mono_arch_find_jit_info (domain=0x816af50, 
+    jit_tls=0x8147c60, ctx=0xbfffea24, new_ctx=0xbfffe954, trace=0xbfffe9bc, 
+    lmf=0xbfffe9c4, native_offset=0x0, managed=0x0) at exception.c:648 
+#5  0x080b07c0 in arch_handle_exception (ctx=0xbfffea24, obj=0x83d3188, 
+    test_only=1) at exception.c:846 
+#6  0x080b0732 in arch_handle_exception (ctx=0xbfffeae4, obj=0x83d3188, 
+    test_only=0) at exception.c:832 
+#7  0x080af79d in throw_exception (eax=138228104, ecx=138268632, 
+    edx=138418379, ebx=1081243204, esi=138228104, edi=137986008, 
+    ebp=3221220268, exc=0x83d3188, eip=137965935, esp=3221220220) 
+    at exception.c:445 
+#8  0x08144839 in start.4 () 
+#9  0x083931aa in ?? () 
+#10 0x407247aa in CustomSlot::callback() () from /usr/local/lib/libqtsharp.so 
+#11 0x00000065 in ?? () 
+#12 0x7ee17b08 in ?? () 
+#13 0x40cbbecc in QUType_Null::desc() const (this=0x67c38100) 
+    at tools/qucom.cpp:44 
+#14 0x0015a3e8 in ?? () 
+Steps to reproduce the problem: 
+1. Compile the program: mcs -r Qt slot-exception.cs 
+2. Run the program in mono or gdb 
+Actual Results: 
+Unhandled Exception: System.NullReferenceException: A null value was found where 
+an object instance was required 
+in (unmanaged) 06 Qt.QApplication:qt_QApplication_exec (intptr) 
+in <0x00004> 06 Qt.QApplication:qt_QApplication_exec (intptr) 
+in <0x00106> 00 .Example:Main (string[]) 
+Expected Results: 
+Unhandled Exception: System.ArgumentException: X 
+How often does this happen?  
+Additional Information: