5

I am working on a pet project: A programing language in the Javascript/Scheme mindset the project can be found here

I have looked through existing Stackoverflow questions such as Making a CLR/.NET Language Debuggable. However most of these solutions deal with generating assemblies. For numerous reasons I would prefer to avoid creating a new assembly.

class Program
{

    public static void ThrowingFunction()
    {
        throw new Exception("Test Exception");
    }

    static void Main(string[] args)
    {
        Action thw = ThrowingFunction;
        ParameterExpression param = Expression.Parameter(typeof(int), "arg");
        SymbolDocumentInfo info = Expression.SymbolDocument("example-script", new Guid("83c65910-8376-11e2-9e96-0800200c9a66"));
        Expression<Func<int,int>> exp = Expression.Lambda<Func<int,int>>(
            Expression.Block(
                Expression.DebugInfo(info,1,1,1,20),
                Expression.Invoke(Expression.Constant(thw, typeof(Action))),
                Expression.Add(param,Expression.Constant(1))
            ),
            new List<ParameterExpression> { param }
            );
        Console.WriteLine(exp);
        Func<int,int> Fn = exp.Compile(DebugInfoGenerator.CreatePdbGenerator());
        try {
            Fn(1);
        }
        catch (Exception e) {
            Console.WriteLine(e);
            Console.WriteLine(e.InnerException);
        }
    }
}

The above code works however the debug info does not contain the line information for the lambda instead referring obliquely to lambda_method with no other information in the stack trace.

How can I get the stack trace to also show line information.

Community
  • 1
  • 1
Thomas Devries
  • 839
  • 4
  • 18
  • 1
    I started with [this code](http://stackoverflow.com/q/6769122/41071), where line information works. Then I modified it to use `Expression.Compile()`, and line information stopped working. So either I'm missing something, or it's broken. – svick May 13 '16 at 21:08
  • I would be surprised if you needed to create an assembly to get debug info to work. If that where the case why would the have an Overload on compile that accepts a DebugInfoGenerator); – Thomas Devries May 16 '16 at 00:26

0 Answers0