[Mono-bugs] [Bug 367665] New: Stack walking is incorrect when a native method is on the stack

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Mar 6 02:38:17 EST 2008


https://bugzilla.novell.com/show_bug.cgi?id=367665


           Summary: Stack walking is incorrect when a native method is on
                    the stack
           Product: Mono: Runtime
           Version: 1.9.0
          Platform: Other
        OS/Version: Windows Vista
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: JIT
        AssignedTo: lupus at novell.com
        ReportedBy: jeroen at sumatra.nl
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


The following program is not a full repro of what I'm seeing (because in my
case a managed method is actually disappearing from the call stack), but it
does show that something is wrong, because you'll see the Foo method show up
twice. If you comment out the calli and uncomment the call, you'll see the
InternalInvoke method show up twice.

using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;

public class Program
{
        static System.Threading.ThreadStart del = Foo;

        static void Main()
        {
                AssemblyBuilder ab =
AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("foo"),
AssemblyBuilderAccess.Run);
                ModuleBuilder modb = ab.DefineDynamicModule("foo.dll");
                TypeBuilder tb = modb.DefineType("Foo");
                MethodBuilder mb = tb.DefineMethod("Frub",
MethodAttributes.Static, null, new Type[] { typeof(IntPtr) });
                mb.SetImplementationFlags(MethodImplAttributes.NoInlining);
                ILGenerator ilgen = mb.GetILGenerator();
                ilgen.Emit(OpCodes.Ldarg_0);
                ilgen.EmitCalli(OpCodes.Calli, CallingConvention.StdCall,
typeof(void), Type.EmptyTypes);
                //ilgen.Emit(OpCodes.Call, typeof(Program).GetMethod("Foo"));
                ilgen.Emit(OpCodes.Ret);
                Type type = tb.CreateType();
                type.GetMethod("Frub", BindingFlags.NonPublic |
BindingFlags.Static)
                        .Invoke(null, new object[] {
Marshal.GetFunctionPointerForDelegate(del) });
        }

        public static void Foo()
        {
                for (int i = 0; i < 4; i++)
                {
                        MethodBase m = new
System.Diagnostics.StackFrame(i).GetMethod();
                        Console.WriteLine(m.DeclaringType.Name + "::" +
m.Name);
                }
        }
}


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list