Skip to content
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

Implement basic source maps. Refs #1252. #1267

Merged
merged 5 commits into from
Jun 9, 2013

Conversation

int3
Copy link
Contributor

@int3 int3 commented Jun 7, 2013

  • Only works for unoptimized / uncompressed builds.
  • Implements a simplistic lexer that makes some assumptions about the lexed source (as described in comments). This should be much faster than running a full parser.

I've separated out the addition of the source-map library as a separate commit, so you can review a cleaner diff by looking at the second commit alone.

@kripken
Copy link
Member

kripken commented Jun 7, 2013

Good start, some initial comments:

  1. I think we need to check keep_llvm_debug too. llvm debug is the llvm debug info itself, js debug info is if we keep js readable (if js is not readable, llvm debug info is pointless, but we can have the opposite).
  2. We should have a test for this. see test_debug which tests our llvm debug info as a starting point.

@int3
Copy link
Contributor Author

int3 commented Jun 7, 2013

Initial comments have been addressed.

@kripken
Copy link
Member

kripken commented Jun 7, 2013

Does the output work ok in both firefox and chrome?

@int3
Copy link
Contributor Author

int3 commented Jun 8, 2013

Ah. It only seems to work fully on Aurora. On both Firefox Nightly and Chrome, the line number mapping works, but the actual source doesn't get loaded in the debugger. Still trying to figure out if this is a bug in my code or in the browser(s).

Tweak behavior of post_build; the `post2` hook now expects a function.
@int3
Copy link
Contributor Author

int3 commented Jun 8, 2013

Okay, I found my very silly mistake. It works on Chrome and Firefox (Aurora and Nightly) now.

Chrome and FF seem to be able to handle the extra empty lines, but no
harm making things more accurate. One thing less to worry about when
debugging.
@kripken
Copy link
Member

kripken commented Jun 9, 2013

How can i see this work in the browser? I added the .js file generated from the test here to a script tag, but don't seem to see source maps being used.

@kripken
Copy link
Member

kripken commented Jun 9, 2013

@fitzgen

@fitzgen
Copy link

fitzgen commented Jun 9, 2013

Initial support is in Firefox 23 (Aurora, currently) with a bunch of improvements (and more to land) in Nightly.

When the debugger is open, there is an options cog wheel in the top right corner, there should be a "show original sources" option which enables source maps.

There are some pictures showing this process at the end of this article: https://hacks.mozilla.org/2013/05/compiling-to-javascript-and-debugging-with-source-maps/

@int3
Copy link
Contributor Author

int3 commented Jun 9, 2013

As for Chrome, source map usage should be automatic. You should be able to see in work for uncaught exceptions, when breaking on exceptions, and when setting breakpoints in the sources panel of the debugger. Note that the point where the exception actually gets thrown is usually unmapped, because that's in runtime code; the mapped lines usually start 1 or 2 steps up on the stack trace.

Some issues I've noticed upon further poking around:

  • FF and Chrome Stable seem to start the line numbering for inline scripts from the beginning of the html file, not the beginning of the <script> tag, unlike what @fitzgen told me on IRC. Right now we generate line numbers relative to the <script> tag. Could @fitzgen verify the correct behavior? I can't find anything in the spec that talks about this. Regardless, generating the JS separately and including it in a tag should work right now.
  • Chrome Canary seems to not detect the source map at all.
  • Chrome's 'pause on exceptions' doesn't seem to update the source-mapped line number after the first exception; that is, after I resume execution after the first pause.
  • FF Aurora + Nightly have this problem with 'pause on exceptions' not working when the page is refreshed. Workaround is to toggle the option off and on again.

I should probably file bugs against Chrome / FF devtools for some of those issues, once I'm sure it's not our fault.

@kripken kripken merged commit 56e5dcd into emscripten-core:incoming Jun 9, 2013
@kripken
Copy link
Member

kripken commented Jun 9, 2013

Hmm, I made a mistake in git apparently, and this is marked as merged even though it is not. I don't see a way to reopen it. Can you open another pull for this? Sorry about that.

@kripken
Copy link
Member

kripken commented Jun 9, 2013

When I do "show original sources" it just says "loading.." and nothing seems to happen. In Chrome nothing happens either.

Here are the files I have in /tmp/emscripten_temp when i try this https://gist.github.com/kripken/5737516

@int3
Copy link
Contributor Author

int3 commented Jun 9, 2013

Oops, it turns out that I was using Chrome Beta (28) instead of Stable (27). Sorry! (I wish they had different icons...) I can reproduce the issue with 27, but it works on 28.

As for FF -- it seems like if the entries in the "sources" array use an absolute path name, and the "sourcesContent" entry is present, then we get that perma-loading issue. Making the path relative fixes things. (I think this is a bug in devtools.) I hadn't noticed it earlier as I was testing files compiled by passing emcc a relative path parameter.

Independent of the above issues, the JS should be included in shell.html by manually replacing the <script>{{{ SCRIPT_CODE }}}</script> with an externally sourced src.cpp.o.js. Otherwise (with the empty HTML file in the above-linked gist) the cpp source should still load, but the script errors out due to the undefined library variables.

Edit: I'll open a new PR once I fix the inline script bug, so that the user can get source maps working just by typing em++ test.cpp -o test.html.

@fitzgen
Copy link

fitzgen commented Jun 10, 2013

FF and Chrome Stable seem to start the line numbering for inline scripts from the beginning of the html file, not the beginning of the <script> tag, unlike what @fitzgen told me on IRC. Right now we generate line numbers relative to the <script> tag. Could @fitzgen verify the correct behavior? I can't find anything in the spec that talks about this. Regardless, generating the JS separately and including it in a tag should work right now.

Apologies, I was incorrect and this is the expected behavior.

As for FF -- it seems like if the entries in the "sources" array use an absolute path name, and the "sourcesContent" entry is present, then we get that perma-loading issue. Making the path relative fixes things. (I think this is a bug in devtools.) I hadn't noticed it earlier as I was testing files compiled by passing emcc a relative path parameter.

Are you using a sourceRoot as well? This is probably a bug in the source map library. Any chance you could create a minimal test case and file a bug at mozilla/source-map? Thanks a bunch :)

@kripken
Copy link
Member

kripken commented Jun 10, 2013

Does the gist I pasted above work for either of you? Not sure if it should or shouldn't given the last few comments...

@int3
Copy link
Contributor Author

int3 commented Jun 10, 2013

In Chrome 28, there should be a src.cpp in the "sources" pane of the debugger. The script itself errors out, though, since the runtime library isn't included in a.html. It doesn't work (gets stuck on 'Loading...') on FF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants