diff options
author | Jukka Jylänki <jujjyl@gmail.com> | 2013-12-19 23:32:26 +0200 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-12-20 11:49:34 +0200 |
commit | 55660c394d5f3db2d57984256dd6c3cce088e4c5 (patch) | |
tree | 20099712556194717acfdb9815bf5695f32c49a1 | |
parent | 184a425ce07a95e882f3f60b87c1c5037cbffec5 (diff) |
Update emscripten_log to work with the handwritten JS demangler. Update tests.
-rw-r--r-- | src/library.js | 22 | ||||
-rw-r--r-- | src/preamble.js | 4 | ||||
-rw-r--r-- | tests/emscripten_log/emscripten-source-map.min.js | 7 | ||||
-rw-r--r-- | tests/emscripten_log/emscripten_log.cpp | 22 | ||||
-rw-r--r-- | tests/emscripten_log/shell-emscripten-log.html | 93 | ||||
-rw-r--r-- | tests/test_browser.py | 3 | ||||
-rw-r--r-- | tests/test_core.py | 3 |
7 files changed, 22 insertions, 132 deletions
diff --git a/src/library.js b/src/library.js index 1a4d685a..3a56df06 100644 --- a/src/library.js +++ b/src/library.js @@ -8838,27 +8838,7 @@ LibraryManager.library = { // Returns the given mangled C++ function name demangled to a readable form, or an empty string if the given string could not be demangled. // E.g. "_Z3foov" -> "foo()". emscripten_demangle: function(functionname) { - if (typeof ___cxa_demangle === 'undefined') { - Runtime.warnOnce('emscripten_demangle is not available in the current build. Please add the file $EMSCRIPTEN/system/lib/libcxxabi/src/cxa_demangle.cpp to your build to show demangled symbol names.'); - return ''; - } - // The application entry point has a special name, so treat it manually. - if (functionname == 'Object._main' || functionname == '_main') { - return 'main()'; - } - // If the compiled symbol starts with two underscores, there's one extra, which throws off cxa_demangle, so remove the first underscore. - if (functionname.indexOf("__") == 0) { - functionname = functionname.slice(1); - } - var sp = STACKTOP; - var stat = allocate([0, 0, 0, 0], 'i32', ALLOC_STACK); - var mangledname = allocate(512, 'i32*', ALLOC_STACK); - writeStringToMemory(functionname, mangledname, false); - var demangledname = allocate(512, 'i32*', ALLOC_STACK); - ___cxa_demangle(mangledname, demangledname, 512, stat); - var str = Pointer_stringify(demangledname); - STACKTOP = sp; - return str; + return demangle(functionname); }, // Returns [parentFuncArguments, functionName, paramListName] diff --git a/src/preamble.js b/src/preamble.js index 710b7c52..832ec2c3 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -642,6 +642,10 @@ Module['stringToUTF32'] = stringToUTF32; function demangle(func) { try { + // Special-case the entry point, since its name differs from other name mangling. + if (func == 'Object._main' || func == '_main') { + return 'main()'; + } if (typeof func === 'number') func = Pointer_stringify(func); if (func[0] !== '_') return func; if (func[1] !== '_') return func; // C function diff --git a/tests/emscripten_log/emscripten-source-map.min.js b/tests/emscripten_log/emscripten-source-map.min.js index 1788d3eb..9151400f 100644 --- a/tests/emscripten_log/emscripten-source-map.min.js +++ b/tests/emscripten_log/emscripten-source-map.min.js @@ -22,3 +22,10 @@ function emscripten_loadSourceMap() { emscripten_sourcemap_xmlHttp.open("GET", url, true); emscripten_sourcemap_xmlHttp.send(null); } + +var Module; +if (Module['preRun'] instanceof Array) { + Module['preRun'].push(emscripten_loadSourceMap); +} else { + Module['preRun'] = [emscripten_loadSourceMap]; +} diff --git a/tests/emscripten_log/emscripten_log.cpp b/tests/emscripten_log/emscripten_log.cpp index 0cd77467..a5bb8432 100644 --- a/tests/emscripten_log/emscripten_log.cpp +++ b/tests/emscripten_log/emscripten_log.cpp @@ -2,8 +2,6 @@ #include <stdio.h> #include <cstring> -#include <../lib/libcxxabi/include/cxxabi.h> - #define STRINGIZE_HELPER(x) #x #define STRINGIZE(x) STRINGIZE_HELPER(x) @@ -23,7 +21,7 @@ int result = 1; // If 1, this test succeeded. } \ } while(0) -void kitten() +void __attribute__((noinline)) kitten() { // Log to Emscripten Module. emscripten_log(EM_LOG_NO_PATHS, "Print a log message: int: %d, string: %s.", 42, "hello"); @@ -49,7 +47,7 @@ void kitten() emscripten_log(EM_LOG_NO_PATHS | EM_LOG_ERROR | EM_LOG_C_STACK | EM_LOG_JS_STACK | EM_LOG_DEMANGLE); } -void bar(int = 0, char * = 0, double = 0) // Arbitrary function signature to add some content to callstack. +void __attribute__((noinline)) bar(int = 0, char * = 0, double = 0) // Arbitrary function signature to add some content to callstack. { if (1 == 2) MYASSERT(2 == 1, "World falls apart!"); @@ -114,22 +112,15 @@ void bar(int = 0, char * = 0, double = 0) // Arbitrary function signature to add MYASSERT(!!strstr(str, "at __Z3bariPcd (src.cpp"), "Callstack was %s!", str); MYASSERT(!!strstr(str, "at __Z3FooIiEvv (src.cpp"), "Callstack was %s!", str); #else - MYASSERT(!!strstr(str, "at __Z3bariPcd (page.html"), "Callstack was %s!", str); - MYASSERT(!!strstr(str, "at __Z3FooIiEvv (page.html"), "Callstack was %s!", str); + MYASSERT(!!strstr(str, "at __Z3bariPcd (page.js"), "Callstack was %s!", str); + MYASSERT(!!strstr(str, "at __Z3FooIiEvv (page.js"), "Callstack was %s!", str); #endif } template<typename T> -void Foo() // Arbitrary function signature to add some content to callstack. +void __attribute__((noinline)) Foo() // Arbitrary function signature to add some content to callstack. { bar(); - - // Test cxa_demangle. - int stat; - char* demangled = abi::__cxa_demangle("_Z3foov", NULL, NULL, &stat); - if (stat == 0 && demangled) { - printf("Demangled name is '%s'.", demangled); - } } int main() @@ -138,5 +129,8 @@ int main() #ifndef RUN_FROM_JS_SHELL REPORT_RESULT(); return 0; +#else + if (result) + printf("Success!\n"); #endif } diff --git a/tests/emscripten_log/shell-emscripten-log.html b/tests/emscripten_log/shell-emscripten-log.html deleted file mode 100644 index 6963460a..00000000 --- a/tests/emscripten_log/shell-emscripten-log.html +++ /dev/null @@ -1,93 +0,0 @@ -<!doctype html> -<html lang="en-us"> - <head> - <meta charset="utf-8"> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - <title>Emscripten-Generated Code</title> - <style> - .emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; } - textarea.emscripten { font-family: monospace; width: 80%; } - div.emscripten { text-align: center; } - div.emscripten_border { border: 1px solid black; } - /* the canvas *must not* have any border or padding, or mouse coords will be wrong */ - canvas.emscripten { border: 0px none; } - </style> - </head> - <body> - <hr/> - <div class="emscripten" id="status">Downloading...</div> - <div class="emscripten"> - <progress value="0" max="100" id="progress" hidden=1></progress> - </div> - <div class="emscripten_border"> - <canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas> - </div> - <hr/> - <div class="emscripten"> - <input type="checkbox" id="resize">Resize canvas - <input type="checkbox" id="pointerLock" checked>Lock/hide mouse pointer - - <input type="button" value="Fullscreen" onclick="Module.requestFullScreen(document.getElementById('pointerLock').checked, - document.getElementById('resize').checked)"> - </div> - - <hr/> - <textarea class="emscripten" id="output" rows="8"></textarea> - <hr> - <script src="emscripten-source-map.min.js"></script> - <script type='text/javascript'> - // connect to canvas - var Module = { - preRun: [emscripten_loadSourceMap], - postRun: [], - print: (function() { - var element = document.getElementById('output'); - element.value = ''; // clear browser cache - return function(text) { - text = Array.prototype.slice.call(arguments).join(' '); - // These replacements are necessary if you render to raw HTML - //text = text.replace(/&/g, "&"); - //text = text.replace(/</g, "<"); - //text = text.replace(/>/g, ">"); - //text = text.replace('\n', '<br>', 'g'); - element.value += text + "\n"; - element.scrollTop = 99999; // focus on bottom - }; - })(), - printErr: function(text) { - text = Array.prototype.slice.call(arguments).join(' '); - if (0) { // XXX disabled for safety typeof dump == 'function') { - dump(text + '\n'); // fast, straight to the real console - } else { - console.log(text); - } - }, - canvas: document.getElementById('canvas'), - setStatus: function(text) { - if (Module.setStatus.interval) clearInterval(Module.setStatus.interval); - var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/); - var statusElement = document.getElementById('status'); - var progressElement = document.getElementById('progress'); - if (m) { - text = m[1]; - progressElement.value = parseInt(m[2])*100; - progressElement.max = parseInt(m[4])*100; - progressElement.hidden = false; - } else { - progressElement.value = null; - progressElement.max = null; - progressElement.hidden = true; - } - statusElement.innerHTML = text; - }, - totalDependencies: 0, - monitorRunDependencies: function(left) { - this.totalDependencies = Math.max(this.totalDependencies, left); - Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.'); - } - }; - Module.setStatus('Downloading...'); - </script> - <script async type='text/javascript'>{{{ SCRIPT_CODE }}}</script> - </body> -</html> diff --git a/tests/test_browser.py b/tests/test_browser.py index 55e368a8..c3de1861 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -122,9 +122,8 @@ If manually bisecting: def test_emscripten_log(self): src = os.path.join(self.get_dir(), 'src.cpp') open(src, 'w').write(self.with_report_result(open(path_from_root('tests', 'emscripten_log', 'emscripten_log.cpp')).read())) - shutil.copyfile(path_from_root('tests', 'emscripten_log', 'emscripten-source-map.min.js'), os.path.join(self.get_dir(), 'emscripten-source-map.min.js')) - Popen([PYTHON, EMCC, src, path_from_root('system', 'lib', 'libcxxabi', 'src', 'cxa_demangle.cpp'), '-I'+path_from_root('system', 'lib', 'libcxxabi', 'include'), '--shell-file', path_from_root('tests', 'emscripten_log', 'shell-emscripten-log.html'), '-g', '-o', 'page.html']).communicate() + Popen([PYTHON, EMCC, src, '--pre-js', path_from_root('tests', 'emscripten_log', 'emscripten-source-map.min.js'), '-g', '-o', 'page.html']).communicate() self.run_browser('page.html', None, '/report_result?1') def build_native_lzma(self): diff --git a/tests/test_core.py b/tests/test_core.py index 9991ccbd..80fb3cc5 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -6084,9 +6084,8 @@ def process(filename): def test_emscripten_log(self): if self.emcc_args is None: return self.skip('This test needs libc.') - self.emcc_args += [path_from_root('system', 'lib', 'libcxxabi', 'src', 'cxa_demangle.cpp'), '-I'+path_from_root('system', 'lib', 'libcxxabi', 'include'), '--shell-file', path_from_root('tests', 'emscripten_log', 'shell-emscripten-log.html')] if '-g' not in Building.COMPILER_TEST_OPTS: Building.COMPILER_TEST_OPTS.append('-g') - self.do_run('#define RUN_FROM_JS_SHELL\n' + open(path_from_root('tests', 'emscripten_log', 'emscripten_log.cpp')).read(), "Demangled name is 'foo()'.") + self.do_run('#define RUN_FROM_JS_SHELL\n' + open(path_from_root('tests', 'emscripten_log', 'emscripten_log.cpp')).read(), "Success!") def test_linespecific(self): if Settings.ASM_JS: return self.skip('asm always has corrections on') |