New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Investigate Debugging story #68
Comments
I can give this a shot, as long as there is no need to have it ASAP as I don't know how much time I'll have to work on this. |
@dschenkelman no rush. |
I have created a small spike that takes a .csx file (with a main method as entry point) and creates a console app .exe and a related .pdb. I have uploaded it to my repo fork, and created a readme that explains the most important things. Check it out here. The spike shows that a .pdb file can be correclty created (assuming tweaks are performed to scriptcs code gen) and debugged (tried it using mdbg). If you think the spike is useful, we can have a discussion about where to go next. |
Wow, this is awesome dude! I can't wait to check it out. On Thu, Mar 7, 2013 at 8:23 PM, dschenkelman notifications@github.comwrote:
|
Took a quick peak, I see you are compiling the syntax tree. One question is On Thu, Mar 7, 2013 at 9:38 PM, Glenn Block glenn.block@gmail.com wrote:
|
Or at least allow the same code to still compile i.e. the host object On Thu, Mar 7, 2013 at 9:41 PM, Glenn Block glenn.block@gmail.com wrote:
|
I'll spend a bit of time checking out possible approaches to get this done although I don't know if it will be possible. Perhaps I'm getting ahead, but what I believe is the bad part of this approach is generating code that can be compiled using the SyntaxTree approach from the *.csx files. |
You ae making great progress. Can you do a test as a dll? On Friday, March 8, 2013, dschenkelman wrote:
|
Just performed one to see if the script runs using this code: var scriptEngine = new ScriptEngine();
scriptEngine.AddReference("System");
scriptEngine.AddReference("System.Core");
var session = scriptEngine.CreateSession();
Submission<string> s = session.CompileSubmission<string>(code);
var compilation = (Compilation)s.Compilation;
// need to add assemblies
CommonEmitResult result;
using (FileStream outputStream = new FileStream(outputPath, FileMode.OpenOrCreate))
using (FileStream pdbStream = new FileStream(pdbPath, FileMode.OpenOrCreate))
{
result = compilation.Emit(outputStream, outputName, pdbPath, pdbStream);
}
if (result.Success)
{
Console.WriteLine("Compilation successful");
Console.WriteLine(string.Format("Output .exe at {0}", outputPath));
Console.WriteLine(string.Format("Output .pdb at {0}", pdbPath));
var assembly = Assembly.LoadFrom(outputName);
var type = assembly.GetType("Submission#0");
var method = type.GetMethod("<Factory>", BindingFlags.Static | BindingFlags.Public);
method.Invoke(null, new[]{ session });
} This produced the expected output:
My next step will be to either attach to the running instance with mdbg (if possible), or create an .exe that just invokes the script through reflection assuming that the .dll is in the same dir. |
Nice! |
Been working on attaching to a running console app (which simulates scriptcs.exe) from either VS or mdbg.
VS issueAs there is no 1 to 1 mapping between source and compiled code, so the .pdb does not have a related file and VS cannot attached to a particular file to be debugged (any ideas to work around this?). For example, this source: using System;
using System.Diagnostics;
Debugger.Break();
Console.WriteLine("Testing");
public class Writer
{
public void Write(string s)
{
Console.WriteLine(s);
}
}
int a = 1;
int b = 2;
int c = a + b;
new Writer().Write(c.ToString());
Console.ReadLine Is compiled into: using Microsoft.CSharp.RuntimeHelpers;
using Roslyn.Scripting;
using System;
using System.Diagnostics;
public sealed class Submission#0
{
public class Writer
{
public void Write(string s)
{
Console.WriteLine(s);
}
}
public int a;
public int b;
public int c;
public Submission#0(Session session, ref object submissionResult)
{
SessionHelpers.SetSubmission(session, 0, this);
Debugger.Break();
Console.WriteLine("Testing");
this.a = 1;
this.b = 2;
this.c = checked(this.a + this.b);
new Submission#0.Writer().Write(this.c.ToString());
submissionResult = Console.ReadLine();
}
public static object <Factory>(Session session)
{
object result;
new Submission#0(session, ref result);
return result;
}
} Using mdbgI have been able to run a console app that compiles the .csx into a .dll with its related .pdb and attach to it using mdbg.exe that is located at C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools (the location is important because there are might be others at C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin that are installed with the Windows SDK that did not work).
The following figures show a simple debugging session (using the source code provided above). The line numbers are the same as the ones in the original source code file, but there is no out-of-the-box way to check the source code from mdbg because .pdb does not point to the source file: Possible improvementsThe aforementioned approach does work but is definitely a "poor man's debugger". Some of the things I have considered to improve this are (in no particular order):
Nevertheless, there are some related items that you might probably would like to see addressed before 1 and 3, such as:
ProposalFor the time being (unless you would like to me help in any of the above), I could:
Let me know if you would like to have a discussion about any of this. |
We'd love for you to do this! I didn't digest it all, but does it need a new executor? Should we have a On Sat, Mar 9, 2013 at 1:10 PM, dschenkelman notifications@github.comwrote:
|
Instead of #break, we could just add the diagnostics namespace / ref by or are you thinking we make #break because it is less verbose? On Sat, Mar 9, 2013 at 1:41 PM, Glenn Block glenn.block@gmail.com wrote:
|
The idea of having a new executor is that the normal (current one) won't generate the .dll and the .pdb. The -debug activated one will. They will probably end up inheriting from a base class and overriding just one or two methods. I like #break better because it is less verbose. We should automatically add System.Diagnostics if -debug is provided. |
I've created #76 and will start to work on it. |
The downside to #break is it will "break" scenarios of upgrading to a full I like the simplicity, but interested to hear what others think. On Sat, Mar 9, 2013 at 2:36 PM, dschenkelman notifications@github.comwrote:
|
Yes, I agree with that. There's no rush for this and it would be good to On Sat, Mar 9, 2013 at 8:27 PM, Glenn Block notifications@github.comwrote:
|
This one should probaly be closed. At least for the time being there probably won't be any major updates in debugging per se. |
Closing in favor of #76. |
@dschenkelman I got a pointer from the Roslyn team that might be worth investigating aroun the #line directive: http://blogs.msdn.com/b/abhinaba/archive/2005/10/10/479016.aspx This "might" allow doing the source mapping if the CTP supports it. |
@glennblock Wow! That absolutely did the trick. We definitely need to address #71 before adding support for this, but it seems to be definitely working! |
Been going over the opened pull requests. We would need to:
After that I will work automatically generating #line directives correctly #104. |
@dschenkelman awesome!!!!! |
@dschenkelman this is amazingly awesome!! |
@glennblock @dschenkelman Agreed, 100%. Best screen shot I've seen all day. |
Thanks guys, I'm really having a good time as I can do something fun while also adding value. |
@dschenkelman and we're having a good time with you! |
@glennblock @filipw @jrusbatch |
One of the things people are asking is how they can debug Rosyln sripts. Today Roslyn doesn't support debugging, though it does support compiling to a dll.
So, the question is can one figure out how using that you could attach to a process using VS to debug.
I am not sure it's doable, as Roslyn may not include PDBs. Anyway, if someone wants to run with this to see if it's possible, we'd love it!
We're not asking for a PR (yet) we're asking for a proof of concept.
The text was updated successfully, but these errors were encountered: