jeremy-rifkin / cpptrace

Simple, portable, and self-contained stacktrace library for C++11 and newer
MIT License
736 stars 77 forks source link

Feature Request: Emscripten support #175

Open vittorioromeo opened 2 months ago

vittorioromeo commented 2 months ago

Would be nice to get even (partial) support for Emscripten -- I currently only need cpptrace::generate_trace().print() in my project, and I have to #ifdef for Emscripten like this:

#ifdef SFML_SYSTEM_EMSCRIPTEN
    char callstack[4096];
    emscripten_get_callstack(EM_LOG_C_STACK, callstack, sizeof(callstack));
    std::puts(callstack);
#else
    cpptrace::generate_trace().print();
#endif

Would be nice if cpptrace handled this automatically :)

jeremy-rifkin commented 1 week ago

I've started looking into adding support for this. The main issue would be parsing the result from emscripten_get_callstack and I don't have as much confidence in doing this as I'd like. It seems the format can differ depending on where the js/wasm is being ran. Do you have any advice?

vittorioromeo commented 1 week ago

Unfortunately I do not have any experience with that, the only pointer I can provide is the function that generates the callstack in Emscripten: https://github.com/emscripten-core/emscripten/blob/e6ed9d3fc2821a72cc8ded4a02cac72b9f306f88/src/library_stack_trace.js#L12-L97

It seems it already does some normalization between browsers