summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHood Chatham <roberthoodchatham@gmail.com>2025-03-13 00:28:15 (GMT)
committerGitHub <noreply@github.com>2025-03-13 00:28:15 (GMT)
commitdb1e5827c45ad737bf83f358a2851e943626d29b (patch)
treee3eea2ddbddd1673d7a95db6dd8e91e4fa44c8e8
parent3618240624d98de2a68a79dc174d49efb96cc2e6 (diff)
downloadcpython-db1e5827c45ad737bf83f358a2851e943626d29b.zip
cpython-db1e5827c45ad737bf83f358a2851e943626d29b.tar.gz
cpython-db1e5827c45ad737bf83f358a2851e943626d29b.tar.bz2
gh-127503: Improve tracebacks on Emscripten when there is a trap (#131158)
Modifies the behavior of the interpreter on crash under Emscripten: 1. No Python traceback shown on segfault/trap 2. The JavaScript source line is shown The JavaScript source line is super long and completely unenlightening, whereas the Python traceback is very helpful.
-rw-r--r--Lib/test/test_isinstance.py1
-rw-r--r--Tools/wasm/emscripten/node_entry.mjs12
-rwxr-xr-xconfigure2
-rw-r--r--configure.ac2
4 files changed, 14 insertions, 3 deletions
diff --git a/Lib/test/test_isinstance.py b/Lib/test/test_isinstance.py
index 4f98cbb..daad00e 100644
--- a/Lib/test/test_isinstance.py
+++ b/Lib/test/test_isinstance.py
@@ -327,6 +327,7 @@ class TestIsInstanceIsSubclass(unittest.TestCase):
with self.assertRaises(RecursionError):
issubclass(Failure(), int)
+ @support.skip_emscripten_stack_overflow()
def test_infinite_cycle_in_bases(self):
"""Regression test for bpo-30570."""
class X:
diff --git a/Tools/wasm/emscripten/node_entry.mjs b/Tools/wasm/emscripten/node_entry.mjs
index 98b8f57..166df40 100644
--- a/Tools/wasm/emscripten/node_entry.mjs
+++ b/Tools/wasm/emscripten/node_entry.mjs
@@ -32,6 +32,8 @@ const thisProgramIndex = process.argv.findIndex((x) =>
const settings = {
preRun(Module) {
+ // Globally expose API object so we can access it if we raise on startup.
+ globalThis.Module = Module;
mountDirectories(Module);
Module.FS.chdir(process.cwd());
Object.assign(Module.ENV, process.env);
@@ -45,4 +47,12 @@ const settings = {
arguments: process.argv.slice(thisProgramIndex + 1),
};
-await EmscriptenModule(settings);
+try {
+ await EmscriptenModule(settings);
+} catch(e) {
+ // Show JavaScript exception and traceback
+ console.warn(e);
+ // Show Python exception and traceback
+ Module.__Py_DumpTraceback(2, Module._PyGILState_GetThisThreadState());
+ process.exit(1);
+}
diff --git a/configure b/configure
index 677d0e8..d0ae103 100755
--- a/configure
+++ b/configure
@@ -9631,7 +9631,7 @@ fi
as_fn_append LINKFORSHARED " -sFORCE_FILESYSTEM -lidbfs.js -lnodefs.js -lproxyfs.js -lworkerfs.js"
as_fn_append LINKFORSHARED " -sEXPORTED_RUNTIME_METHODS=FS,callMain,ENV"
- as_fn_append LINKFORSHARED " -sEXPORTED_FUNCTIONS=_main,_Py_Version,__PyRuntime,__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET"
+ as_fn_append LINKFORSHARED " -sEXPORTED_FUNCTIONS=_main,_Py_Version,__PyRuntime,__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET,_PyGILState_GetThisThreadState,__Py_DumpTraceback"
as_fn_append LINKFORSHARED " -sSTACK_SIZE=5MB"
if test "x$enable_wasm_dynamic_linking" = xyes
diff --git a/configure.ac b/configure.ac
index 7ff0251..8bb0f1c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2370,7 +2370,7 @@ AS_CASE([$ac_sys_system],
dnl Include file system support
AS_VAR_APPEND([LINKFORSHARED], [" -sFORCE_FILESYSTEM -lidbfs.js -lnodefs.js -lproxyfs.js -lworkerfs.js"])
AS_VAR_APPEND([LINKFORSHARED], [" -sEXPORTED_RUNTIME_METHODS=FS,callMain,ENV"])
- AS_VAR_APPEND([LINKFORSHARED], [" -sEXPORTED_FUNCTIONS=_main,_Py_Version,__PyRuntime,__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET"])
+ AS_VAR_APPEND([LINKFORSHARED], [" -sEXPORTED_FUNCTIONS=_main,_Py_Version,__PyRuntime,__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET,_PyGILState_GetThisThreadState,__Py_DumpTraceback"])
AS_VAR_APPEND([LINKFORSHARED], [" -sSTACK_SIZE=5MB"])
AS_VAR_IF([enable_wasm_dynamic_linking], [yes], [