Bug 45677 - IronPython Embedding and Stack Trace
Summary: IronPython Embedding and Stack Trace
Status: CONFIRMED
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: 4.6.0 (C8)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Alexis Christoforides
URL:
Depends on:
Blocks:
 
Reported: 2016-10-18 23:54 UTC by Keith O'Hara
Modified: 2017-07-06 23:24 UTC (History)
4 users (show)

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


Attachments

Description Keith O'Hara 2016-10-18 23:54:24 UTC
We have recently run into a problem with stack traces in a project where we embed IronPython into a C# project (the calico educational IDE). We have contacted IronPython, but it seems to be a problem with StackFrame.GetMethod() on Mono.

https://github.com/IronLanguages/main/issues/1473

Here's a simpler version of the issue:

using IronPython.Hosting;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;

using System;

public class Test
{
  static public void Main ()
  {
    Console.WriteLine ("Hello Mono World");
    ScriptEngine engine = Python.CreateEngine();

    ScriptSource source = engine.CreateScriptSourceFromString("1+\"2\"", SourceCodeKind.SingleStatement);

    try
      {
    source.Execute(engine.CreateScope());
      }
    catch(Exception e)
      {
    Microsoft.Scripting.Hosting.ExceptionOperations eo = engine.GetService<Microsoft.Scripting.Hosting.ExceptionOperations>();
    Console.WriteLine(eo.FormatException(e));
      }
  }
}

This reports a proper stack trace on windows, but on mac os x and linux

Ubuntu 14.04
Mono JIT compiler version 4.6.1 (Stable 4.6.1.5/ef43c15 Wed Oct 12 09:10:37 UTC 2016)
IronPython-2.7.6.3


OUTPUT: 

Hello Mono World

Unhandled Exception:
System.ArgumentNullException: Value cannot be null.
Parameter name: method
  at Microsoft.Scripting.Interpreter.InterpretedFrame.IsInterpretedFrame (System.Reflection.MethodBase method) [0x00034] in <79cfb7a2f3e64d08b5229af806595a85>:0 
  at Microsoft.Scripting.Interpreter.InterpretedFrame+<GroupStackFrames>d__27.MoveNext () [0x00050] in <79cfb7a2f3e64d08b5229af806595a85>:0 
  at IronPython.Runtime.Exceptions.PythonExceptions.GetDynamicStackFrames (System.Exception e) [0x000fd] in <da43f94b98a64284b9b087d7c5165967>:0 
  at IronPython.Runtime.PythonContext.FormatStackTraceNoDetail (System.Exception e, System.Boolean& printedHeader) [0x00051] in <da43f94b98a64284b9b087d7c5165967>:0 
  at IronPython.Runtime.PythonContext.FormatStackTraces (System.Exception e, System.Boolean& printedHeader) [0x000c9] in <da43f94b98a64284b9b087d7c5165967>:0 
  at IronPython.Runtime.PythonContext.FormatStackTraces (System.Exception e) [0x00002] in <da43f94b98a64284b9b087d7c5165967>:0 
  at IronPython.Runtime.PythonContext.FormatException (System.Exception exception) [0x00023] in <da43f94b98a64284b9b087d7c5165967>:0 
  at Microsoft.Scripting.Hosting.ExceptionOperations.FormatException (System.Exception exception) [0x00000] in <7cb5a539966b4a04a6d50e87834d41cf>:0 
  at (wrapper remoting-invoke-with-check) Microsoft.Scripting.Hosting.ExceptionOperations:FormatException (System.Exception)
  at Test.Main () [0x0003c] in <cd04668617a64140bec7fdd31c2138b3>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentNullException: Value cannot be null.
Parameter name: method
  at Microsoft.Scripting.Interpreter.InterpretedFrame.IsInterpretedFrame (System.Reflection.MethodBase method) [0x00034] in <79cfb7a2f3e64d08b5229af806595a85>:0 
  at Microsoft.Scripting.Interpreter.InterpretedFrame+<GroupStackFrames>d__27.MoveNext () [0x00050] in <79cfb7a2f3e64d08b5229af806595a85>:0 
  at IronPython.Runtime.Exceptions.PythonExceptions.GetDynamicStackFrames (System.Exception e) [0x000fd] in <da43f94b98a64284b9b087d7c5165967>:0 
  at IronPython.Runtime.PythonContext.FormatStackTraceNoDetail (System.Exception e, System.Boolean& printedHeader) [0x00051] in <da43f94b98a64284b9b087d7c5165967>:0 
  at IronPython.Runtime.PythonContext.FormatStackTraces (System.Exception e, System.Boolean& printedHeader) [0x000c9] in <da43f94b98a64284b9b087d7c5165967>:0 
  at IronPython.Runtime.PythonContext.FormatStackTraces (System.Exception e) [0x00002] in <da43f94b98a64284b9b087d7c5165967>:0 
  at IronPython.Runtime.PythonContext.FormatException (System.Exception exception) [0x00023] in <da43f94b98a64284b9b087d7c5165967>:0 
  at Microsoft.Scripting.Hosting.ExceptionOperations.FormatException (System.Exception exception) [0x00000] in <7cb5a539966b4a04a6d50e87834d41cf>:0 
  at (wrapper remoting-invoke-with-check) Microsoft.Scripting.Hosting.ExceptionOperations:FormatException (System.Exception)
  at Test.Main () [0x0003c] in <cd04668617a64140bec7fdd31c2138b3>:0
Comment 1 Alexis Christoforides 2017-03-10 19:19:16 UTC
Confirmed on Mono 4.8 and IronPython 2.7.7 (latest)
Comment 2 Alex Earl 2017-03-10 21:03:00 UTC
I am one of the maintainers for IronPython, let me know if there is anything useful we can do to help on this.
Comment 3 Alex Earl 2017-06-08 23:50:25 UTC
Confirmed this still occurs on 

Mono JIT compiler version 5.0.1.1 (2017-02/5077205 Thu May 25 09:19:18 UTC 2017)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            sgen (concurrent by default)
Comment 4 Alex Earl 2017-07-06 23:24:31 UTC
I found that Mono sets the method of the StackFrame to null if it's a wrapper type. See https://github.com/mono/mono/blob/master/mono/mini/mini-exceptions.c#L922. Some of the items in the stacktrace are dynamic methods, which fall under this wrapper type category.

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