Skip to content
Open
10 changes: 10 additions & 0 deletions site/source/docs/porting/connecting_cpp_and_javascript/embind.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,16 @@ registered using :cpp:func:`EMSCRIPTEN_DECLARE_VAL_TYPE` in combination with
register_type<CallbackType>("(message: string) => void");
}

Embind Debugging
======================

TO help you debug, you can use enable `-sEMBIND_DEBUG` which log every wasm call.
To use it, invoke *emcc* with the `-sEMBIND_DEBUG` option

emcc -lembind quick_example.cpp -sEMBIND_DEBUG example.js

Running this command will build the program with an js call every time you call the wasm.

Performance
===========

Expand Down
7 changes: 7 additions & 0 deletions src/embind/embind.js
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,13 @@ var LibraryEmbind = {
if (arguments.length !== expectedArgCount) {
throwBindingError(`function ${humanName} called with ${arguments.length} arguments, expected ${expectedArgCount}`);
}
#if EMBIND_DEBUG
if (Object.values(arguments).length > 0){
dbg('${humanName}(' + Object.values(arguments).join(',') + ')');
} else {
dbg('${humanName}()');
}
#endif
#if EMSCRIPTEN_TRACING
Module.emscripten_trace_enter_context(`embind::${humanName}`);
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ var DEMANGLE_SUPPORT = false;
// [link]
var LIBRARY_DEBUG = false;

// If nonzero, prints out each call to WebAssembly with arguments
// [compile+link]
var EMBIND_DEBUG = false;

// Print out all musl syscalls, including translating their numeric index
// to the string name, which can be convenient for debugging. (Other system
// calls are not numbered and already have clear names; use LIBRARY_DEBUG
Expand Down
1 change: 1 addition & 0 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ def phase_linker_setup(options, state, newargs):

if not settings.RUNTIME_DEBUG:
settings.RUNTIME_DEBUG = bool(settings.LIBRARY_DEBUG or
settings.EMBIND_DEBUG or
settings.GL_DEBUG or
settings.DYLINK_DEBUG or
settings.OPENAL_DEBUG or
Expand Down