emscripten_log() and emscripten_get_callstack()#1635
Conversation
There was a problem hiding this comment.
This is reported as a bug at https://bugzilla.mozilla.org/show_bug.cgi?id=762556 .
There was a problem hiding this comment.
need a comment on that in the source, not just on github
|
I suggest we build cxa_demangle standalone into js. Then we would include it in emcc if the user asks for this option. Including could be as a pre-js for example. This would fix the first two issues here. Regarding the loading of the map file - are source maps text? Then we can do a sync xhr to load them the first time. Regarding node, we can file a bug. Working in the browser is a great first step. |
|
I now had a go at building the cxa_demangle.cpp to a .js library. I first tried (in emscripten root directory of this branch): but I suppose --pre-js'ing side modules is not a supported machinery. The result in running that code is that the function ___cxa_demangle is not seen by the main code, since it's inside an unnamed function(). Second I tried to follow the linking guide directly with: but that gives an error I added a "if 'var ' not in part: continue" to asm_module.py to try to get past of this, but then I got another error with which looks like the code gets confused by comments or whitespace? @kripken, could you take a peek when you have time? |
|
emlink only works with asm.js code... |
|
Yes, emlink is only for asm.js code - we should error on |
|
Reading the docs on name mangling, it looks pretty trivial: http://en.wikipedia.org/wiki/Name_mangling#Complex_example Basically |
|
See last commits on adding |
|
I wonder if we shouldn't add a printf option for the stack. So |
|
I'm trying to port some code that relies on __cxa_demangle (among other cxxabi features -- see this thread https://groups.google.com/forum/#!topic/emscripten-discuss/nzlKaLNQFrE). Should I follow the steps outlined by @juj in the first comment above? |
|
That worked for me, though I'm still curious if I should officially integrate this step into our build system, or if a better solution is available. |
|
@jcowles : Alon did great work in supporting demangle() from native JS side. It's in my todo list to convert to using that, which will solve the inconveniency with the two first bullet points in the PR message. To get callstacks, the third and fourth bullet points still stand. Even after this pull request is merged, nothing should break if you already did the same manually in your own codebase. Sorry for not giving this much attention in a while, there's been a lot of higher priority work in the meanwhile. |
|
Ok, updated this pull request to latest. Thanks azakai for the handwritten demangler, it works beautifully now! |
There was a problem hiding this comment.
stackTrace() will by default show both demangled and mangled names, i guess you prefer to just show one at a time?
There was a problem hiding this comment.
you could just call demangle here, and avoid the dependency on emscripten_demangle (although keeping it as a C function is nice for C code).
There was a problem hiding this comment.
Yeah, I followed the approach of letting user print the version he wants. I did not remove _emscripten_demangle since I also thought at first I had exposed it to emscripten.h, but now notice it was not the case, and it takes in a JS string anyways, so not immediately useful from C code. I'll remove emscripten_demangle function for now - perhaps add that later if it's useful.
…ing out log messages with callstack information, and function emscripten_get_callstack(), which allows programmatically obtaining the current callstack.
…ck with emscripten_get_callstack.
…e needed by public use when user wants to emscripten_log with a C callstack. Remove redundant emscripten_demangle function.
|
Updated the PR. Also added the bug number to the source. |
There was a problem hiding this comment.
we should eventually refactor this to a list of regexes, as we will want to support IE and safari as well.
emscripten_log() and emscripten_get_callstack()
Add new functions emscripten_log() in emscripten.h which allows printing out log messages with callstack information, and function emscripten_get_callstack(), which allows programmatically obtaining the current callstack.
The callstack retrieval supports both symbol demangling and file+line+column in .js -> file+line+column in original .cpp mapping through source maps.
I am not completely satisfied about the current requirements that are needed to add demangling and source map support to the build. Namely:
Thoughts on what would be the best ways to simplify the above requirements?