nikhilk / scriptsharp

Script# Project - a C# to JavaScript compiler, to power your HTML5 and Node.js web development.
http://scriptsharp.com
Other
659 stars 183 forks source link

C# Source Level Debugging #306

Open Mike-E-angelo opened 11 years ago

Mike-E-angelo commented 11 years ago

My first inclination when running Script# was to put a breakpoint in my C# code. Of course this doesn't work because the DLL is never loaded. However, I'm looking at this article and it mentions source mapping:

http://blogs.msdn.com/b/typescript/archive/2012/11/15/announcing-typescript-0-8-1.aspx

This might be horribly challenging, but might it possible to get debugging in C# code with Script#?

theoutlander commented 11 years ago

That's really interesting. It might not be impossible, but I would think it could be very time consuming to implement.

I'm not an expert in this, but I think there are a few ways to accomplish this. One way is to just target the V8 Engine's Remote Debugging Protocol.

Some of the components that would have to be implemented would be:

  1. S# Debug Library that can sit between VS and the V8 Debugger
  2. S# project that can be launched via the debugger or attached to this library
  3. Ability to debug the JS executing in V8 through VS talking to the S# Debug Library.
  4. Compiler that generates a Javascript based PDB that allows mapping JS code to CS

I'm sure Nikhil would know of a better and simpler way to accomplish this. If we have a feasible plan, I'm all for helping out ;)

nikhilk commented 11 years ago

Yep, would be super interesting, and quite time consuming, in a way that interesting things usually are... :)

It would be a bit cheaper to support debugging in chrome via source maps (http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/), to avoid doing the VS debug engine support work. The script# compiler would produce a source map that would allow inspecting variables, call stack, see c# source etc. within the inspector and dev tools within chrome.

This has certainly been requested, and I am all for someone taking a stab at the work which includes not just the actual implementation, but fully understanding source maps, thinking through the design, discussing it, etc.

theoutlander commented 11 years ago

That's a nice way to do it in Chrome. We should definitely start out with implementing SourceMaps and VS integration won't be necessary. I'll look into SourceMaps when I get a chance.

theoutlander commented 11 years ago

Btw, here's an interesting discussion on SourceMaps for CoffeeScript: https://github.com/jashkenas/coffee-script/issues/558

Mike-E-angelo commented 11 years ago

Hmmm... so this means we'd be debugging out of Chrome and not Visual Studio?

nikhilk commented 11 years ago

Yes, debugging would happen in chrome. I wouldn't be surprised if other browsers eventually support source maps too, and perhaps even VS would.

Mike-E-angelo commented 11 years ago

Based on the original blog post above, TypeScript debugs in Visual Studio using source mapping currently... I for one would rather debug out of my development environment if possible.

nikhilk commented 11 years ago

I can only hope that the VS languages team created a more general sourcemap-enabled script debugging solution rather than a more constrained typescript debugging solution... though I wouldn't be surprised if it is in fact the latter.

I have no disagreement with the desire to debug out of the development environment.

That said sourcemap support will be the pre-requisite, and it gets debugging enabled in more environments, and I can't help but imagine that the javascript tooling in VS will catch on in the meantime to allow you to debug in IE or in VS ... just like DOM exploration which was added in IE, is now integrated into VS as well.